@agentscope-ai/chat 1.1.39 → 1.1.41-beta.1764749089549
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/bin/starter_webui.zip +0 -0
- package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.tsx +8 -4
- package/components/ImageGenerator/index.tsx +1 -1
- package/components/Markdown/Markdown.tsx +105 -0
- package/components/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.tsx +1 -1
- package/components/Markdown/core/components/Null.tsx +1 -0
- package/components/Markdown/core/components/Raw.tsx +18 -0
- package/components/Markdown/{Markdown → core}/hooks/useCitationsData.tsx +3 -7
- package/components/Markdown/core/hooks/useCursorContent.tsx +15 -0
- package/components/Markdown/{Markdown/hooks/useTyping.ts → core/hooks/useTyping.tsx} +4 -1
- package/components/Markdown/core/index.tsx +18 -0
- package/components/Markdown/{plugins → core/plugins}/citations/CitationComponent.tsx +5 -3
- package/components/Markdown/{plugins → core/plugins}/citations/index.tsx +3 -4
- package/components/Markdown/{plugins → core/plugins}/cursor/Underline.tsx +1 -1
- package/components/Markdown/{plugins → core/plugins}/cursor/index.tsx +8 -8
- package/components/Markdown/demo/cursor.tsx +2 -3
- package/components/Markdown/index.en-US.md +1 -2
- package/components/Markdown/index.tsx +6 -0
- package/components/Markdown/index.zh-CN.md +1 -2
- package/components/Markdown/{Markdown/style.ts → styles.ts} +12 -21
- package/components/Markdown/types.tsx +94 -0
- package/components/index.ts +1 -3
- package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.js +5 -3
- package/lib/ImageGenerator/index.js +1 -1
- package/lib/Markdown/Markdown.d.ts +4 -0
- package/lib/Markdown/Markdown.js +110 -0
- package/lib/Markdown/core/components/Null.d.ts +2 -0
- package/lib/Markdown/core/components/Null.js +3 -0
- package/lib/Markdown/core/components/Raw.d.ts +8 -0
- package/lib/Markdown/core/components/Raw.js +13 -0
- package/lib/Markdown/core/hooks/useCitationsData.d.ts +6 -0
- package/lib/Markdown/{Markdown → core}/hooks/useCitationsData.js +1 -1
- package/lib/Markdown/core/hooks/useCursorContent.d.ts +4 -0
- package/lib/Markdown/core/hooks/useCursorContent.js +14 -0
- package/lib/Markdown/core/hooks/useTyping.d.ts +5 -0
- package/lib/Markdown/{Markdown → core}/hooks/useTyping.js +3 -2
- package/lib/Markdown/core/index.d.ts +2 -0
- package/lib/Markdown/{Markdown/hooks/useAnimation.js → core/index.js} +23 -23
- package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.js +5 -5
- package/lib/Markdown/{plugins → core/plugins}/citations/index.d.ts +1 -2
- package/lib/Markdown/{plugins → core/plugins}/citations/index.js +1 -1
- package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.js +1 -1
- package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.js +1 -1
- package/lib/Markdown/{plugins → core/plugins}/cursor/index.js +4 -4
- package/lib/Markdown/index.d.ts +2 -1
- package/lib/Markdown/styles.js +32 -0
- package/lib/Markdown/types.d.ts +78 -0
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/package.json +7 -31
- package/components/AGUI/components/HelpModal/icons.tsx +0 -68
- package/components/AGUI/components/HelpModal/index.tsx +0 -1
- package/components/AGUI/components/HelpModal/modal.tsx +0 -101
- package/components/AGUI/components/chat/Button.tsx +0 -18
- package/components/AGUI/components/chat/Chat.tsx +0 -780
- package/components/AGUI/components/chat/ChatContext.tsx +0 -248
- package/components/AGUI/components/chat/CodeBlock.tsx +0 -406
- package/components/AGUI/components/chat/Header.tsx +0 -22
- package/components/AGUI/components/chat/Icons.tsx +0 -237
- package/components/AGUI/components/chat/ImageUploadQueue.tsx +0 -77
- package/components/AGUI/components/chat/Input.tsx +0 -24
- package/components/AGUI/components/chat/Markdown.tsx +0 -134
- package/components/AGUI/components/chat/Messages.tsx +0 -259
- package/components/AGUI/components/chat/Modal.tsx +0 -133
- package/components/AGUI/components/chat/Popup.tsx +0 -57
- package/components/AGUI/components/chat/PoweredByTag.tsx +0 -29
- package/components/AGUI/components/chat/Sidebar.tsx +0 -74
- package/components/AGUI/components/chat/Suggestion.tsx +0 -132
- package/components/AGUI/components/chat/Suggestions.tsx +0 -20
- package/components/AGUI/components/chat/Textarea.tsx +0 -61
- package/components/AGUI/components/chat/Window.tsx +0 -152
- package/components/AGUI/components/chat/index.tsx +0 -11
- package/components/AGUI/components/chat/messages/AssistantMessage.tsx +0 -69
- package/components/AGUI/components/chat/messages/RenderActionExecutionMessage.tsx +0 -129
- package/components/AGUI/components/chat/messages/RenderAgentStateMessage.tsx +0 -116
- package/components/AGUI/components/chat/messages/RenderImageMessage.tsx +0 -64
- package/components/AGUI/components/chat/messages/RenderResultMessage.tsx +0 -26
- package/components/AGUI/components/chat/messages/RenderTextMessage.tsx +0 -51
- package/components/AGUI/components/chat/messages/UserMessage.tsx +0 -10
- package/components/AGUI/components/chat/props.ts +0 -186
- package/components/AGUI/components/index.ts +0 -1
- package/components/AGUI/context/index.ts +0 -1
- package/components/AGUI/hooks/index.ts +0 -1
- package/components/AGUI/hooks/use-copilot-chat-suggestions.tsx +0 -122
- package/components/AGUI/hooks/use-copy-to-clipboard.tsx +0 -29
- package/components/AGUI/hooks/use-dark-mode.ts +0 -10
- package/components/AGUI/hooks/use-push-to-talk.tsx +0 -166
- package/components/AGUI/index.tsx +0 -4
- package/components/AGUI/lib/utils.test.ts +0 -7
- package/components/AGUI/lib/utils.ts +0 -27
- package/components/AGUI/styles.css +0 -0
- package/components/AGUI/types/css.ts +0 -0
- package/components/AGUI/types/index.ts +0 -1
- package/components/AGUI/types/suggestions.ts +0 -6
- package/components/Markdown/Markdown/AnimationNode.tsx +0 -89
- package/components/Markdown/Markdown/Markdown.tsx +0 -61
- package/components/Markdown/Markdown/core/Parser.ts +0 -52
- package/components/Markdown/Markdown/core/Renderer.ts +0 -121
- package/components/Markdown/Markdown/core/index.ts +0 -4
- package/components/Markdown/Markdown/hooks/index.ts +0 -4
- package/components/Markdown/Markdown/hooks/useAnimation.tsx +0 -27
- package/components/Markdown/Markdown/hooks/useStreaming.ts +0 -503
- package/components/Markdown/Markdown/index.tsx +0 -198
- package/components/Markdown/Markdown/interface.ts +0 -217
- package/components/Markdown/demo/typing.tsx +0 -82
- package/components/Markdown/index.ts +0 -1
- package/components/Markdown/plugins/latex/index.ts +0 -109
- package/components/Markdown/plugins/type.ts +0 -71
- package/lib/AGUI/components/HelpModal/icons.d.ts +0 -5
- package/lib/AGUI/components/HelpModal/icons.js +0 -84
- package/lib/AGUI/components/HelpModal/index.d.ts +0 -1
- package/lib/AGUI/components/HelpModal/index.js +0 -1
- package/lib/AGUI/components/HelpModal/modal.d.ts +0 -1
- package/lib/AGUI/components/HelpModal/modal.js +0 -104
- package/lib/AGUI/components/chat/Button.d.ts +0 -2
- package/lib/AGUI/components/chat/Button.js +0 -27
- package/lib/AGUI/components/chat/Chat.d.ts +0 -242
- package/lib/AGUI/components/chat/Chat.js +0 -634
- package/lib/AGUI/components/chat/ChatContext.d.ts +0 -142
- package/lib/AGUI/components/chat/ChatContext.js +0 -75
- package/lib/AGUI/components/chat/CodeBlock.d.ts +0 -12
- package/lib/AGUI/components/chat/CodeBlock.js +0 -398
- package/lib/AGUI/components/chat/Header.d.ts +0 -2
- package/lib/AGUI/components/chat/Header.js +0 -28
- package/lib/AGUI/components/chat/Icons.d.ts +0 -16
- package/lib/AGUI/components/chat/Icons.js +0 -247
- package/lib/AGUI/components/chat/ImageUploadQueue.d.ts +0 -11
- package/lib/AGUI/components/chat/ImageUploadQueue.js +0 -65
- package/lib/AGUI/components/chat/Input.d.ts +0 -2
- package/lib/AGUI/components/chat/Input.js +0 -30
- package/lib/AGUI/components/chat/Markdown.d.ts +0 -7
- package/lib/AGUI/components/chat/Markdown.js +0 -187
- package/lib/AGUI/components/chat/Messages.d.ts +0 -7
- package/lib/AGUI/components/chat/Messages.js +0 -242
- package/lib/AGUI/components/chat/Modal.d.ts +0 -43
- package/lib/AGUI/components/chat/Modal.js +0 -113
- package/lib/AGUI/components/chat/Popup.d.ts +0 -49
- package/lib/AGUI/components/chat/Popup.js +0 -64
- package/lib/AGUI/components/chat/PoweredByTag.d.ts +0 -3
- package/lib/AGUI/components/chat/PoweredByTag.js +0 -27
- package/lib/AGUI/components/chat/Sidebar.d.ts +0 -2
- package/lib/AGUI/components/chat/Sidebar.js +0 -85
- package/lib/AGUI/components/chat/Suggestion.d.ts +0 -16
- package/lib/AGUI/components/chat/Suggestion.js +0 -146
- package/lib/AGUI/components/chat/Suggestions.d.ts +0 -2
- package/lib/AGUI/components/chat/Suggestions.js +0 -21
- package/lib/AGUI/components/chat/Textarea.d.ts +0 -11
- package/lib/AGUI/components/chat/Textarea.js +0 -60
- package/lib/AGUI/components/chat/Window.d.ts +0 -2
- package/lib/AGUI/components/chat/Window.js +0 -115
- package/lib/AGUI/components/chat/index.d.ts +0 -11
- package/lib/AGUI/components/chat/index.js +0 -11
- package/lib/AGUI/components/chat/messages/AssistantMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/AssistantMessage.js +0 -56
- package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.js +0 -114
- package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.js +0 -97
- package/lib/AGUI/components/chat/messages/RenderImageMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderImageMessage.js +0 -61
- package/lib/AGUI/components/chat/messages/RenderResultMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderResultMessage.js +0 -27
- package/lib/AGUI/components/chat/messages/RenderTextMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderTextMessage.js +0 -47
- package/lib/AGUI/components/chat/messages/UserMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/UserMessage.js +0 -9
- package/lib/AGUI/components/chat/props.d.ts +0 -157
- package/lib/AGUI/components/index.d.ts +0 -1
- package/lib/AGUI/components/index.js +0 -1
- package/lib/AGUI/context/index.d.ts +0 -1
- package/lib/AGUI/context/index.js +0 -1
- package/lib/AGUI/hooks/index.d.ts +0 -1
- package/lib/AGUI/hooks/index.js +0 -1
- package/lib/AGUI/hooks/use-copilot-chat-suggestions.d.ts +0 -87
- package/lib/AGUI/hooks/use-copilot-chat-suggestions.js +0 -95
- package/lib/AGUI/hooks/use-copy-to-clipboard.d.ts +0 -7
- package/lib/AGUI/hooks/use-copy-to-clipboard.js +0 -34
- package/lib/AGUI/hooks/use-dark-mode.d.ts +0 -1
- package/lib/AGUI/hooks/use-dark-mode.js +0 -4
- package/lib/AGUI/hooks/use-push-to-talk.d.ts +0 -16
- package/lib/AGUI/hooks/use-push-to-talk.js +0 -260
- package/lib/AGUI/index.d.ts +0 -4
- package/lib/AGUI/index.js +0 -4
- package/lib/AGUI/lib/utils.d.ts +0 -2
- package/lib/AGUI/lib/utils.js +0 -52
- package/lib/AGUI/styles.css +0 -0
- package/lib/AGUI/types/css.d.ts +0 -0
- package/lib/AGUI/types/css.js +0 -0
- package/lib/AGUI/types/index.d.ts +0 -1
- package/lib/AGUI/types/index.js +0 -1
- package/lib/AGUI/types/suggestions.d.ts +0 -6
- package/lib/AGUI/types/suggestions.js +0 -1
- package/lib/Markdown/Markdown/AnimationNode.d.ts +0 -20
- package/lib/Markdown/Markdown/AnimationNode.js +0 -84
- package/lib/Markdown/Markdown/Markdown.d.ts +0 -4
- package/lib/Markdown/Markdown/Markdown.js +0 -58
- package/lib/Markdown/Markdown/core/Parser.d.ts +0 -16
- package/lib/Markdown/Markdown/core/Parser.js +0 -65
- package/lib/Markdown/Markdown/core/Renderer.d.ts +0 -24
- package/lib/Markdown/Markdown/core/Renderer.js +0 -137
- package/lib/Markdown/Markdown/core/index.d.ts +0 -3
- package/lib/Markdown/Markdown/core/index.js +0 -3
- package/lib/Markdown/Markdown/hooks/index.d.ts +0 -3
- package/lib/Markdown/Markdown/hooks/index.js +0 -3
- package/lib/Markdown/Markdown/hooks/useAnimation.d.ts +0 -4
- package/lib/Markdown/Markdown/hooks/useCitationsData.d.ts +0 -7
- package/lib/Markdown/Markdown/hooks/useStreaming.d.ts +0 -3
- package/lib/Markdown/Markdown/hooks/useStreaming.js +0 -521
- package/lib/Markdown/Markdown/hooks/useTyping.d.ts +0 -4
- package/lib/Markdown/Markdown/index.d.ts +0 -84
- package/lib/Markdown/Markdown/index.js +0 -161
- package/lib/Markdown/Markdown/interface.d.ts +0 -203
- package/lib/Markdown/Markdown/interface.js +0 -1
- package/lib/Markdown/Markdown/style.js +0 -32
- package/lib/Markdown/plugins/latex/index.d.ts +0 -9
- package/lib/Markdown/plugins/latex/index.js +0 -97
- package/lib/Markdown/plugins/type.d.ts +0 -60
- package/lib/Markdown/plugins/type.js +0 -1
- /package/components/Markdown/{Markdown/defaultComponents/DisabledImage.tsx → core/components/DisableImage.tsx} +0 -0
- /package/components/Markdown/{Markdown/defaultComponents → core/components}/Media.tsx +0 -0
- /package/components/Markdown/{plugins → core/plugins}/cursor/Dot.tsx +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.d.ts +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.js +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.d.ts → core/components/DisableImage.d.ts} +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.js → core/components/DisableImage.js} +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.d.ts +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.js +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.d.ts +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.d.ts +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.d.ts +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/cursor/index.d.ts +0 -0
- /package/lib/Markdown/{Markdown/style.d.ts → styles.d.ts} +0 -0
- /package/lib/{AGUI/components/chat/props.js → Markdown/types.js} +0 -0
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
-
import { MessagesProps } from "./props";
|
|
3
|
-
import { useChatContext } from "./ChatContext";
|
|
4
|
-
import { Message, ResultMessage, TextMessage, Role } from "@copilotkit/runtime-client-gql";
|
|
5
|
-
import { useLangGraphInterruptRender } from "@copilotkit/react-core";
|
|
6
|
-
import { Bubble } from "@agentscope-ai/chat";
|
|
7
|
-
|
|
8
|
-
export const Messages = ({
|
|
9
|
-
messages,
|
|
10
|
-
inProgress,
|
|
11
|
-
children,
|
|
12
|
-
RenderTextMessage,
|
|
13
|
-
RenderActionExecutionMessage,
|
|
14
|
-
RenderAgentStateMessage,
|
|
15
|
-
RenderResultMessage,
|
|
16
|
-
RenderImageMessage,
|
|
17
|
-
AssistantMessage,
|
|
18
|
-
UserMessage,
|
|
19
|
-
onRegenerate,
|
|
20
|
-
onCopy,
|
|
21
|
-
onThumbsUp,
|
|
22
|
-
onThumbsDown,
|
|
23
|
-
markdownTagRenderers,
|
|
24
|
-
}: MessagesProps) => {
|
|
25
|
-
const actionResults: Record<string, string> = {};
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < messages.length; i++) {
|
|
28
|
-
if (messages[i].isActionExecutionMessage()) {
|
|
29
|
-
const id = messages[i].id;
|
|
30
|
-
const resultMessage: ResultMessage | undefined = messages.find(
|
|
31
|
-
(message) => message.isResultMessage() && message.actionExecutionId === id,
|
|
32
|
-
) as ResultMessage | undefined;
|
|
33
|
-
|
|
34
|
-
if (resultMessage) {
|
|
35
|
-
actionResults[id] = ResultMessage.decodeResult(resultMessage.result || "");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return <Bubble.List
|
|
42
|
-
style={{ height: 0, flex: 1, }}
|
|
43
|
-
>
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
messages.map((message, index) => {
|
|
47
|
-
const isCurrentMessage = index === messages.length - 1;
|
|
48
|
-
|
|
49
|
-
if (message.isTextMessage()) {
|
|
50
|
-
return (
|
|
51
|
-
<RenderTextMessage
|
|
52
|
-
key={message.id}
|
|
53
|
-
message={message}
|
|
54
|
-
inProgress={inProgress}
|
|
55
|
-
index={index}
|
|
56
|
-
isCurrentMessage={isCurrentMessage}
|
|
57
|
-
AssistantMessage={AssistantMessage}
|
|
58
|
-
UserMessage={UserMessage}
|
|
59
|
-
onRegenerate={onRegenerate}
|
|
60
|
-
onCopy={onCopy}
|
|
61
|
-
onThumbsUp={onThumbsUp}
|
|
62
|
-
onThumbsDown={onThumbsDown}
|
|
63
|
-
markdownTagRenderers={markdownTagRenderers}
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
66
|
-
} else if (message.isActionExecutionMessage()) {
|
|
67
|
-
return (
|
|
68
|
-
<RenderActionExecutionMessage
|
|
69
|
-
key={index}
|
|
70
|
-
message={message}
|
|
71
|
-
inProgress={inProgress}
|
|
72
|
-
index={index}
|
|
73
|
-
isCurrentMessage={isCurrentMessage}
|
|
74
|
-
actionResult={actionResults[message.id]}
|
|
75
|
-
AssistantMessage={AssistantMessage}
|
|
76
|
-
UserMessage={UserMessage}
|
|
77
|
-
/>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return null;
|
|
84
|
-
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
</Bubble.List>
|
|
88
|
-
|
|
89
|
-
// return (
|
|
90
|
-
// <div className="copilotKitMessages" ref={messagesContainerRef}>
|
|
91
|
-
// <div className="copilotKitMessagesContainer">
|
|
92
|
-
// {messages.map((message, index) => {
|
|
93
|
-
// const isCurrentMessage = index === messages.length - 1;
|
|
94
|
-
|
|
95
|
-
// if (message.isTextMessage()) {
|
|
96
|
-
// return (
|
|
97
|
-
// <RenderTextMessage
|
|
98
|
-
// key={index}
|
|
99
|
-
// message={message}
|
|
100
|
-
// inProgress={inProgress}
|
|
101
|
-
// index={index}
|
|
102
|
-
// isCurrentMessage={isCurrentMessage}
|
|
103
|
-
// AssistantMessage={AssistantMessage}
|
|
104
|
-
// UserMessage={UserMessage}
|
|
105
|
-
// onRegenerate={onRegenerate}
|
|
106
|
-
// onCopy={onCopy}
|
|
107
|
-
// onThumbsUp={onThumbsUp}
|
|
108
|
-
// onThumbsDown={onThumbsDown}
|
|
109
|
-
// markdownTagRenderers={markdownTagRenderers}
|
|
110
|
-
// />
|
|
111
|
-
// );
|
|
112
|
-
// } else if (message.isActionExecutionMessage()) {
|
|
113
|
-
// return (
|
|
114
|
-
// <RenderActionExecutionMessage
|
|
115
|
-
// key={index}
|
|
116
|
-
// message={message}
|
|
117
|
-
// inProgress={inProgress}
|
|
118
|
-
// index={index}
|
|
119
|
-
// isCurrentMessage={isCurrentMessage}
|
|
120
|
-
// actionResult={actionResults[message.id]}
|
|
121
|
-
// AssistantMessage={AssistantMessage}
|
|
122
|
-
// UserMessage={UserMessage}
|
|
123
|
-
// />
|
|
124
|
-
// );
|
|
125
|
-
// } else if (message.isAgentStateMessage()) {
|
|
126
|
-
// return (
|
|
127
|
-
// <RenderAgentStateMessage
|
|
128
|
-
// key={index}
|
|
129
|
-
// message={message}
|
|
130
|
-
// inProgress={inProgress}
|
|
131
|
-
// index={index}
|
|
132
|
-
// isCurrentMessage={isCurrentMessage}
|
|
133
|
-
// AssistantMessage={AssistantMessage}
|
|
134
|
-
// UserMessage={UserMessage}
|
|
135
|
-
// />
|
|
136
|
-
// );
|
|
137
|
-
// } else if (message.isResultMessage()) {
|
|
138
|
-
// return (
|
|
139
|
-
// <RenderResultMessage
|
|
140
|
-
// key={index}
|
|
141
|
-
// message={message}
|
|
142
|
-
// inProgress={inProgress}
|
|
143
|
-
// index={index}
|
|
144
|
-
// isCurrentMessage={isCurrentMessage}
|
|
145
|
-
// AssistantMessage={AssistantMessage}
|
|
146
|
-
// UserMessage={UserMessage}
|
|
147
|
-
// />
|
|
148
|
-
// );
|
|
149
|
-
// } else if (message.isImageMessage && message.isImageMessage()) {
|
|
150
|
-
// return (
|
|
151
|
-
// <RenderImageMessage
|
|
152
|
-
// key={index}
|
|
153
|
-
// message={message}
|
|
154
|
-
// inProgress={inProgress}
|
|
155
|
-
// index={index}
|
|
156
|
-
// isCurrentMessage={isCurrentMessage}
|
|
157
|
-
// AssistantMessage={AssistantMessage}
|
|
158
|
-
// UserMessage={UserMessage}
|
|
159
|
-
// onRegenerate={onRegenerate}
|
|
160
|
-
// onCopy={onCopy}
|
|
161
|
-
// onThumbsUp={onThumbsUp}
|
|
162
|
-
// onThumbsDown={onThumbsDown}
|
|
163
|
-
// />
|
|
164
|
-
// );
|
|
165
|
-
// }
|
|
166
|
-
// })}
|
|
167
|
-
// {interrupt}
|
|
168
|
-
// </div>
|
|
169
|
-
|
|
170
|
-
// </div>
|
|
171
|
-
// );
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
function makeInitialMessages(initial?: string | string[]): Message[] {
|
|
175
|
-
let initialArray: string[] = [];
|
|
176
|
-
if (initial) {
|
|
177
|
-
if (Array.isArray(initial)) {
|
|
178
|
-
initialArray.push(...initial);
|
|
179
|
-
} else {
|
|
180
|
-
initialArray.push(initial);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return initialArray.map(
|
|
185
|
-
(message) =>
|
|
186
|
-
new TextMessage({
|
|
187
|
-
role: Role.Assistant,
|
|
188
|
-
content: message,
|
|
189
|
-
}),
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function useScrollToBottom(messages: any[]) {
|
|
194
|
-
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
195
|
-
const messagesContainerRef = useRef<HTMLDivElement | null>(null);
|
|
196
|
-
const isProgrammaticScrollRef = useRef(false);
|
|
197
|
-
const isUserScrollUpRef = useRef(false);
|
|
198
|
-
|
|
199
|
-
const scrollToBottom = () => {
|
|
200
|
-
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
201
|
-
isProgrammaticScrollRef.current = true;
|
|
202
|
-
messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const handleScroll = () => {
|
|
207
|
-
if (isProgrammaticScrollRef.current) {
|
|
208
|
-
isProgrammaticScrollRef.current = false;
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (messagesContainerRef.current) {
|
|
213
|
-
const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
|
|
214
|
-
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
const container = messagesContainerRef.current;
|
|
220
|
-
if (container) {
|
|
221
|
-
container.addEventListener("scroll", handleScroll);
|
|
222
|
-
}
|
|
223
|
-
return () => {
|
|
224
|
-
if (container) {
|
|
225
|
-
container.removeEventListener("scroll", handleScroll);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
}, []);
|
|
229
|
-
|
|
230
|
-
useEffect(() => {
|
|
231
|
-
const container = messagesContainerRef.current;
|
|
232
|
-
if (!container) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const mutationObserver = new MutationObserver(() => {
|
|
237
|
-
if (!isUserScrollUpRef.current) {
|
|
238
|
-
scrollToBottom();
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
mutationObserver.observe(container, {
|
|
243
|
-
childList: true,
|
|
244
|
-
subtree: true,
|
|
245
|
-
characterData: true,
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
return () => {
|
|
249
|
-
mutationObserver.disconnect();
|
|
250
|
-
};
|
|
251
|
-
}, []);
|
|
252
|
-
|
|
253
|
-
useEffect(() => {
|
|
254
|
-
isUserScrollUpRef.current = false;
|
|
255
|
-
scrollToBottom();
|
|
256
|
-
}, [messages.filter((m) => m.isTextMessage() && m.role === Role.User).length]);
|
|
257
|
-
|
|
258
|
-
return { messagesEndRef, messagesContainerRef };
|
|
259
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from "react";
|
|
2
|
-
import { ChatContextProvider } from "./ChatContext";
|
|
3
|
-
import { ButtonProps, HeaderProps, WindowProps } from "./props";
|
|
4
|
-
import { Window as DefaultWindow } from "./Window";
|
|
5
|
-
import { Button as DefaultButton } from "./Button";
|
|
6
|
-
import { Header as DefaultHeader } from "./Header";
|
|
7
|
-
import { Messages as DefaultMessages } from "./Messages";
|
|
8
|
-
import { Input as DefaultInput } from "./Input";
|
|
9
|
-
import { CopilotChat, CopilotChatProps } from "./Chat";
|
|
10
|
-
import { AssistantMessage as DefaultAssistantMessage } from "./messages/AssistantMessage";
|
|
11
|
-
import { UserMessage as DefaultUserMessage } from "./messages/UserMessage";
|
|
12
|
-
|
|
13
|
-
export interface CopilotModalProps extends CopilotChatProps {
|
|
14
|
-
/**
|
|
15
|
-
* Whether the chat window should be open by default.
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
defaultOpen?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* If the chat window should close when the user clicks outside of it.
|
|
22
|
-
* @default true
|
|
23
|
-
*/
|
|
24
|
-
clickOutsideToClose?: boolean;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* If the chat window should close when the user hits the Escape key.
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
hitEscapeToClose?: boolean;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The shortcut key to open the chat window.
|
|
34
|
-
* Uses Command-[shortcut] on a Mac and Ctrl-[shortcut] on Windows.
|
|
35
|
-
* @default '/'
|
|
36
|
-
*/
|
|
37
|
-
shortcut?: string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A callback that gets called when the chat window opens or closes.
|
|
41
|
-
*/
|
|
42
|
-
onSetOpen?: (open: boolean) => void;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A custom Window component to use instead of the default.
|
|
46
|
-
*/
|
|
47
|
-
Window?: React.ComponentType<WindowProps>;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* A custom Button component to use instead of the default.
|
|
51
|
-
*/
|
|
52
|
-
Button?: React.ComponentType<ButtonProps>;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* A custom Header component to use instead of the default.
|
|
56
|
-
*/
|
|
57
|
-
Header?: React.ComponentType<HeaderProps>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const CopilotModal = ({
|
|
61
|
-
instructions,
|
|
62
|
-
defaultOpen = false,
|
|
63
|
-
clickOutsideToClose = true,
|
|
64
|
-
hitEscapeToClose = true,
|
|
65
|
-
onSetOpen,
|
|
66
|
-
onSubmitMessage,
|
|
67
|
-
onStopGeneration,
|
|
68
|
-
onReloadMessages,
|
|
69
|
-
shortcut = "/",
|
|
70
|
-
icons,
|
|
71
|
-
labels,
|
|
72
|
-
makeSystemMessage,
|
|
73
|
-
onInProgress,
|
|
74
|
-
Window = DefaultWindow,
|
|
75
|
-
Button = DefaultButton,
|
|
76
|
-
Header = DefaultHeader,
|
|
77
|
-
Messages = DefaultMessages,
|
|
78
|
-
Input = DefaultInput,
|
|
79
|
-
AssistantMessage = DefaultAssistantMessage,
|
|
80
|
-
UserMessage = DefaultUserMessage,
|
|
81
|
-
onThumbsUp,
|
|
82
|
-
onThumbsDown,
|
|
83
|
-
onCopy,
|
|
84
|
-
onRegenerate,
|
|
85
|
-
markdownTagRenderers,
|
|
86
|
-
className,
|
|
87
|
-
children,
|
|
88
|
-
...props
|
|
89
|
-
}: CopilotModalProps) => {
|
|
90
|
-
const [openState, setOpenState] = React.useState(defaultOpen);
|
|
91
|
-
|
|
92
|
-
const setOpen = (open: boolean) => {
|
|
93
|
-
onSetOpen?.(open);
|
|
94
|
-
setOpenState(open);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const memoizedHeader = useMemo(() => <Header />, [Header]);
|
|
98
|
-
const memoizedChildren = useMemo(() => children, [children]);
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<ChatContextProvider icons={icons} labels={labels} open={openState} setOpen={setOpen}>
|
|
102
|
-
{memoizedChildren}
|
|
103
|
-
<div className={className}>
|
|
104
|
-
<Button></Button>
|
|
105
|
-
<Window
|
|
106
|
-
clickOutsideToClose={clickOutsideToClose}
|
|
107
|
-
shortcut={shortcut}
|
|
108
|
-
hitEscapeToClose={hitEscapeToClose}
|
|
109
|
-
>
|
|
110
|
-
{memoizedHeader}
|
|
111
|
-
<CopilotChat
|
|
112
|
-
{...props}
|
|
113
|
-
instructions={instructions}
|
|
114
|
-
onSubmitMessage={onSubmitMessage}
|
|
115
|
-
onStopGeneration={onStopGeneration}
|
|
116
|
-
onReloadMessages={onReloadMessages}
|
|
117
|
-
makeSystemMessage={makeSystemMessage}
|
|
118
|
-
onInProgress={onInProgress}
|
|
119
|
-
Messages={Messages}
|
|
120
|
-
Input={Input}
|
|
121
|
-
AssistantMessage={AssistantMessage}
|
|
122
|
-
UserMessage={UserMessage}
|
|
123
|
-
onThumbsUp={onThumbsUp}
|
|
124
|
-
onThumbsDown={onThumbsDown}
|
|
125
|
-
onCopy={onCopy}
|
|
126
|
-
onRegenerate={onRegenerate}
|
|
127
|
-
markdownTagRenderers={markdownTagRenderers}
|
|
128
|
-
/>
|
|
129
|
-
</Window>
|
|
130
|
-
</div>
|
|
131
|
-
</ChatContextProvider>
|
|
132
|
-
);
|
|
133
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* <br/>
|
|
3
|
-
* <img src="/images/CopilotPopup.gif" width="500" />
|
|
4
|
-
*
|
|
5
|
-
* A chatbot popup component for the CopilotKit framework. The component allows for a high degree
|
|
6
|
-
* of customization through various props and custom CSS.
|
|
7
|
-
*
|
|
8
|
-
* See [CopilotSidebar](/reference/components/chat/CopilotSidebar) for a sidebar version of this component.
|
|
9
|
-
*
|
|
10
|
-
* ## Install Dependencies
|
|
11
|
-
*
|
|
12
|
-
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
13
|
-
*
|
|
14
|
-
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
15
|
-
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
16
|
-
* ```
|
|
17
|
-
* ## Usage
|
|
18
|
-
*
|
|
19
|
-
* ```tsx
|
|
20
|
-
* import { CopilotPopup } from "@copilotkit/react-ui";
|
|
21
|
-
* import "@copilotkit/react-ui/styles.css";
|
|
22
|
-
*
|
|
23
|
-
* <CopilotPopup
|
|
24
|
-
* labels={{
|
|
25
|
-
* title: "Your Assistant",
|
|
26
|
-
* initial: "Hi! 👋 How can I assist you today?",
|
|
27
|
-
* }}
|
|
28
|
-
* />
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* ### Look & Feel
|
|
32
|
-
*
|
|
33
|
-
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
34
|
-
* ```tsx title="YourRootComponent.tsx"
|
|
35
|
-
* ...
|
|
36
|
-
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
37
|
-
*
|
|
38
|
-
* export function YourRootComponent() {
|
|
39
|
-
* return (
|
|
40
|
-
* <CopilotKit>
|
|
41
|
-
* ...
|
|
42
|
-
* </CopilotKit>
|
|
43
|
-
* );
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
50
|
-
|
|
51
|
-
export function CopilotPopup(props: CopilotModalProps) {
|
|
52
|
-
props = {
|
|
53
|
-
...props,
|
|
54
|
-
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup",
|
|
55
|
-
};
|
|
56
|
-
return <CopilotModal {...props}>{props.children}</CopilotModal>;
|
|
57
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useDarkMode } from "../../hooks/use-dark-mode";
|
|
3
|
-
|
|
4
|
-
export function PoweredByTag({ showPoweredBy = true }: { showPoweredBy?: boolean }) {
|
|
5
|
-
const isDark = useDarkMode();
|
|
6
|
-
|
|
7
|
-
if (!showPoweredBy) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const poweredByStyle = {
|
|
12
|
-
visibility: "visible",
|
|
13
|
-
display: "block",
|
|
14
|
-
position: "static",
|
|
15
|
-
textAlign: "center",
|
|
16
|
-
fontSize: "12px",
|
|
17
|
-
padding: "3px 0",
|
|
18
|
-
color: isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<div>
|
|
23
|
-
{/*@ts-expect-error -- expecting position not to be a string, but it can be.*/}
|
|
24
|
-
<p className="poweredBy" style={poweredByStyle}>
|
|
25
|
-
Powered by CopilotKit
|
|
26
|
-
</p>
|
|
27
|
-
</div>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* <br/>
|
|
3
|
-
* <img src="/images/CopilotSidebar.gif" width="500" />
|
|
4
|
-
*
|
|
5
|
-
* A chatbot sidebar component for the CopilotKit framework. Highly customizable through various props and custom CSS.
|
|
6
|
-
*
|
|
7
|
-
* See [CopilotPopup](/reference/components/chat/CopilotPopup) for a popup version of this component.
|
|
8
|
-
*
|
|
9
|
-
* ## Install Dependencies
|
|
10
|
-
*
|
|
11
|
-
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
12
|
-
*
|
|
13
|
-
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
14
|
-
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* ## Usage
|
|
18
|
-
*
|
|
19
|
-
* ```tsx
|
|
20
|
-
* import { CopilotSidebar } from "@copilotkit/react-ui";
|
|
21
|
-
* import "@copilotkit/react-ui/styles.css";
|
|
22
|
-
*
|
|
23
|
-
* <CopilotSidebar
|
|
24
|
-
* labels={{
|
|
25
|
-
* title: "Your Assistant",
|
|
26
|
-
* initial: "Hi! 👋 How can I assist you today?",
|
|
27
|
-
* }}
|
|
28
|
-
* >
|
|
29
|
-
* <YourApp/>
|
|
30
|
-
* </CopilotSidebar>
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* ### Look & Feel
|
|
34
|
-
*
|
|
35
|
-
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
|
|
36
|
-
* ```tsx title="YourRootComponent.tsx"
|
|
37
|
-
* ...
|
|
38
|
-
* import "@copilotkit/react-ui/styles.css"; // [!code highlight]
|
|
39
|
-
*
|
|
40
|
-
* export function YourRootComponent() {
|
|
41
|
-
* return (
|
|
42
|
-
* <CopilotKit>
|
|
43
|
-
* ...
|
|
44
|
-
* </CopilotKit>
|
|
45
|
-
* );
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
* For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.
|
|
49
|
-
*/
|
|
50
|
-
import React, { useState } from "react";
|
|
51
|
-
import { CopilotModal, CopilotModalProps } from "./Modal";
|
|
52
|
-
|
|
53
|
-
export function CopilotSidebar(props: CopilotModalProps) {
|
|
54
|
-
props = {
|
|
55
|
-
...props,
|
|
56
|
-
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar",
|
|
57
|
-
};
|
|
58
|
-
const [expandedClassName, setExpandedClassName] = useState(
|
|
59
|
-
props.defaultOpen ? "sidebarExpanded" : "",
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const onSetOpen = (open: boolean) => {
|
|
63
|
-
props.onSetOpen?.(open);
|
|
64
|
-
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<div className={`copilotKitSidebarContentWrapper ${expandedClassName}`}>
|
|
69
|
-
<CopilotModal {...props} {...{ onSetOpen }}>
|
|
70
|
-
{props.children}
|
|
71
|
-
</CopilotModal>
|
|
72
|
-
</div>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CopilotContextParams,
|
|
3
|
-
extract,
|
|
4
|
-
CopilotChatSuggestionConfiguration,
|
|
5
|
-
CopilotMessagesContextParams,
|
|
6
|
-
} from "@copilotkit/react-core";
|
|
7
|
-
import { SmallSpinnerIcon } from "./Icons";
|
|
8
|
-
import { CopilotChatSuggestion } from "../../types/suggestions";
|
|
9
|
-
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
10
|
-
import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
|
|
11
|
-
|
|
12
|
-
interface SuggestionsProps {
|
|
13
|
-
title: string;
|
|
14
|
-
message: string;
|
|
15
|
-
partial?: boolean;
|
|
16
|
-
className?: string;
|
|
17
|
-
onClick: () => void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function Suggestion({ title, onClick, partial, className }: SuggestionsProps) {
|
|
21
|
-
return (
|
|
22
|
-
<button
|
|
23
|
-
disabled={partial}
|
|
24
|
-
onClick={(e) => {
|
|
25
|
-
e.preventDefault();
|
|
26
|
-
onClick();
|
|
27
|
-
}}
|
|
28
|
-
className={className || (partial ? "suggestion loading" : "suggestion")}
|
|
29
|
-
data-test-id="suggestion"
|
|
30
|
-
>
|
|
31
|
-
{partial ? SmallSpinnerIcon : <span>{title}</span>}
|
|
32
|
-
</button>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const reloadSuggestions = async (
|
|
37
|
-
context: CopilotContextParams & CopilotMessagesContextParams,
|
|
38
|
-
chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },
|
|
39
|
-
setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,
|
|
40
|
-
abortControllerRef: React.MutableRefObject<AbortController | null>,
|
|
41
|
-
) => {
|
|
42
|
-
const abortController = abortControllerRef.current;
|
|
43
|
-
|
|
44
|
-
const tools = JSON.stringify(
|
|
45
|
-
Object.values(context.actions).map((action) => ({
|
|
46
|
-
name: action.name,
|
|
47
|
-
description: action.description,
|
|
48
|
-
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),
|
|
49
|
-
})),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const allSuggestions: CopilotChatSuggestion[] = [];
|
|
53
|
-
|
|
54
|
-
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
55
|
-
try {
|
|
56
|
-
const numOfSuggestionsInstructions =
|
|
57
|
-
config.minSuggestions === 0
|
|
58
|
-
? `Produce up to ${config.maxSuggestions} suggestions. ` +
|
|
59
|
-
`If there are no highly relevant suggestions you can think of, provide an empty array.`
|
|
60
|
-
: `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;
|
|
61
|
-
|
|
62
|
-
const result = await extract({
|
|
63
|
-
context,
|
|
64
|
-
instructions:
|
|
65
|
-
"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
66
|
-
data:
|
|
67
|
-
config.instructions +
|
|
68
|
-
"\n\n" +
|
|
69
|
-
numOfSuggestionsInstructions +
|
|
70
|
-
"\n\n" +
|
|
71
|
-
"Available tools: " +
|
|
72
|
-
tools +
|
|
73
|
-
"\n\n",
|
|
74
|
-
requestType: CopilotRequestType.Task,
|
|
75
|
-
parameters: [
|
|
76
|
-
{
|
|
77
|
-
name: "suggestions",
|
|
78
|
-
type: "object[]",
|
|
79
|
-
attributes: [
|
|
80
|
-
{
|
|
81
|
-
name: "title",
|
|
82
|
-
description:
|
|
83
|
-
"The title of the suggestion. This is shown as a button and should be short.",
|
|
84
|
-
type: "string",
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: "message",
|
|
88
|
-
description:
|
|
89
|
-
"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.",
|
|
90
|
-
type: "string",
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
include: {
|
|
96
|
-
messages: true,
|
|
97
|
-
readable: true,
|
|
98
|
-
},
|
|
99
|
-
abortSignal: abortController?.signal,
|
|
100
|
-
stream: ({ status, args }) => {
|
|
101
|
-
const suggestions = args.suggestions || [];
|
|
102
|
-
const newSuggestions: CopilotChatSuggestion[] = [];
|
|
103
|
-
for (let i = 0; i < suggestions.length; i++) {
|
|
104
|
-
// if GPT provides too many suggestions, limit the number of suggestions
|
|
105
|
-
if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
const { title, message } = suggestions[i];
|
|
109
|
-
|
|
110
|
-
// If this is the last suggestion and the status is not complete, mark it as partial
|
|
111
|
-
const partial = i == suggestions.length - 1 && status !== "complete";
|
|
112
|
-
|
|
113
|
-
newSuggestions.push({
|
|
114
|
-
title,
|
|
115
|
-
message,
|
|
116
|
-
partial,
|
|
117
|
-
className: config.className,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
setCurrentSuggestions([...allSuggestions, ...newSuggestions]);
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
allSuggestions.push(...result.suggestions);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.error("Error loading suggestions", error);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (abortControllerRef.current === abortController) {
|
|
130
|
-
abortControllerRef.current = null;
|
|
131
|
-
}
|
|
132
|
-
};
|