@copilotkit/react-ui 1.55.3 → 1.56.0
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/index.cjs +10 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +25 -19
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +11 -15
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +10 -14
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/components/chat/Markdown.test.ts +101 -0
- package/src/components/chat/Markdown.tsx +2 -3
- package/src/components/chat/messages/AssistantMessage.tsx +7 -8
- package/src/components/chat/messages/ErrorMessage.tsx +7 -8
- package/src/components/dev-console/console.tsx +5 -4
- package/src/css/colors.css +1 -1
- package/src/css/console.css +16 -10
- package/src/css/input.css +5 -5
- package/src/css/markdown.css +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/react-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.56.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"rehype-raw": "^7.0.0",
|
|
49
49
|
"remark-gfm": "^4.0.1",
|
|
50
50
|
"remark-math": "^6.0.0",
|
|
51
|
-
"@copilotkit/
|
|
52
|
-
"@copilotkit/
|
|
53
|
-
"@copilotkit/shared": "1.
|
|
51
|
+
"@copilotkit/react-core": "1.56.0",
|
|
52
|
+
"@copilotkit/runtime-client-gql": "1.56.0",
|
|
53
|
+
"@copilotkit/shared": "1.56.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/react": "^19.1.0",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* These tests verify that CSS selectors in markdown.css correctly target
|
|
6
|
+
* the class names used by the Markdown component. When the p tag was changed
|
|
7
|
+
* to a div (to fix hydration errors), the CSS selectors must use class-only
|
|
8
|
+
* selectors instead of element-qualified selectors for paragraphs.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const cssPath = resolve(__dirname, "../../css/markdown.css");
|
|
12
|
+
const tsxPath = resolve(__dirname, "Markdown.tsx");
|
|
13
|
+
|
|
14
|
+
const cssContent = readFileSync(cssPath, "utf-8");
|
|
15
|
+
const tsxContent = readFileSync(tsxPath, "utf-8");
|
|
16
|
+
|
|
17
|
+
describe("Markdown CSS/component selector consistency", () => {
|
|
18
|
+
it("should not use p.copilotKitMarkdownElement selector in CSS", () => {
|
|
19
|
+
// After the p->div change, CSS must not use element-qualified p selectors
|
|
20
|
+
expect(cssContent).not.toMatch(/\bp\.copilotKitMarkdownElement\b/);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should have .copilotKitParagraph selector in CSS for paragraph styling", () => {
|
|
24
|
+
expect(cssContent).toMatch(/\.copilotKitParagraph\s*\{/);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should have .copilotKitParagraph:not(:last-child) selector for paragraph spacing", () => {
|
|
28
|
+
expect(cssContent).toMatch(/\.copilotKitParagraph:not\(:last-child\)/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should use copilotKitParagraph class on the paragraph component", () => {
|
|
32
|
+
// The p component override in Markdown.tsx should include copilotKitParagraph
|
|
33
|
+
expect(tsxContent).toMatch(/copilotKitParagraph/);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should render a div instead of p for the paragraph component", () => {
|
|
37
|
+
// The paragraph component should use <div> to avoid hydration errors
|
|
38
|
+
// when block-level elements are nested inside markdown paragraphs
|
|
39
|
+
const pComponentMatch = tsxContent.match(
|
|
40
|
+
/p:\s*\(\{[^}]*\}\)\s*=>\s*\(\s*<(\w+)/,
|
|
41
|
+
);
|
|
42
|
+
expect(pComponentMatch).not.toBeNull();
|
|
43
|
+
expect(pComponentMatch![1]).toBe("div");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should still have copilotKitMarkdownElement class on the paragraph div", () => {
|
|
47
|
+
// The div should retain the base class for any shared styling
|
|
48
|
+
const pSection = tsxContent.match(/p:\s*\([^)]*\)\s*=>\s*\([^)]+\)/s);
|
|
49
|
+
expect(pSection).not.toBeNull();
|
|
50
|
+
expect(pSection![0]).toContain("copilotKitMarkdownElement");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should use .copilotKitParagraph (not p) inside blockquote selector", () => {
|
|
54
|
+
// After p->div, blockquote nested paragraph selector must target the class
|
|
55
|
+
expect(cssContent).toMatch(
|
|
56
|
+
/blockquote\.copilotKitMarkdownElement\s+\.copilotKitParagraph\s*\{/,
|
|
57
|
+
);
|
|
58
|
+
expect(cssContent).not.toMatch(
|
|
59
|
+
/blockquote\.copilotKitMarkdownElement\s+p\s*\{/,
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("other element selectors remain valid", () => {
|
|
64
|
+
const elementSelectors = [
|
|
65
|
+
{ element: "h1", selector: "h1.copilotKitMarkdownElement" },
|
|
66
|
+
{ element: "h2", selector: "h2.copilotKitMarkdownElement" },
|
|
67
|
+
{ element: "h3", selector: "h3.copilotKitMarkdownElement" },
|
|
68
|
+
{ element: "h4", selector: "h4.copilotKitMarkdownElement" },
|
|
69
|
+
{ element: "h5", selector: "h5.copilotKitMarkdownElement" },
|
|
70
|
+
{ element: "h6", selector: "h6.copilotKitMarkdownElement" },
|
|
71
|
+
{ element: "a", selector: "a.copilotKitMarkdownElement" },
|
|
72
|
+
{ element: "pre", selector: "pre.copilotKitMarkdownElement" },
|
|
73
|
+
{
|
|
74
|
+
element: "blockquote",
|
|
75
|
+
selector: "blockquote.copilotKitMarkdownElement",
|
|
76
|
+
},
|
|
77
|
+
{ element: "ul", selector: "ul.copilotKitMarkdownElement" },
|
|
78
|
+
{ element: "li", selector: "li.copilotKitMarkdownElement" },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
for (const { element, selector } of elementSelectors) {
|
|
82
|
+
it(`should have ${element} component rendering <${element}> with copilotKitMarkdownElement class`, () => {
|
|
83
|
+
// Verify the component still uses the actual HTML element
|
|
84
|
+
// Some components use arrow syntax, others use function syntax
|
|
85
|
+
const arrowRegex = new RegExp(
|
|
86
|
+
`${element}:\\s*\\(\\{[^}]*\\}\\)\\s*=>\\s*\\(\\s*<${element}[\\s\\S]*?copilotKitMarkdownElement`,
|
|
87
|
+
);
|
|
88
|
+
const funcRegex = new RegExp(
|
|
89
|
+
`${element}\\([^)]*\\)\\s*\\{[\\s\\S]*?<${element}[\\s\\S]*?copilotKitMarkdownElement`,
|
|
90
|
+
);
|
|
91
|
+
const matches =
|
|
92
|
+
arrowRegex.test(tsxContent) || funcRegex.test(tsxContent);
|
|
93
|
+
expect(matches).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it(`should have CSS selector ${selector}`, () => {
|
|
97
|
+
expect(cssContent).toContain(selector);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -59,7 +59,6 @@ const defaultComponents: Components = {
|
|
|
59
59
|
|
|
60
60
|
return (
|
|
61
61
|
<CodeBlock
|
|
62
|
-
key={Math.random()}
|
|
63
62
|
language={(match && match[1]) || ""}
|
|
64
63
|
value={String(children).replace(/\n$/, "")}
|
|
65
64
|
{...props}
|
|
@@ -97,9 +96,9 @@ const defaultComponents: Components = {
|
|
|
97
96
|
</h6>
|
|
98
97
|
),
|
|
99
98
|
p: ({ children, ...props }) => (
|
|
100
|
-
<
|
|
99
|
+
<div className="copilotKitMarkdownElement copilotKitParagraph" {...props}>
|
|
101
100
|
{children}
|
|
102
|
-
</
|
|
101
|
+
</div>
|
|
103
102
|
),
|
|
104
103
|
pre: ({ children, ...props }) => (
|
|
105
104
|
<pre className="copilotKitMarkdownElement" {...props}>
|
|
@@ -3,6 +3,7 @@ import { useChatContext } from "../ChatContext";
|
|
|
3
3
|
import { Markdown } from "../Markdown";
|
|
4
4
|
import { useState } from "react";
|
|
5
5
|
import React from "react";
|
|
6
|
+
import { copyToClipboard } from "@copilotkit/shared";
|
|
6
7
|
|
|
7
8
|
export const AssistantMessage = (props: AssistantMessageProps) => {
|
|
8
9
|
const { icons, labels } = useChatContext();
|
|
@@ -19,16 +20,14 @@ export const AssistantMessage = (props: AssistantMessageProps) => {
|
|
|
19
20
|
} = props;
|
|
20
21
|
const [copied, setCopied] = useState(false);
|
|
21
22
|
|
|
22
|
-
const handleCopy = () => {
|
|
23
|
+
const handleCopy = async () => {
|
|
23
24
|
const content = message?.content || "";
|
|
24
|
-
if (content
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
setTimeout(() => setCopied(false), 2000);
|
|
29
|
-
} else if (content) {
|
|
30
|
-
navigator.clipboard.writeText(content);
|
|
25
|
+
if (!content) return;
|
|
26
|
+
|
|
27
|
+
const success = await copyToClipboard(content);
|
|
28
|
+
if (success) {
|
|
31
29
|
setCopied(true);
|
|
30
|
+
if (onCopy) onCopy(content);
|
|
32
31
|
setTimeout(() => setCopied(false), 2000);
|
|
33
32
|
}
|
|
34
33
|
};
|
|
@@ -2,22 +2,21 @@ import { ErrorMessageProps } from "../props";
|
|
|
2
2
|
import { useChatContext } from "../ChatContext";
|
|
3
3
|
import { Markdown } from "../Markdown";
|
|
4
4
|
import { useState } from "react";
|
|
5
|
+
import { copyToClipboard } from "@copilotkit/shared";
|
|
5
6
|
|
|
6
7
|
export const ErrorMessage = (props: ErrorMessageProps) => {
|
|
7
8
|
const { icons, labels } = useChatContext();
|
|
8
9
|
const { error, onRegenerate, onCopy, isCurrentMessage } = props;
|
|
9
10
|
const [copied, setCopied] = useState(false);
|
|
10
11
|
|
|
11
|
-
const handleCopy = () => {
|
|
12
|
+
const handleCopy = async () => {
|
|
12
13
|
const content = error.message;
|
|
13
|
-
if (content
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
setTimeout(() => setCopied(false), 2000);
|
|
18
|
-
} else if (content) {
|
|
19
|
-
navigator.clipboard.writeText(content);
|
|
14
|
+
if (!content) return;
|
|
15
|
+
|
|
16
|
+
const success = await copyToClipboard(content);
|
|
17
|
+
if (success) {
|
|
20
18
|
setCopied(true);
|
|
19
|
+
if (onCopy) onCopy(content);
|
|
21
20
|
setTimeout(() => setCopied(false), 2000);
|
|
22
21
|
}
|
|
23
22
|
};
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
ExclamationMarkTriangleIcon,
|
|
21
21
|
} from "./icons";
|
|
22
22
|
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
|
|
23
|
-
import { COPILOTKIT_VERSION } from "@copilotkit/shared";
|
|
23
|
+
import { COPILOTKIT_VERSION, copyToClipboard } from "@copilotkit/shared";
|
|
24
24
|
import { SmallSpinnerIcon } from "../chat/Icons";
|
|
25
25
|
import { CopilotKitHelpModal } from "../help-modal";
|
|
26
26
|
|
|
@@ -170,11 +170,12 @@ function VersionInfo({
|
|
|
170
170
|
`&& npm install @copilotkit/runtime@${latestVersion}`,
|
|
171
171
|
].join(" ");
|
|
172
172
|
|
|
173
|
-
const handleCopyClick = () => {
|
|
174
|
-
|
|
173
|
+
const handleCopyClick = async () => {
|
|
174
|
+
const success = await copyToClipboard(installCommand.trim());
|
|
175
|
+
if (success) {
|
|
175
176
|
setCopyStatus("Command copied to clipboard!");
|
|
176
177
|
setTimeout(() => setCopyStatus(""), 1000);
|
|
177
|
-
}
|
|
178
|
+
}
|
|
178
179
|
};
|
|
179
180
|
|
|
180
181
|
if (versionStatus === "update-available" || versionStatus === "outdated") {
|
package/src/css/colors.css
CHANGED
|
@@ -48,7 +48,7 @@ html.dark,
|
|
|
48
48
|
body.dark,
|
|
49
49
|
[data-theme="dark"],
|
|
50
50
|
html[style*="color-scheme: dark"],
|
|
51
|
-
body[style*="color-scheme: dark"]
|
|
51
|
+
body[style*="color-scheme: dark"] {
|
|
52
52
|
/* Main brand/action color - used for buttons, interactive elements */
|
|
53
53
|
--copilot-kit-primary-color: rgb(255, 255, 255);
|
|
54
54
|
/* Color that contrasts with primary - used for text on primary elements */
|
package/src/css/console.css
CHANGED
|
@@ -83,22 +83,28 @@
|
|
|
83
83
|
color: var(--copilot-kit-dev-console-text);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
.dark,
|
|
87
|
-
html.dark,
|
|
88
|
-
body.dark,
|
|
89
|
-
[data-theme="dark"],
|
|
90
|
-
html[style*="color-scheme: dark"]
|
|
86
|
+
.dark .copilotKitDevConsole .copilotKitDebugMenuTriggerButton,
|
|
87
|
+
html.dark .copilotKitDevConsole .copilotKitDebugMenuTriggerButton,
|
|
88
|
+
body.dark .copilotKitDevConsole .copilotKitDebugMenuTriggerButton,
|
|
89
|
+
[data-theme="dark"] .copilotKitDevConsole .copilotKitDebugMenuTriggerButton,
|
|
90
|
+
html[style*="color-scheme: dark"]
|
|
91
|
+
.copilotKitDevConsole
|
|
92
|
+
.copilotKitDebugMenuTriggerButton,
|
|
91
93
|
body[style*="color-scheme: dark"]
|
|
92
94
|
.copilotKitDevConsole
|
|
93
95
|
.copilotKitDebugMenuTriggerButton {
|
|
94
96
|
color: white;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
.dark,
|
|
98
|
-
html.dark,
|
|
99
|
-
body.dark,
|
|
100
|
-
[data-theme="dark"]
|
|
101
|
-
|
|
99
|
+
.dark .copilotKitDevConsole .copilotKitDebugMenuTriggerButton:hover,
|
|
100
|
+
html.dark .copilotKitDevConsole .copilotKitDebugMenuTriggerButton:hover,
|
|
101
|
+
body.dark .copilotKitDevConsole .copilotKitDebugMenuTriggerButton:hover,
|
|
102
|
+
[data-theme="dark"]
|
|
103
|
+
.copilotKitDevConsole
|
|
104
|
+
.copilotKitDebugMenuTriggerButton:hover,
|
|
105
|
+
html[style*="color-scheme: dark"]
|
|
106
|
+
.copilotKitDevConsole
|
|
107
|
+
.copilotKitDebugMenuTriggerButton:hover,
|
|
102
108
|
body[style*="color-scheme: dark"]
|
|
103
109
|
.copilotKitDevConsole
|
|
104
110
|
.copilotKitDebugMenuTriggerButton:hover {
|
package/src/css/input.css
CHANGED
|
@@ -145,11 +145,11 @@
|
|
|
145
145
|
margin: 0 !important;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
.dark,
|
|
149
|
-
html.dark,
|
|
150
|
-
body.dark,
|
|
151
|
-
[data-theme="dark"],
|
|
152
|
-
html[style*="color-scheme: dark"],
|
|
148
|
+
.dark .poweredBy,
|
|
149
|
+
html.dark .poweredBy,
|
|
150
|
+
body.dark .poweredBy,
|
|
151
|
+
[data-theme="dark"] .poweredBy,
|
|
152
|
+
html[style*="color-scheme: dark"] .poweredBy,
|
|
153
153
|
body[style*="color-scheme: dark"] .poweredBy {
|
|
154
154
|
color: rgb(69, 69, 69) !important;
|
|
155
155
|
}
|
package/src/css/markdown.css
CHANGED
|
@@ -47,14 +47,14 @@ a.copilotKitMarkdownElement {
|
|
|
47
47
|
text-decoration: underline;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
.copilotKitParagraph {
|
|
51
51
|
padding: 0px;
|
|
52
52
|
margin: 0px;
|
|
53
53
|
line-height: 1.75;
|
|
54
54
|
font-size: 1rem;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
.copilotKitParagraph:not(:last-child),
|
|
58
58
|
pre.copilotKitMarkdownElement:not(:last-child),
|
|
59
59
|
ol.copilotKitMarkdownElement:not(:last-child),
|
|
60
60
|
ul.copilotKitMarkdownElement:not(:last-child),
|
|
@@ -70,7 +70,7 @@ blockquote.copilotKitMarkdownElement {
|
|
|
70
70
|
padding-left: 10px;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
blockquote.copilotKitMarkdownElement
|
|
73
|
+
blockquote.copilotKitMarkdownElement .copilotKitParagraph {
|
|
74
74
|
padding: 0.7em 0;
|
|
75
75
|
}
|
|
76
76
|
|