@copilotkit/react-ui 0.22.0 → 0.36.0-mme-pre.1
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/.turbo/turbo-build.log +211 -178
- package/CHANGELOG.md +24 -0
- package/dist/chunk-4MKP23AD.mjs +97 -0
- package/dist/chunk-4MKP23AD.mjs.map +1 -0
- package/dist/{chunk-T3WYKWNC.mjs → chunk-6XLZXLM5.mjs} +6 -6
- package/dist/chunk-6XLZXLM5.mjs.map +1 -0
- package/dist/{chunk-73EBDGYK.mjs → chunk-7FES2IQA.mjs} +5 -5
- package/dist/chunk-7FES2IQA.mjs.map +1 -0
- package/dist/chunk-ANO23V2M.mjs +135 -0
- package/dist/chunk-ANO23V2M.mjs.map +1 -0
- package/dist/chunk-BL65ZC6L.mjs +83 -0
- package/dist/chunk-BL65ZC6L.mjs.map +1 -0
- package/dist/{chunk-YEHO5VMA.mjs → chunk-CE7PJAAO.mjs} +2 -2
- package/dist/{chunk-7YXG7D47.mjs → chunk-FZC7X5PK.mjs} +57 -2
- package/dist/chunk-FZC7X5PK.mjs.map +1 -0
- package/dist/chunk-LTCJCXCP.mjs +29 -0
- package/dist/chunk-LTCJCXCP.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/{chunk-7JYUCW7H.mjs → chunk-PAQWLSA4.mjs} +2 -2
- package/dist/{chunk-YTIGBBTC.mjs → chunk-RT2XG2T7.mjs} +2 -2
- package/dist/chunk-RT2XG2T7.mjs.map +1 -0
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/{chunk-6U3O2JZP.mjs → chunk-T3JTSIHT.mjs} +32 -39
- package/dist/chunk-T3JTSIHT.mjs.map +1 -0
- package/dist/{chunk-MBYUBR3F.mjs → chunk-UPTB2MVO.mjs} +2 -2
- package/dist/chunk-VUZA5AFH.mjs +73 -0
- package/dist/chunk-VUZA5AFH.mjs.map +1 -0
- package/dist/{chunk-YAORLSQ3.mjs → chunk-XRODMID5.mjs} +6 -6
- package/dist/chunk-XRODMID5.mjs.map +1 -0
- package/dist/{chunk-WDHLWSSU.mjs → chunk-YQ3D5IQV.mjs} +2 -2
- package/dist/{chunk-WM6BS77F.mjs → chunk-YQFVRDNC.mjs} +2 -2
- package/dist/{chunk-WM6BS77F.mjs.map → chunk-YQFVRDNC.mjs.map} +1 -1
- package/dist/chunk-ZO3GLN23.mjs +137 -0
- package/dist/chunk-ZO3GLN23.mjs.map +1 -0
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +3 -3
- package/dist/components/chat/Chat.d.ts +66 -46
- package/dist/components/chat/Chat.js +433 -278
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +15 -14
- package/dist/components/chat/ChatContext.d.ts +16 -16
- package/dist/components/chat/ChatContext.js +43 -27
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +2 -2
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +2 -2
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +3 -3
- package/dist/components/chat/Icons.d.ts +7 -5
- package/dist/components/chat/Icons.js +57 -0
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +5 -1
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +148 -11
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +5 -4
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +3 -3
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +2 -2
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.d.ts +50 -0
- package/dist/components/chat/Modal.js +1584 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +23 -0
- package/dist/components/chat/Modal.mjs.map +1 -0
- package/dist/components/chat/Popup.d.ts +56 -4
- package/dist/components/chat/Popup.js +428 -78
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +15 -12
- package/dist/components/chat/Response.js.map +1 -1
- package/dist/components/chat/Response.mjs +3 -3
- package/dist/components/chat/Sidebar.d.ts +7 -8
- package/dist/components/chat/Sidebar.js +430 -80
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +15 -12
- package/dist/components/chat/Suggestion.d.ts +13 -0
- package/dist/components/chat/Suggestion.js +172 -0
- package/dist/components/chat/Suggestion.js.map +1 -0
- package/dist/components/chat/Suggestion.mjs +11 -0
- package/dist/components/chat/Suggestion.mjs.map +1 -0
- package/dist/components/chat/Textarea.d.ts +4 -4
- package/dist/components/chat/Textarea.js +1 -1
- package/dist/components/chat/Textarea.js.map +1 -1
- package/dist/components/chat/Textarea.mjs +1 -1
- package/dist/components/chat/index.d.ts +4 -2
- package/dist/components/chat/index.js +436 -84
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +22 -16
- package/dist/components/chat/props.d.ts +10 -3
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/components/index.js +436 -84
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +22 -16
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +36 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +8 -1
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +87 -0
- package/dist/hooks/use-copilot-chat-suggestions.js +53 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-push-to-talk.d.ts +19 -0
- package/dist/hooks/use-push-to-talk.js +177 -0
- package/dist/hooks/use-push-to-talk.js.map +1 -0
- package/dist/hooks/use-push-to-talk.mjs +12 -0
- package/dist/hooks/use-push-to-talk.mjs.map +1 -0
- package/dist/index.css +101 -13
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +465 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -19
- package/dist/types/suggestions.d.ts +8 -0
- package/dist/types/suggestions.js +19 -0
- package/dist/types/suggestions.js.map +1 -0
- package/dist/types/suggestions.mjs +1 -0
- package/dist/types/suggestions.mjs.map +1 -0
- package/package.json +6 -6
- package/src/components/chat/Button.tsx +1 -2
- package/src/components/chat/Chat.tsx +163 -104
- package/src/components/chat/ChatContext.tsx +36 -38
- package/src/components/chat/Icons.tsx +44 -0
- package/src/components/chat/Input.tsx +38 -7
- package/src/components/chat/Messages.tsx +3 -3
- package/src/components/chat/Modal.tsx +115 -0
- package/src/components/chat/Popup.tsx +53 -7
- package/src/components/chat/Sidebar.tsx +62 -9
- package/src/components/chat/Suggestion.tsx +109 -0
- package/src/components/chat/Textarea.tsx +1 -1
- package/src/components/chat/index.tsx +1 -0
- package/src/components/chat/props.ts +10 -2
- package/src/css/input.css +18 -8
- package/src/css/messages.css +7 -1
- package/src/css/panel.css +38 -0
- package/src/css/response.css +1 -4
- package/src/css/suggestions.css +35 -0
- package/src/css/window.css +3 -1
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +117 -0
- package/src/hooks/use-push-to-talk.tsx +162 -0
- package/src/styles.css +2 -0
- package/src/types/suggestions.ts +6 -0
- package/typedoc.json +4 -0
- package/dist/chunk-6U3O2JZP.mjs.map +0 -1
- package/dist/chunk-73EBDGYK.mjs.map +0 -1
- package/dist/chunk-7LMXXGJT.mjs +0 -75
- package/dist/chunk-7LMXXGJT.mjs.map +0 -1
- package/dist/chunk-7YXG7D47.mjs.map +0 -1
- package/dist/chunk-H4VKQGVU.mjs +0 -1
- package/dist/chunk-KE3N45ZY.mjs +0 -63
- package/dist/chunk-KE3N45ZY.mjs.map +0 -1
- package/dist/chunk-T3WYKWNC.mjs.map +0 -1
- package/dist/chunk-UGQQ4WEQ.mjs +0 -1
- package/dist/chunk-YAORLSQ3.mjs.map +0 -1
- package/dist/chunk-YTIGBBTC.mjs.map +0 -1
- /package/dist/{chunk-YEHO5VMA.mjs.map → chunk-CE7PJAAO.mjs.map} +0 -0
- /package/dist/{chunk-H4VKQGVU.mjs.map → chunk-MRFF7GSQ.mjs.map} +0 -0
- /package/dist/{chunk-7JYUCW7H.mjs.map → chunk-PAQWLSA4.mjs.map} +0 -0
- /package/dist/{chunk-UGQQ4WEQ.mjs.map → chunk-T26KLXLH.mjs.map} +0 -0
- /package/dist/{chunk-MBYUBR3F.mjs.map → chunk-UPTB2MVO.mjs.map} +0 -0
- /package/dist/{chunk-WDHLWSSU.mjs.map → chunk-YQ3D5IQV.mjs.map} +0 -0
|
@@ -1,13 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A chatbot popup component for CopilotKit.
|
|
3
|
+
*
|
|
4
|
+
* <img src="/images/CopilotPopup/CopilotPopup.gif" width="500" />
|
|
5
|
+
*
|
|
6
|
+
* <img referrerPolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be" />
|
|
7
|
+
*
|
|
8
|
+
* A chatbot popup component for the CopilotKit framework. The component allows for a high degree
|
|
9
|
+
* of customization through various props and custom CSS.
|
|
10
|
+
*
|
|
11
|
+
* See [CopilotSidebar](./CopilotSidebar) for a sidebar version of this component.
|
|
12
|
+
*
|
|
13
|
+
* <RequestExample>
|
|
14
|
+
* ```jsx CopilotPopup Example
|
|
15
|
+
* import { CopilotPopup } from "@copilotkit/react-ui";
|
|
16
|
+
*
|
|
17
|
+
* <CopilotPopup
|
|
18
|
+
* labels={{
|
|
19
|
+
* title: "Your Assistant",
|
|
20
|
+
* initial: "Hi! 👋 How can I assist you today?",
|
|
21
|
+
* }}
|
|
22
|
+
* />
|
|
23
|
+
* ```
|
|
24
|
+
* </RequestExample>
|
|
25
|
+
*
|
|
26
|
+
* ## Custom CSS
|
|
27
|
+
*
|
|
28
|
+
* You can customize the colors of the chat window by overriding the CSS variables
|
|
29
|
+
* defined in the [default styles](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/colors.css).
|
|
30
|
+
*
|
|
31
|
+
* For example, to set the primary color to purple:
|
|
32
|
+
*
|
|
33
|
+
* ```jsx
|
|
34
|
+
* <div style={{ "--copilot-kit-primary-color": "#7D5BA6" }}>
|
|
35
|
+
* <CopilotPopup />
|
|
36
|
+
* </div>
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* To further customize the chat window, you can override the CSS classes defined
|
|
40
|
+
* [here](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/).
|
|
41
|
+
*
|
|
42
|
+
* For example:
|
|
43
|
+
*
|
|
44
|
+
* ```css
|
|
45
|
+
* .copilotKitButton {
|
|
46
|
+
* border-radius: 0;
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
2
50
|
|
|
3
|
-
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
}
|
|
51
|
+
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
6
52
|
|
|
7
|
-
export
|
|
53
|
+
export function CopilotPopup(props: CopilotModalProps) {
|
|
8
54
|
props = {
|
|
9
55
|
...props,
|
|
10
56
|
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup",
|
|
11
57
|
};
|
|
12
|
-
return <
|
|
13
|
-
}
|
|
58
|
+
return <CopilotModal {...props}>{props.children}</CopilotModal>;
|
|
59
|
+
}
|
|
@@ -1,11 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A chatbot sidebar component for CopilotKit.
|
|
3
|
+
*
|
|
4
|
+
* <img src="/images/CopilotSidebar/CopilotSidebar.gif" width="500" />
|
|
5
|
+
*
|
|
6
|
+
* <img referrerPolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be" />
|
|
7
|
+
*
|
|
8
|
+
* A chatbot sidebar component for the CopilotKit framework. Highly customizable through various props and custom CSS.
|
|
9
|
+
*
|
|
10
|
+
* <RequestExample>
|
|
11
|
+
* ```jsx CopilotSidebar Example
|
|
12
|
+
* import { CopilotSidebar } from "@copilotkit/react-ui";
|
|
13
|
+
*
|
|
14
|
+
* <CopilotSidebar
|
|
15
|
+
* labels={{
|
|
16
|
+
* title: "Your Assistant",
|
|
17
|
+
* initial: "Hi! 👋 How can I assist you today?",
|
|
18
|
+
* }}
|
|
19
|
+
* >
|
|
20
|
+
* <YourApp/>
|
|
21
|
+
* </CopilotSidebar>
|
|
22
|
+
* ```
|
|
23
|
+
* </RequestExample>
|
|
24
|
+
*
|
|
25
|
+
*
|
|
26
|
+
* See [CopilotPopup](./CopilotPopup) for a popup version of this component.
|
|
27
|
+
*
|
|
28
|
+
* <Note>
|
|
29
|
+
* To make the sidebar push your content to the side, wrap your content in the
|
|
30
|
+
* sidebar component. If you want the sidebar to overlay your content, place the
|
|
31
|
+
* sidebar component outside of your content.
|
|
32
|
+
* </Note>
|
|
33
|
+
*
|
|
34
|
+
* ## Custom CSS
|
|
35
|
+
*
|
|
36
|
+
* You can customize the colors of the chat window by overriding the CSS variables
|
|
37
|
+
* defined in the [default styles](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/colors.css).
|
|
38
|
+
*
|
|
39
|
+
* For example, to set the primary color to purple:
|
|
40
|
+
*
|
|
41
|
+
* ```jsx
|
|
42
|
+
* <div style={{ "--copilot-kit-primary-color": "#7D5BA6" }}>
|
|
43
|
+
* <CopilotSidebar />
|
|
44
|
+
* </div>
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* To further customize the chat window, you can override the CSS classes defined
|
|
48
|
+
* [here](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/).
|
|
49
|
+
*
|
|
50
|
+
* For example:
|
|
51
|
+
*
|
|
52
|
+
* ```css
|
|
53
|
+
* .copilotKitButton {
|
|
54
|
+
* border-radius: 0;
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
1
58
|
import React, { useState } from "react";
|
|
2
|
-
import {
|
|
59
|
+
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
3
60
|
|
|
4
|
-
|
|
5
|
-
children?: React.ReactNode;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const CopilotSidebar = (props: CopilotSidebarProps) => {
|
|
61
|
+
export function CopilotSidebar(props: CopilotModalProps) {
|
|
9
62
|
props = {
|
|
10
63
|
...props,
|
|
11
64
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar",
|
|
@@ -21,9 +74,9 @@ export const CopilotSidebar = (props: CopilotSidebarProps) => {
|
|
|
21
74
|
|
|
22
75
|
return (
|
|
23
76
|
<div className={`copilotKitSidebarContentWrapper ${expandedClassName}`}>
|
|
24
|
-
<
|
|
77
|
+
<CopilotModal {...props} {...{ onSetOpen }}>
|
|
25
78
|
{props.children}
|
|
26
|
-
</
|
|
79
|
+
</CopilotModal>
|
|
27
80
|
</div>
|
|
28
81
|
);
|
|
29
|
-
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CopilotContextParams,
|
|
3
|
+
extract,
|
|
4
|
+
CopilotChatSuggestionConfiguration,
|
|
5
|
+
} from "@copilotkit/react-core";
|
|
6
|
+
import { SuggestionsProps } from "./props";
|
|
7
|
+
import { SmallSpinnerIcon } from "./Icons";
|
|
8
|
+
import { CopilotChatSuggestion } from "../../types/suggestions";
|
|
9
|
+
|
|
10
|
+
export function Suggestion({ title, message, onClick, partial, className }: SuggestionsProps) {
|
|
11
|
+
return (
|
|
12
|
+
<button
|
|
13
|
+
disabled={partial}
|
|
14
|
+
onClick={(e) => {
|
|
15
|
+
e.preventDefault();
|
|
16
|
+
onClick(message);
|
|
17
|
+
}}
|
|
18
|
+
className={className || "suggestion"}
|
|
19
|
+
>
|
|
20
|
+
{partial && SmallSpinnerIcon}
|
|
21
|
+
<span>{title}</span>
|
|
22
|
+
</button>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const reloadSuggestions = async (
|
|
27
|
+
context: CopilotContextParams,
|
|
28
|
+
chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },
|
|
29
|
+
setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,
|
|
30
|
+
abortControllerRef: React.MutableRefObject<AbortController | null>,
|
|
31
|
+
) => {
|
|
32
|
+
const abortController = abortControllerRef.current;
|
|
33
|
+
const tools = JSON.stringify(context.getChatCompletionFunctionDescriptions(context.entryPoints));
|
|
34
|
+
|
|
35
|
+
const allSuggestions: CopilotChatSuggestion[] = [];
|
|
36
|
+
|
|
37
|
+
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
38
|
+
try {
|
|
39
|
+
const numOfSuggestionsInstructions =
|
|
40
|
+
config.minSuggestions === 0
|
|
41
|
+
? `Produce up to ${config.maxSuggestions} suggestions. ` +
|
|
42
|
+
`If there are no highly relevant suggestions you can think of, provide an empty array.`
|
|
43
|
+
: `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;
|
|
44
|
+
const result = await extract({
|
|
45
|
+
context,
|
|
46
|
+
instructions:
|
|
47
|
+
"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " +
|
|
48
|
+
config.instructions +
|
|
49
|
+
"\n\n" +
|
|
50
|
+
numOfSuggestionsInstructions,
|
|
51
|
+
data: "Available tools: " + tools + "\n\n",
|
|
52
|
+
parameters: [
|
|
53
|
+
{
|
|
54
|
+
name: "suggestions",
|
|
55
|
+
type: "object[]",
|
|
56
|
+
attributes: [
|
|
57
|
+
{
|
|
58
|
+
name: "title",
|
|
59
|
+
description:
|
|
60
|
+
"The title of the suggestion. This is shown as a button and should be short.",
|
|
61
|
+
type: "string",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "message",
|
|
65
|
+
description:
|
|
66
|
+
"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
|
|
67
|
+
type: "string",
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
include: {
|
|
73
|
+
messages: true,
|
|
74
|
+
readable: true,
|
|
75
|
+
},
|
|
76
|
+
abortSignal: abortController?.signal,
|
|
77
|
+
stream: ({ status, args }) => {
|
|
78
|
+
const suggestions = args.suggestions || [];
|
|
79
|
+
const newSuggestions: CopilotChatSuggestion[] = [];
|
|
80
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
81
|
+
// if GPT provides too many suggestions, limit the number of suggestions
|
|
82
|
+
if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
const { title, message } = suggestions[i];
|
|
86
|
+
|
|
87
|
+
// If this is the last suggestion and the status is not complete, mark it as partial
|
|
88
|
+
const partial = i == suggestions.length - 1 && status !== "complete";
|
|
89
|
+
|
|
90
|
+
newSuggestions.push({
|
|
91
|
+
title,
|
|
92
|
+
message,
|
|
93
|
+
partial,
|
|
94
|
+
className: config.className,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
setCurrentSuggestions([...allSuggestions, ...newSuggestions]);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
allSuggestions.push(...result.suggestions);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("Error loading suggestions", error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (abortControllerRef.current === abortController) {
|
|
107
|
+
abortControllerRef.current = null;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
@@ -19,15 +19,23 @@ export interface HeaderProps {
|
|
|
19
19
|
setOpen: (open: boolean) => void;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export interface SuggestionsProps {
|
|
23
|
+
title: string;
|
|
24
|
+
message: string;
|
|
25
|
+
partial?: boolean;
|
|
26
|
+
className?: string;
|
|
27
|
+
onClick: (message: string) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export interface MessagesProps {
|
|
23
31
|
messages: Message[];
|
|
24
32
|
inProgress: boolean;
|
|
33
|
+
children?: React.ReactNode;
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
export interface InputProps {
|
|
28
37
|
inProgress: boolean;
|
|
29
|
-
onSend: (text: string) =>
|
|
30
|
-
children?: React.ReactNode;
|
|
38
|
+
onSend: (text: string) => Promise<Message>;
|
|
31
39
|
isVisible?: boolean;
|
|
32
40
|
}
|
|
33
41
|
|
package/src/css/input.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
.copilotKitInput {
|
|
2
2
|
border-top: 1px solid var(--copilot-kit-input-separator-color);
|
|
3
3
|
padding-left: 2rem;
|
|
4
|
-
padding-right:
|
|
4
|
+
padding-right: 1rem;
|
|
5
5
|
padding-top: 1rem;
|
|
6
6
|
padding-bottom: 1rem;
|
|
7
7
|
display: flex;
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
background-color: var(--copilot-kit-input-background-color);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
.copilotKitInput > button {
|
|
17
|
-
position: absolute;
|
|
18
|
-
right: 0.5rem;
|
|
16
|
+
.copilotKitInput > .copilotKitInputControls > button {
|
|
19
17
|
padding: 0.25rem;
|
|
20
18
|
cursor: pointer;
|
|
21
19
|
transition-property: transform;
|
|
@@ -38,22 +36,27 @@
|
|
|
38
36
|
text-shadow: none;
|
|
39
37
|
display: inline-block;
|
|
40
38
|
text-align: center;
|
|
39
|
+
margin-left: 0.5rem; /* Add margin to separate button from textarea */
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
.copilotKitInput > button:not([disabled]) {
|
|
42
|
+
.copilotKitInput > .copilotKitInputControls > button:not([disabled]) {
|
|
44
43
|
color: var(--copilot-kit-input-send-button-color);
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
.copilotKitInput > button:not([disabled]):hover {
|
|
46
|
+
.copilotKitInput > .copilotKitInputControls > button:not([disabled]):hover {
|
|
48
47
|
transform: scale(1.1);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
.copilotKitInput > button[disabled] {
|
|
50
|
+
.copilotKitInput > .copilotKitInputControls > button[disabled] {
|
|
52
51
|
color: var(--copilot-kit-input-send-button-disabled-color);
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
.copilotKitInputControls {
|
|
55
|
+
display: flex;
|
|
56
|
+
}
|
|
57
|
+
|
|
55
58
|
.copilotKitInput > textarea {
|
|
56
|
-
|
|
59
|
+
flex: 1; /* Allow textarea to take up remaining space */
|
|
57
60
|
outline: 2px solid transparent;
|
|
58
61
|
outline-offset: 2px;
|
|
59
62
|
resize: none;
|
|
@@ -77,3 +80,10 @@
|
|
|
77
80
|
color: var(--copilot-kit-input-placeholder-color);
|
|
78
81
|
opacity: 1;
|
|
79
82
|
}
|
|
83
|
+
|
|
84
|
+
.copilotKitInput > .copilotKitInputControls > button.copilotKitPushToTalkRecording {
|
|
85
|
+
background-color: red;
|
|
86
|
+
color: white;
|
|
87
|
+
border-radius: 50%;
|
|
88
|
+
animation: copilotKitPulseAnimation 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
|
89
|
+
}
|
package/src/css/messages.css
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
overflow-y: scroll;
|
|
3
3
|
flex: 1;
|
|
4
4
|
padding: 1rem 2rem;
|
|
5
|
-
padding-bottom: 3rem;
|
|
6
5
|
display: flex;
|
|
7
6
|
flex-direction: column;
|
|
8
7
|
background-color: var(--copilot-kit-messages-background-color);
|
|
@@ -65,3 +64,10 @@
|
|
|
65
64
|
.copilotKitMessage .inProgressLabel {
|
|
66
65
|
margin-left: 10px;
|
|
67
66
|
}
|
|
67
|
+
|
|
68
|
+
.copilotKitMessages footer {
|
|
69
|
+
flex-grow: 1;
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
justify-content: flex-end;
|
|
73
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
.copilotKitPanel {
|
|
2
|
+
z-index: 30;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
-webkit-text-size-adjust: 100%;
|
|
5
|
+
-moz-tab-size: 4;
|
|
6
|
+
-o-tab-size: 4;
|
|
7
|
+
tab-size: 4;
|
|
8
|
+
font-family:
|
|
9
|
+
ui-sans-serif,
|
|
10
|
+
system-ui,
|
|
11
|
+
-apple-system,
|
|
12
|
+
BlinkMacSystemFont,
|
|
13
|
+
"Segoe UI",
|
|
14
|
+
Roboto,
|
|
15
|
+
"Helvetica Neue",
|
|
16
|
+
Arial,
|
|
17
|
+
"Noto Sans",
|
|
18
|
+
sans-serif,
|
|
19
|
+
"Apple Color Emoji",
|
|
20
|
+
"Segoe UI Emoji",
|
|
21
|
+
"Segoe UI Symbol",
|
|
22
|
+
"Noto Color Emoji";
|
|
23
|
+
font-feature-settings: normal;
|
|
24
|
+
font-variation-settings: normal;
|
|
25
|
+
touch-action: manipulation;
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
height: 100%;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.copilotKitPanel svg {
|
|
32
|
+
display: inline-block;
|
|
33
|
+
vertical-align: middle;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.copilotKitPanel .copilotKitMessages {
|
|
37
|
+
flex-grow: 1;
|
|
38
|
+
}
|
package/src/css/response.css
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.copilotKitMessages footer .suggestions {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
gap: 8px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.copilotKitMessages footer h6 {
|
|
8
|
+
font-weight: 500;
|
|
9
|
+
font-size: 0.7rem;
|
|
10
|
+
margin-bottom: 8px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.copilotKitMessages footer .suggestions .suggestion {
|
|
14
|
+
padding: 8px 12px;
|
|
15
|
+
font-size: 0.7rem;
|
|
16
|
+
border-radius: 0.5rem;
|
|
17
|
+
background: var(--copilot-kit-message-user-background-color);
|
|
18
|
+
color: var(--copilot-kit-message-user-color);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.copilotKitMessages footer .suggestions button {
|
|
22
|
+
transition: transform 0.3s ease;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.copilotKitMessages footer .suggestions button:not(:disabled):hover {
|
|
26
|
+
transform: scale(1.05);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.copilotKitMessages footer .suggestions button:disabled {
|
|
30
|
+
cursor: wait;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.copilotKitMessages footer .suggestions button svg {
|
|
34
|
+
margin-right: 6px;
|
|
35
|
+
}
|
package/src/css/window.css
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
border-radius: 0.75rem;
|
|
8
8
|
box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px;
|
|
9
9
|
flex-direction: column;
|
|
10
|
-
transition:
|
|
10
|
+
transition:
|
|
11
|
+
opacity 100ms ease-out,
|
|
12
|
+
transform 200ms ease-out;
|
|
11
13
|
opacity: 0;
|
|
12
14
|
transform: scale(0.95) translateY(20px);
|
|
13
15
|
display: flex;
|
package/src/hooks/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./use-copilot-chat-suggestions";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook for providing suggestions to the user in the Copilot chat.
|
|
3
|
+
*
|
|
4
|
+
* <Warning>
|
|
5
|
+
* useCopilotChatSuggestions is experimental. The interface is not final and
|
|
6
|
+
* can change without further notice.
|
|
7
|
+
* </Warning>
|
|
8
|
+
*
|
|
9
|
+
* <img src="/images/useCopilotChatSuggestions/use-copilot-chat-suggestions.gif" width="500" />
|
|
10
|
+
*
|
|
11
|
+
* <img referrerPolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be" />
|
|
12
|
+
*
|
|
13
|
+
* `useCopilotChatSuggestions` integrates auto-generated chat suggestions into your application in the context of your
|
|
14
|
+
* app's state. It dynamically manages suggestions based on provided configurations and
|
|
15
|
+
* dependencies.
|
|
16
|
+
*
|
|
17
|
+
* <RequestExample>
|
|
18
|
+
* ```jsx useCopilotChatSuggestions Example
|
|
19
|
+
* import { useCopilotChatSuggestions }
|
|
20
|
+
* from "@copilotkit/react-ui";
|
|
21
|
+
*
|
|
22
|
+
* useCopilotChatSuggestions({
|
|
23
|
+
* instructions: "Your instructions for suggestions.",
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
* </RequestExample>
|
|
27
|
+
*
|
|
28
|
+
* ## Basic Setup
|
|
29
|
+
*
|
|
30
|
+
* To incorporate this hook into your React components, start by importing it:
|
|
31
|
+
*
|
|
32
|
+
* ```tsx
|
|
33
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Then, use it in your component to initiate suggestion functionality:
|
|
37
|
+
*
|
|
38
|
+
* ```tsx
|
|
39
|
+
* useCopilotChatSuggestions({
|
|
40
|
+
* instructions: "Your instructions for suggestions.",
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* ## Dependency Management
|
|
45
|
+
*
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
48
|
+
*
|
|
49
|
+
* useCopilotChatSuggestions(
|
|
50
|
+
* {
|
|
51
|
+
* instructions: "Suggest the most relevant next actions.",
|
|
52
|
+
* },
|
|
53
|
+
* [appState],
|
|
54
|
+
* );
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* In the example above, the suggestions are generated based on the given instructions.
|
|
58
|
+
* The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
|
|
59
|
+
*
|
|
60
|
+
* ## Behavior and Lifecycle
|
|
61
|
+
*
|
|
62
|
+
* The hook registers the configuration with the chat context upon component mount and
|
|
63
|
+
* removes it on unmount, ensuring a clean and efficient lifecycle management.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
import { useEffect } from "react";
|
|
67
|
+
import { useChatContext } from "../components";
|
|
68
|
+
import { nanoid } from "nanoid";
|
|
69
|
+
import { CopilotChatSuggestionConfiguration, useCopilotContext } from "@copilotkit/react-core";
|
|
70
|
+
|
|
71
|
+
interface UseCopilotChatSuggestionsConfiguration {
|
|
72
|
+
/**
|
|
73
|
+
* A prompt or instructions for the GPT to generate suggestions.
|
|
74
|
+
*/
|
|
75
|
+
instructions: string;
|
|
76
|
+
/**
|
|
77
|
+
* The minimum number of suggestions to generate. Defaults to `1`.
|
|
78
|
+
* @default 1
|
|
79
|
+
*/
|
|
80
|
+
minSuggestions?: number;
|
|
81
|
+
/**
|
|
82
|
+
* The maximum number of suggestions to generate. Defaults to `3`.
|
|
83
|
+
* @default 1
|
|
84
|
+
*/
|
|
85
|
+
maxSuggestions?: number;
|
|
86
|
+
/**
|
|
87
|
+
* An optional class name to apply to the suggestions.
|
|
88
|
+
*/
|
|
89
|
+
className?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function useCopilotChatSuggestions(
|
|
93
|
+
{
|
|
94
|
+
instructions,
|
|
95
|
+
className,
|
|
96
|
+
minSuggestions = 1,
|
|
97
|
+
maxSuggestions = 3,
|
|
98
|
+
}: UseCopilotChatSuggestionsConfiguration,
|
|
99
|
+
dependencies: any[] = [],
|
|
100
|
+
) {
|
|
101
|
+
const context = useCopilotContext();
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const id = nanoid();
|
|
105
|
+
|
|
106
|
+
context.addChatSuggestionConfiguration(id, {
|
|
107
|
+
instructions,
|
|
108
|
+
minSuggestions,
|
|
109
|
+
maxSuggestions,
|
|
110
|
+
className,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return () => {
|
|
114
|
+
context.removeChatSuggestionConfiguration(id);
|
|
115
|
+
};
|
|
116
|
+
}, dependencies);
|
|
117
|
+
}
|