@copilotkit/react-ui 0.37.0 → 0.38.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/.turbo/turbo-build.log +72 -77
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-IEV5SYHX.mjs → chunk-5B6K3N4M.mjs} +7 -7
- package/dist/{chunk-GKZ5DRPT.mjs → chunk-B5UDC4YJ.mjs} +2 -2
- package/dist/chunk-DYXI54LF.mjs +126 -0
- package/dist/chunk-DYXI54LF.mjs.map +1 -0
- package/dist/{chunk-F4KCDLRJ.mjs → chunk-GICTFOCR.mjs} +11 -11
- package/dist/chunk-GICTFOCR.mjs.map +1 -0
- package/dist/{chunk-MSSOYSBR.mjs → chunk-U3TLLYFC.mjs} +2 -2
- package/dist/{chunk-4MKP23AD.mjs → chunk-U566UC72.mjs} +9 -2
- package/dist/chunk-U566UC72.mjs.map +1 -0
- package/dist/{chunk-LZHY5L7A.mjs → chunk-U6J5DGOE.mjs} +2 -2
- package/dist/{chunk-ANO23V2M.mjs → chunk-VOBX4JOA.mjs} +5 -2
- package/dist/chunk-VOBX4JOA.mjs.map +1 -0
- package/dist/components/chat/Button.d.ts +1 -1
- package/dist/components/chat/Chat.d.ts +1 -1
- package/dist/components/chat/Chat.js +73 -65
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +7 -7
- package/dist/components/chat/Header.d.ts +1 -1
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +4 -1
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +2 -2
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +55 -59
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +2 -2
- package/dist/components/chat/Modal.d.ts +1 -1
- package/dist/components/chat/Modal.js +73 -65
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +8 -8
- package/dist/components/chat/Popup.d.ts +1 -1
- package/dist/components/chat/Popup.js +73 -65
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +9 -9
- package/dist/components/chat/Response.d.ts +1 -1
- package/dist/components/chat/Sidebar.d.ts +1 -1
- package/dist/components/chat/Sidebar.js +73 -65
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +9 -9
- package/dist/components/chat/Suggestion.d.ts +1 -1
- package/dist/components/chat/Suggestion.js +8 -1
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +1 -1
- package/dist/components/chat/Window.d.ts +1 -1
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.js +73 -65
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +10 -10
- package/dist/components/chat/props.d.ts +1 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +73 -65
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -10
- package/dist/hooks/use-push-to-talk.d.ts +1 -1
- package/dist/hooks/use-push-to-talk.js +4 -1
- package/dist/hooks/use-push-to-talk.js.map +1 -1
- package/dist/hooks/use-push-to-talk.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +75 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/package.json +7 -6
- package/src/components/chat/Chat.tsx +4 -5
- package/src/components/chat/Messages.tsx +98 -98
- package/src/components/chat/Suggestion.tsx +9 -1
- package/src/components/chat/props.ts +1 -1
- package/src/hooks/use-push-to-talk.tsx +5 -3
- package/dist/chunk-23PTCJ2T.mjs +0 -122
- package/dist/chunk-23PTCJ2T.mjs.map +0 -1
- package/dist/chunk-4MKP23AD.mjs.map +0 -1
- package/dist/chunk-ANO23V2M.mjs.map +0 -1
- package/dist/chunk-F4KCDLRJ.mjs.map +0 -1
- package/dist/types/types.d.ts +0 -16
- package/dist/types/types.js +0 -19
- package/dist/types/types.js.map +0 -1
- package/dist/types/types.mjs +0 -1
- package/dist/types/types.mjs.map +0 -1
- package/src/types/types.ts +0 -18
- /package/dist/{chunk-IEV5SYHX.mjs.map → chunk-5B6K3N4M.mjs.map} +0 -0
- /package/dist/{chunk-GKZ5DRPT.mjs.map → chunk-B5UDC4YJ.mjs.map} +0 -0
- /package/dist/{chunk-MSSOYSBR.mjs.map → chunk-U3TLLYFC.mjs.map} +0 -0
- /package/dist/{chunk-LZHY5L7A.mjs.map → chunk-U6J5DGOE.mjs.map} +0 -0
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
extract
|
|
11
11
|
} from "@copilotkit/react-core";
|
|
12
|
+
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
12
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
14
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
14
15
|
return /* @__PURE__ */ jsxs(
|
|
@@ -29,7 +30,13 @@ function Suggestion({ title, message, onClick, partial, className }) {
|
|
|
29
30
|
}
|
|
30
31
|
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
31
32
|
const abortController = abortControllerRef.current;
|
|
32
|
-
const tools = JSON.stringify(
|
|
33
|
+
const tools = JSON.stringify(
|
|
34
|
+
Object.values(context.actions).map((action) => ({
|
|
35
|
+
name: action.name,
|
|
36
|
+
description: action.description,
|
|
37
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters))
|
|
38
|
+
}))
|
|
39
|
+
);
|
|
33
40
|
const allSuggestions = [];
|
|
34
41
|
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
35
42
|
try {
|
|
@@ -94,4 +101,4 @@ export {
|
|
|
94
101
|
Suggestion,
|
|
95
102
|
reloadSuggestions
|
|
96
103
|
};
|
|
97
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-U566UC72.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/Suggestion.tsx"],"sourcesContent":["import {\n CopilotContextParams,\n extract,\n CopilotChatSuggestionConfiguration,\n} from \"@copilotkit/react-core\";\nimport { SuggestionsProps } from \"./props\";\nimport { SmallSpinnerIcon } from \"./Icons\";\nimport { CopilotChatSuggestion } from \"../../types/suggestions\";\nimport { actionParametersToJsonSchema } from \"@copilotkit/shared\";\n\nexport function Suggestion({ title, message, onClick, partial, className }: SuggestionsProps) {\n return (\n <button\n disabled={partial}\n onClick={(e) => {\n e.preventDefault();\n onClick(message);\n }}\n className={className || \"suggestion\"}\n >\n {partial && SmallSpinnerIcon}\n <span>{title}</span>\n </button>\n );\n}\n\nexport const reloadSuggestions = async (\n context: CopilotContextParams,\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },\n setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,\n abortControllerRef: React.MutableRefObject<AbortController | null>,\n) => {\n const abortController = abortControllerRef.current;\n\n const tools = JSON.stringify(\n Object.values(context.actions).map((action) => ({\n name: action.name,\n description: action.description,\n jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),\n })),\n );\n\n const allSuggestions: CopilotChatSuggestion[] = [];\n\n for (const config of Object.values(chatSuggestionConfiguration)) {\n try {\n const numOfSuggestionsInstructions =\n config.minSuggestions === 0\n ? `Produce up to ${config.maxSuggestions} suggestions. ` +\n `If there are no highly relevant suggestions you can think of, provide an empty array.`\n : `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;\n const result = await extract({\n context,\n instructions:\n \"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. \" +\n config.instructions +\n \"\\n\\n\" +\n numOfSuggestionsInstructions,\n data: \"Available tools: \" + tools + \"\\n\\n\",\n parameters: [\n {\n name: \"suggestions\",\n type: \"object[]\",\n attributes: [\n {\n name: \"title\",\n description:\n \"The title of the suggestion. This is shown as a button and should be short.\",\n type: \"string\",\n },\n {\n name: \"message\",\n description:\n \"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.\",\n type: \"string\",\n },\n ],\n },\n ],\n include: {\n messages: true,\n readable: true,\n },\n abortSignal: abortController?.signal,\n stream: ({ status, args }) => {\n const suggestions = args.suggestions || [];\n const newSuggestions: CopilotChatSuggestion[] = [];\n for (let i = 0; i < suggestions.length; i++) {\n // if GPT provides too many suggestions, limit the number of suggestions\n if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {\n break;\n }\n const { title, message } = suggestions[i];\n\n // If this is the last suggestion and the status is not complete, mark it as partial\n const partial = i == suggestions.length - 1 && status !== \"complete\";\n\n newSuggestions.push({\n title,\n message,\n partial,\n className: config.className,\n });\n }\n setCurrentSuggestions([...allSuggestions, ...newSuggestions]);\n },\n });\n allSuggestions.push(...result.suggestions);\n } catch (error) {\n console.error(\"Error loading suggestions\", error);\n }\n }\n\n if (abortControllerRef.current === abortController) {\n abortControllerRef.current = null;\n }\n};\n"],"mappings":";;;;;;;;AAAA;AAAA,EAEE;AAAA,OAEK;AAIP,SAAS,oCAAoC;AAIzC,SASE,KATF;AAFG,SAAS,WAAW,EAAE,OAAO,SAAS,SAAS,SAAS,UAAU,GAAqB;AAC5F,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU;AAAA,MACV,SAAS,CAAC,MAAM;AACd,UAAE,eAAe;AACjB,gBAAQ,OAAO;AAAA,MACjB;AAAA,MACA,WAAW,aAAa;AAAA,MAEvB;AAAA,mBAAW;AAAA,QACZ,oBAAC,UAAM,iBAAM;AAAA;AAAA;AAAA,EACf;AAEJ;AAEO,IAAM,oBAAoB,CAC/B,SACA,6BACA,uBACA,uBACG;AACH,QAAM,kBAAkB,mBAAmB;AAE3C,QAAM,QAAQ,KAAK;AAAA,IACjB,OAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC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,gCAAsB,CAAC,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAAA,QAC9D;AAAA,MACF,CAAC;AACD,qBAAe,KAAK,GAAG,OAAO,WAAW;AAAA,IAC3C,SAAS,OAAP;AACA,cAAQ,MAAM,6BAA6B,KAAK;AAAA,IAClD;AAAA,EACF;AAEA,MAAI,mBAAmB,YAAY,iBAAiB;AAClD,uBAAmB,UAAU;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-BJPGMY3I.mjs";
|
|
7
7
|
import {
|
|
8
8
|
usePushToTalk
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VOBX4JOA.mjs";
|
|
10
10
|
|
|
11
11
|
// src/components/chat/Input.tsx
|
|
12
12
|
import { useEffect, useRef, useState } from "react";
|
|
@@ -80,4 +80,4 @@ var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
|
80
80
|
export {
|
|
81
81
|
Input
|
|
82
82
|
};
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-U6J5DGOE.mjs.map
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/hooks/use-push-to-talk.tsx
|
|
6
6
|
import { useCopilotContext } from "@copilotkit/react-core";
|
|
7
|
+
import { TextMessage } from "@copilotkit/runtime-client-gql";
|
|
7
8
|
import { useEffect, useRef, useState } from "react";
|
|
8
9
|
var checkMicrophonePermission = () => __async(void 0, null, function* () {
|
|
9
10
|
try {
|
|
@@ -118,7 +119,9 @@ var usePushToTalk = ({
|
|
|
118
119
|
const lastMessageIndex = context.messages.findIndex(
|
|
119
120
|
(message) => message.id === startReadingFromMessageId
|
|
120
121
|
);
|
|
121
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
122
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
123
|
+
(message) => message instanceof TextMessage && message.role === "assistant"
|
|
124
|
+
);
|
|
122
125
|
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
123
126
|
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
124
127
|
setStartReadingFromMessageId(null);
|
|
@@ -132,4 +135,4 @@ export {
|
|
|
132
135
|
requestMicAndPlaybackPermission,
|
|
133
136
|
usePushToTalk
|
|
134
137
|
};
|
|
135
|
-
//# sourceMappingURL=chunk-
|
|
138
|
+
//# sourceMappingURL=chunk-VOBX4JOA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-push-to-talk.tsx"],"sourcesContent":["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,SAAS,yBAAyB;AAClC,SAAkB,mBAAmB;AACrC,SAA2B,WAAW,QAAQ,gBAAgB;AAEvD,IAAM,4BAA4B,MAAY;AACnD,MAAI;AACF,UAAM,mBAAmB,MAAM,UAAU,YAAY,MAAM;AAAA,MACzD,MAAM;AAAA,IACR,CAAC;AACD,QAAI,iBAAiB,UAAU,WAAW;AACxC,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF,SAAS,KAAP;AACA,YAAQ,MAAM,wCAAwC,GAAG;AAAA,EAC3D;AACF;AAEO,IAAM,kCAAkC,MAAY;AACzD,MAAI;AACF,UAAM,SAAS,MAAM,UAAU,aAAa,aAAa,EAAE,OAAO,KAAK,CAAC;AACxE,UAAM,eAAe,IAAI,OAAO,aAAa;AAC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EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,YAAU,MAAM;AACd,QAAI,eAAe,SAAS,2BAA2B;AACrD,YAAM,mBAAmB,QAAQ,SAAS;AAAA,QACxC,CAAC,YAAY,QAAQ,OAAO;AAAA,MAC9B;AAEA,YAAM,oBAAoB,QAAQ,SAC/B,MAAM,mBAAmB,CAAC,EAC1B;AAAA,QACC,CAAC,YAAY,mBAAmB,eAAe,QAAQ,SAAS;AAAA,MAClE;AAEF,YAAM,OAAO,kBAAkB,IAAI,CAAC,YAAY,QAAQ,OAAO,EAAE,KAAK,IAAI;AAC1E,wBAAkB,MAAM,QAAQ,iBAAiB,iBAAkB,gBAAgB,OAAQ;AAE3F,mCAA6B,IAAI;AAAA,IACnC;AAAA,EACF,GAAG,CAAC,2BAA2B,UAAU,CAAC;AAE1C,SAAO,EAAE,iBAAiB,mBAAmB;AAC/C;","names":[]}
|
|
@@ -2,7 +2,7 @@ import { CopilotChatIcons, CopilotChatLabels } from './ChatContext.js';
|
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { SystemMessageFunction } from '@copilotkit/react-core';
|
|
4
4
|
import { CopilotChatSuggestion } from '../../types/suggestions.js';
|
|
5
|
-
import { Message } from '@copilotkit/
|
|
5
|
+
import { Message } from '@copilotkit/runtime-client-gql';
|
|
6
6
|
import { MessagesProps, InputProps, ResponseButtonProps } from './props.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -378,8 +378,6 @@ var ChatContextProvider = ({
|
|
|
378
378
|
|
|
379
379
|
// src/components/chat/Messages.tsx
|
|
380
380
|
var import_react4 = __toESM(require("react"));
|
|
381
|
-
var import_nanoid = require("nanoid");
|
|
382
|
-
var import_shared = require("@copilotkit/shared");
|
|
383
381
|
|
|
384
382
|
// src/components/chat/Markdown.tsx
|
|
385
383
|
var import_react3 = require("react");
|
|
@@ -851,6 +849,7 @@ var components = {
|
|
|
851
849
|
|
|
852
850
|
// src/components/chat/Messages.tsx
|
|
853
851
|
var import_react_core = require("@copilotkit/react-core");
|
|
852
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
854
853
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
855
854
|
var Messages = ({ messages, inProgress, children }) => {
|
|
856
855
|
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
@@ -862,10 +861,13 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
862
861
|
messages = [...initialMessages, ...messages];
|
|
863
862
|
const functionResults = {};
|
|
864
863
|
for (let i = 0; i < messages.length; i++) {
|
|
865
|
-
if (messages[i]
|
|
864
|
+
if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
866
865
|
const id = messages[i].id;
|
|
867
|
-
|
|
868
|
-
|
|
866
|
+
const resultMessage = messages.find(
|
|
867
|
+
(message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
|
|
868
|
+
);
|
|
869
|
+
if (resultMessage) {
|
|
870
|
+
functionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
869
871
|
}
|
|
870
872
|
}
|
|
871
873
|
}
|
|
@@ -882,60 +884,55 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
882
884
|
}, [messages]);
|
|
883
885
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
884
886
|
messages.map((message, index) => {
|
|
885
|
-
var _a, _b, _c;
|
|
886
887
|
const isCurrentMessage = index === messages.length - 1;
|
|
887
|
-
if (message.role === "user") {
|
|
888
|
+
if (message instanceof import_runtime_client_gql.TextMessage && message.role === "user") {
|
|
888
889
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
889
|
-
} else if (message.role == "assistant") {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inProgressLabel", children: render })
|
|
902
|
-
] }, index);
|
|
903
|
-
} else {
|
|
904
|
-
return null;
|
|
905
|
-
}
|
|
890
|
+
} else if (message instanceof import_runtime_client_gql.TextMessage && message.role == "assistant") {
|
|
891
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: isCurrentMessage && inProgress && !message.content ? context.icons.spinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Markdown, { content: message.content }) }, index);
|
|
892
|
+
} else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
893
|
+
if (chatComponentsCache.current !== null && chatComponentsCache.current[message.name]) {
|
|
894
|
+
const render = chatComponentsCache.current[message.name];
|
|
895
|
+
if (typeof render === "string") {
|
|
896
|
+
if (isCurrentMessage && inProgress) {
|
|
897
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
898
|
+
context.icons.spinnerIcon,
|
|
899
|
+
" ",
|
|
900
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inProgressLabel", children: render })
|
|
901
|
+
] }, index);
|
|
906
902
|
} else {
|
|
907
|
-
|
|
908
|
-
let status = "inProgress";
|
|
909
|
-
if (functionResults[message.id] !== void 0) {
|
|
910
|
-
status = "complete";
|
|
911
|
-
} else if (message.function_call) {
|
|
912
|
-
status = "executing";
|
|
913
|
-
}
|
|
914
|
-
const toRender = render({
|
|
915
|
-
status,
|
|
916
|
-
args,
|
|
917
|
-
result: functionResults[message.id]
|
|
918
|
-
});
|
|
919
|
-
if (!toRender && status === "complete") {
|
|
920
|
-
return null;
|
|
921
|
-
}
|
|
922
|
-
if (typeof toRender === "string") {
|
|
923
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
924
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
925
|
-
" ",
|
|
926
|
-
toRender
|
|
927
|
-
] }, index);
|
|
928
|
-
} else {
|
|
929
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
930
|
-
}
|
|
903
|
+
return null;
|
|
931
904
|
}
|
|
932
|
-
} else if ((!inProgress || !isCurrentMessage) && message.function_call) {
|
|
933
|
-
return null;
|
|
934
905
|
} else {
|
|
935
|
-
|
|
906
|
+
const args = message.arguments;
|
|
907
|
+
let status = "inProgress";
|
|
908
|
+
if (functionResults[message.id] !== void 0) {
|
|
909
|
+
status = "complete";
|
|
910
|
+
} else if (message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending) {
|
|
911
|
+
status = "executing";
|
|
912
|
+
}
|
|
913
|
+
const toRender = render({
|
|
914
|
+
status,
|
|
915
|
+
args,
|
|
916
|
+
result: functionResults[message.id]
|
|
917
|
+
});
|
|
918
|
+
if (!toRender && status === "complete") {
|
|
919
|
+
return null;
|
|
920
|
+
}
|
|
921
|
+
if (typeof toRender === "string") {
|
|
922
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
923
|
+
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
924
|
+
" ",
|
|
925
|
+
toRender
|
|
926
|
+
] }, index);
|
|
927
|
+
} else {
|
|
928
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
929
|
+
}
|
|
936
930
|
}
|
|
931
|
+
} else if (!inProgress || !isCurrentMessage) {
|
|
932
|
+
return null;
|
|
933
|
+
} else {
|
|
934
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
937
935
|
}
|
|
938
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Markdown, { content: message.content }) }, index);
|
|
939
936
|
}
|
|
940
937
|
}),
|
|
941
938
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("footer", { ref: messagesEndRef, children })
|
|
@@ -950,11 +947,12 @@ function makeInitialMessages(initial) {
|
|
|
950
947
|
initialArray.push(initial);
|
|
951
948
|
}
|
|
952
949
|
}
|
|
953
|
-
return initialArray.map(
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
950
|
+
return initialArray.map(
|
|
951
|
+
(message) => new import_runtime_client_gql.TextMessage({
|
|
952
|
+
role: import_runtime_client_gql.Role.Assistant,
|
|
953
|
+
content: message
|
|
954
|
+
})
|
|
955
|
+
);
|
|
958
956
|
}
|
|
959
957
|
|
|
960
958
|
// src/components/chat/Input.tsx
|
|
@@ -1011,6 +1009,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
1011
1009
|
|
|
1012
1010
|
// src/hooks/use-push-to-talk.tsx
|
|
1013
1011
|
var import_react_core2 = require("@copilotkit/react-core");
|
|
1012
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
1014
1013
|
var import_react6 = require("react");
|
|
1015
1014
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
1016
1015
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
@@ -1100,7 +1099,9 @@ var usePushToTalk = ({
|
|
|
1100
1099
|
const lastMessageIndex = context.messages.findIndex(
|
|
1101
1100
|
(message) => message.id === startReadingFromMessageId
|
|
1102
1101
|
);
|
|
1103
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
1102
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
1103
|
+
(message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
|
|
1104
|
+
);
|
|
1104
1105
|
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1105
1106
|
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1106
1107
|
setStartReadingFromMessageId(null);
|
|
@@ -1189,6 +1190,7 @@ var ResponseButton = ({ onClick, inProgress }) => {
|
|
|
1189
1190
|
|
|
1190
1191
|
// src/components/chat/Suggestion.tsx
|
|
1191
1192
|
var import_react_core4 = require("@copilotkit/react-core");
|
|
1193
|
+
var import_shared = require("@copilotkit/shared");
|
|
1192
1194
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1193
1195
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1194
1196
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
@@ -1209,7 +1211,13 @@ function Suggestion({ title, message, onClick, partial, className }) {
|
|
|
1209
1211
|
}
|
|
1210
1212
|
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1211
1213
|
const abortController = abortControllerRef.current;
|
|
1212
|
-
const tools = JSON.stringify(
|
|
1214
|
+
const tools = JSON.stringify(
|
|
1215
|
+
Object.values(context.actions).map((action) => ({
|
|
1216
|
+
name: action.name,
|
|
1217
|
+
description: action.description,
|
|
1218
|
+
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters))
|
|
1219
|
+
}))
|
|
1220
|
+
);
|
|
1213
1221
|
const allSuggestions = [];
|
|
1214
1222
|
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1215
1223
|
try {
|
|
@@ -1273,7 +1281,8 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1273
1281
|
// src/components/chat/Chat.tsx
|
|
1274
1282
|
var import_react8 = __toESM(require("react"));
|
|
1275
1283
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1276
|
-
var
|
|
1284
|
+
var import_nanoid = require("nanoid");
|
|
1285
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1277
1286
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1278
1287
|
function CopilotChat({
|
|
1279
1288
|
instructions,
|
|
@@ -1345,7 +1354,7 @@ function WrappedCopilotChat({
|
|
|
1345
1354
|
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
1346
1355
|
var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
1347
1356
|
const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0, import_react_core5.useCopilotChat)({
|
|
1348
|
-
id: (0,
|
|
1357
|
+
id: (0, import_nanoid.nanoid)(),
|
|
1349
1358
|
makeSystemMessage
|
|
1350
1359
|
});
|
|
1351
1360
|
const [currentSuggestions, setCurrentSuggestions] = (0, import_react8.useState)([]);
|
|
@@ -1382,11 +1391,10 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
1382
1391
|
abortSuggestions();
|
|
1383
1392
|
setCurrentSuggestions([]);
|
|
1384
1393
|
onSubmitMessage == null ? void 0 : onSubmitMessage(messageContent);
|
|
1385
|
-
const message = {
|
|
1386
|
-
id: (0, import_nanoid2.nanoid)(),
|
|
1394
|
+
const message = new import_runtime_client_gql3.TextMessage({
|
|
1387
1395
|
content: messageContent,
|
|
1388
|
-
role:
|
|
1389
|
-
};
|
|
1396
|
+
role: import_runtime_client_gql3.Role.User
|
|
1397
|
+
});
|
|
1390
1398
|
appendMessage(message);
|
|
1391
1399
|
return message;
|
|
1392
1400
|
});
|