@copilotkitnext/react 0.0.2 → 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 +5 -5
  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 -0
  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,43 +0,0 @@
1
- import { useRenderToolCall } from "@/hooks";
2
- import { AssistantMessage, Message, ToolMessage } from "@ag-ui/core";
3
- import React from "react";
4
-
5
- export type CopilotChatToolCallsViewProps = {
6
- message: AssistantMessage;
7
- messages?: Message[];
8
- isLoading?: boolean;
9
- };
10
-
11
- export function CopilotChatToolCallsView({
12
- message,
13
- messages = [],
14
- isLoading = false,
15
- }: CopilotChatToolCallsViewProps) {
16
- const renderToolCall = useRenderToolCall();
17
-
18
- if (!message.toolCalls || message.toolCalls.length === 0) {
19
- return null;
20
- }
21
-
22
- return (
23
- <>
24
- {message.toolCalls.map((toolCall) => {
25
- const toolMessage = messages.find(
26
- (m) => m.role === "tool" && m.toolCallId === toolCall.id
27
- ) as ToolMessage | undefined;
28
-
29
- return (
30
- <React.Fragment key={toolCall.id}>
31
- {renderToolCall({
32
- toolCall,
33
- toolMessage,
34
- isLoading,
35
- })}
36
- </React.Fragment>
37
- );
38
- })}
39
- </>
40
- );
41
- }
42
-
43
- export default CopilotChatToolCallsView;
@@ -1,337 +0,0 @@
1
- import { useState } from "react";
2
- import { Copy, Check, Edit, ChevronLeft, ChevronRight } from "lucide-react";
3
- import { useCopilotChatConfiguration } from "@/providers/CopilotChatConfigurationProvider";
4
- import { twMerge } from "tailwind-merge";
5
- import { Button } from "@/components/ui/button";
6
- import { UserMessage } from "@ag-ui/core";
7
- import {
8
- Tooltip,
9
- TooltipContent,
10
- TooltipTrigger,
11
- } from "@/components/ui/tooltip";
12
- import { renderSlot, WithSlots } from "@/lib/slots";
13
-
14
- export interface CopilotChatUserMessageOnEditMessageProps {
15
- message: UserMessage;
16
- }
17
-
18
- export interface CopilotChatUserMessageOnSwitchToBranchProps {
19
- message: UserMessage;
20
- branchIndex: number;
21
- numberOfBranches: number;
22
- }
23
-
24
- export type CopilotChatUserMessageProps = WithSlots<
25
- {
26
- messageRenderer: typeof CopilotChatUserMessage.MessageRenderer;
27
- toolbar: typeof CopilotChatUserMessage.Toolbar;
28
- copyButton: typeof CopilotChatUserMessage.CopyButton;
29
- editButton: typeof CopilotChatUserMessage.EditButton;
30
- branchNavigation: typeof CopilotChatUserMessage.BranchNavigation;
31
- },
32
- {
33
- onEditMessage?: (props: CopilotChatUserMessageOnEditMessageProps) => void;
34
- onSwitchToBranch?: (
35
- props: CopilotChatUserMessageOnSwitchToBranchProps
36
- ) => void;
37
- message: UserMessage;
38
- branchIndex?: number;
39
- numberOfBranches?: number;
40
- additionalToolbarItems?: React.ReactNode;
41
- } & React.HTMLAttributes<HTMLDivElement>
42
- >;
43
-
44
- export function CopilotChatUserMessage({
45
- message,
46
- onEditMessage,
47
- branchIndex,
48
- numberOfBranches,
49
- onSwitchToBranch,
50
- additionalToolbarItems,
51
- messageRenderer,
52
- toolbar,
53
- copyButton,
54
- editButton,
55
- branchNavigation,
56
- children,
57
- className,
58
- ...props
59
- }: CopilotChatUserMessageProps) {
60
- const BoundMessageRenderer = renderSlot(
61
- messageRenderer,
62
- CopilotChatUserMessage.MessageRenderer,
63
- {
64
- content: message.content || "",
65
- }
66
- );
67
-
68
- const BoundCopyButton = renderSlot(
69
- copyButton,
70
- CopilotChatUserMessage.CopyButton,
71
- {
72
- onClick: async () => {
73
- if (message.content) {
74
- try {
75
- await navigator.clipboard.writeText(message.content);
76
- } catch (err) {
77
- console.error("Failed to copy message:", err);
78
- }
79
- }
80
- },
81
- }
82
- );
83
-
84
- const BoundEditButton = renderSlot(
85
- editButton,
86
- CopilotChatUserMessage.EditButton,
87
- {
88
- onClick: () => onEditMessage?.({ message }),
89
- }
90
- );
91
-
92
- const BoundBranchNavigation = renderSlot(
93
- branchNavigation,
94
- CopilotChatUserMessage.BranchNavigation,
95
- {
96
- currentBranch: branchIndex,
97
- numberOfBranches,
98
- onSwitchToBranch,
99
- message,
100
- }
101
- );
102
-
103
- const showBranchNavigation =
104
- numberOfBranches && numberOfBranches > 1 && onSwitchToBranch;
105
-
106
- const BoundToolbar = renderSlot(toolbar, CopilotChatUserMessage.Toolbar, {
107
- children: (
108
- <div className="flex items-center gap-1 justify-end">
109
- {additionalToolbarItems}
110
- {BoundCopyButton}
111
- {onEditMessage && BoundEditButton}
112
- {showBranchNavigation && BoundBranchNavigation}
113
- </div>
114
- ),
115
- });
116
-
117
- if (children) {
118
- return (
119
- <>
120
- {children({
121
- messageRenderer: BoundMessageRenderer,
122
- toolbar: BoundToolbar,
123
- copyButton: BoundCopyButton,
124
- editButton: BoundEditButton,
125
- branchNavigation: BoundBranchNavigation,
126
- message,
127
- branchIndex,
128
- numberOfBranches,
129
- additionalToolbarItems,
130
- })}
131
- </>
132
- );
133
- }
134
-
135
- return (
136
- <div
137
- className={twMerge("flex flex-col items-end group pt-10", className)}
138
- data-message-id={message.id}
139
- {...props}
140
- >
141
- {BoundMessageRenderer}
142
- {BoundToolbar}
143
- </div>
144
- );
145
- }
146
-
147
- // eslint-disable-next-line @typescript-eslint/no-namespace
148
- export namespace CopilotChatUserMessage {
149
- export const Container: React.FC<
150
- React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>
151
- > = ({ children, className, ...props }) => (
152
- <div
153
- className={twMerge("flex flex-col items-end group", className)}
154
- {...props}
155
- >
156
- {children}
157
- </div>
158
- );
159
-
160
- export const MessageRenderer: React.FC<{
161
- content: string;
162
- className?: string;
163
- }> = ({ content, className }) => (
164
- <div
165
- className={twMerge(
166
- "prose dark:prose-invert bg-muted relative max-w-[80%] rounded-[18px] px-4 py-1.5 data-[multiline]:py-3 inline-block whitespace-pre-wrap",
167
- className
168
- )}
169
- >
170
- {content}
171
- </div>
172
- );
173
-
174
- export const Toolbar: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
175
- className,
176
- ...props
177
- }) => (
178
- <div
179
- className={twMerge(
180
- "w-full bg-transparent flex items-center justify-end -mr-[5px] mt-[4px] invisible group-hover:visible",
181
- className
182
- )}
183
- {...props}
184
- />
185
- );
186
-
187
- export const ToolbarButton: React.FC<
188
- React.ButtonHTMLAttributes<HTMLButtonElement> & {
189
- title: string;
190
- children: React.ReactNode;
191
- }
192
- > = ({ title, children, className, ...props }) => {
193
- return (
194
- <Tooltip>
195
- <TooltipTrigger asChild>
196
- <Button
197
- type="button"
198
- variant="assistantMessageToolbarButton"
199
- aria-label={title}
200
- className={twMerge(className)}
201
- {...props}
202
- >
203
- {children}
204
- </Button>
205
- </TooltipTrigger>
206
- <TooltipContent side="bottom">
207
- <p>{title}</p>
208
- </TooltipContent>
209
- </Tooltip>
210
- );
211
- };
212
-
213
- export const CopyButton: React.FC<
214
- React.ButtonHTMLAttributes<HTMLButtonElement> & { copied?: boolean }
215
- > = ({ className, title, onClick, ...props }) => {
216
- const { labels } = useCopilotChatConfiguration();
217
- const [copied, setCopied] = useState(false);
218
-
219
- const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
220
- setCopied(true);
221
- setTimeout(() => setCopied(false), 2000);
222
-
223
- if (onClick) {
224
- onClick(event);
225
- }
226
- };
227
-
228
- return (
229
- <ToolbarButton
230
- title={title || labels.userMessageToolbarCopyMessageLabel}
231
- onClick={handleClick}
232
- className={className}
233
- {...props}
234
- >
235
- {copied ? (
236
- <Check className="size-[18px]" />
237
- ) : (
238
- <Copy className="size-[18px]" />
239
- )}
240
- </ToolbarButton>
241
- );
242
- };
243
-
244
- export const EditButton: React.FC<
245
- React.ButtonHTMLAttributes<HTMLButtonElement>
246
- > = ({ className, title, ...props }) => {
247
- const { labels } = useCopilotChatConfiguration();
248
- return (
249
- <ToolbarButton
250
- title={title || labels.userMessageToolbarEditMessageLabel}
251
- className={className}
252
- {...props}
253
- >
254
- <Edit className="size-[18px]" />
255
- </ToolbarButton>
256
- );
257
- };
258
-
259
- export const BranchNavigation: React.FC<
260
- React.HTMLAttributes<HTMLDivElement> & {
261
- currentBranch?: number;
262
- numberOfBranches?: number;
263
- onSwitchToBranch?: (
264
- props: CopilotChatUserMessageOnSwitchToBranchProps
265
- ) => void;
266
- message: UserMessage;
267
- }
268
- > = ({
269
- className,
270
- currentBranch = 0,
271
- numberOfBranches = 1,
272
- onSwitchToBranch,
273
- message,
274
- ...props
275
- }) => {
276
- if (!numberOfBranches || numberOfBranches <= 1 || !onSwitchToBranch) {
277
- return null;
278
- }
279
-
280
- const canGoPrev = currentBranch > 0;
281
- const canGoNext = currentBranch < numberOfBranches - 1;
282
-
283
- return (
284
- <div className={twMerge("flex items-center gap-1", className)} {...props}>
285
- <Button
286
- type="button"
287
- variant="assistantMessageToolbarButton"
288
- onClick={() =>
289
- onSwitchToBranch?.({
290
- branchIndex: currentBranch - 1,
291
- numberOfBranches,
292
- message,
293
- })
294
- }
295
- disabled={!canGoPrev}
296
- className="h-6 w-6 p-0"
297
- >
298
- <ChevronLeft className="size-[20px]" />
299
- </Button>
300
- <span className="text-sm text-muted-foreground px-0 font-medium">
301
- {currentBranch + 1}/{numberOfBranches}
302
- </span>
303
- <Button
304
- type="button"
305
- variant="assistantMessageToolbarButton"
306
- onClick={() =>
307
- onSwitchToBranch?.({
308
- branchIndex: currentBranch + 1,
309
- numberOfBranches,
310
- message,
311
- })
312
- }
313
- disabled={!canGoNext}
314
- className="h-6 w-6 p-0"
315
- >
316
- <ChevronRight className="size-[20px]" />
317
- </Button>
318
- </div>
319
- );
320
- };
321
- }
322
-
323
- CopilotChatUserMessage.Container.displayName =
324
- "CopilotChatUserMessage.Container";
325
- CopilotChatUserMessage.MessageRenderer.displayName =
326
- "CopilotChatUserMessage.MessageRenderer";
327
- CopilotChatUserMessage.Toolbar.displayName = "CopilotChatUserMessage.Toolbar";
328
- CopilotChatUserMessage.ToolbarButton.displayName =
329
- "CopilotChatUserMessage.ToolbarButton";
330
- CopilotChatUserMessage.CopyButton.displayName =
331
- "CopilotChatUserMessage.CopyButton";
332
- CopilotChatUserMessage.EditButton.displayName =
333
- "CopilotChatUserMessage.EditButton";
334
- CopilotChatUserMessage.BranchNavigation.displayName =
335
- "CopilotChatUserMessage.BranchNavigation";
336
-
337
- export default CopilotChatUserMessage;