@copilotkit/react-ui 1.10.0-next.1 → 1.10.0-next.11
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/CHANGELOG.md +112 -0
- package/dist/{chunk-O7KTFUAN.mjs → chunk-226ZMOE3.mjs} +2 -2
- package/dist/{chunk-WHDNKXMP.mjs → chunk-BJHJBS5M.mjs} +46 -6
- package/dist/chunk-BJHJBS5M.mjs.map +1 -0
- package/dist/{chunk-FOSKS7AI.mjs → chunk-FFJHOZX6.mjs} +5 -5
- package/dist/{chunk-QELAC6XJ.mjs → chunk-GBP47ONN.mjs} +2 -2
- package/dist/chunk-GBP47ONN.mjs.map +1 -0
- package/dist/{chunk-7CAK2CNK.mjs → chunk-GDSZGYCE.mjs} +2 -2
- package/dist/{chunk-O7PYQO73.mjs → chunk-GJ4SX4JE.mjs} +153 -37
- package/dist/chunk-GJ4SX4JE.mjs.map +1 -0
- package/dist/{chunk-TCIZDWPC.mjs → chunk-J5ZZR6YB.mjs} +2 -2
- package/dist/chunk-J5ZZR6YB.mjs.map +1 -0
- package/dist/{chunk-QN7T3GWI.mjs → chunk-JY2CSDKN.mjs} +4 -6
- package/dist/chunk-JY2CSDKN.mjs.map +1 -0
- package/dist/chunk-MIVUCSGO.mjs +126 -0
- package/dist/chunk-MIVUCSGO.mjs.map +1 -0
- package/dist/{chunk-OQM7D3Z3.mjs → chunk-T5QU6KSB.mjs} +8 -4
- package/dist/chunk-T5QU6KSB.mjs.map +1 -0
- package/dist/{chunk-Q2467VHZ.mjs → chunk-W26XFBEG.mjs} +2 -2
- package/dist/chunk-W26XFBEG.mjs.map +1 -0
- package/dist/chunk-Y44VLEUH.mjs +222 -0
- package/dist/chunk-Y44VLEUH.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +52 -15
- package/dist/components/chat/Chat.js +1136 -869
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +9 -8
- package/dist/components/chat/Header.js +6 -8
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +4 -4
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +984 -23
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +9 -1
- package/dist/components/chat/Modal.d.ts +2 -2
- package/dist/components/chat/Modal.js +1267 -931
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +14 -13
- package/dist/components/chat/Popup.d.ts +1 -1
- package/dist/components/chat/Popup.js +1269 -933
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +15 -14
- package/dist/components/chat/Sidebar.d.ts +1 -1
- package/dist/components/chat/Sidebar.js +1269 -933
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +15 -14
- package/dist/components/chat/Suggestion.js +1 -1
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +1 -1
- package/dist/components/chat/Suggestions.js +1 -1
- package/dist/components/chat/Suggestions.js.map +1 -1
- package/dist/components/chat/Suggestions.mjs +2 -2
- package/dist/components/chat/index.d.ts +2 -2
- package/dist/components/chat/index.js +1271 -935
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +22 -21
- package/dist/components/chat/messages/LegacyRenderMessage.d.ts +28 -0
- package/dist/components/chat/messages/LegacyRenderMessage.js +980 -0
- package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -0
- package/dist/components/chat/messages/LegacyRenderMessage.mjs +17 -0
- package/dist/components/chat/messages/LegacyRenderMessage.mjs.map +1 -0
- package/dist/components/chat/messages/RenderMessage.js +4 -0
- package/dist/components/chat/messages/RenderMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderMessage.mjs +2 -2
- package/dist/components/chat/props.d.ts +94 -2
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/dev-console/console.d.ts +1 -0
- package/dist/components/dev-console/console.js +6 -8
- package/dist/components/dev-console/console.js.map +1 -1
- package/dist/components/dev-console/console.mjs +3 -3
- package/dist/components/dev-console/index.d.ts +1 -3
- package/dist/components/dev-console/index.js +7 -9
- package/dist/components/dev-console/index.js.map +1 -1
- package/dist/components/dev-console/index.mjs +5 -5
- package/dist/components/dev-console/utils.d.ts +2 -2
- package/dist/components/dev-console/utils.js +2 -4
- package/dist/components/dev-console/utils.js.map +1 -1
- package/dist/components/dev-console/utils.mjs +1 -1
- package/dist/components/index.d.ts +3 -5
- package/dist/components/index.js +1272 -936
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +24 -23
- package/dist/index.d.ts +3 -5
- package/dist/index.js +1303 -967
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -23
- package/package.json +6 -6
- package/src/components/chat/Chat.tsx +241 -23
- package/src/components/chat/Messages.tsx +58 -5
- package/src/components/chat/Modal.tsx +128 -41
- package/src/components/chat/Popup.tsx +20 -0
- package/src/components/chat/Sidebar.tsx +22 -0
- package/src/components/chat/Suggestion.tsx +1 -1
- package/src/components/chat/messages/LegacyRenderMessage.tsx +143 -0
- package/src/components/chat/messages/RenderMessage.tsx +3 -0
- package/src/components/chat/props.ts +110 -1
- package/src/components/dev-console/utils.ts +1 -6
- package/dist/chunk-7RNOT3GM.mjs +0 -144
- package/dist/chunk-7RNOT3GM.mjs.map +0 -1
- package/dist/chunk-O7PYQO73.mjs.map +0 -1
- package/dist/chunk-OQM7D3Z3.mjs.map +0 -1
- package/dist/chunk-Q2467VHZ.mjs.map +0 -1
- package/dist/chunk-QELAC6XJ.mjs.map +0 -1
- package/dist/chunk-QN7T3GWI.mjs.map +0 -1
- package/dist/chunk-TCIZDWPC.mjs.map +0 -1
- package/dist/chunk-WHDNKXMP.mjs.map +0 -1
- /package/dist/{chunk-O7KTFUAN.mjs.map → chunk-226ZMOE3.mjs.map} +0 -0
- /package/dist/{chunk-FOSKS7AI.mjs.map → chunk-FFJHOZX6.mjs.map} +0 -0
- /package/dist/{chunk-7CAK2CNK.mjs.map → chunk-GDSZGYCE.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,117 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 1.10.0-next.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.11
|
|
8
|
+
- @copilotkit/react-core@1.10.0-next.11
|
|
9
|
+
- @copilotkit/shared@1.10.0-next.11
|
|
10
|
+
|
|
11
|
+
## 1.10.0-next.10
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 6d1de58: - fix: address issues that would cause headless UI breaking changes in the next release
|
|
16
|
+
|
|
17
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
18
|
+
|
|
19
|
+
- fix: more fixes addressing breaking changes in new Headless UI
|
|
20
|
+
|
|
21
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
22
|
+
|
|
23
|
+
- chore: address linting issues
|
|
24
|
+
|
|
25
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
26
|
+
|
|
27
|
+
- chore: fixing branding and docs
|
|
28
|
+
|
|
29
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
30
|
+
|
|
31
|
+
- chore: more docs fixing
|
|
32
|
+
|
|
33
|
+
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [6d1de58]
|
|
36
|
+
- @copilotkit/react-core@1.10.0-next.10
|
|
37
|
+
- @copilotkit/shared@1.10.0-next.10
|
|
38
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.10
|
|
39
|
+
|
|
40
|
+
## 1.10.0-next.9
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- 2354be4: - feat(chat): implement custom error handling in CopilotChat and Modal components
|
|
45
|
+
|
|
46
|
+
- Added `renderError` prop to `CopilotChat` for inline error rendering.
|
|
47
|
+
- Introduced `triggerChatError` function to manage chat-specific errors and observability hooks.
|
|
48
|
+
- Updated `Modal` to handle observability hooks with public API key checks.
|
|
49
|
+
- Enhanced `CopilotObservabilityHooks` interface to include `onError` for error event handling.
|
|
50
|
+
- @copilotkit/react-core@1.10.0-next.9
|
|
51
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.9
|
|
52
|
+
- @copilotkit/shared@1.10.0-next.9
|
|
53
|
+
|
|
54
|
+
## 1.10.0-next.8
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [6de24ce]
|
|
59
|
+
- @copilotkit/react-core@1.10.0-next.8
|
|
60
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.8
|
|
61
|
+
- @copilotkit/shared@1.10.0-next.8
|
|
62
|
+
|
|
63
|
+
## 1.10.0-next.7
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.7
|
|
68
|
+
- @copilotkit/react-core@1.10.0-next.7
|
|
69
|
+
- @copilotkit/shared@1.10.0-next.7
|
|
70
|
+
|
|
71
|
+
## 1.10.0-next.6
|
|
72
|
+
|
|
73
|
+
### Patch Changes
|
|
74
|
+
|
|
75
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.6
|
|
76
|
+
- @copilotkit/react-core@1.10.0-next.6
|
|
77
|
+
- @copilotkit/shared@1.10.0-next.6
|
|
78
|
+
|
|
79
|
+
## 1.10.0-next.5
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- a8c0263: - feat: add event hooks system for chat components
|
|
84
|
+
- Updated dependencies [a8c0263]
|
|
85
|
+
- @copilotkit/shared@1.10.0-next.5
|
|
86
|
+
- @copilotkit/react-core@1.10.0-next.5
|
|
87
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.5
|
|
88
|
+
|
|
89
|
+
## 1.10.0-next.4
|
|
90
|
+
|
|
91
|
+
### Patch Changes
|
|
92
|
+
|
|
93
|
+
- 967d0ab: - refactor(chat): separate useCopilotChat into internal implementation and public API
|
|
94
|
+
- Updated dependencies [967d0ab]
|
|
95
|
+
- @copilotkit/react-core@1.10.0-next.4
|
|
96
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.4
|
|
97
|
+
- @copilotkit/shared@1.10.0-next.4
|
|
98
|
+
|
|
99
|
+
## 1.10.0-next.3
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.3
|
|
104
|
+
- @copilotkit/react-core@1.10.0-next.3
|
|
105
|
+
- @copilotkit/shared@1.10.0-next.3
|
|
106
|
+
|
|
107
|
+
## 1.10.0-next.2
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- @copilotkit/runtime-client-gql@1.10.0-next.2
|
|
112
|
+
- @copilotkit/react-core@1.10.0-next.2
|
|
113
|
+
- @copilotkit/shared@1.10.0-next.2
|
|
114
|
+
|
|
3
115
|
## 1.10.0-next.1
|
|
4
116
|
|
|
5
117
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Suggestion
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-W26XFBEG.mjs";
|
|
4
4
|
|
|
5
5
|
// src/components/chat/Suggestions.tsx
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -21,4 +21,4 @@ function Suggestions({ suggestions, onSuggestionClick }) {
|
|
|
21
21
|
export {
|
|
22
22
|
Suggestions
|
|
23
23
|
};
|
|
24
|
-
//# sourceMappingURL=chunk-
|
|
24
|
+
//# sourceMappingURL=chunk-226ZMOE3.mjs.map
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LegacyRenderMessage
|
|
3
|
+
} from "./chunk-MIVUCSGO.mjs";
|
|
1
4
|
import {
|
|
2
5
|
useChatContext
|
|
3
6
|
} from "./chunk-IEMQ2SQW.mjs";
|
|
7
|
+
import {
|
|
8
|
+
__spreadProps,
|
|
9
|
+
__spreadValues
|
|
10
|
+
} from "./chunk-MRXNTQOX.mjs";
|
|
4
11
|
|
|
5
12
|
// src/components/chat/Messages.tsx
|
|
6
13
|
import { useEffect, useMemo, useRef } from "react";
|
|
7
|
-
import { useCopilotChat } from "@copilotkit/react-core";
|
|
14
|
+
import { useCopilotChatInternal as useCopilotChat } from "@copilotkit/react-core";
|
|
8
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
16
|
var Messages = ({
|
|
10
17
|
inProgress,
|
|
@@ -12,23 +19,55 @@ var Messages = ({
|
|
|
12
19
|
RenderMessage,
|
|
13
20
|
AssistantMessage,
|
|
14
21
|
UserMessage,
|
|
22
|
+
ImageRenderer,
|
|
15
23
|
onRegenerate,
|
|
16
24
|
onCopy,
|
|
17
25
|
onThumbsUp,
|
|
18
26
|
onThumbsDown,
|
|
19
|
-
markdownTagRenderers
|
|
27
|
+
markdownTagRenderers,
|
|
28
|
+
// Legacy props
|
|
29
|
+
RenderTextMessage,
|
|
30
|
+
RenderActionExecutionMessage,
|
|
31
|
+
RenderAgentStateMessage,
|
|
32
|
+
RenderResultMessage,
|
|
33
|
+
RenderImageMessage
|
|
20
34
|
}) => {
|
|
21
35
|
const { labels } = useChatContext();
|
|
22
|
-
const { visibleMessages, interrupt } = useCopilotChat();
|
|
36
|
+
const { messages: visibleMessages, interrupt } = useCopilotChat();
|
|
23
37
|
const initialMessages = useMemo(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
24
38
|
const messages = [...initialMessages, ...visibleMessages];
|
|
25
39
|
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
40
|
+
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (hasLegacyProps) {
|
|
43
|
+
console.warn(
|
|
44
|
+
"[CopilotKit] Legacy message render props (RenderTextMessage, RenderActionExecutionMessage, etc.) are deprecated. Please use the unified 'RenderMessage' prop instead. See migration guide: https://docs.copilotkit.ai/migration/render-message"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}, [hasLegacyProps]);
|
|
48
|
+
const legacyProps = useMemo(
|
|
49
|
+
() => ({
|
|
50
|
+
RenderTextMessage,
|
|
51
|
+
RenderActionExecutionMessage,
|
|
52
|
+
RenderAgentStateMessage,
|
|
53
|
+
RenderResultMessage,
|
|
54
|
+
RenderImageMessage
|
|
55
|
+
}),
|
|
56
|
+
[
|
|
57
|
+
RenderTextMessage,
|
|
58
|
+
RenderActionExecutionMessage,
|
|
59
|
+
RenderAgentStateMessage,
|
|
60
|
+
RenderResultMessage,
|
|
61
|
+
RenderImageMessage
|
|
62
|
+
]
|
|
63
|
+
);
|
|
64
|
+
const MessageRenderer = hasLegacyProps ? (props) => /* @__PURE__ */ jsx(LegacyRenderMessage, __spreadProps(__spreadValues({}, props), { legacyProps })) : RenderMessage;
|
|
26
65
|
return /* @__PURE__ */ jsxs("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
|
|
27
66
|
/* @__PURE__ */ jsxs("div", { className: "copilotKitMessagesContainer", children: [
|
|
28
67
|
messages.map((message, index) => {
|
|
29
68
|
const isCurrentMessage = index === messages.length - 1;
|
|
30
69
|
return /* @__PURE__ */ jsx(
|
|
31
|
-
|
|
70
|
+
MessageRenderer,
|
|
32
71
|
{
|
|
33
72
|
message,
|
|
34
73
|
inProgress,
|
|
@@ -36,6 +75,7 @@ var Messages = ({
|
|
|
36
75
|
isCurrentMessage,
|
|
37
76
|
AssistantMessage,
|
|
38
77
|
UserMessage,
|
|
78
|
+
ImageRenderer,
|
|
39
79
|
onRegenerate,
|
|
40
80
|
onCopy,
|
|
41
81
|
onThumbsUp,
|
|
@@ -65,7 +105,7 @@ function makeInitialMessages(initial) {
|
|
|
65
105
|
return [
|
|
66
106
|
{
|
|
67
107
|
id: initial,
|
|
68
|
-
role: "
|
|
108
|
+
role: "assistant",
|
|
69
109
|
content: initial
|
|
70
110
|
}
|
|
71
111
|
];
|
|
@@ -132,4 +172,4 @@ export {
|
|
|
132
172
|
Messages,
|
|
133
173
|
useScrollToBottom
|
|
134
174
|
};
|
|
135
|
-
//# sourceMappingURL=chunk-
|
|
175
|
+
//# sourceMappingURL=chunk-BJHJBS5M.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/Messages.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { MessagesProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport { Message } from \"@copilotkit/shared\";\nimport { useCopilotChatInternal as useCopilotChat } from \"@copilotkit/react-core\";\nimport { LegacyRenderMessage, LegacyRenderProps } from \"./messages/LegacyRenderMessage\";\n\nexport const Messages = ({\n inProgress,\n children,\n RenderMessage,\n AssistantMessage,\n UserMessage,\n ImageRenderer,\n onRegenerate,\n onCopy,\n onThumbsUp,\n onThumbsDown,\n markdownTagRenderers,\n\n // Legacy props\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n RenderImageMessage,\n}: MessagesProps) => {\n const { labels } = useChatContext();\n const { messages: visibleMessages, interrupt } = useCopilotChat();\n const initialMessages = useMemo(() => makeInitialMessages(labels.initial), [labels.initial]);\n const messages = [...initialMessages, ...visibleMessages];\n const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);\n\n // Check if any legacy props are provided\n const hasLegacyProps = !!(\n RenderTextMessage ||\n RenderActionExecutionMessage ||\n RenderAgentStateMessage ||\n RenderResultMessage ||\n RenderImageMessage\n );\n\n // Show deprecation warning if legacy props are used\n useEffect(() => {\n if (hasLegacyProps) {\n console.warn(\n \"[CopilotKit] Legacy message render props (RenderTextMessage, RenderActionExecutionMessage, etc.) are deprecated. \" +\n \"Please use the unified 'RenderMessage' prop instead. \" +\n \"See migration guide: https://docs.copilotkit.ai/migration/render-message\",\n );\n }\n }, [hasLegacyProps]);\n\n // Create legacy props object for the adapter\n const legacyProps: LegacyRenderProps = useMemo(\n () => ({\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n RenderImageMessage,\n }),\n [\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n RenderImageMessage,\n ],\n );\n\n // Determine which render component to use\n const MessageRenderer = hasLegacyProps\n ? (props: any) => <LegacyRenderMessage {...props} legacyProps={legacyProps} />\n : RenderMessage;\n\n return (\n <div className=\"copilotKitMessages\" ref={messagesContainerRef}>\n <div className=\"copilotKitMessagesContainer\">\n {messages.map((message, index) => {\n const isCurrentMessage = index === messages.length - 1;\n return (\n <MessageRenderer\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n AssistantMessage={AssistantMessage}\n UserMessage={UserMessage}\n ImageRenderer={ImageRenderer}\n onRegenerate={onRegenerate}\n onCopy={onCopy}\n onThumbsUp={onThumbsUp}\n onThumbsDown={onThumbsDown}\n markdownTagRenderers={markdownTagRenderers}\n />\n );\n })}\n {interrupt}\n </div>\n <footer className=\"copilotKitMessagesFooter\" ref={messagesEndRef}>\n {children}\n </footer>\n </div>\n );\n};\n\nfunction makeInitialMessages(initial: string | string[] | undefined): Message[] {\n if (!initial) return [];\n\n if (Array.isArray(initial)) {\n return initial.map((message) => {\n return {\n id: message,\n role: \"assistant\",\n content: message,\n };\n });\n }\n\n return [\n {\n id: initial,\n role: \"assistant\",\n content: initial,\n },\n ];\n}\n\nexport function useScrollToBottom(messages: Message[]) {\n const messagesEndRef = useRef<HTMLDivElement>(null);\n const messagesContainerRef = useRef<HTMLDivElement | null>(null);\n const isProgrammaticScrollRef = useRef(false);\n const isUserScrollUpRef = useRef(false);\n\n const scrollToBottom = () => {\n if (messagesContainerRef.current && messagesEndRef.current) {\n isProgrammaticScrollRef.current = true;\n messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;\n }\n };\n\n const handleScroll = () => {\n if (isProgrammaticScrollRef.current) {\n isProgrammaticScrollRef.current = false;\n return;\n }\n\n if (messagesContainerRef.current) {\n const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;\n isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;\n }\n };\n\n useEffect(() => {\n const container = messagesContainerRef.current;\n if (container) {\n container.addEventListener(\"scroll\", handleScroll);\n }\n return () => {\n if (container) {\n container.removeEventListener(\"scroll\", handleScroll);\n }\n };\n }, []);\n\n useEffect(() => {\n const container = messagesContainerRef.current;\n if (!container) {\n return;\n }\n\n const mutationObserver = new MutationObserver(() => {\n if (!isUserScrollUpRef.current) {\n scrollToBottom();\n }\n });\n\n mutationObserver.observe(container, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n return () => {\n mutationObserver.disconnect();\n };\n }, []);\n\n useEffect(() => {\n isUserScrollUpRef.current = false;\n scrollToBottom();\n }, [messages.filter((m) => m.role === \"user\").length]);\n\n return { messagesEndRef, messagesContainerRef };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,WAAW,SAAS,cAAc;AAI3C,SAAS,0BAA0B,sBAAsB;AAqEnC,cAKhB,YALgB;AAlEf,IAAM,WAAW,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAqB;AACnB,QAAM,EAAE,OAAO,IAAI,eAAe;AAClC,QAAM,EAAE,UAAU,iBAAiB,UAAU,IAAI,eAAe;AAChE,QAAM,kBAAkB,QAAQ,MAAM,oBAAoB,OAAO,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC;AAC3F,QAAM,WAAW,CAAC,GAAG,iBAAiB,GAAG,eAAe;AACxD,QAAM,EAAE,sBAAsB,eAAe,IAAI,kBAAkB,QAAQ;AAG3E,QAAM,iBAAiB,CAAC,EACtB,qBACA,gCACA,2BACA,uBACA;AAIF,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,cAAQ;AAAA,QACN;AAAA,MAGF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,cAAc,CAAC;AAGnB,QAAM,cAAiC;AAAA,IACrC,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,QAAM,kBAAkB,iBACpB,CAAC,UAAe,oBAAC,sDAAwB,QAAxB,EAA+B,cAA0B,IAC1E;AAEJ,SACE,qBAAC,SAAI,WAAU,sBAAqB,KAAK,sBACvC;AAAA,yBAAC,SAAI,WAAU,+BACZ;AAAA,eAAS,IAAI,CAAC,SAAS,UAAU;AAChC,cAAM,mBAAmB,UAAU,SAAS,SAAS;AACrD,eACE;AAAA,UAAC;AAAA;AAAA,YAEC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA;AAAA,UAZK;AAAA,QAaP;AAAA,MAEJ,CAAC;AAAA,MACA;AAAA,OACH;AAAA,IACA,oBAAC,YAAO,WAAU,4BAA2B,KAAK,gBAC/C,UACH;AAAA,KACF;AAEJ;AAEA,SAAS,oBAAoB,SAAmD;AAC9E,MAAI,CAAC;AAAS,WAAO,CAAC;AAEtB,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,QAAQ,IAAI,CAAC,YAAY;AAC9B,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,UAAqB;AACrD,QAAM,iBAAiB,OAAuB,IAAI;AAClD,QAAM,uBAAuB,OAA8B,IAAI;AAC/D,QAAM,0BAA0B,OAAO,KAAK;AAC5C,QAAM,oBAAoB,OAAO,KAAK;AAEtC,QAAM,iBAAiB,MAAM;AAC3B,QAAI,qBAAqB,WAAW,eAAe,SAAS;AAC1D,8BAAwB,UAAU;AAClC,2BAAqB,QAAQ,YAAY,qBAAqB,QAAQ;AAAA,IACxE;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AACzB,QAAI,wBAAwB,SAAS;AACnC,8BAAwB,UAAU;AAClC;AAAA,IACF;AAEA,QAAI,qBAAqB,SAAS;AAChC,YAAM,EAAE,WAAW,cAAc,aAAa,IAAI,qBAAqB;AACvE,wBAAkB,UAAU,YAAY,eAAe;AAAA,IACzD;AAAA,EACF;AAEA,YAAU,MAAM;AACd,UAAM,YAAY,qBAAqB;AACvC,QAAI,WAAW;AACb,gBAAU,iBAAiB,UAAU,YAAY;AAAA,IACnD;AACA,WAAO,MAAM;AACX,UAAI,WAAW;AACb,kBAAU,oBAAoB,UAAU,YAAY;AAAA,MACtD;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,UAAM,YAAY,qBAAqB;AACvC,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEA,UAAM,mBAAmB,IAAI,iBAAiB,MAAM;AAClD,UAAI,CAAC,kBAAkB,SAAS;AAC9B,uBAAe;AAAA,MACjB;AAAA,IACF,CAAC;AAED,qBAAiB,QAAQ,WAAW;AAAA,MAClC,WAAW;AAAA,MACX,SAAS;AAAA,MACT,eAAe;AAAA,IACjB,CAAC;AAED,WAAO,MAAM;AACX,uBAAiB,WAAW;AAAA,IAC9B;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,sBAAkB,UAAU;AAC5B,mBAAe;AAAA,EACjB,GAAG,CAAC,SAAS,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,MAAM,CAAC;AAErD,SAAO,EAAE,gBAAgB,qBAAqB;AAChD;","names":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CopilotKitHelpModal
|
|
3
|
-
} from "./chunk-NRA3CFEE.mjs";
|
|
4
1
|
import {
|
|
5
2
|
CheckIcon,
|
|
6
3
|
ChevronDownIcon,
|
|
@@ -13,7 +10,10 @@ import {
|
|
|
13
10
|
logMessages,
|
|
14
11
|
logReadables,
|
|
15
12
|
shouldShowDevConsole
|
|
16
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-JY2CSDKN.mjs";
|
|
14
|
+
import {
|
|
15
|
+
CopilotKitHelpModal
|
|
16
|
+
} from "./chunk-NRA3CFEE.mjs";
|
|
17
17
|
import {
|
|
18
18
|
SmallSpinnerIcon
|
|
19
19
|
} from "./chunk-XWG3L6QC.mjs";
|
|
@@ -199,4 +199,4 @@ export {
|
|
|
199
199
|
CopilotDevConsole,
|
|
200
200
|
DebugMenuButton
|
|
201
201
|
};
|
|
202
|
-
//# sourceMappingURL=chunk-
|
|
202
|
+
//# sourceMappingURL=chunk-FFJHOZX6.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Y44VLEUH.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__spreadProps,
|
|
6
6
|
__spreadValues
|
|
@@ -27,4 +27,4 @@ function CopilotSidebar(props) {
|
|
|
27
27
|
export {
|
|
28
28
|
CopilotSidebar
|
|
29
29
|
};
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
30
|
+
//# sourceMappingURL=chunk-GBP47ONN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/Sidebar.tsx"],"sourcesContent":["/**\n * <br/>\n * <img src=\"https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotSidebar.gif\" width=\"500\" />\n *\n * A chatbot sidebar component for the CopilotKit framework. Highly customizable through various props and custom CSS.\n *\n * See [CopilotPopup](/reference/components/chat/CopilotPopup) for a popup version of this component.\n *\n * ## Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ## Usage\n *\n * ```tsx\n * import { CopilotSidebar } from \"@copilotkit/react-ui\";\n * import \"@copilotkit/react-ui/styles.css\";\n *\n * <CopilotSidebar\n * labels={{\n * title: \"Your Assistant\",\n * initial: \"Hi! 👋 How can I assist you today?\",\n * }}\n * >\n * <YourApp/>\n * </CopilotSidebar>\n * ```\n *\n * ### With Observability Hooks\n *\n * To monitor user interactions, provide the `observabilityHooks` prop.\n * **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.\n *\n * ```tsx\n * <CopilotKit publicApiKey=\"YOUR_PUBLIC_API_KEY\">\n * <CopilotSidebar\n * observabilityHooks={{\n * onChatExpanded: () => {\n * console.log(\"Sidebar opened\");\n * },\n * onChatMinimized: () => {\n * console.log(\"Sidebar closed\");\n * },\n * }}\n * >\n * <YourApp/>\n * </CopilotSidebar>\n * </CopilotKit>\n * ```\n *\n * ### Look & Feel\n *\n * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:\n * ```tsx title=\"YourRootComponent.tsx\"\n * ...\n * import \"@copilotkit/react-ui/styles.css\"; // [!code highlight]\n *\n * export function YourRootComponent() {\n * return (\n * <CopilotKit>\n * ...\n * </CopilotKit>\n * );\n * }\n * ```\n * 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.\n */\nimport React, { useState } from \"react\";\nimport { CopilotModal, CopilotModalProps } from \"./Modal\";\n\nexport function CopilotSidebar(props: CopilotModalProps) {\n props = {\n ...props,\n className: props.className ? props.className + \" copilotKitSidebar\" : \"copilotKitSidebar\",\n };\n const [expandedClassName, setExpandedClassName] = useState(\n props.defaultOpen ? \"sidebarExpanded\" : \"\",\n );\n\n const onSetOpen = (open: boolean) => {\n props.onSetOpen?.(open);\n setExpandedClassName(open ? \"sidebarExpanded\" : \"\");\n };\n\n return (\n <div className={`copilotKitSidebarContentWrapper ${expandedClassName}`}>\n <CopilotModal {...props} {...{ onSetOpen }}>\n {props.children}\n </CopilotModal>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAuEA,SAAgB,gBAAgB;AAmB1B;AAhBC,SAAS,eAAe,OAA0B;AACvD,UAAQ,iCACH,QADG;AAAA,IAEN,WAAW,MAAM,YAAY,MAAM,YAAY,uBAAuB;AAAA,EACxE;AACA,QAAM,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,MAAM,cAAc,oBAAoB;AAAA,EAC1C;AAEA,QAAM,YAAY,CAAC,SAAkB;AAnFvC;AAoFI,gBAAM,cAAN,+BAAkB;AAClB,yBAAqB,OAAO,oBAAoB,EAAE;AAAA,EACpD;AAEA,SACE,oBAAC,SAAI,WAAW,mCAAmC,qBACjD,8BAAC,8DAAiB,QAAW,EAAE,UAAU,IAAxC,EACE,gBAAM,WACT,GACF;AAEJ;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotDevConsole
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FFJHOZX6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useChatContext
|
|
6
6
|
} from "./chunk-IEMQ2SQW.mjs";
|
|
@@ -29,4 +29,4 @@ var Header = ({}) => {
|
|
|
29
29
|
export {
|
|
30
30
|
Header
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-GDSZGYCE.mjs.map
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RenderMessage
|
|
3
|
-
} from "./chunk-OQM7D3Z3.mjs";
|
|
4
|
-
import {
|
|
5
|
-
UserMessage
|
|
6
|
-
} from "./chunk-VVL6JFCJ.mjs";
|
|
7
|
-
import {
|
|
8
|
-
AssistantMessage
|
|
9
|
-
} from "./chunk-GCKKSSBU.mjs";
|
|
10
|
-
import {
|
|
11
|
-
ImageRenderer
|
|
12
|
-
} from "./chunk-DBKRAOH7.mjs";
|
|
13
1
|
import {
|
|
14
2
|
Suggestions
|
|
15
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-226ZMOE3.mjs";
|
|
16
4
|
import {
|
|
17
5
|
ImageUploadQueue
|
|
18
6
|
} from "./chunk-PLHTVHUW.mjs";
|
|
@@ -21,7 +9,19 @@ import {
|
|
|
21
9
|
} from "./chunk-DTRPPNSA.mjs";
|
|
22
10
|
import {
|
|
23
11
|
Messages
|
|
24
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-BJHJBS5M.mjs";
|
|
13
|
+
import {
|
|
14
|
+
RenderMessage
|
|
15
|
+
} from "./chunk-T5QU6KSB.mjs";
|
|
16
|
+
import {
|
|
17
|
+
AssistantMessage
|
|
18
|
+
} from "./chunk-GCKKSSBU.mjs";
|
|
19
|
+
import {
|
|
20
|
+
ImageRenderer
|
|
21
|
+
} from "./chunk-DBKRAOH7.mjs";
|
|
22
|
+
import {
|
|
23
|
+
UserMessage
|
|
24
|
+
} from "./chunk-VVL6JFCJ.mjs";
|
|
25
25
|
import {
|
|
26
26
|
ChatContext,
|
|
27
27
|
ChatContextProvider
|
|
@@ -35,10 +35,17 @@ import {
|
|
|
35
35
|
// src/components/chat/Chat.tsx
|
|
36
36
|
import React, { useEffect, useRef, useState, useCallback, useMemo } from "react";
|
|
37
37
|
import {
|
|
38
|
-
useCopilotChat,
|
|
38
|
+
useCopilotChatInternal as useCopilotChat,
|
|
39
39
|
useCopilotContext,
|
|
40
40
|
useCopilotMessagesContext
|
|
41
41
|
} from "@copilotkit/react-core";
|
|
42
|
+
import {
|
|
43
|
+
CopilotKitError,
|
|
44
|
+
CopilotKitErrorCode,
|
|
45
|
+
Severity,
|
|
46
|
+
ErrorVisibility,
|
|
47
|
+
styledConsole
|
|
48
|
+
} from "@copilotkit/shared";
|
|
42
49
|
import { randomId } from "@copilotkit/shared";
|
|
43
50
|
import { runAgent, stopAgent } from "@copilotkit/react-core";
|
|
44
51
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -67,11 +74,83 @@ function CopilotChat({
|
|
|
67
74
|
ImageRenderer: ImageRenderer2 = ImageRenderer,
|
|
68
75
|
imageUploadsEnabled,
|
|
69
76
|
inputFileAccept = "image/*",
|
|
70
|
-
hideStopButton
|
|
77
|
+
hideStopButton,
|
|
78
|
+
observabilityHooks,
|
|
79
|
+
renderError,
|
|
80
|
+
// Legacy props - deprecated
|
|
81
|
+
RenderTextMessage,
|
|
82
|
+
RenderActionExecutionMessage,
|
|
83
|
+
RenderAgentStateMessage,
|
|
84
|
+
RenderResultMessage,
|
|
85
|
+
RenderImageMessage
|
|
71
86
|
}) {
|
|
72
|
-
const { additionalInstructions, setChatInstructions } = useCopilotContext();
|
|
87
|
+
const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = useCopilotContext();
|
|
88
|
+
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
73
89
|
const [selectedImages, setSelectedImages] = useState([]);
|
|
90
|
+
const [chatError, setChatError] = useState(null);
|
|
74
91
|
const fileInputRef = useRef(null);
|
|
92
|
+
const triggerObservabilityHook = useCallback(
|
|
93
|
+
(hookName, ...args) => {
|
|
94
|
+
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
95
|
+
observabilityHooks[hookName](...args);
|
|
96
|
+
}
|
|
97
|
+
if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
|
|
98
|
+
setBannerError(
|
|
99
|
+
new CopilotKitError({
|
|
100
|
+
message: "observabilityHooks requires a publicApiKey to function.",
|
|
101
|
+
code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
102
|
+
severity: Severity.CRITICAL,
|
|
103
|
+
visibility: ErrorVisibility.BANNER
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
[publicApiKey, observabilityHooks, setBannerError]
|
|
110
|
+
);
|
|
111
|
+
const triggerChatError = useCallback(
|
|
112
|
+
(error, operation, originalError) => {
|
|
113
|
+
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
114
|
+
setChatError({
|
|
115
|
+
message: errorMessage,
|
|
116
|
+
operation,
|
|
117
|
+
timestamp: Date.now()
|
|
118
|
+
});
|
|
119
|
+
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks.onError)) {
|
|
120
|
+
const errorEvent = {
|
|
121
|
+
type: "error",
|
|
122
|
+
timestamp: Date.now(),
|
|
123
|
+
context: {
|
|
124
|
+
source: "ui",
|
|
125
|
+
request: {
|
|
126
|
+
operation,
|
|
127
|
+
url: chatApiEndpoint,
|
|
128
|
+
startTime: Date.now()
|
|
129
|
+
},
|
|
130
|
+
technical: {
|
|
131
|
+
environment: "browser",
|
|
132
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
133
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
error
|
|
137
|
+
};
|
|
138
|
+
observabilityHooks.onError(errorEvent);
|
|
139
|
+
}
|
|
140
|
+
if ((observabilityHooks == null ? void 0 : observabilityHooks.onError) && !publicApiKey) {
|
|
141
|
+
setBannerError(
|
|
142
|
+
new CopilotKitError({
|
|
143
|
+
message: "observabilityHooks.onError requires a publicApiKey to function.",
|
|
144
|
+
code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
145
|
+
severity: Severity.CRITICAL,
|
|
146
|
+
visibility: ErrorVisibility.BANNER
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
styledConsole.publicApiKeyRequired("observabilityHooks.onError");
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
153
|
+
);
|
|
75
154
|
useEffect(() => {
|
|
76
155
|
if (!imageUploadsEnabled)
|
|
77
156
|
return;
|
|
@@ -111,12 +190,13 @@ function CopilotChat({
|
|
|
111
190
|
const loadedImages = (yield Promise.all(imagePromises)).filter((img) => img !== null);
|
|
112
191
|
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
113
192
|
} catch (error) {
|
|
193
|
+
triggerChatError(error, "processClipboardImages", error);
|
|
114
194
|
console.error("Error processing pasted images:", error);
|
|
115
195
|
}
|
|
116
196
|
});
|
|
117
197
|
document.addEventListener("paste", handlePaste);
|
|
118
198
|
return () => document.removeEventListener("paste", handlePaste);
|
|
119
|
-
}, [imageUploadsEnabled]);
|
|
199
|
+
}, [imageUploadsEnabled, triggerChatError]);
|
|
120
200
|
useEffect(() => {
|
|
121
201
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
122
202
|
setChatInstructions(instructions || "");
|
|
@@ -130,7 +210,7 @@ function CopilotChat({
|
|
|
130
210
|
setChatInstructions(combinedAdditionalInstructions.join("\n") || "");
|
|
131
211
|
}, [instructions, additionalInstructions]);
|
|
132
212
|
const {
|
|
133
|
-
|
|
213
|
+
messages,
|
|
134
214
|
isLoading,
|
|
135
215
|
sendMessage,
|
|
136
216
|
stopGeneration,
|
|
@@ -144,12 +224,24 @@ function CopilotChat({
|
|
|
144
224
|
onStopGeneration,
|
|
145
225
|
onReloadMessages
|
|
146
226
|
);
|
|
227
|
+
const prevIsLoading = useRef(isLoading);
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (prevIsLoading.current !== isLoading) {
|
|
230
|
+
if (isLoading) {
|
|
231
|
+
triggerObservabilityHook("onChatStarted");
|
|
232
|
+
} else {
|
|
233
|
+
triggerObservabilityHook("onChatStopped");
|
|
234
|
+
}
|
|
235
|
+
prevIsLoading.current = isLoading;
|
|
236
|
+
}
|
|
237
|
+
}, [isLoading, triggerObservabilityHook]);
|
|
147
238
|
const handleSendMessage = (text) => {
|
|
148
239
|
const images = selectedImages;
|
|
149
240
|
setSelectedImages([]);
|
|
150
241
|
if (fileInputRef.current) {
|
|
151
242
|
fileInputRef.current.value = "";
|
|
152
243
|
}
|
|
244
|
+
triggerObservabilityHook("onMessageSent", text);
|
|
153
245
|
return sendMessage(text, images);
|
|
154
246
|
};
|
|
155
247
|
const chatContext = React.useContext(ChatContext);
|
|
@@ -158,12 +250,14 @@ function CopilotChat({
|
|
|
158
250
|
if (onRegenerate) {
|
|
159
251
|
onRegenerate(messageId);
|
|
160
252
|
}
|
|
253
|
+
triggerObservabilityHook("onMessageRegenerated", messageId);
|
|
161
254
|
reloadMessages(messageId);
|
|
162
255
|
};
|
|
163
256
|
const handleCopy = (message) => {
|
|
164
257
|
if (onCopy) {
|
|
165
258
|
onCopy(message);
|
|
166
259
|
}
|
|
260
|
+
triggerObservabilityHook("onMessageCopied", message);
|
|
167
261
|
};
|
|
168
262
|
const handleImageUpload = (event) => __async(this, null, function* () {
|
|
169
263
|
if (!event.target.files || event.target.files.length === 0) {
|
|
@@ -193,27 +287,51 @@ function CopilotChat({
|
|
|
193
287
|
const loadedImages = yield Promise.all(fileReadPromises);
|
|
194
288
|
setSelectedImages((prev) => [...prev, ...loadedImages]);
|
|
195
289
|
} catch (error) {
|
|
290
|
+
triggerChatError(error, "processUploadedImages", error);
|
|
196
291
|
console.error("Error reading files:", error);
|
|
197
292
|
}
|
|
198
293
|
});
|
|
199
294
|
const removeSelectedImage = (index) => {
|
|
200
295
|
setSelectedImages((prev) => prev.filter((_, i) => i !== index));
|
|
201
296
|
};
|
|
297
|
+
const handleThumbsUp = (message) => {
|
|
298
|
+
if (onThumbsUp) {
|
|
299
|
+
onThumbsUp(message);
|
|
300
|
+
}
|
|
301
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
|
|
302
|
+
};
|
|
303
|
+
const handleThumbsDown = (message) => {
|
|
304
|
+
if (onThumbsDown) {
|
|
305
|
+
onThumbsDown(message);
|
|
306
|
+
}
|
|
307
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
|
|
308
|
+
};
|
|
202
309
|
return /* @__PURE__ */ jsxs(WrappedCopilotChat, { icons, labels, className, children: [
|
|
310
|
+
chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
|
|
311
|
+
onDismiss: () => setChatError(null),
|
|
312
|
+
onRetry: () => {
|
|
313
|
+
setChatError(null);
|
|
314
|
+
}
|
|
315
|
+
})),
|
|
203
316
|
/* @__PURE__ */ jsx(
|
|
204
317
|
Messages2,
|
|
205
318
|
{
|
|
206
319
|
AssistantMessage: AssistantMessage2,
|
|
207
320
|
UserMessage: UserMessage2,
|
|
208
321
|
RenderMessage: RenderMessage2,
|
|
209
|
-
messages
|
|
322
|
+
messages,
|
|
210
323
|
inProgress: isLoading,
|
|
211
324
|
onRegenerate: handleRegenerate,
|
|
212
325
|
onCopy: handleCopy,
|
|
213
|
-
onThumbsUp,
|
|
214
|
-
onThumbsDown,
|
|
326
|
+
onThumbsUp: handleThumbsUp,
|
|
327
|
+
onThumbsDown: handleThumbsDown,
|
|
215
328
|
markdownTagRenderers,
|
|
216
329
|
ImageRenderer: ImageRenderer2,
|
|
330
|
+
RenderTextMessage,
|
|
331
|
+
RenderActionExecutionMessage,
|
|
332
|
+
RenderAgentStateMessage,
|
|
333
|
+
RenderResultMessage,
|
|
334
|
+
RenderImageMessage,
|
|
217
335
|
children: currentSuggestions.length > 0 && /* @__PURE__ */ jsx(
|
|
218
336
|
RenderSuggestionsList,
|
|
219
337
|
{
|
|
@@ -269,8 +387,8 @@ function WrappedCopilotChat({
|
|
|
269
387
|
var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
|
|
270
388
|
var _a;
|
|
271
389
|
const {
|
|
272
|
-
|
|
273
|
-
|
|
390
|
+
messages,
|
|
391
|
+
sendMessage,
|
|
274
392
|
setMessages,
|
|
275
393
|
reloadMessages: defaultReloadMessages,
|
|
276
394
|
stopGeneration: defaultStopGeneration,
|
|
@@ -316,12 +434,12 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
316
434
|
if (Object.keys(generalContext.chatSuggestionConfiguration).length === 0) {
|
|
317
435
|
return;
|
|
318
436
|
}
|
|
319
|
-
if (
|
|
437
|
+
if (messages.length === 0 && !hasGeneratedInitialSuggestions.current) {
|
|
320
438
|
hasGeneratedInitialSuggestions.current = true;
|
|
321
439
|
generateSuggestionsWithErrorHandling("initial");
|
|
322
440
|
return;
|
|
323
441
|
}
|
|
324
|
-
if (
|
|
442
|
+
if (messages.length > 0 && suggestions.length === 0) {
|
|
325
443
|
generateSuggestionsWithErrorHandling("post-message");
|
|
326
444
|
return;
|
|
327
445
|
}
|
|
@@ -329,7 +447,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
329
447
|
chatSuggestions,
|
|
330
448
|
isLoadingSuggestions,
|
|
331
449
|
suggestionsFailed,
|
|
332
|
-
|
|
450
|
+
messages.length,
|
|
333
451
|
isLoading,
|
|
334
452
|
suggestions.length,
|
|
335
453
|
Object.keys(generalContext.chatSuggestionConfiguration).join(","),
|
|
@@ -359,7 +477,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
359
477
|
useEffect(() => {
|
|
360
478
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
361
479
|
}, [onInProgress, isLoading]);
|
|
362
|
-
const
|
|
480
|
+
const safelySendMessage = (messageContent, imagesToUse) => __async(void 0, null, function* () {
|
|
363
481
|
const images = imagesToUse || [];
|
|
364
482
|
if (chatSuggestions === "auto" || chatSuggestions === "manual") {
|
|
365
483
|
setSuggestions([]);
|
|
@@ -378,7 +496,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
378
496
|
console.error("Error in onSubmitMessage:", error);
|
|
379
497
|
}
|
|
380
498
|
}
|
|
381
|
-
yield
|
|
499
|
+
yield sendMessage(textMessage, {
|
|
382
500
|
followUp: images.length === 0,
|
|
383
501
|
clearSuggestions: chatSuggestions === "auto" || chatSuggestions === "manual"
|
|
384
502
|
});
|
|
@@ -396,7 +514,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
396
514
|
bytes: images[i].bytes
|
|
397
515
|
}
|
|
398
516
|
};
|
|
399
|
-
yield
|
|
517
|
+
yield sendMessage(imageMessage, { followUp: i === images.length - 1 });
|
|
400
518
|
if (!firstMessage) {
|
|
401
519
|
firstMessage = imageMessage;
|
|
402
520
|
}
|
|
@@ -407,7 +525,6 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
407
525
|
}
|
|
408
526
|
return firstMessage;
|
|
409
527
|
});
|
|
410
|
-
const messages = visibleMessages;
|
|
411
528
|
const currentAgentName = (_a = generalContext.agentSession) == null ? void 0 : _a.agentName;
|
|
412
529
|
const restartCurrentAgent = (hint) => __async(void 0, null, function* () {
|
|
413
530
|
if (generalContext.agentSession) {
|
|
@@ -431,9 +548,9 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
431
548
|
yield runAgent(
|
|
432
549
|
generalContext.agentSession.agentName,
|
|
433
550
|
stableContext,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
551
|
+
messagesContext.messages,
|
|
552
|
+
sendMessage,
|
|
553
|
+
runChatCompletion
|
|
437
554
|
);
|
|
438
555
|
}
|
|
439
556
|
});
|
|
@@ -489,10 +606,9 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
489
606
|
}
|
|
490
607
|
return {
|
|
491
608
|
messages,
|
|
492
|
-
visibleMessages,
|
|
493
609
|
isLoading,
|
|
494
610
|
suggestions,
|
|
495
|
-
sendMessage,
|
|
611
|
+
sendMessage: safelySendMessage,
|
|
496
612
|
stopGeneration,
|
|
497
613
|
reloadMessages,
|
|
498
614
|
resetSuggestions,
|
|
@@ -506,4 +622,4 @@ export {
|
|
|
506
622
|
WrappedCopilotChat,
|
|
507
623
|
useCopilotChatLogic
|
|
508
624
|
};
|
|
509
|
-
//# sourceMappingURL=chunk-
|
|
625
|
+
//# sourceMappingURL=chunk-GJ4SX4JE.mjs.map
|