@copilotkit/react-ui 1.10.6 → 1.50.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-H5Y4W7DM.mjs → chunk-3JYVJHL5.mjs} +6 -6
- package/dist/chunk-3YWFGNSM.mjs +32 -0
- package/dist/chunk-3YWFGNSM.mjs.map +1 -0
- package/dist/{chunk-BAD2NFZ7.mjs → chunk-CQ2WALZ7.mjs} +2 -2
- package/dist/{chunk-W7ONZTSW.mjs → chunk-E6WVAOQA.mjs} +11 -5
- package/dist/chunk-E6WVAOQA.mjs.map +1 -0
- package/dist/{chunk-ME2WM7IP.mjs → chunk-G35HUUDA.mjs} +36 -260
- package/dist/chunk-G35HUUDA.mjs.map +1 -0
- package/dist/{chunk-EZQA3UPQ.mjs → chunk-HBZW7E5Z.mjs} +16 -13
- package/dist/chunk-HBZW7E5Z.mjs.map +1 -0
- package/dist/{chunk-3QYTKBWC.mjs → chunk-IHFR6PYG.mjs} +8 -5
- package/dist/chunk-IHFR6PYG.mjs.map +1 -0
- package/dist/{chunk-5XLGXUQI.mjs → chunk-MPF6BJUF.mjs} +7 -3
- package/dist/chunk-MPF6BJUF.mjs.map +1 -0
- package/dist/{chunk-W26XFBEG.mjs → chunk-NGJ32FAP.mjs} +3 -3
- package/dist/chunk-NGJ32FAP.mjs.map +1 -0
- package/dist/{chunk-2LIO4Z3E.mjs → chunk-ODEHR7KI.mjs} +9 -2
- package/dist/chunk-ODEHR7KI.mjs.map +1 -0
- package/dist/chunk-OYRZ4VLU.mjs +12 -0
- package/dist/chunk-OYRZ4VLU.mjs.map +1 -0
- package/dist/chunk-QB3GUN2N.mjs +31 -0
- package/dist/chunk-QB3GUN2N.mjs.map +1 -0
- package/dist/{chunk-7RDGZ5JL.mjs → chunk-SOB5EIL7.mjs} +2 -2
- package/dist/components/chat/Chat.d.ts +3 -98
- package/dist/components/chat/Chat.js +100 -279
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +12 -14
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +11 -8
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +2 -2
- package/dist/components/chat/Messages.d.ts +4 -4
- package/dist/components/chat/Messages.js +44 -8
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.d.ts +1 -6
- package/dist/components/chat/Modal.js +106 -283
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +11 -11
- package/dist/components/chat/Popup.d.ts +1 -6
- package/dist/components/chat/Popup.js +106 -283
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +12 -12
- package/dist/components/chat/Sidebar.d.ts +1 -6
- package/dist/components/chat/Sidebar.js +106 -283
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +12 -12
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +1 -1
- package/dist/components/chat/Suggestions.d.ts +1 -1
- package/dist/components/chat/Suggestions.js +19 -12
- package/dist/components/chat/Suggestions.js.map +1 -1
- package/dist/components/chat/Suggestions.mjs +2 -2
- package/dist/components/chat/index.d.ts +0 -5
- package/dist/components/chat/index.js +106 -283
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +13 -13
- package/dist/components/chat/messages/AssistantMessage.js +7 -4
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.js +37 -7
- package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.mjs +4 -4
- package/dist/components/chat/messages/RenderMessage.js +30 -7
- package/dist/components/chat/messages/RenderMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderMessage.mjs +3 -3
- package/dist/components/chat/messages/UserMessage.js +19 -3
- package/dist/components/chat/messages/UserMessage.js.map +1 -1
- package/dist/components/chat/messages/UserMessage.mjs +1 -1
- package/dist/components/chat/props.d.ts +16 -0
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +0 -5
- package/dist/components/index.js +106 -283
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +13 -13
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +2 -24
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +4 -26
- package/dist/hooks/use-copilot-chat-suggestions.js +2 -24
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +1 -1
- package/dist/index.css +8 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.js +109 -308
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -14
- package/dist/types/suggestions.d.ts +1 -0
- package/dist/types/suggestions.js.map +1 -1
- package/package.json +23 -22
- package/src/components/chat/Chat.tsx +40 -325
- package/src/components/chat/Input.tsx +13 -12
- package/src/components/chat/Messages.tsx +10 -4
- package/src/components/chat/Suggestion.tsx +2 -2
- package/src/components/chat/Suggestions.tsx +6 -2
- package/src/components/chat/messages/AssistantMessage.tsx +14 -4
- package/src/components/chat/messages/LegacyRenderMessage.tsx +7 -0
- package/src/components/chat/messages/RenderMessage.tsx +4 -0
- package/src/components/chat/messages/UserMessage.tsx +30 -6
- package/src/components/chat/props.ts +19 -0
- package/src/css/messages.css +10 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +6 -57
- package/src/types/suggestions.ts +1 -0
- package/tsup.config.ts +1 -1
- package/dist/chunk-226ZMOE3.mjs +0 -24
- package/dist/chunk-226ZMOE3.mjs.map +0 -1
- package/dist/chunk-2LIO4Z3E.mjs.map +0 -1
- package/dist/chunk-3QYTKBWC.mjs.map +0 -1
- package/dist/chunk-5XLGXUQI.mjs.map +0 -1
- package/dist/chunk-EYRKZDP5.mjs +0 -32
- package/dist/chunk-EYRKZDP5.mjs.map +0 -1
- package/dist/chunk-EZQA3UPQ.mjs.map +0 -1
- package/dist/chunk-ME2WM7IP.mjs.map +0 -1
- package/dist/chunk-VVL6JFCJ.mjs +0 -16
- package/dist/chunk-VVL6JFCJ.mjs.map +0 -1
- package/dist/chunk-W26XFBEG.mjs.map +0 -1
- package/dist/chunk-W7ONZTSW.mjs.map +0 -1
- /package/dist/{chunk-H5Y4W7DM.mjs.map → chunk-3JYVJHL5.mjs.map} +0 -0
- /package/dist/{chunk-BAD2NFZ7.mjs.map → chunk-CQ2WALZ7.mjs.map} +0 -0
- /package/dist/{chunk-7RDGZ5JL.mjs.map → chunk-SOB5EIL7.mjs.map} +0 -0
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotChat,
|
|
3
|
-
WrappedCopilotChat
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import "../../chunk-
|
|
7
|
-
import "../../chunk-W26XFBEG.mjs";
|
|
3
|
+
WrappedCopilotChat
|
|
4
|
+
} from "../../chunk-G35HUUDA.mjs";
|
|
5
|
+
import "../../chunk-QB3GUN2N.mjs";
|
|
6
|
+
import "../../chunk-NGJ32FAP.mjs";
|
|
8
7
|
import "../../chunk-PLHTVHUW.mjs";
|
|
9
|
-
import "../../chunk-
|
|
8
|
+
import "../../chunk-HBZW7E5Z.mjs";
|
|
10
9
|
import "../../chunk-ELGRNEAO.mjs";
|
|
11
10
|
import "../../chunk-QIOJXTIQ.mjs";
|
|
12
|
-
import "../../chunk-
|
|
13
|
-
import "../../chunk-
|
|
14
|
-
import "../../chunk-
|
|
15
|
-
import "../../chunk-
|
|
11
|
+
import "../../chunk-E6WVAOQA.mjs";
|
|
12
|
+
import "../../chunk-ODEHR7KI.mjs";
|
|
13
|
+
import "../../chunk-MPF6BJUF.mjs";
|
|
14
|
+
import "../../chunk-IHFR6PYG.mjs";
|
|
16
15
|
import "../../chunk-DBKRAOH7.mjs";
|
|
17
|
-
import "../../chunk-
|
|
16
|
+
import "../../chunk-3YWFGNSM.mjs";
|
|
18
17
|
import "../../chunk-JZ3RFQQ6.mjs";
|
|
19
|
-
import "../../chunk-O72ZB5V3.mjs";
|
|
20
18
|
import "../../chunk-IEMQ2SQW.mjs";
|
|
21
19
|
import "../../chunk-IK2BPURM.mjs";
|
|
22
20
|
import "../../chunk-XWG3L6QC.mjs";
|
|
23
21
|
import "../../chunk-54JAUBUJ.mjs";
|
|
24
22
|
import "../../chunk-JGMFJZMG.mjs";
|
|
23
|
+
import "../../chunk-O72ZB5V3.mjs";
|
|
25
24
|
import "../../chunk-MRXNTQOX.mjs";
|
|
26
25
|
export {
|
|
27
26
|
CopilotChat,
|
|
28
|
-
WrappedCopilotChat
|
|
29
|
-
useCopilotChatLogic
|
|
27
|
+
WrappedCopilotChat
|
|
30
28
|
};
|
|
31
29
|
//# sourceMappingURL=Chat.mjs.map
|
|
@@ -4,6 +4,6 @@ import '@copilotkit/shared';
|
|
|
4
4
|
import '../../types/suggestions.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
|
7
|
-
declare const Input: ({ inProgress, onSend,
|
|
7
|
+
declare const Input: ({ inProgress, onSend, chatReady, onStop, onUpload, hideStopButton, }: InputProps) => react_jsx_runtime.JSX.Element;
|
|
8
8
|
|
|
9
9
|
export { Input };
|
|
@@ -289,12 +289,12 @@ var MAX_NEWLINES = 6;
|
|
|
289
289
|
var Input = ({
|
|
290
290
|
inProgress,
|
|
291
291
|
onSend,
|
|
292
|
-
|
|
292
|
+
chatReady = true,
|
|
293
293
|
onStop,
|
|
294
294
|
onUpload,
|
|
295
295
|
hideStopButton = false
|
|
296
296
|
}) => {
|
|
297
|
-
var _a
|
|
297
|
+
var _a;
|
|
298
298
|
const context = useChatContext();
|
|
299
299
|
const copilotContext = (0, import_react_core2.useCopilotContext)();
|
|
300
300
|
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
@@ -324,14 +324,16 @@ var Input = ({
|
|
|
324
324
|
inProgress
|
|
325
325
|
});
|
|
326
326
|
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
327
|
-
const buttonIcon
|
|
327
|
+
const { buttonIcon, buttonAlt } = (0, import_react5.useMemo)(() => {
|
|
328
|
+
if (!chatReady)
|
|
329
|
+
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
330
|
+
return isInProgress && !hideStopButton ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
331
|
+
}, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
|
|
328
332
|
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
333
|
+
const { interrupt } = (0, import_react_core2.useCopilotChatInternal)();
|
|
329
334
|
const canSend = (0, import_react5.useMemo)(() => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const interruptInProgress = (interruptEvent == null ? void 0 : interruptEvent.name) === "LangGraphInterruptEvent" && !(interruptEvent == null ? void 0 : interruptEvent.response);
|
|
333
|
-
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interruptInProgress;
|
|
334
|
-
}, [(_b = copilotContext.langGraphInterruptAction) == null ? void 0 : _b.event, isInProgress, text, pushToTalkState]);
|
|
335
|
+
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
336
|
+
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
335
337
|
const canStop = (0, import_react5.useMemo)(() => {
|
|
336
338
|
return isInProgress && !hideStopButton;
|
|
337
339
|
}, [isInProgress, hideStopButton]);
|
|
@@ -378,6 +380,7 @@ var Input = ({
|
|
|
378
380
|
"data-copilotkit-in-progress": inProgress,
|
|
379
381
|
"data-test-id": inProgress ? "copilot-chat-request-in-progress" : "copilot-chat-ready",
|
|
380
382
|
className: "copilotKitInputControlButton",
|
|
383
|
+
"aria-label": buttonAlt,
|
|
381
384
|
children: buttonIcon
|
|
382
385
|
}
|
|
383
386
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/chat/Input.tsx","../../../src/components/chat/ChatContext.tsx","../../../src/components/chat/Textarea.tsx","../../../src/hooks/use-push-to-talk.tsx","../../../src/components/chat/PoweredByTag.tsx","../../../src/hooks/use-dark-mode.ts"],"sourcesContent":["import React, { useMemo, useRef, useState } from \"react\";\nimport { InputProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport AutoResizingTextarea from \"./Textarea\";\nimport { usePushToTalk } from \"../../hooks/use-push-to-talk\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { PoweredByTag } from \"./PoweredByTag\";\n\nconst MAX_NEWLINES = 6;\n\nexport const Input = ({\n inProgress,\n onSend,\n isVisible = false,\n onStop,\n onUpload,\n hideStopButton = false,\n}: InputProps) => {\n const context = useChatContext();\n const copilotContext = useCopilotContext();\n\n const showPoweredBy = !copilotContext.copilotApiConfig?.publicApiKey;\n\n const pushToTalkConfigured =\n copilotContext.copilotApiConfig.textToSpeechUrl !== undefined &&\n copilotContext.copilotApiConfig.transcribeAudioUrl !== undefined;\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const [isComposing, setIsComposing] = useState(false);\n\n const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const target = event.target as HTMLElement;\n\n // If the user clicked a button or inside a button, don't focus the textarea\n if (target.closest(\"button\")) return;\n\n // If the user clicked the textarea, do nothing (it's already focused)\n if (target.tagName === \"TEXTAREA\") return;\n\n // Otherwise, focus the textarea\n textareaRef.current?.focus();\n };\n\n const [text, setText] = useState(\"\");\n const send = () => {\n if (inProgress) return;\n onSend(text);\n setText(\"\");\n\n textareaRef.current?.focus();\n };\n\n // tylerslaton:\n //\n // This scrolls CopilotKit into view always. Reading the commit history, it was likely\n // added to fix a bug but it is causing issues now.\n //\n // For the future, if we want this behavior again, we will need to find a way to do it without\n // forcing CopilotKit to always be in view. This code causes this because focusing an element\n // in most browsers will scroll that element into view.\n //\n // useEffect(() => {\n // if (isVisible) {\n // textareaRef.current?.focus();\n // }\n // }, [isVisible]);\n\n const { pushToTalkState, setPushToTalkState } = usePushToTalk({\n sendFunction: onSend,\n inProgress,\n });\n\n const isInProgress = inProgress || pushToTalkState === \"transcribing\";\n const buttonIcon =\n isInProgress && !hideStopButton ? context.icons.stopIcon : context.icons.sendIcon;\n const showPushToTalk =\n pushToTalkConfigured &&\n (pushToTalkState === \"idle\" || pushToTalkState === \"recording\") &&\n !inProgress;\n\n const canSend = useMemo(() => {\n const interruptEvent = copilotContext.langGraphInterruptAction?.event;\n const interruptInProgress =\n interruptEvent?.name === \"LangGraphInterruptEvent\" && !interruptEvent?.response;\n\n return (\n !isInProgress && text.trim().length > 0 && pushToTalkState === \"idle\" && !interruptInProgress\n );\n }, [copilotContext.langGraphInterruptAction?.event, isInProgress, text, pushToTalkState]);\n\n const canStop = useMemo(() => {\n return isInProgress && !hideStopButton;\n }, [isInProgress, hideStopButton]);\n\n const sendDisabled = !canSend && !canStop;\n\n return (\n <div className={`copilotKitInputContainer ${showPoweredBy ? \"poweredByContainer\" : \"\"}`}>\n <div className=\"copilotKitInput\" onClick={handleDivClick}>\n <AutoResizingTextarea\n ref={textareaRef}\n placeholder={context.labels.placeholder}\n autoFocus={false}\n maxRows={MAX_NEWLINES}\n value={text}\n onChange={(event) => setText(event.target.value)}\n onCompositionStart={() => setIsComposing(true)}\n onCompositionEnd={() => setIsComposing(false)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey && !isComposing) {\n event.preventDefault();\n if (canSend) {\n send();\n }\n }\n }}\n />\n <div className=\"copilotKitInputControls\">\n {onUpload && (\n <button onClick={onUpload} className=\"copilotKitInputControlButton\">\n {context.icons.uploadIcon}\n </button>\n )}\n\n <div style={{ flexGrow: 1 }} />\n\n {showPushToTalk && (\n <button\n onClick={() =>\n setPushToTalkState(pushToTalkState === \"idle\" ? \"recording\" : \"transcribing\")\n }\n className={\n pushToTalkState === \"recording\"\n ? \"copilotKitInputControlButton copilotKitPushToTalkRecording\"\n : \"copilotKitInputControlButton\"\n }\n >\n {context.icons.pushToTalkIcon}\n </button>\n )}\n <button\n disabled={sendDisabled}\n onClick={isInProgress && !hideStopButton ? onStop : send}\n data-copilotkit-in-progress={inProgress}\n data-test-id={inProgress ? \"copilot-chat-request-in-progress\" : \"copilot-chat-ready\"}\n className=\"copilotKitInputControlButton\"\n >\n {buttonIcon}\n </button>\n </div>\n </div>\n <PoweredByTag showPoweredBy={showPoweredBy} />\n </div>\n );\n};\n","import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons from \"./Icons\";\nimport { ThumbsDownIcon, ThumbsUpIcon } from \"./Icons\";\n\n/**\n * Icons for CopilotChat component.\n */\nexport interface CopilotChatIcons {\n /**\n * The icon to use for the open chat button.\n * @default <OpenIcon />\n */\n openIcon?: React.ReactNode;\n\n /**\n * The icon to use for the close chat button.\n * @default <CloseIcon />\n */\n closeIcon?: React.ReactNode;\n\n /**\n * The icon to use for the close chat button in the header.\n * @default <HeaderCloseIcon />\n */\n headerCloseIcon?: React.ReactNode;\n\n /**\n * The icon to use for the send button.\n * @default <SendIcon />\n */\n sendIcon?: React.ReactNode;\n\n /**\n * The icon to use for the activity indicator.\n * @default <ActivityIcon />\n */\n activityIcon?: React.ReactNode;\n\n /**\n * The icon to use for the spinner.\n * @default <SpinnerIcon />\n */\n spinnerIcon?: React.ReactNode;\n\n /**\n * The icon to use for the stop button.\n * @default <StopIcon />\n */\n stopIcon?: React.ReactNode;\n\n /**\n * The icon to use for the regenerate button.\n * @default <RegenerateIcon />\n */\n regenerateIcon?: React.ReactNode;\n\n /**\n * The icons to use for push to talk.\n * @default <PushToTalkIcon />\n */\n\n pushToTalkIcon?: React.ReactNode;\n\n /**\n * The icons to use for copy assistant response\n * @default <CopyIcon />\n */\n\n copyIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs up/response approval.\n * @default <ThumbsUpIcon />\n */\n\n thumbsUpIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs down/response rejection.\n * @default <ThumbsDownIcon />\n */\n\n thumbsDownIcon?: React.ReactNode;\n\n /**\n * The icon to use for the upload button.\n * @default <UploadIcon />\n */\n uploadIcon?: React.ReactNode;\n}\n\n/**\n * Labels for CopilotChat component.\n */\nexport interface CopilotChatLabels {\n /**\n * The initial message(s) to display in the chat window.\n */\n initial?: string | string[];\n\n /**\n * The title to display in the header.\n * @default \"CopilotKit\"\n */\n title?: string;\n\n /**\n * The placeholder to display in the input.\n * @default \"Type a message...\"\n */\n placeholder?: string;\n\n /**\n * The message to display when an error occurs.\n * @default \"❌ An error occurred. Please try again.\"\n */\n error?: string;\n\n /**\n * The label to display on the stop button.\n * @default \"Stop generating\"\n */\n stopGenerating?: string;\n\n /**\n * The label to display on the regenerate button.\n * @default \"Regenerate response\"\n */\n regenerateResponse?: string;\n\n /**\n * The label for the copy button.\n * @default \"Copy to clipboard\"\n */\n copyToClipboard?: string;\n\n /**\n * The label for the thumbs up button.\n * @default \"Thumbs up\"\n */\n thumbsUp?: string;\n\n /**\n * The label for the thumbs down button.\n * @default \"Thumbs down\"\n */\n thumbsDown?: string;\n\n /**\n * The text to display when content is copied.\n * @default \"Copied!\"\n */\n copied?: string;\n}\n\ninterface ChatContext {\n labels: Required<CopilotChatLabels>;\n icons: Required<CopilotChatIcons>;\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nexport const ChatContext = React.createContext<ChatContext | undefined>(undefined);\n\nexport function useChatContext(): ChatContext {\n const context = React.useContext(ChatContext);\n if (context === undefined) {\n throw new Error(\n \"Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?\",\n );\n }\n return context;\n}\n\ninterface ChatContextProps {\n // temperature?: number;\n // instructions?: string;\n // maxFeedback?: number;\n labels?: CopilotChatLabels;\n icons?: CopilotChatIcons;\n children?: React.ReactNode;\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nexport const ChatContextProvider = ({\n // temperature,\n // instructions,\n // maxFeedback,\n labels,\n icons,\n children,\n open,\n setOpen,\n}: ChatContextProps) => {\n const memoizedLabels = useMemo(\n () => ({\n ...{\n initial: \"\",\n title: \"CopilotKit\",\n placeholder: \"Type a message...\",\n error: \"❌ An error occurred. Please try again.\",\n stopGenerating: \"Stop generating\",\n regenerateResponse: \"Regenerate response\",\n copyToClipboard: \"Copy to clipboard\",\n thumbsUp: \"Thumbs up\",\n thumbsDown: \"Thumbs down\",\n copied: \"Copied!\",\n },\n ...labels,\n }),\n [labels],\n );\n\n const memoizedIcons = useMemo(\n () => ({\n ...{\n openIcon: DefaultIcons.OpenIcon,\n closeIcon: DefaultIcons.CloseIcon,\n headerCloseIcon: DefaultIcons.HeaderCloseIcon,\n sendIcon: DefaultIcons.SendIcon,\n activityIcon: DefaultIcons.ActivityIcon,\n spinnerIcon: DefaultIcons.SpinnerIcon,\n stopIcon: DefaultIcons.StopIcon,\n regenerateIcon: DefaultIcons.RegenerateIcon,\n pushToTalkIcon: DefaultIcons.MicrophoneIcon,\n copyIcon: DefaultIcons.CopyIcon,\n thumbsUpIcon: DefaultIcons.ThumbsUpIcon,\n thumbsDownIcon: DefaultIcons.ThumbsDownIcon,\n uploadIcon: DefaultIcons.UploadIcon,\n },\n ...icons,\n }),\n [icons],\n );\n\n const context = useMemo(\n () => ({\n labels: memoizedLabels,\n icons: memoizedIcons,\n open,\n setOpen,\n }),\n [memoizedLabels, memoizedIcons, open, setOpen],\n );\n\n return <ChatContext.Provider value={context}>{children}</ChatContext.Provider>;\n};\n","import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from \"react\";\n\ninterface AutoResizingTextareaProps {\n maxRows?: number;\n placeholder?: string;\n value: string;\n onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n onCompositionStart?: () => void;\n onCompositionEnd?: () => void;\n autoFocus?: boolean;\n}\n\nconst AutoResizingTextarea = forwardRef<HTMLTextAreaElement, AutoResizingTextareaProps>(\n (\n {\n maxRows = 1,\n placeholder,\n value,\n onChange,\n onKeyDown,\n onCompositionStart,\n onCompositionEnd,\n autoFocus,\n },\n ref,\n ) => {\n const internalTextareaRef = useRef<HTMLTextAreaElement>(null);\n const [maxHeight, setMaxHeight] = useState<number>(0);\n\n useImperativeHandle(ref, () => internalTextareaRef.current as HTMLTextAreaElement);\n\n useEffect(() => {\n const calculateMaxHeight = () => {\n const textarea = internalTextareaRef.current;\n if (textarea) {\n textarea.style.height = \"auto\";\n const singleRowHeight = textarea.scrollHeight;\n setMaxHeight(singleRowHeight * maxRows);\n if (autoFocus) {\n textarea.focus();\n }\n }\n };\n\n calculateMaxHeight();\n }, [maxRows]);\n\n useEffect(() => {\n const textarea = internalTextareaRef.current;\n if (textarea) {\n textarea.style.height = \"auto\";\n textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;\n }\n }, [value, maxHeight]);\n\n return (\n <textarea\n ref={internalTextareaRef}\n value={value}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onCompositionStart={onCompositionStart}\n onCompositionEnd={onCompositionEnd}\n placeholder={placeholder}\n style={{\n overflow: \"auto\",\n resize: \"none\",\n maxHeight: `${maxHeight}px`,\n }}\n rows={1}\n />\n );\n },\n);\n\nexport default AutoResizingTextarea;\n","import { useCopilotContext, useCopilotMessagesContext } from \"@copilotkit/react-core\";\nimport { gqlToAGUI } from \"@copilotkit/runtime-client-gql\";\nimport { Message } from \"@copilotkit/shared\";\nimport { MutableRefObject, useEffect, useRef, useState } from \"react\";\n\nexport const checkMicrophonePermission = async () => {\n try {\n const permissionStatus = await navigator.permissions.query({\n name: \"microphone\" as PermissionName,\n });\n if (permissionStatus.state === \"granted\") {\n return true;\n } else {\n return false;\n }\n } catch (err) {\n console.error(\"Error checking microphone permission\", err);\n }\n};\n\nexport const requestMicAndPlaybackPermission = async () => {\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n const audioContext = new window.AudioContext();\n await audioContext.resume();\n return { stream, audioContext };\n } catch (err) {\n console.error(\"Error requesting microphone and playback permissions\", err);\n return null;\n }\n};\n\nconst startRecording = async (\n mediaStreamRef: MutableRefObject<MediaStream | null>,\n mediaRecorderRef: MutableRefObject<MediaRecorder | null>,\n audioContextRef: MutableRefObject<AudioContext | null>,\n recordedChunks: Blob[],\n onStop: () => void,\n) => {\n if (!mediaStreamRef.current || !audioContextRef.current) {\n mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({ audio: true });\n audioContextRef.current = new window.AudioContext();\n await audioContextRef.current.resume();\n }\n\n mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current!);\n mediaRecorderRef.current.start(1000);\n mediaRecorderRef.current.ondataavailable = (event) => {\n recordedChunks.push(event.data);\n };\n mediaRecorderRef.current.onstop = onStop;\n};\n\nconst stopRecording = (mediaRecorderRef: MutableRefObject<MediaRecorder | null>) => {\n if (mediaRecorderRef.current && mediaRecorderRef.current.state !== \"inactive\") {\n mediaRecorderRef.current.stop();\n }\n};\n\nconst transcribeAudio = async (recordedChunks: Blob[], transcribeAudioUrl: string) => {\n const completeBlob = new Blob(recordedChunks, { type: \"audio/mp4\" });\n const formData = new FormData();\n formData.append(\"file\", completeBlob, \"recording.mp4\");\n\n const response = await fetch(transcribeAudioUrl, {\n method: \"POST\",\n body: formData,\n });\n\n if (!response.ok) {\n throw new Error(`Error: ${response.statusText}`);\n }\n\n const transcription = await response.json();\n return transcription.text;\n};\n\nconst playAudioResponse = (text: string, textToSpeechUrl: string, audioContext: AudioContext) => {\n const encodedText = encodeURIComponent(text);\n const url = `${textToSpeechUrl}?text=${encodedText}`;\n\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer))\n .then((audioBuffer) => {\n const source = audioContext.createBufferSource();\n source.buffer = audioBuffer;\n source.connect(audioContext.destination);\n source.start(0);\n })\n .catch((error) => {\n console.error(\"Error with decoding audio data\", error);\n });\n};\n\nexport type PushToTalkState = \"idle\" | \"recording\" | \"transcribing\";\n\nexport type SendFunction = (text: string) => Promise<Message>;\n\nexport const usePushToTalk = ({\n sendFunction,\n inProgress,\n}: {\n sendFunction: SendFunction;\n inProgress: boolean;\n}) => {\n const [pushToTalkState, setPushToTalkState] = useState<PushToTalkState>(\"idle\");\n const mediaStreamRef = useRef<MediaStream | null>(null);\n const audioContextRef = useRef<AudioContext | null>(null);\n const mediaRecorderRef = useRef<MediaRecorder | null>(null);\n const recordedChunks = useRef<Blob[]>([]);\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n const [startReadingFromMessageId, setStartReadingFromMessageId] = useState<string | null>(null);\n\n useEffect(() => {\n if (pushToTalkState === \"recording\") {\n startRecording(\n mediaStreamRef,\n mediaRecorderRef,\n audioContextRef,\n recordedChunks.current,\n () => {\n setPushToTalkState(\"transcribing\");\n },\n );\n } else {\n stopRecording(mediaRecorderRef);\n if (pushToTalkState === \"transcribing\") {\n transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl!).then(\n async (transcription) => {\n recordedChunks.current = [];\n setPushToTalkState(\"idle\");\n const message = await sendFunction(transcription);\n setStartReadingFromMessageId(message.id);\n },\n );\n }\n }\n\n return () => {\n stopRecording(mediaRecorderRef);\n };\n }, [pushToTalkState]);\n\n useEffect(() => {\n if (inProgress === false && startReadingFromMessageId) {\n const lastMessageIndex = context.messages.findIndex(\n (message) => message.id === startReadingFromMessageId,\n );\n\n const aguiMessages = gqlToAGUI(context.messages);\n\n const messagesAfterLast = aguiMessages\n .slice(lastMessageIndex + 1)\n .filter((message) => message.role === \"assistant\");\n\n const text = messagesAfterLast.map((message) => message.content).join(\"\\n\");\n playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl!, audioContextRef.current!);\n\n setStartReadingFromMessageId(null);\n }\n }, [startReadingFromMessageId, inProgress]);\n\n return { pushToTalkState, setPushToTalkState };\n};\n","import React, { useState, useEffect } from \"react\";\nimport { useDarkMode } from \"../../hooks/use-dark-mode\";\n\nexport function PoweredByTag({ showPoweredBy = true }: { showPoweredBy?: boolean }) {\n const [mounted, setMounted] = useState(false);\n const isDark = useDarkMode();\n\n /*\n note(tylerslaton):\n\n Ensure we only use the isDark computed value after client-side mount.\n This prevents hydration mismatches by using a default color on the\n server and initial client render, then updating to the correct\n dark mode color after hydration is complete.\n */\n useEffect(() => {\n setMounted(true);\n }, []);\n\n if (!showPoweredBy) {\n return null;\n }\n\n const poweredByStyle = {\n visibility: \"visible\",\n display: \"block\",\n position: \"static\",\n textAlign: \"center\",\n fontSize: \"12px\",\n padding: \"3px 0\",\n color: mounted && isDark ? \"rgb(69, 69, 69)\" : \"rgb(214, 214, 214)\",\n };\n\n return (\n <div>\n {/*@ts-expect-error -- expecting position not to be a string, but it can be.*/}\n <p className=\"poweredBy\" style={poweredByStyle}>\n Powered by CopilotKit\n </p>\n </div>\n );\n}\n","export const useDarkMode = () => {\n if (typeof window === \"undefined\") return false;\n return (\n document.documentElement.classList.contains(\"dark\") ||\n document.body.classList.contains(\"dark\") ||\n document.documentElement.getAttribute(\"data-theme\") === \"dark\" ||\n document.body.getAttribute(\"data-theme\") === \"dark\" ||\n window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAiD;;;ACAjD,mBAAyC;AAsPhC;AApFF,IAAM,cAAc,aAAAC,QAAM,cAAuC,MAAS;AAE1E,SAAS,iBAA8B;AAC5C,QAAM,UAAU,aAAAA,QAAM,WAAW,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mB,oBAAoB,SAAS,cAAc,cAAc;AAAA,YAE9E,WACE,oBAAoB,cAChB,+DACA;AAAA,YAGL,kBAAQ,MAAM;AAAA;AAAA,QACjB;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACC,UAAU;AAAA,YACV,SAAS,gBAAgB,CAAC,iBAAiB,SAAS;AAAA,YACpD,+BAA6B;AAAA,YAC7B,gBAAc,aAAa,qCAAqC;AAAA,YAChE,WAAU;AAAA,YAET;AAAA;AAAA,QACH;AAAA,SACF;AAAA,OACF;AAAA,IACA,6CAAC,gBAAa,eAA8B;AAAA,KAC9C;AAEJ;","names":["import_react","React","import_react","import_jsx_runtime","import_react","import_react_core","import_react","import_jsx_runtime","import_jsx_runtime","_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/chat/Input.tsx","../../../src/components/chat/ChatContext.tsx","../../../src/components/chat/Textarea.tsx","../../../src/hooks/use-push-to-talk.tsx","../../../src/components/chat/PoweredByTag.tsx","../../../src/hooks/use-dark-mode.ts"],"sourcesContent":["import React, { useMemo, useRef, useState } from \"react\";\nimport { InputProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport AutoResizingTextarea from \"./Textarea\";\nimport { usePushToTalk } from \"../../hooks/use-push-to-talk\";\nimport { useCopilotContext, useCopilotChatInternal } from \"@copilotkit/react-core\";\nimport { PoweredByTag } from \"./PoweredByTag\";\n\nconst MAX_NEWLINES = 6;\n\nexport const Input = ({\n inProgress,\n onSend,\n chatReady = true,\n onStop,\n onUpload,\n hideStopButton = false,\n}: InputProps) => {\n const context = useChatContext();\n const copilotContext = useCopilotContext();\n\n const showPoweredBy = !copilotContext.copilotApiConfig?.publicApiKey;\n\n const pushToTalkConfigured =\n copilotContext.copilotApiConfig.textToSpeechUrl !== undefined &&\n copilotContext.copilotApiConfig.transcribeAudioUrl !== undefined;\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const [isComposing, setIsComposing] = useState(false);\n\n const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const target = event.target as HTMLElement;\n\n // If the user clicked a button or inside a button, don't focus the textarea\n if (target.closest(\"button\")) return;\n\n // If the user clicked the textarea, do nothing (it's already focused)\n if (target.tagName === \"TEXTAREA\") return;\n\n // Otherwise, focus the textarea\n textareaRef.current?.focus();\n };\n\n const [text, setText] = useState(\"\");\n const send = () => {\n if (inProgress) return;\n onSend(text);\n setText(\"\");\n\n textareaRef.current?.focus();\n };\n\n // tylerslaton:\n //\n // This scrolls CopilotKit into view always. Reading the commit history, it was likely\n // added to fix a bug but it is causing issues now.\n //\n // For the future, if we want this behavior again, we will need to find a way to do it without\n // forcing CopilotKit to always be in view. This code causes this because focusing an element\n // in most browsers will scroll that element into view.\n //\n // useEffect(() => {\n // if (isVisible) {\n // textareaRef.current?.focus();\n // }\n // }, [isVisible]);\n\n const { pushToTalkState, setPushToTalkState } = usePushToTalk({\n sendFunction: onSend,\n inProgress,\n });\n\n const isInProgress = inProgress || pushToTalkState === \"transcribing\";\n const { buttonIcon, buttonAlt } = useMemo(() => {\n if (!chatReady) return { buttonIcon: context.icons.spinnerIcon, buttonAlt: \"Loading\" };\n return isInProgress && !hideStopButton\n ? { buttonIcon: context.icons.stopIcon, buttonAlt: \"Stop\" }\n : { buttonIcon: context.icons.sendIcon, buttonAlt: \"Send\" };\n }, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);\n const showPushToTalk =\n pushToTalkConfigured &&\n (pushToTalkState === \"idle\" || pushToTalkState === \"recording\") &&\n !inProgress;\n\n const { interrupt } = useCopilotChatInternal();\n\n const canSend = useMemo(() => {\n return !isInProgress && text.trim().length > 0 && pushToTalkState === \"idle\" && !interrupt;\n }, [interrupt, isInProgress, text, pushToTalkState]);\n\n const canStop = useMemo(() => {\n return isInProgress && !hideStopButton;\n }, [isInProgress, hideStopButton]);\n\n const sendDisabled = !canSend && !canStop;\n\n return (\n <div className={`copilotKitInputContainer ${showPoweredBy ? \"poweredByContainer\" : \"\"}`}>\n <div className=\"copilotKitInput\" onClick={handleDivClick}>\n <AutoResizingTextarea\n ref={textareaRef}\n placeholder={context.labels.placeholder}\n autoFocus={false}\n maxRows={MAX_NEWLINES}\n value={text}\n onChange={(event) => setText(event.target.value)}\n onCompositionStart={() => setIsComposing(true)}\n onCompositionEnd={() => setIsComposing(false)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey && !isComposing) {\n event.preventDefault();\n if (canSend) {\n send();\n }\n }\n }}\n />\n <div className=\"copilotKitInputControls\">\n {onUpload && (\n <button onClick={onUpload} className=\"copilotKitInputControlButton\">\n {context.icons.uploadIcon}\n </button>\n )}\n\n <div style={{ flexGrow: 1 }} />\n\n {showPushToTalk && (\n <button\n onClick={() =>\n setPushToTalkState(pushToTalkState === \"idle\" ? \"recording\" : \"transcribing\")\n }\n className={\n pushToTalkState === \"recording\"\n ? \"copilotKitInputControlButton copilotKitPushToTalkRecording\"\n : \"copilotKitInputControlButton\"\n }\n >\n {context.icons.pushToTalkIcon}\n </button>\n )}\n <button\n disabled={sendDisabled}\n onClick={isInProgress && !hideStopButton ? onStop : send}\n data-copilotkit-in-progress={inProgress}\n data-test-id={inProgress ? \"copilot-chat-request-in-progress\" : \"copilot-chat-ready\"}\n className=\"copilotKitInputControlButton\"\n aria-label={buttonAlt}\n >\n {buttonIcon}\n </button>\n </div>\n </div>\n <PoweredByTag showPoweredBy={showPoweredBy} />\n </div>\n );\n};\n","import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons from \"./Icons\";\nimport { ThumbsDownIcon, ThumbsUpIcon } from \"./Icons\";\n\n/**\n * Icons for CopilotChat component.\n */\nexport interface CopilotChatIcons {\n /**\n * The icon to use for the open chat button.\n * @default <OpenIcon />\n */\n openIcon?: React.ReactNode;\n\n /**\n * The icon to use for the close chat button.\n * @default <CloseIcon />\n */\n closeIcon?: React.ReactNode;\n\n /**\n * The icon to use for the close chat button in the header.\n * @default <HeaderCloseIcon />\n */\n headerCloseIcon?: React.ReactNode;\n\n /**\n * The icon to use for the send button.\n * @default <SendIcon />\n */\n sendIcon?: React.ReactNode;\n\n /**\n * The icon to use for the activity indicator.\n * @default <ActivityIcon />\n */\n activityIcon?: React.ReactNode;\n\n /**\n * The icon to use for the spinner.\n * @default <SpinnerIcon />\n */\n spinnerIcon?: React.ReactNode;\n\n /**\n * The icon to use for the stop button.\n * @default <StopIcon />\n */\n stopIcon?: React.ReactNode;\n\n /**\n * The icon to use for the regenerate button.\n * @default <RegenerateIcon />\n */\n regenerateIcon?: React.ReactNode;\n\n /**\n * The icons to use for push to talk.\n * @default <PushToTalkIcon />\n */\n\n pushToTalkIcon?: React.ReactNode;\n\n /**\n * The icons to use for copy assistant response\n * @default <CopyIcon />\n */\n\n copyIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs up/response approval.\n * @default <ThumbsUpIcon />\n */\n\n thumbsUpIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs down/response rejection.\n * @default <ThumbsDownIcon />\n */\n\n thumbsDownIcon?: React.ReactNode;\n\n /**\n * The icon to use for the upload button.\n * @default <UploadIcon />\n */\n uploadIcon?: React.ReactNode;\n}\n\n/**\n * Labels for CopilotChat component.\n */\nexport interface CopilotChatLabels {\n /**\n * The initial message(s) to display in the chat window.\n */\n initial?: string | string[];\n\n /**\n * The title to display in the header.\n * @default \"CopilotKit\"\n */\n title?: string;\n\n /**\n * The placeholder to display in the input.\n * @default \"Type a message...\"\n */\n placeholder?: string;\n\n /**\n * The message to display when an error occurs.\n * @default \"❌ An error occurred. Please try again.\"\n */\n error?: string;\n\n /**\n * The label to display on the stop button.\n * @default \"Stop generating\"\n */\n stopGenerating?: string;\n\n /**\n * The label to display on the regenerate button.\n * @default \"Regenerate response\"\n */\n regenerateResponse?: string;\n\n /**\n * The label for the copy button.\n * @default \"Copy to clipboard\"\n */\n copyToClipboard?: string;\n\n /**\n * The label for the thumbs up button.\n * @default \"Thumbs up\"\n */\n thumbsUp?: string;\n\n /**\n * The label for the thumbs down button.\n * @default \"Thumbs down\"\n */\n thumbsDown?: string;\n\n /**\n * The text to display when content is copied.\n * @default \"Copied!\"\n */\n copied?: string;\n}\n\ninterface ChatContext {\n labels: Required<CopilotChatLabels>;\n icons: Required<CopilotChatIcons>;\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nexport const ChatContext = React.createContext<ChatContext | undefined>(undefined);\n\nexport function useChatContext(): ChatContext {\n const context = React.useContext(ChatContext);\n if (context === undefined) {\n throw new Error(\n \"Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?\",\n );\n }\n return context;\n}\n\ninterface ChatContextProps {\n // temperature?: number;\n // instructions?: string;\n // maxFeedback?: number;\n labels?: CopilotChatLabels;\n icons?: CopilotChatIcons;\n children?: React.ReactNode;\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nexport const ChatContextProvider = ({\n // temperature,\n // instructions,\n // maxFeedback,\n labels,\n icons,\n children,\n open,\n setOpen,\n}: ChatContextProps) => {\n const memoizedLabels = useMemo(\n () => ({\n ...{\n initial: \"\",\n title: \"CopilotKit\",\n placeholder: \"Type a message...\",\n error: \"❌ An error occurred. Please try again.\",\n stopGenerating: \"Stop generating\",\n regenerateResponse: \"Regenerate response\",\n copyToClipboard: \"Copy to clipboard\",\n thumbsUp: \"Thumbs up\",\n thumbsDown: \"Thumbs down\",\n copied: \"Copied!\",\n },\n ...labels,\n }),\n [labels],\n );\n\n const memoizedIcons = useMemo(\n () => ({\n ...{\n openIcon: DefaultIcons.OpenIcon,\n closeIcon: DefaultIcons.CloseIcon,\n headerCloseIcon: DefaultIcons.HeaderCloseIcon,\n sendIcon: DefaultIcons.SendIcon,\n activityIcon: DefaultIcons.ActivityIcon,\n spinnerIcon: DefaultIcons.SpinnerIcon,\n stopIcon: DefaultIcons.StopIcon,\n regenerateIcon: DefaultIcons.RegenerateIcon,\n pushToTalkIcon: DefaultIcons.MicrophoneIcon,\n copyIcon: DefaultIcons.CopyIcon,\n thumbsUpIcon: DefaultIcons.ThumbsUpIcon,\n thumbsDownIcon: DefaultIcons.ThumbsDownIcon,\n uploadIcon: DefaultIcons.UploadIcon,\n },\n ...icons,\n }),\n [icons],\n );\n\n const context = useMemo(\n () => ({\n labels: memoizedLabels,\n icons: memoizedIcons,\n open,\n setOpen,\n }),\n [memoizedLabels, memoizedIcons, open, setOpen],\n );\n\n return <ChatContext.Provider value={context}>{children}</ChatContext.Provider>;\n};\n","import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from \"react\";\n\ninterface AutoResizingTextareaProps {\n maxRows?: number;\n placeholder?: string;\n value: string;\n onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n onCompositionStart?: () => void;\n onCompositionEnd?: () => void;\n autoFocus?: boolean;\n}\n\nconst AutoResizingTextarea = forwardRef<HTMLTextAreaElement, AutoResizingTextareaProps>(\n (\n {\n maxRows = 1,\n placeholder,\n value,\n onChange,\n onKeyDown,\n onCompositionStart,\n onCompositionEnd,\n autoFocus,\n },\n ref,\n ) => {\n const internalTextareaRef = useRef<HTMLTextAreaElement>(null);\n const [maxHeight, setMaxHeight] = useState<number>(0);\n\n useImperativeHandle(ref, () => internalTextareaRef.current as HTMLTextAreaElement);\n\n useEffect(() => {\n const calculateMaxHeight = () => {\n const textarea = internalTextareaRef.current;\n if (textarea) {\n textarea.style.height = \"auto\";\n const singleRowHeight = textarea.scrollHeight;\n setMaxHeight(singleRowHeight * maxRows);\n if (autoFocus) {\n textarea.focus();\n }\n }\n };\n\n calculateMaxHeight();\n }, [maxRows]);\n\n useEffect(() => {\n const textarea = internalTextareaRef.current;\n if (textarea) {\n textarea.style.height = \"auto\";\n textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;\n }\n }, [value, maxHeight]);\n\n return (\n <textarea\n ref={internalTextareaRef}\n value={value}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onCompositionStart={onCompositionStart}\n onCompositionEnd={onCompositionEnd}\n placeholder={placeholder}\n style={{\n overflow: \"auto\",\n resize: \"none\",\n maxHeight: `${maxHeight}px`,\n }}\n rows={1}\n />\n );\n },\n);\n\nexport default AutoResizingTextarea;\n","import { useCopilotContext, useCopilotMessagesContext } from \"@copilotkit/react-core\";\nimport { gqlToAGUI } from \"@copilotkit/runtime-client-gql\";\nimport { Message } from \"@copilotkit/shared\";\nimport { MutableRefObject, useEffect, useRef, useState } from \"react\";\n\nexport const checkMicrophonePermission = async () => {\n try {\n const permissionStatus = await navigator.permissions.query({\n name: \"microphone\" as PermissionName,\n });\n if (permissionStatus.state === \"granted\") {\n return true;\n } else {\n return false;\n }\n } catch (err) {\n console.error(\"Error checking microphone permission\", err);\n }\n};\n\nexport const requestMicAndPlaybackPermission = async () => {\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n const audioContext = new window.AudioContext();\n await audioContext.resume();\n return { stream, audioContext };\n } catch (err) {\n console.error(\"Error requesting microphone and playback permissions\", err);\n return null;\n }\n};\n\nconst startRecording = async (\n mediaStreamRef: MutableRefObject<MediaStream | null>,\n mediaRecorderRef: MutableRefObject<MediaRecorder | null>,\n audioContextRef: MutableRefObject<AudioContext | null>,\n recordedChunks: Blob[],\n onStop: () => void,\n) => {\n if (!mediaStreamRef.current || !audioContextRef.current) {\n mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({ audio: true });\n audioContextRef.current = new window.AudioContext();\n await audioContextRef.current.resume();\n }\n\n mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current!);\n mediaRecorderRef.current.start(1000);\n mediaRecorderRef.current.ondataavailable = (event) => {\n recordedChunks.push(event.data);\n };\n mediaRecorderRef.current.onstop = onStop;\n};\n\nconst stopRecording = (mediaRecorderRef: MutableRefObject<MediaRecorder | null>) => {\n if (mediaRecorderRef.current && mediaRecorderRef.current.state !== \"inactive\") {\n mediaRecorderRef.current.stop();\n }\n};\n\nconst transcribeAudio = async (recordedChunks: Blob[], transcribeAudioUrl: string) => {\n const completeBlob = new Blob(recordedChunks, { type: \"audio/mp4\" });\n const formData = new FormData();\n formData.append(\"file\", completeBlob, \"recording.mp4\");\n\n const response = await fetch(transcribeAudioUrl, {\n method: \"POST\",\n body: formData,\n });\n\n if (!response.ok) {\n throw new Error(`Error: ${response.statusText}`);\n }\n\n const transcription = await response.json();\n return transcription.text;\n};\n\nconst playAudioResponse = (text: string, textToSpeechUrl: string, audioContext: AudioContext) => {\n const encodedText = encodeURIComponent(text);\n const url = `${textToSpeechUrl}?text=${encodedText}`;\n\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer))\n .then((audioBuffer) => {\n const source = audioContext.createBufferSource();\n source.buffer = audioBuffer;\n source.connect(audioContext.destination);\n source.start(0);\n })\n .catch((error) => {\n console.error(\"Error with decoding audio data\", error);\n });\n};\n\nexport type PushToTalkState = \"idle\" | \"recording\" | \"transcribing\";\n\nexport type SendFunction = (text: string) => Promise<Message>;\n\nexport const usePushToTalk = ({\n sendFunction,\n inProgress,\n}: {\n sendFunction: SendFunction;\n inProgress: boolean;\n}) => {\n const [pushToTalkState, setPushToTalkState] = useState<PushToTalkState>(\"idle\");\n const mediaStreamRef = useRef<MediaStream | null>(null);\n const audioContextRef = useRef<AudioContext | null>(null);\n const mediaRecorderRef = useRef<MediaRecorder | null>(null);\n const recordedChunks = useRef<Blob[]>([]);\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n const [startReadingFromMessageId, setStartReadingFromMessageId] = useState<string | null>(null);\n\n useEffect(() => {\n if (pushToTalkState === \"recording\") {\n startRecording(\n mediaStreamRef,\n mediaRecorderRef,\n audioContextRef,\n recordedChunks.current,\n () => {\n setPushToTalkState(\"transcribing\");\n },\n );\n } else {\n stopRecording(mediaRecorderRef);\n if (pushToTalkState === \"transcribing\") {\n transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl!).then(\n async (transcription) => {\n recordedChunks.current = [];\n setPushToTalkState(\"idle\");\n const message = await sendFunction(transcription);\n setStartReadingFromMessageId(message.id);\n },\n );\n }\n }\n\n return () => {\n stopRecording(mediaRecorderRef);\n };\n }, [pushToTalkState]);\n\n useEffect(() => {\n if (inProgress === false && startReadingFromMessageId) {\n const lastMessageIndex = context.messages.findIndex(\n (message) => message.id === startReadingFromMessageId,\n );\n\n const aguiMessages = gqlToAGUI(context.messages);\n\n const messagesAfterLast = aguiMessages\n .slice(lastMessageIndex + 1)\n .filter((message) => message.role === \"assistant\");\n\n const text = messagesAfterLast.map((message) => message.content).join(\"\\n\");\n playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl!, audioContextRef.current!);\n\n setStartReadingFromMessageId(null);\n }\n }, [startReadingFromMessageId, inProgress]);\n\n return { pushToTalkState, setPushToTalkState };\n};\n","import React, { useState, useEffect } from \"react\";\nimport { useDarkMode } from \"../../hooks/use-dark-mode\";\n\nexport function PoweredByTag({ showPoweredBy = true }: { showPoweredBy?: boolean }) {\n const [mounted, setMounted] = useState(false);\n const isDark = useDarkMode();\n\n /*\n note(tylerslaton):\n\n Ensure we only use the isDark computed value after client-side mount.\n This prevents hydration mismatches by using a default color on the\n server and initial client render, then updating to the correct\n dark mode color after hydration is complete.\n */\n useEffect(() => {\n setMounted(true);\n }, []);\n\n if (!showPoweredBy) {\n return null;\n }\n\n const poweredByStyle = {\n visibility: \"visible\",\n display: \"block\",\n position: \"static\",\n textAlign: \"center\",\n fontSize: \"12px\",\n padding: \"3px 0\",\n color: mounted && isDark ? \"rgb(69, 69, 69)\" : \"rgb(214, 214, 214)\",\n };\n\n return (\n <div>\n {/*@ts-expect-error -- expecting position not to be a string, but it can be.*/}\n <p className=\"poweredBy\" style={poweredByStyle}>\n Powered by CopilotKit\n </p>\n </div>\n );\n}\n","export const useDarkMode = () => {\n if (typeof window === \"undefined\") return false;\n return (\n document.documentElement.classList.contains(\"dark\") ||\n document.body.classList.contains(\"dark\") ||\n document.documentElement.getAttribute(\"data-theme\") === \"dark\" ||\n document.body.getAttribute(\"data-theme\") === \"dark\" ||\n window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAiD;;;ACAjD,mBAAyC;AAsPhC;AApFF,IAAM,cAAc,aAAAC,QAAM,cAAuC,MAAS;AAE1E,SAAS,iBAA8B;AAC5C,QAAM,UAAU,aAAAA,QAAM,WAAW,WAAW;AAC5C,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;;;AC5KA,IAAAC,gBAAoF;AAyD9E,IAAAC,sBAAA;AA5CN,IAAM,2BAAuB;AAAA,EAC3B,CACE;AAAA,IACE,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GACA,QACG;AACH,UAAM,0BAAsB,sBAA4B,IAAI;AAC5D,UAAM,CAAC,WAAW,YAAY,QAAI,wBAAiB,CAAC;AAEpD,2CAAoB,KAAK,MAAM,oBAAoB,OAA8B;AAEjF,iCAAU,MAAM;AACd,YAAM,qBAAqB,MAAM;AAC/B,cAAM,WAAW,oBAAoB;AACrC,YAAI,UAAU;AACZ,mBAAS,MAAM,SAAS;AACxB,gBAAM,kBAAkB,SAAS;AACjC,uBAAa,kBAAkB,OAAO;AACtC,cAAI,WAAW;AACb,qBAAS,MAAM;AAAA,UACjB;AAAA,QACF;AAAA,MACF;AAEA,yBAAmB;AAAA,IACrB,GAAG,CAAC,OAAO,CAAC;AAEZ,iCAAU,MAAM;AACd,YAAM,WAAW,oBAAoB;AACrC,UAAI,UAAU;AACZ,iBAAS,MAAM,SAAS;AACxB,iBAAS,MAAM,SAAS,GAAG,KA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ACP,UAAU,CAAC,UAAU,QAAQ,MAAM,OAAO,KAAK;AAAA,UAC/C,oBAAoB,MAAM,eAAe,IAAI;AAAA,UAC7C,kBAAkB,MAAM,eAAe,KAAK;AAAA,UAC5C,WAAW,CAAC,UAAU;AACpB,gBAAI,MAAM,QAAQ,WAAW,CAAC,MAAM,YAAY,CAAC,aAAa;AAC5D,oBAAM,eAAe;AACrB,kBAAI,SAAS;AACX,qBAAK;AAAA,cACP;AAAA,YACF;AAAA,UACF;AAAA;AAAA,MACF;AAAA,MACA,8CAAC,SAAI,WAAU,2BACZ;AAAA,oBACC,6CAAC,YAAO,SAAS,UAAU,WAAU,gCAClC,kBAAQ,MAAM,YACjB;AAAA,QAGF,6CAAC,SAAI,OAAO,EAAE,UAAU,EAAE,GAAG;AAAA,QAE5B,kBACC;AAAA,UAAC;AAAA;AAAA,YACC,SAAS,MACP,mBAAmB,oBAAoB,SAAS,cAAc,cAAc;AAAA,YAE9E,WACE,oBAAoB,cAChB,+DACA;AAAA,YAGL,kBAAQ,MAAM;AAAA;AAAA,QACjB;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACC,UAAU;AAAA,YACV,SAAS,gBAAgB,CAAC,iBAAiB,SAAS;AAAA,YACpD,+BAA6B;AAAA,YAC7B,gBAAc,aAAa,qCAAqC;AAAA,YAChE,WAAU;AAAA,YACV,cAAY;AAAA,YAEX;AAAA;AAAA,QACH;AAAA,SACF;AAAA,OACF;AAAA,IACA,6CAAC,gBAAa,eAA8B;AAAA,KAC9C;AAEJ;","names":["import_react","React","import_react","import_jsx_runtime","import_react","import_react_core","import_react","import_jsx_runtime","import_jsx_runtime","_a"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Input
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-HBZW7E5Z.mjs";
|
|
4
4
|
import "../../chunk-ELGRNEAO.mjs";
|
|
5
5
|
import "../../chunk-QIOJXTIQ.mjs";
|
|
6
|
-
import "../../chunk-O72ZB5V3.mjs";
|
|
7
6
|
import "../../chunk-IEMQ2SQW.mjs";
|
|
8
7
|
import "../../chunk-XWG3L6QC.mjs";
|
|
9
8
|
import "../../chunk-JGMFJZMG.mjs";
|
|
9
|
+
import "../../chunk-O72ZB5V3.mjs";
|
|
10
10
|
import "../../chunk-MRXNTQOX.mjs";
|
|
11
11
|
export {
|
|
12
12
|
Input
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React__default from 'react';
|
|
3
3
|
import { MessagesProps } from './props.js';
|
|
4
4
|
import { Message } from '@copilotkit/shared';
|
|
5
5
|
import '../../types/suggestions.js';
|
|
6
6
|
|
|
7
|
-
declare const Messages: ({ inProgress, children, RenderMessage, AssistantMessage, UserMessage, ErrorMessage, ImageRenderer, onRegenerate, onCopy, onThumbsUp, onThumbsDown, markdownTagRenderers, chatError, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage, }: MessagesProps) => react_jsx_runtime.JSX.Element;
|
|
7
|
+
declare const Messages: ({ inProgress, children, RenderMessage, AssistantMessage, UserMessage, ErrorMessage, ImageRenderer, onRegenerate, onCopy, onThumbsUp, onThumbsDown, messageFeedback, markdownTagRenderers, chatError, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage, }: MessagesProps) => react_jsx_runtime.JSX.Element;
|
|
8
8
|
declare function useScrollToBottom(messages: Message[]): {
|
|
9
|
-
messagesEndRef:
|
|
10
|
-
messagesContainerRef:
|
|
9
|
+
messagesEndRef: React__default.RefObject<HTMLDivElement | null>;
|
|
10
|
+
messagesContainerRef: React__default.RefObject<HTMLDivElement | null>;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { Messages, useScrollToBottom };
|
|
@@ -145,14 +145,30 @@ var import_react_core = require("@copilotkit/react-core");
|
|
|
145
145
|
|
|
146
146
|
// src/components/chat/messages/UserMessage.tsx
|
|
147
147
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
148
|
+
var getTextContent = (content) => {
|
|
149
|
+
if (typeof content === "undefined") {
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
if (typeof content === "string") {
|
|
153
|
+
return content;
|
|
154
|
+
}
|
|
155
|
+
return content.map((part) => {
|
|
156
|
+
if (part.type === "text") {
|
|
157
|
+
return part.text;
|
|
158
|
+
}
|
|
159
|
+
return void 0;
|
|
160
|
+
}).filter((value) => typeof value === "string" && value.length > 0).join(" ").trim() || void 0;
|
|
161
|
+
};
|
|
148
162
|
var UserMessage = (props) => {
|
|
149
163
|
const { message, ImageRenderer: ImageRenderer2 } = props;
|
|
150
|
-
const isImageMessage = message && "image" in message && message.image;
|
|
164
|
+
const isImageMessage = message && "image" in message && Boolean(message.image);
|
|
151
165
|
if (isImageMessage) {
|
|
152
166
|
const imageMessage = message;
|
|
153
|
-
|
|
167
|
+
const content2 = getTextContent(imageMessage == null ? void 0 : imageMessage.content);
|
|
168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ImageRenderer2, { image: imageMessage.image, content: content2 }) });
|
|
154
169
|
}
|
|
155
|
-
|
|
170
|
+
const content = getTextContent(message == null ? void 0 : message.content);
|
|
171
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: content });
|
|
156
172
|
};
|
|
157
173
|
|
|
158
174
|
// src/components/chat/Markdown.tsx
|
|
@@ -695,6 +711,7 @@ var AssistantMessage = (props) => {
|
|
|
695
711
|
onThumbsUp,
|
|
696
712
|
onThumbsDown,
|
|
697
713
|
isCurrentMessage,
|
|
714
|
+
feedback,
|
|
698
715
|
markdownTagRenderers
|
|
699
716
|
} = props;
|
|
700
717
|
const [copied, setCopied] = (0, import_react4.useState)(false);
|
|
@@ -716,12 +733,14 @@ var AssistantMessage = (props) => {
|
|
|
716
733
|
onRegenerate();
|
|
717
734
|
};
|
|
718
735
|
const handleThumbsUp = () => {
|
|
719
|
-
if (onThumbsUp && message)
|
|
736
|
+
if (onThumbsUp && message) {
|
|
720
737
|
onThumbsUp(message);
|
|
738
|
+
}
|
|
721
739
|
};
|
|
722
740
|
const handleThumbsDown = () => {
|
|
723
|
-
if (onThumbsDown && message)
|
|
741
|
+
if (onThumbsDown && message) {
|
|
724
742
|
onThumbsDown(message);
|
|
743
|
+
}
|
|
725
744
|
};
|
|
726
745
|
const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: icons.activityIcon });
|
|
727
746
|
const content = (message == null ? void 0 : message.content) || "";
|
|
@@ -757,7 +776,7 @@ var AssistantMessage = (props) => {
|
|
|
757
776
|
onThumbsUp && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
758
777
|
"button",
|
|
759
778
|
{
|
|
760
|
-
className:
|
|
779
|
+
className: `copilotKitMessageControlButton ${feedback === "thumbsUp" ? "active" : ""}`,
|
|
761
780
|
onClick: handleThumbsUp,
|
|
762
781
|
"aria-label": labels.thumbsUp,
|
|
763
782
|
title: labels.thumbsUp,
|
|
@@ -767,7 +786,7 @@ var AssistantMessage = (props) => {
|
|
|
767
786
|
onThumbsDown && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
768
787
|
"button",
|
|
769
788
|
{
|
|
770
|
-
className:
|
|
789
|
+
className: `copilotKitMessageControlButton ${feedback === "thumbsDown" ? "active" : ""}`,
|
|
771
790
|
onClick: handleThumbsDown,
|
|
772
791
|
"aria-label": labels.thumbsDown,
|
|
773
792
|
title: labels.thumbsDown,
|
|
@@ -828,6 +847,7 @@ function RenderMessage(_a) {
|
|
|
828
847
|
var _a2;
|
|
829
848
|
const {
|
|
830
849
|
message,
|
|
850
|
+
messages,
|
|
831
851
|
inProgress,
|
|
832
852
|
index,
|
|
833
853
|
isCurrentMessage,
|
|
@@ -835,6 +855,7 @@ function RenderMessage(_a) {
|
|
|
835
855
|
onCopy,
|
|
836
856
|
onThumbsUp,
|
|
837
857
|
onThumbsDown,
|
|
858
|
+
messageFeedback,
|
|
838
859
|
markdownTagRenderers
|
|
839
860
|
} = props;
|
|
840
861
|
switch (message.role) {
|
|
@@ -857,6 +878,7 @@ function RenderMessage(_a) {
|
|
|
857
878
|
subComponent: (_a2 = message.generativeUI) == null ? void 0 : _a2.call(message),
|
|
858
879
|
rawData: message,
|
|
859
880
|
message,
|
|
881
|
+
messages,
|
|
860
882
|
isLoading: inProgress && isCurrentMessage && !message.content,
|
|
861
883
|
isGenerating: inProgress && isCurrentMessage && !!message.content,
|
|
862
884
|
isCurrentMessage,
|
|
@@ -864,6 +886,7 @@ function RenderMessage(_a) {
|
|
|
864
886
|
onCopy,
|
|
865
887
|
onThumbsUp,
|
|
866
888
|
onThumbsDown,
|
|
889
|
+
feedback: (messageFeedback == null ? void 0 : messageFeedback[message.id]) || null,
|
|
867
890
|
markdownTagRenderers,
|
|
868
891
|
ImageRenderer: ImageRenderer2
|
|
869
892
|
},
|
|
@@ -877,6 +900,7 @@ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
|
877
900
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
878
901
|
var LegacyRenderMessage = ({
|
|
879
902
|
message,
|
|
903
|
+
messages,
|
|
880
904
|
inProgress,
|
|
881
905
|
index,
|
|
882
906
|
isCurrentMessage,
|
|
@@ -905,6 +929,7 @@ var LegacyRenderMessage = ({
|
|
|
905
929
|
RenderTextMessage,
|
|
906
930
|
{
|
|
907
931
|
message,
|
|
932
|
+
messages,
|
|
908
933
|
inProgress,
|
|
909
934
|
index,
|
|
910
935
|
isCurrentMessage,
|
|
@@ -922,6 +947,7 @@ var LegacyRenderMessage = ({
|
|
|
922
947
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
923
948
|
RenderActionExecutionMessage,
|
|
924
949
|
{
|
|
950
|
+
messages,
|
|
925
951
|
message,
|
|
926
952
|
inProgress,
|
|
927
953
|
index,
|
|
@@ -936,6 +962,7 @@ var LegacyRenderMessage = ({
|
|
|
936
962
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
937
963
|
RenderAgentStateMessage,
|
|
938
964
|
{
|
|
965
|
+
messages,
|
|
939
966
|
message,
|
|
940
967
|
inProgress,
|
|
941
968
|
index,
|
|
@@ -949,6 +976,7 @@ var LegacyRenderMessage = ({
|
|
|
949
976
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
950
977
|
RenderResultMessage,
|
|
951
978
|
{
|
|
979
|
+
messages,
|
|
952
980
|
message,
|
|
953
981
|
inProgress,
|
|
954
982
|
index,
|
|
@@ -962,6 +990,7 @@ var LegacyRenderMessage = ({
|
|
|
962
990
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
963
991
|
RenderImageMessage,
|
|
964
992
|
{
|
|
993
|
+
messages,
|
|
965
994
|
message,
|
|
966
995
|
inProgress,
|
|
967
996
|
index,
|
|
@@ -974,6 +1003,7 @@ var LegacyRenderMessage = ({
|
|
|
974
1003
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
975
1004
|
RenderMessage,
|
|
976
1005
|
{
|
|
1006
|
+
messages,
|
|
977
1007
|
message,
|
|
978
1008
|
inProgress,
|
|
979
1009
|
index,
|
|
@@ -1004,6 +1034,7 @@ var Messages = ({
|
|
|
1004
1034
|
onCopy,
|
|
1005
1035
|
onThumbsUp,
|
|
1006
1036
|
onThumbsDown,
|
|
1037
|
+
messageFeedback,
|
|
1007
1038
|
markdownTagRenderers,
|
|
1008
1039
|
chatError,
|
|
1009
1040
|
// Legacy props
|
|
@@ -1013,7 +1044,8 @@ var Messages = ({
|
|
|
1013
1044
|
RenderResultMessage,
|
|
1014
1045
|
RenderImageMessage
|
|
1015
1046
|
}) => {
|
|
1016
|
-
|
|
1047
|
+
var _a;
|
|
1048
|
+
const { labels, icons } = useChatContext();
|
|
1017
1049
|
const { messages: visibleMessages, interrupt } = (0, import_react_core.useCopilotChatInternal)();
|
|
1018
1050
|
const initialMessages = (0, import_react6.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
1019
1051
|
const messages = [...initialMessages, ...visibleMessages];
|
|
@@ -1043,6 +1075,7 @@ var Messages = ({
|
|
|
1043
1075
|
]
|
|
1044
1076
|
);
|
|
1045
1077
|
const MessageRenderer = hasLegacyProps ? (props) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LegacyRenderMessage, __spreadProps(__spreadValues({}, props), { legacyProps })) : RenderMessage2;
|
|
1078
|
+
const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: icons.activityIcon });
|
|
1046
1079
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
|
|
1047
1080
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessagesContainer", children: [
|
|
1048
1081
|
messages.map((message, index) => {
|
|
@@ -1051,6 +1084,7 @@ var Messages = ({
|
|
|
1051
1084
|
MessageRenderer,
|
|
1052
1085
|
{
|
|
1053
1086
|
message,
|
|
1087
|
+
messages,
|
|
1054
1088
|
inProgress,
|
|
1055
1089
|
index,
|
|
1056
1090
|
isCurrentMessage,
|
|
@@ -1061,11 +1095,13 @@ var Messages = ({
|
|
|
1061
1095
|
onCopy,
|
|
1062
1096
|
onThumbsUp,
|
|
1063
1097
|
onThumbsDown,
|
|
1098
|
+
messageFeedback,
|
|
1064
1099
|
markdownTagRenderers
|
|
1065
1100
|
},
|
|
1066
1101
|
index
|
|
1067
1102
|
);
|
|
1068
1103
|
}),
|
|
1104
|
+
((_a = messages[messages.length - 1]) == null ? void 0 : _a.role) === "user" && inProgress && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LoadingIcon, {}),
|
|
1069
1105
|
interrupt,
|
|
1070
1106
|
chatError && ErrorMessage && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ErrorMessage, { error: chatError, isCurrentMessage: true })
|
|
1071
1107
|
] }),
|