@copilotkit/react-ui 1.3.6 → 1.3.7
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 +10 -0
- package/dist/{chunk-H7TM5JE6.mjs → chunk-4FIGRRFS.mjs} +8 -8
- package/dist/chunk-4FIGRRFS.mjs.map +1 -0
- package/dist/{chunk-SPZEI5EN.mjs → chunk-6VYMULPK.mjs} +4 -4
- package/dist/{chunk-HIX4HRWU.mjs → chunk-7YQICPBC.mjs} +19 -12
- package/dist/chunk-7YQICPBC.mjs.map +1 -0
- package/dist/{chunk-RF3KLUPD.mjs → chunk-AAY3WWWC.mjs} +2 -3
- package/dist/chunk-AAY3WWWC.mjs.map +1 -0
- package/dist/{chunk-U6J5DGOE.mjs → chunk-BNCTYKEP.mjs} +2 -2
- package/dist/{chunk-GOTHQ665.mjs → chunk-DP5YVGNX.mjs} +2 -3
- package/dist/chunk-DP5YVGNX.mjs.map +1 -0
- package/dist/{chunk-TSQVQAAC.mjs → chunk-JQOSF44H.mjs} +2 -2
- package/dist/{chunk-WCPLXRZX.mjs → chunk-KFQYJ5R5.mjs} +1 -1
- package/dist/chunk-KFQYJ5R5.mjs.map +1 -0
- package/dist/{chunk-LT5YTQ4F.mjs → chunk-RS6UPR5N.mjs} +12 -4
- package/dist/chunk-RS6UPR5N.mjs.map +1 -0
- package/dist/{chunk-YH2STM73.mjs → chunk-RWT7WRG2.mjs} +3 -3
- package/dist/chunk-RWT7WRG2.mjs.map +1 -0
- package/dist/{chunk-VOBX4JOA.mjs → chunk-S5MBUNGN.mjs} +8 -6
- package/dist/chunk-S5MBUNGN.mjs.map +1 -0
- package/dist/{chunk-GDNJRSD4.mjs → chunk-SHTMRY45.mjs} +8 -10
- package/dist/chunk-SHTMRY45.mjs.map +1 -0
- package/dist/{chunk-P47XGGRX.mjs → chunk-TYYJR3LE.mjs} +2 -2
- package/dist/{chunk-MA5B5ELM.mjs → chunk-WHSD7DBC.mjs} +2 -3
- package/dist/chunk-WHSD7DBC.mjs.map +1 -0
- package/dist/components/chat/Chat.js +37 -33
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +11 -11
- package/dist/components/chat/Input.js +18 -3
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +2 -2
- package/dist/components/chat/Messages.js +6 -6
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +1 -1
- package/dist/components/chat/Modal.js +37 -33
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +12 -12
- package/dist/components/chat/Popup.js +37 -33
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +13 -13
- package/dist/components/chat/Sidebar.js +37 -33
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +13 -13
- package/dist/components/chat/Suggestion.d.ts +2 -2
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +1 -1
- package/dist/components/chat/index.js +37 -33
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +14 -14
- package/dist/components/chat/messages/RenderActionExecutionMessage.js +1 -1
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +1 -1
- package/dist/components/chat/messages/RenderAgentStateMessage.js +1 -2
- package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderAgentStateMessage.mjs +1 -1
- package/dist/components/chat/messages/RenderResultMessage.js +1 -2
- package/dist/components/chat/messages/RenderResultMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderResultMessage.mjs +1 -1
- package/dist/components/chat/messages/RenderTextMessage.js +1 -2
- package/dist/components/chat/messages/RenderTextMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderTextMessage.mjs +1 -1
- package/dist/components/dev-console/console.js +13 -7
- package/dist/components/dev-console/console.js.map +1 -1
- package/dist/components/dev-console/console.mjs +2 -2
- package/dist/components/dev-console/index.js +13 -7
- package/dist/components/dev-console/index.js.map +1 -1
- package/dist/components/dev-console/index.mjs +2 -2
- package/dist/components/dev-console/utils.d.ts +2 -2
- package/dist/components/dev-console/utils.js +4 -6
- package/dist/components/dev-console/utils.js.map +1 -1
- package/dist/components/dev-console/utils.mjs +1 -1
- package/dist/components/index.js +37 -33
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +14 -14
- package/dist/hooks/use-push-to-talk.js +18 -3
- package/dist/hooks/use-push-to-talk.js.map +1 -1
- package/dist/hooks/use-push-to-talk.mjs +1 -1
- package/dist/index.js +37 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -14
- package/package.json +8 -8
- package/src/components/chat/Chat.tsx +9 -2
- package/src/components/chat/Messages.tsx +6 -6
- package/src/components/chat/Suggestion.tsx +2 -2
- package/src/components/chat/messages/RenderActionExecutionMessage.tsx +1 -1
- package/src/components/chat/messages/RenderAgentStateMessage.tsx +1 -1
- package/src/components/chat/messages/RenderResultMessage.tsx +1 -1
- package/src/components/chat/messages/RenderTextMessage.tsx +1 -1
- package/src/components/dev-console/console.tsx +6 -2
- package/src/components/dev-console/utils.ts +10 -6
- package/src/hooks/use-push-to-talk.tsx +5 -3
- package/dist/chunk-GDNJRSD4.mjs.map +0 -1
- package/dist/chunk-GOTHQ665.mjs.map +0 -1
- package/dist/chunk-H7TM5JE6.mjs.map +0 -1
- package/dist/chunk-HIX4HRWU.mjs.map +0 -1
- package/dist/chunk-LT5YTQ4F.mjs.map +0 -1
- package/dist/chunk-MA5B5ELM.mjs.map +0 -1
- package/dist/chunk-RF3KLUPD.mjs.map +0 -1
- package/dist/chunk-VOBX4JOA.mjs.map +0 -1
- package/dist/chunk-WCPLXRZX.mjs.map +0 -1
- package/dist/chunk-YH2STM73.mjs.map +0 -1
- /package/dist/{chunk-SPZEI5EN.mjs.map → chunk-6VYMULPK.mjs.map} +0 -0
- /package/dist/{chunk-U6J5DGOE.mjs.map → chunk-BNCTYKEP.mjs.map} +0 -0
- /package/dist/{chunk-TSQVQAAC.mjs.map → chunk-JQOSF44H.mjs.map} +0 -0
- /package/dist/{chunk-P47XGGRX.mjs.map → chunk-TYYJR3LE.mjs.map} +0 -0
|
@@ -2,26 +2,26 @@ import {
|
|
|
2
2
|
CopilotChat,
|
|
3
3
|
WrappedCopilotChat,
|
|
4
4
|
useCopilotChatLogic
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-7YQICPBC.mjs";
|
|
6
6
|
import "../../chunk-V7W6IM2V.mjs";
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
10
|
-
import "../../chunk-
|
|
11
|
-
import "../../chunk-
|
|
12
|
-
import "../../chunk-
|
|
13
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-RWT7WRG2.mjs";
|
|
8
|
+
import "../../chunk-AAY3WWWC.mjs";
|
|
9
|
+
import "../../chunk-DP5YVGNX.mjs";
|
|
10
|
+
import "../../chunk-WHSD7DBC.mjs";
|
|
11
|
+
import "../../chunk-KFQYJ5R5.mjs";
|
|
12
|
+
import "../../chunk-RS6UPR5N.mjs";
|
|
13
|
+
import "../../chunk-4FIGRRFS.mjs";
|
|
14
14
|
import "../../chunk-OTPAZXVR.mjs";
|
|
15
|
-
import "../../chunk-
|
|
15
|
+
import "../../chunk-BNCTYKEP.mjs";
|
|
16
16
|
import "../../chunk-YQFVRDNC.mjs";
|
|
17
17
|
import "../../chunk-YQ3D5IQV.mjs";
|
|
18
|
-
import "../../chunk-
|
|
18
|
+
import "../../chunk-SHTMRY45.mjs";
|
|
19
19
|
import "../../chunk-XSUSSWDS.mjs";
|
|
20
20
|
import "../../chunk-BJPGMY3I.mjs";
|
|
21
21
|
import "../../chunk-UPTB2MVO.mjs";
|
|
22
22
|
import "../../chunk-FZC7X5PK.mjs";
|
|
23
23
|
import "../../chunk-54JAUBUJ.mjs";
|
|
24
|
-
import "../../chunk-
|
|
24
|
+
import "../../chunk-S5MBUNGN.mjs";
|
|
25
25
|
import "../../chunk-MRXNTQOX.mjs";
|
|
26
26
|
export {
|
|
27
27
|
CopilotChat,
|
|
@@ -3,8 +3,22 @@ var __create = Object.create;
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
8
22
|
var __export = (target, all) => {
|
|
9
23
|
for (var name in all)
|
|
10
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -120,7 +134,6 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
120
134
|
|
|
121
135
|
// src/hooks/use-push-to-talk.tsx
|
|
122
136
|
var import_react_core = require("@copilotkit/react-core");
|
|
123
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
124
137
|
var import_react3 = require("react");
|
|
125
138
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
126
139
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
@@ -175,7 +188,9 @@ var usePushToTalk = ({
|
|
|
175
188
|
const audioContextRef = (0, import_react3.useRef)(null);
|
|
176
189
|
const mediaRecorderRef = (0, import_react3.useRef)(null);
|
|
177
190
|
const recordedChunks = (0, import_react3.useRef)([]);
|
|
178
|
-
const
|
|
191
|
+
const generalContext = (0, import_react_core.useCopilotContext)();
|
|
192
|
+
const messagesContext = (0, import_react_core.useCopilotMessagesContext)();
|
|
193
|
+
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
179
194
|
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react3.useState)(null);
|
|
180
195
|
(0, import_react3.useEffect)(() => {
|
|
181
196
|
if (pushToTalkState === "recording") {
|
|
@@ -211,7 +226,7 @@ var usePushToTalk = ({
|
|
|
211
226
|
(message) => message.id === startReadingFromMessageId
|
|
212
227
|
);
|
|
213
228
|
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
214
|
-
(message) => message
|
|
229
|
+
(message) => message.isTextMessage() && message.role === "assistant"
|
|
215
230
|
);
|
|
216
231
|
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
217
232
|
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
@@ -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"],"sourcesContent":["import React, { useEffect, 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\";\n\nexport const Input = ({ inProgress, onSend, isVisible = false }: InputProps) => {\n const context = useChatContext();\n const copilotContext = useCopilotContext();\n\n const pushToTalkConfigured =\n copilotContext.copilotApiConfig.textToSpeechUrl !== undefined &&\n copilotContext.copilotApiConfig.transcribeAudioUrl !== undefined;\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {\n // Check if the clicked element is not the textarea itself\n if (event.target !== event.currentTarget) return;\n\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 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 sendIcon =\n inProgress || pushToTalkState === \"transcribing\"\n ? context.icons.activityIcon\n : context.icons.sendIcon;\n const showPushToTalk =\n pushToTalkConfigured &&\n (pushToTalkState === \"idle\" || pushToTalkState === \"recording\") &&\n !inProgress;\n const sendDisabled = inProgress || text.length === 0 || pushToTalkState !== \"idle\";\n\n return (\n <div className=\"copilotKitInput\" onClick={handleDivClick}>\n <AutoResizingTextarea\n ref={textareaRef}\n placeholder={context.labels.placeholder}\n autoFocus={true}\n maxRows={5}\n value={text}\n onChange={(event) => setText(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n send();\n }\n }}\n />\n <div className=\"copilotKitInputControls\">\n {showPushToTalk && (\n <button\n onClick={() =>\n setPushToTalkState(pushToTalkState === \"idle\" ? \"recording\" : \"transcribing\")\n }\n className={pushToTalkState === \"recording\" ? \"copilotKitPushToTalkRecording\" : \"\"}\n >\n {context.icons.pushToTalkIcon}\n </button>\n )}\n <button disabled={sendDisabled} onClick={send}>\n {sendIcon}\n </button>\n </div>\n </div>\n );\n};\n","import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons 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/**\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\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 context = {\n labels: {\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 },\n ...labels,\n },\n\n icons: {\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.PushToTalkIcon,\n },\n ...icons,\n },\n open,\n setOpen,\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 autoFocus?: boolean;\n}\n\nconst AutoResizingTextarea = forwardRef<HTMLTextAreaElement, AutoResizingTextareaProps>(\n ({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {\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 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 } from \"@copilotkit/react-core\";\nimport { Message, TextMessage } from \"@copilotkit/runtime-client-gql\";\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 context = useCopilotContext();\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 messagesAfterLast = context.messages\n .slice(lastMessageIndex + 1)\n .filter(\n (message) => message instanceof TextMessage && message.role === \"assistant\",\n ) as TextMessage[];\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAmD;;;ACAnD,mBAAyC;AA6KhC;AA/DF,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;AA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cAAc,KAAK,WAAW,KAAK,oBAAoB;AAE5E,SACE,8CAAC,SAAI,WAAU,mBAAkB,SAAS,gBACxC;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,aAAa,QAAQ,OAAO;AAAA,QAC5B,WAAW;AAAA,QACX,SAAS;AAAA,QACT,OAAO;AAAA,QACP,UAAU,CAAC,UAAU,QAAQ,MAAM,OAAO,KAAK;AAAA,QAC/C,WAAW,CAAC,UAAU;AACpB,cAAI,MAAM,QAAQ,WAAW,CAAC,MAAM,UAAU;AAC5C,kBAAM,eAAe;AACrB,iBAAK;AAAA,UACP;AAAA,QACF;AAAA;AAAA,IACF;AAAA,IACA,8CAAC,SAAI,WAAU,2BACZ;AAAA,wBACC;AAAA,QAAC;AAAA;AAAA,UACC,SAAS,MACP,mBAAmB,oBAAoB,SAAS,cAAc,cAAc;AAAA,UAE9E,WAAW,oBAAoB,cAAc,kCAAkC;AAAA,UAE9E,kBAAQ,MAAM;AAAA;AAAA,MACjB;AAAA,MAEF,6CAAC,YAAO,UAAU,cAAc,SAAS,MACtC,oBACH;AAAA,OACF;AAAA,KACF;AAEJ;","names":["import_react","React","import_react","import_jsx_runtime","import_react","import_react_core","import_jsx_runtime"]}
|
|
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"],"sourcesContent":["import React, { useEffect, 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\";\n\nexport const Input = ({ inProgress, onSend, isVisible = false }: InputProps) => {\n const context = useChatContext();\n const copilotContext = useCopilotContext();\n\n const pushToTalkConfigured =\n copilotContext.copilotApiConfig.textToSpeechUrl !== undefined &&\n copilotContext.copilotApiConfig.transcribeAudioUrl !== undefined;\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {\n // Check if the clicked element is not the textarea itself\n if (event.target !== event.currentTarget) return;\n\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 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 sendIcon =\n inProgress || pushToTalkState === \"transcribing\"\n ? context.icons.activityIcon\n : context.icons.sendIcon;\n const showPushToTalk =\n pushToTalkConfigured &&\n (pushToTalkState === \"idle\" || pushToTalkState === \"recording\") &&\n !inProgress;\n const sendDisabled = inProgress || text.length === 0 || pushToTalkState !== \"idle\";\n\n return (\n <div className=\"copilotKitInput\" onClick={handleDivClick}>\n <AutoResizingTextarea\n ref={textareaRef}\n placeholder={context.labels.placeholder}\n autoFocus={true}\n maxRows={5}\n value={text}\n onChange={(event) => setText(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n send();\n }\n }}\n />\n <div className=\"copilotKitInputControls\">\n {showPushToTalk && (\n <button\n onClick={() =>\n setPushToTalkState(pushToTalkState === \"idle\" ? \"recording\" : \"transcribing\")\n }\n className={pushToTalkState === \"recording\" ? \"copilotKitPushToTalkRecording\" : \"\"}\n >\n {context.icons.pushToTalkIcon}\n </button>\n )}\n <button disabled={sendDisabled} onClick={send}>\n {sendIcon}\n </button>\n </div>\n </div>\n );\n};\n","import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons 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/**\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\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 context = {\n labels: {\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 },\n ...labels,\n },\n\n icons: {\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.PushToTalkIcon,\n },\n ...icons,\n },\n open,\n setOpen,\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 autoFocus?: boolean;\n}\n\nconst AutoResizingTextarea = forwardRef<HTMLTextAreaElement, AutoResizingTextareaProps>(\n ({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {\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 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 { Message, TextMessage } from \"@copilotkit/runtime-client-gql\";\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 messagesAfterLast = context.messages\n .slice(lastMessageIndex + 1)\n .filter(\n (message) => message.isTextMessage() && message.role === \"assistant\",\n ) as TextMessage[];\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAmD;;;ACAnD,mBAAyC;AA6KhC;AA/DF,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;;;ACxHA,IAAAC,gBAAoF;AA2C9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,cAAc,KAAK,WAAW,KAAK,oBAAoB;AAE5E,SACE,8CAAC,SAAI,WAAU,mBAAkB,SAAS,gBACxC;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,aAAa,QAAQ,OAAO;AAAA,QAC5B,WAAW;AAAA,QACX,SAAS;AAAA,QACT,OAAO;AAAA,QACP,UAAU,CAAC,UAAU,QAAQ,MAAM,OAAO,KAAK;AAAA,QAC/C,WAAW,CAAC,UAAU;AACpB,cAAI,MAAM,QAAQ,WAAW,CAAC,MAAM,UAAU;AAC5C,kBAAM,eAAe;AACrB,iBAAK;AAAA,UACP;AAAA,QACF;AAAA;AAAA,IACF;AAAA,IACA,8CAAC,SAAI,WAAU,2BACZ;AAAA,wBACC;AAAA,QAAC;AAAA;AAAA,UACC,SAAS,MACP,mBAAmB,oBAAoB,SAAS,cAAc,cAAc;AAAA,UAE9E,WAAW,oBAAoB,cAAc,kCAAkC;AAAA,UAE9E,kBAAQ,MAAM;AAAA;AAAA,MACjB;AAAA,MAEF,6CAAC,YAAO,UAAU,cAAc,SAAS,MACtC,oBACH;AAAA,OACF;AAAA,KACF;AAEJ;","names":["import_react","React","import_react","import_jsx_runtime","import_react","import_react_core","import_jsx_runtime"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Input
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-BNCTYKEP.mjs";
|
|
4
4
|
import "../../chunk-YQFVRDNC.mjs";
|
|
5
5
|
import "../../chunk-BJPGMY3I.mjs";
|
|
6
6
|
import "../../chunk-FZC7X5PK.mjs";
|
|
7
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-S5MBUNGN.mjs";
|
|
8
8
|
import "../../chunk-MRXNTQOX.mjs";
|
|
9
9
|
export {
|
|
10
10
|
Input
|
|
@@ -69,10 +69,10 @@ var Messages = ({
|
|
|
69
69
|
messages = [...initialMessages, ...messages];
|
|
70
70
|
const actionResults = {};
|
|
71
71
|
for (let i = 0; i < messages.length; i++) {
|
|
72
|
-
if (messages[i]
|
|
72
|
+
if (messages[i].isActionExecutionMessage()) {
|
|
73
73
|
const id = messages[i].id;
|
|
74
74
|
const resultMessage = messages.find(
|
|
75
|
-
(message) => message
|
|
75
|
+
(message) => message.isResultMessage() && message.actionExecutionId === id
|
|
76
76
|
);
|
|
77
77
|
if (resultMessage) {
|
|
78
78
|
actionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
@@ -93,7 +93,7 @@ var Messages = ({
|
|
|
93
93
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
94
94
|
messages.map((message, index) => {
|
|
95
95
|
const isCurrentMessage = index === messages.length - 1;
|
|
96
|
-
if (message
|
|
96
|
+
if (message.isTextMessage()) {
|
|
97
97
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
98
98
|
RenderTextMessage,
|
|
99
99
|
{
|
|
@@ -104,7 +104,7 @@ var Messages = ({
|
|
|
104
104
|
},
|
|
105
105
|
index
|
|
106
106
|
);
|
|
107
|
-
} else if (message
|
|
107
|
+
} else if (message.isActionExecutionMessage()) {
|
|
108
108
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
109
109
|
RenderActionExecutionMessage,
|
|
110
110
|
{
|
|
@@ -116,7 +116,7 @@ var Messages = ({
|
|
|
116
116
|
},
|
|
117
117
|
index
|
|
118
118
|
);
|
|
119
|
-
} else if (message
|
|
119
|
+
} else if (message.isAgentStateMessage()) {
|
|
120
120
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
121
121
|
RenderAgentStateMessage,
|
|
122
122
|
{
|
|
@@ -127,7 +127,7 @@ var Messages = ({
|
|
|
127
127
|
},
|
|
128
128
|
index
|
|
129
129
|
);
|
|
130
|
-
} else if (message
|
|
130
|
+
} else if (message.isResultMessage()) {
|
|
131
131
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
132
132
|
RenderResultMessage,
|
|
133
133
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/chat/Messages.tsx","../../../src/components/chat/ChatContext.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport { MessagesProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport {\n ActionExecutionMessage,\n Message,\n ResultMessage,\n TextMessage,\n Role,\n AgentStateMessage,\n} from \"@copilotkit/runtime-client-gql\";\n\nexport const Messages = ({\n messages,\n inProgress,\n children,\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n}: MessagesProps) => {\n const context = useChatContext();\n const initialMessages = useMemo(\n () => makeInitialMessages(context.labels.initial),\n [context.labels.initial],\n );\n messages = [...initialMessages, ...messages];\n\n const actionResults: Record<string, string> = {};\n\n for (let i = 0; i < messages.length; i++) {\n if (messages[i]
|
|
1
|
+
{"version":3,"sources":["../../../src/components/chat/Messages.tsx","../../../src/components/chat/ChatContext.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport { MessagesProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport {\n ActionExecutionMessage,\n Message,\n ResultMessage,\n TextMessage,\n Role,\n AgentStateMessage,\n} from \"@copilotkit/runtime-client-gql\";\n\nexport const Messages = ({\n messages,\n inProgress,\n children,\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n}: MessagesProps) => {\n const context = useChatContext();\n const initialMessages = useMemo(\n () => makeInitialMessages(context.labels.initial),\n [context.labels.initial],\n );\n messages = [...initialMessages, ...messages];\n\n const actionResults: Record<string, string> = {};\n\n for (let i = 0; i < messages.length; i++) {\n if (messages[i].isActionExecutionMessage()) {\n const id = messages[i].id;\n const resultMessage: ResultMessage | undefined = messages.find(\n (message) => message.isResultMessage() && message.actionExecutionId === id,\n ) as ResultMessage | undefined;\n\n if (resultMessage) {\n actionResults[id] = ResultMessage.decodeResult(resultMessage.result || \"\");\n }\n }\n }\n\n const messagesEndRef = React.useRef<HTMLDivElement>(null);\n\n const scrollToBottom = () => {\n if (messagesEndRef.current) {\n messagesEndRef.current.scrollIntoView({\n behavior: \"auto\",\n });\n }\n };\n\n useEffect(() => {\n scrollToBottom();\n }, [messages]);\n\n return (\n <div className=\"copilotKitMessages\">\n {messages.map((message, index) => {\n const isCurrentMessage = index === messages.length - 1;\n\n if (message.isTextMessage()) {\n return (\n <RenderTextMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n />\n );\n } else if (message.isActionExecutionMessage()) {\n return (\n <RenderActionExecutionMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n actionResult={actionResults[message.id]}\n />\n );\n } else if (message.isAgentStateMessage()) {\n return (\n <RenderAgentStateMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n />\n );\n } else if (message.isResultMessage()) {\n return (\n <RenderResultMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n />\n );\n }\n })}\n <footer ref={messagesEndRef}>{children}</footer>\n </div>\n );\n};\n\nfunction makeInitialMessages(initial?: string | string[]): Message[] {\n let initialArray: string[] = [];\n if (initial) {\n if (Array.isArray(initial)) {\n initialArray.push(...initial);\n } else {\n initialArray.push(initial);\n }\n }\n\n return initialArray.map(\n (message) =>\n new TextMessage({\n role: Role.Assistant,\n content: message,\n }),\n );\n}\n","import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons 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/**\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\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 context = {\n labels: {\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 },\n ...labels,\n },\n\n icons: {\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.PushToTalkIcon,\n },\n ...icons,\n },\n open,\n setOpen,\n };\n return <ChatContext.Provider value={context}>{children}</ChatContext.Provider>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA0C;;;ACA1C,mBAAyC;AA6KhC;AA/DF,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;;;ADrHA,gCAOO;AAgDH,IAAAC,sBAAA;AA9CG,IAAM,WAAW,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAqB;AACnB,QAAM,UAAU,eAAe;AAC/B,QAAM,sBAAkB;AAAA,IACtB,MAAM,oBAAoB,QAAQ,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A,YAEC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA;AAAA,UAJK;AAAA,QAKP;AAAA,MAEJ,WAAW,QAAQ,gBAAgB,GAAG;AACpC,eACE;AAAA,UAAC;AAAA;AAAA,YAEC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA;AAAA,UAJK;AAAA,QAKP;AAAA,MAEJ;AAAA,IACF,CAAC;AAAA,IACD,6CAAC,YAAO,KAAK,gBAAiB,UAAS;AAAA,KACzC;AAEJ;AAEA,SAAS,oBAAoB,SAAwC;AACnE,MAAI,eAAyB,CAAC;AAC9B,MAAI,SAAS;AACX,QAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,mBAAa,KAAK,GAAG,OAAO;AAAA,IAC9B,OAAO;AACL,mBAAa,KAAK,OAAO;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO,aAAa;AAAA,IAClB,CAAC,YACC,IAAI,sCAAY;AAAA,MACd,MAAM,+BAAK;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACL;AACF;","names":["import_react","React","import_jsx_runtime","React"]}
|
|
@@ -533,10 +533,10 @@ var Messages = ({
|
|
|
533
533
|
messages = [...initialMessages, ...messages];
|
|
534
534
|
const actionResults = {};
|
|
535
535
|
for (let i = 0; i < messages.length; i++) {
|
|
536
|
-
if (messages[i]
|
|
536
|
+
if (messages[i].isActionExecutionMessage()) {
|
|
537
537
|
const id = messages[i].id;
|
|
538
538
|
const resultMessage = messages.find(
|
|
539
|
-
(message) => message
|
|
539
|
+
(message) => message.isResultMessage() && message.actionExecutionId === id
|
|
540
540
|
);
|
|
541
541
|
if (resultMessage) {
|
|
542
542
|
actionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
@@ -557,7 +557,7 @@ var Messages = ({
|
|
|
557
557
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
558
558
|
messages.map((message, index) => {
|
|
559
559
|
const isCurrentMessage = index === messages.length - 1;
|
|
560
|
-
if (message
|
|
560
|
+
if (message.isTextMessage()) {
|
|
561
561
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
562
562
|
RenderTextMessage2,
|
|
563
563
|
{
|
|
@@ -568,7 +568,7 @@ var Messages = ({
|
|
|
568
568
|
},
|
|
569
569
|
index
|
|
570
570
|
);
|
|
571
|
-
} else if (message
|
|
571
|
+
} else if (message.isActionExecutionMessage()) {
|
|
572
572
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
573
573
|
RenderActionExecutionMessage2,
|
|
574
574
|
{
|
|
@@ -580,7 +580,7 @@ var Messages = ({
|
|
|
580
580
|
},
|
|
581
581
|
index
|
|
582
582
|
);
|
|
583
|
-
} else if (message
|
|
583
|
+
} else if (message.isAgentStateMessage()) {
|
|
584
584
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
585
585
|
RenderAgentStateMessage2,
|
|
586
586
|
{
|
|
@@ -591,7 +591,7 @@ var Messages = ({
|
|
|
591
591
|
},
|
|
592
592
|
index
|
|
593
593
|
);
|
|
594
|
-
} else if (message
|
|
594
|
+
} else if (message.isResultMessage()) {
|
|
595
595
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
596
596
|
RenderResultMessage2,
|
|
597
597
|
{
|
|
@@ -678,7 +678,6 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
678
678
|
|
|
679
679
|
// src/hooks/use-push-to-talk.tsx
|
|
680
680
|
var import_react_core = require("@copilotkit/react-core");
|
|
681
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
682
681
|
var import_react5 = require("react");
|
|
683
682
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
684
683
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
@@ -733,7 +732,9 @@ var usePushToTalk = ({
|
|
|
733
732
|
const audioContextRef = (0, import_react5.useRef)(null);
|
|
734
733
|
const mediaRecorderRef = (0, import_react5.useRef)(null);
|
|
735
734
|
const recordedChunks = (0, import_react5.useRef)([]);
|
|
736
|
-
const
|
|
735
|
+
const generalContext = (0, import_react_core.useCopilotContext)();
|
|
736
|
+
const messagesContext = (0, import_react_core.useCopilotMessagesContext)();
|
|
737
|
+
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
737
738
|
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react5.useState)(null);
|
|
738
739
|
(0, import_react5.useEffect)(() => {
|
|
739
740
|
if (pushToTalkState === "recording") {
|
|
@@ -769,7 +770,7 @@ var usePushToTalk = ({
|
|
|
769
770
|
(message) => message.id === startReadingFromMessageId
|
|
770
771
|
);
|
|
771
772
|
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
772
|
-
(message) => message
|
|
773
|
+
(message) => message.isTextMessage() && message.role === "assistant"
|
|
773
774
|
);
|
|
774
775
|
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
775
776
|
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
@@ -857,9 +858,6 @@ var ResponseButton = ({ onClick, inProgress }) => {
|
|
|
857
858
|
] });
|
|
858
859
|
};
|
|
859
860
|
|
|
860
|
-
// src/components/chat/messages/RenderTextMessage.tsx
|
|
861
|
-
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
862
|
-
|
|
863
861
|
// src/components/chat/Markdown.tsx
|
|
864
862
|
var import_react8 = require("react");
|
|
865
863
|
var import_react_markdown = __toESM(require("react-markdown"));
|
|
@@ -1333,7 +1331,7 @@ var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
|
1333
1331
|
function RenderTextMessage(props) {
|
|
1334
1332
|
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1335
1333
|
const { icons } = useChatContext();
|
|
1336
|
-
if (message
|
|
1334
|
+
if (message.isTextMessage()) {
|
|
1337
1335
|
if (message.role === "user") {
|
|
1338
1336
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
1339
1337
|
} else if (message.role == "assistant") {
|
|
@@ -1343,14 +1341,14 @@ function RenderTextMessage(props) {
|
|
|
1343
1341
|
}
|
|
1344
1342
|
|
|
1345
1343
|
// src/components/chat/messages/RenderActionExecutionMessage.tsx
|
|
1346
|
-
var
|
|
1344
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
1347
1345
|
var import_react_core3 = require("@copilotkit/react-core");
|
|
1348
1346
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1349
1347
|
function RenderActionExecutionMessage(props) {
|
|
1350
1348
|
const { message, inProgress, index, isCurrentMessage, actionResult } = props;
|
|
1351
1349
|
const { chatComponentsCache } = (0, import_react_core3.useCopilotContext)();
|
|
1352
1350
|
const { icons } = useChatContext();
|
|
1353
|
-
if (message
|
|
1351
|
+
if (message.isActionExecutionMessage()) {
|
|
1354
1352
|
if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
|
|
1355
1353
|
const render = chatComponentsCache.current.actions[message.name];
|
|
1356
1354
|
if (typeof render === "string") {
|
|
@@ -1368,7 +1366,7 @@ function RenderActionExecutionMessage(props) {
|
|
|
1368
1366
|
let status = "inProgress";
|
|
1369
1367
|
if (actionResult !== void 0) {
|
|
1370
1368
|
status = "complete";
|
|
1371
|
-
} else if (message.status.code !==
|
|
1369
|
+
} else if (message.status.code !== import_runtime_client_gql2.MessageStatusCode.Pending) {
|
|
1372
1370
|
status = "executing";
|
|
1373
1371
|
}
|
|
1374
1372
|
try {
|
|
@@ -1411,25 +1409,23 @@ function RenderActionExecutionMessage(props) {
|
|
|
1411
1409
|
}
|
|
1412
1410
|
|
|
1413
1411
|
// src/components/chat/messages/RenderResultMessage.tsx
|
|
1414
|
-
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1415
1412
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1416
1413
|
function RenderResultMessage(props) {
|
|
1417
1414
|
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1418
1415
|
const { icons } = useChatContext();
|
|
1419
|
-
if (message
|
|
1416
|
+
if (message.isResultMessage() && inProgress && isCurrentMessage) {
|
|
1420
1417
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
|
|
1421
1418
|
}
|
|
1422
1419
|
}
|
|
1423
1420
|
|
|
1424
1421
|
// src/components/chat/messages/RenderAgentStateMessage.tsx
|
|
1425
|
-
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1426
1422
|
var import_react_core4 = require("@copilotkit/react-core");
|
|
1427
1423
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1428
1424
|
function RenderAgentStateMessage(props) {
|
|
1429
1425
|
const { message, inProgress, index, isCurrentMessage } = props;
|
|
1430
1426
|
const { chatComponentsCache } = (0, import_react_core4.useCopilotContext)();
|
|
1431
1427
|
const { icons } = useChatContext();
|
|
1432
|
-
if (message
|
|
1428
|
+
if (message.isAgentStateMessage()) {
|
|
1433
1429
|
let render;
|
|
1434
1430
|
if (chatComponentsCache.current !== null) {
|
|
1435
1431
|
render = chatComponentsCache.current.coAgentStateRenders[`${message.agentName}-${message.nodeName}`] || chatComponentsCache.current.coAgentStateRenders[`${message.agentName}-global`];
|
|
@@ -1482,7 +1478,7 @@ function RenderAgentStateMessage(props) {
|
|
|
1482
1478
|
// src/components/chat/Suggestion.tsx
|
|
1483
1479
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1484
1480
|
var import_shared = require("@copilotkit/shared");
|
|
1485
|
-
var
|
|
1481
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1486
1482
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1487
1483
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1488
1484
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
@@ -1518,7 +1514,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1518
1514
|
context,
|
|
1519
1515
|
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " + config.instructions + "\n\n" + numOfSuggestionsInstructions,
|
|
1520
1516
|
data: "Available tools: " + tools + "\n\n",
|
|
1521
|
-
requestType:
|
|
1517
|
+
requestType: import_runtime_client_gql3.CopilotRequestType.Task,
|
|
1522
1518
|
parameters: [
|
|
1523
1519
|
{
|
|
1524
1520
|
name: "suggestions",
|
|
@@ -1574,13 +1570,11 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1574
1570
|
// src/components/chat/Chat.tsx
|
|
1575
1571
|
var import_react11 = __toESM(require("react"));
|
|
1576
1572
|
var import_react_core8 = require("@copilotkit/react-core");
|
|
1577
|
-
var
|
|
1573
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1578
1574
|
var import_shared3 = require("@copilotkit/shared");
|
|
1579
1575
|
|
|
1580
1576
|
// src/components/dev-console/utils.ts
|
|
1581
1577
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
1582
|
-
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
1583
|
-
var import_runtime_client_gql9 = require("@copilotkit/runtime-client-gql");
|
|
1584
1578
|
function shouldShowDevConsole(showDevConsole) {
|
|
1585
1579
|
if (typeof showDevConsole === "boolean") {
|
|
1586
1580
|
return showDevConsole;
|
|
@@ -1670,7 +1664,7 @@ function logMessages(context) {
|
|
|
1670
1664
|
return;
|
|
1671
1665
|
}
|
|
1672
1666
|
const tableData = context.messages.map((message) => {
|
|
1673
|
-
if (message
|
|
1667
|
+
if (message.isTextMessage()) {
|
|
1674
1668
|
return {
|
|
1675
1669
|
id: message.id,
|
|
1676
1670
|
type: "TextMessage",
|
|
@@ -1679,7 +1673,7 @@ function logMessages(context) {
|
|
|
1679
1673
|
scope: void 0,
|
|
1680
1674
|
content: message.content
|
|
1681
1675
|
};
|
|
1682
|
-
} else if (message
|
|
1676
|
+
} else if (message.isActionExecutionMessage()) {
|
|
1683
1677
|
return {
|
|
1684
1678
|
id: message.id,
|
|
1685
1679
|
type: "ActionExecutionMessage",
|
|
@@ -1688,7 +1682,7 @@ function logMessages(context) {
|
|
|
1688
1682
|
scope: message.scope,
|
|
1689
1683
|
content: message.arguments
|
|
1690
1684
|
};
|
|
1691
|
-
} else if (message
|
|
1685
|
+
} else if (message.isResultMessage()) {
|
|
1692
1686
|
return {
|
|
1693
1687
|
id: message.id,
|
|
1694
1688
|
type: "ResultMessage",
|
|
@@ -1697,7 +1691,7 @@ function logMessages(context) {
|
|
|
1697
1691
|
scope: message.actionExecutionId,
|
|
1698
1692
|
content: message.result
|
|
1699
1693
|
};
|
|
1700
|
-
} else if (message
|
|
1694
|
+
} else if (message.isAgentStateMessage()) {
|
|
1701
1695
|
return {
|
|
1702
1696
|
id: message.id,
|
|
1703
1697
|
type: `AgentStateMessage (running: ${message.running})`,
|
|
@@ -1969,6 +1963,7 @@ function DebugMenuButton({
|
|
|
1969
1963
|
mode
|
|
1970
1964
|
}) {
|
|
1971
1965
|
const context = (0, import_react_core7.useCopilotContext)();
|
|
1966
|
+
const messagesContext = (0, import_react_core7.useCopilotMessagesContext)();
|
|
1972
1967
|
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "bg-black top-24 w-52 text-right", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react10.Menu, { children: [
|
|
1973
1968
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuButton, { className: `copilotKitDebugMenuButton ${mode === "compact" ? "compact" : ""}`, children: mode == "compact" ? "Debug" : /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
|
|
1974
1969
|
"Debug ",
|
|
@@ -1984,7 +1979,14 @@ function DebugMenuButton({
|
|
|
1984
1979
|
children: [
|
|
1985
1980
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logReadables(context), children: "Log Readables" }) }),
|
|
1986
1981
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logActions(context), children: "Log Actions" }) }),
|
|
1987
|
-
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1982
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1983
|
+
"button",
|
|
1984
|
+
{
|
|
1985
|
+
className: "copilotKitDebugMenuItem",
|
|
1986
|
+
onClick: () => logMessages(messagesContext),
|
|
1987
|
+
children: "Log Messages"
|
|
1988
|
+
}
|
|
1989
|
+
) }),
|
|
1988
1990
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => checkForUpdates(true), children: "Check for Updates" }) }),
|
|
1989
1991
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("hr", {}),
|
|
1990
1992
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => setShowDevConsole(false), children: "Hide Dev Console" }) })
|
|
@@ -2093,7 +2095,9 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
2093
2095
|
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
2094
2096
|
suggestionsAbortControllerRef.current = null;
|
|
2095
2097
|
};
|
|
2096
|
-
const
|
|
2098
|
+
const generalContext = (0, import_react_core8.useCopilotContext)();
|
|
2099
|
+
const messagesContext = (0, import_react_core8.useCopilotMessagesContext)();
|
|
2100
|
+
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2097
2101
|
(0, import_react11.useEffect)(() => {
|
|
2098
2102
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
2099
2103
|
abortSuggestions();
|
|
@@ -2118,9 +2122,9 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
2118
2122
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
2119
2123
|
abortSuggestions();
|
|
2120
2124
|
setCurrentSuggestions([]);
|
|
2121
|
-
const message = new
|
|
2125
|
+
const message = new import_runtime_client_gql4.TextMessage({
|
|
2122
2126
|
content: messageContent,
|
|
2123
|
-
role:
|
|
2127
|
+
role: import_runtime_client_gql4.Role.User
|
|
2124
2128
|
});
|
|
2125
2129
|
if (onSubmitMessage) {
|
|
2126
2130
|
try {
|