@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.
Files changed (85) hide show
  1. package/.turbo/turbo-build.log +72 -77
  2. package/CHANGELOG.md +13 -0
  3. package/dist/{chunk-IEV5SYHX.mjs → chunk-5B6K3N4M.mjs} +7 -7
  4. package/dist/{chunk-GKZ5DRPT.mjs → chunk-B5UDC4YJ.mjs} +2 -2
  5. package/dist/chunk-DYXI54LF.mjs +126 -0
  6. package/dist/chunk-DYXI54LF.mjs.map +1 -0
  7. package/dist/{chunk-F4KCDLRJ.mjs → chunk-GICTFOCR.mjs} +11 -11
  8. package/dist/chunk-GICTFOCR.mjs.map +1 -0
  9. package/dist/{chunk-MSSOYSBR.mjs → chunk-U3TLLYFC.mjs} +2 -2
  10. package/dist/{chunk-4MKP23AD.mjs → chunk-U566UC72.mjs} +9 -2
  11. package/dist/chunk-U566UC72.mjs.map +1 -0
  12. package/dist/{chunk-LZHY5L7A.mjs → chunk-U6J5DGOE.mjs} +2 -2
  13. package/dist/{chunk-ANO23V2M.mjs → chunk-VOBX4JOA.mjs} +5 -2
  14. package/dist/chunk-VOBX4JOA.mjs.map +1 -0
  15. package/dist/components/chat/Button.d.ts +1 -1
  16. package/dist/components/chat/Chat.d.ts +1 -1
  17. package/dist/components/chat/Chat.js +73 -65
  18. package/dist/components/chat/Chat.js.map +1 -1
  19. package/dist/components/chat/Chat.mjs +7 -7
  20. package/dist/components/chat/Header.d.ts +1 -1
  21. package/dist/components/chat/Input.d.ts +1 -1
  22. package/dist/components/chat/Input.js +4 -1
  23. package/dist/components/chat/Input.js.map +1 -1
  24. package/dist/components/chat/Input.mjs +2 -2
  25. package/dist/components/chat/Messages.d.ts +1 -1
  26. package/dist/components/chat/Messages.js +55 -59
  27. package/dist/components/chat/Messages.js.map +1 -1
  28. package/dist/components/chat/Messages.mjs +2 -2
  29. package/dist/components/chat/Modal.d.ts +1 -1
  30. package/dist/components/chat/Modal.js +73 -65
  31. package/dist/components/chat/Modal.js.map +1 -1
  32. package/dist/components/chat/Modal.mjs +8 -8
  33. package/dist/components/chat/Popup.d.ts +1 -1
  34. package/dist/components/chat/Popup.js +73 -65
  35. package/dist/components/chat/Popup.js.map +1 -1
  36. package/dist/components/chat/Popup.mjs +9 -9
  37. package/dist/components/chat/Response.d.ts +1 -1
  38. package/dist/components/chat/Sidebar.d.ts +1 -1
  39. package/dist/components/chat/Sidebar.js +73 -65
  40. package/dist/components/chat/Sidebar.js.map +1 -1
  41. package/dist/components/chat/Sidebar.mjs +9 -9
  42. package/dist/components/chat/Suggestion.d.ts +1 -1
  43. package/dist/components/chat/Suggestion.js +8 -1
  44. package/dist/components/chat/Suggestion.js.map +1 -1
  45. package/dist/components/chat/Suggestion.mjs +1 -1
  46. package/dist/components/chat/Window.d.ts +1 -1
  47. package/dist/components/chat/index.d.ts +1 -1
  48. package/dist/components/chat/index.js +73 -65
  49. package/dist/components/chat/index.js.map +1 -1
  50. package/dist/components/chat/index.mjs +10 -10
  51. package/dist/components/chat/props.d.ts +1 -1
  52. package/dist/components/chat/props.js.map +1 -1
  53. package/dist/components/index.d.ts +1 -1
  54. package/dist/components/index.js +73 -65
  55. package/dist/components/index.js.map +1 -1
  56. package/dist/components/index.mjs +10 -10
  57. package/dist/hooks/use-push-to-talk.d.ts +1 -1
  58. package/dist/hooks/use-push-to-talk.js +4 -1
  59. package/dist/hooks/use-push-to-talk.js.map +1 -1
  60. package/dist/hooks/use-push-to-talk.mjs +1 -1
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.js +75 -67
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +10 -10
  65. package/package.json +7 -6
  66. package/src/components/chat/Chat.tsx +4 -5
  67. package/src/components/chat/Messages.tsx +98 -98
  68. package/src/components/chat/Suggestion.tsx +9 -1
  69. package/src/components/chat/props.ts +1 -1
  70. package/src/hooks/use-push-to-talk.tsx +5 -3
  71. package/dist/chunk-23PTCJ2T.mjs +0 -122
  72. package/dist/chunk-23PTCJ2T.mjs.map +0 -1
  73. package/dist/chunk-4MKP23AD.mjs.map +0 -1
  74. package/dist/chunk-ANO23V2M.mjs.map +0 -1
  75. package/dist/chunk-F4KCDLRJ.mjs.map +0 -1
  76. package/dist/types/types.d.ts +0 -16
  77. package/dist/types/types.js +0 -19
  78. package/dist/types/types.js.map +0 -1
  79. package/dist/types/types.mjs +0 -1
  80. package/dist/types/types.mjs.map +0 -1
  81. package/src/types/types.ts +0 -18
  82. /package/dist/{chunk-IEV5SYHX.mjs.map → chunk-5B6K3N4M.mjs.map} +0 -0
  83. /package/dist/{chunk-GKZ5DRPT.mjs.map → chunk-B5UDC4YJ.mjs.map} +0 -0
  84. /package/dist/{chunk-MSSOYSBR.mjs.map → chunk-U3TLLYFC.mjs.map} +0 -0
  85. /package/dist/{chunk-LZHY5L7A.mjs.map → chunk-U6J5DGOE.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-push-to-talk.tsx"],"sourcesContent":["import { CopilotContextParams, useCopilotContext } from \"@copilotkit/react-core\";\nimport { Message } from \"@copilotkit/shared\";\nimport { MutableRefObject, useEffect, useRef, useState } from \"react\";\n\nexport const checkMicrophonePermission = async () => {\n try {\n const permissionStatus = await navigator.permissions.query({\n name: \"microphone\" as PermissionName,\n });\n if (permissionStatus.state === \"granted\") {\n return true;\n } else {\n return false;\n }\n } catch (err) {\n console.error(\"Error checking microphone permission\", err);\n }\n};\n\nexport const requestMicAndPlaybackPermission = async () => {\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n const audioContext = new window.AudioContext();\n await audioContext.resume();\n return { stream, audioContext };\n } catch (err) {\n console.error(\"Error requesting microphone and playback permissions\", err);\n return null;\n }\n};\n\nconst startRecording = async (\n mediaStreamRef: MutableRefObject<MediaStream | null>,\n mediaRecorderRef: MutableRefObject<MediaRecorder | null>,\n audioContextRef: MutableRefObject<AudioContext | null>,\n recordedChunks: Blob[],\n onStop: () => void,\n) => {\n if (!mediaStreamRef.current || !audioContextRef.current) {\n mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({ audio: true });\n audioContextRef.current = new window.AudioContext();\n await audioContextRef.current.resume();\n }\n\n mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current!);\n mediaRecorderRef.current.start(1000);\n mediaRecorderRef.current.ondataavailable = (event) => {\n recordedChunks.push(event.data);\n };\n mediaRecorderRef.current.onstop = onStop;\n};\n\nconst stopRecording = (mediaRecorderRef: MutableRefObject<MediaRecorder | null>) => {\n if (mediaRecorderRef.current && mediaRecorderRef.current.state !== \"inactive\") {\n mediaRecorderRef.current.stop();\n }\n};\n\nconst transcribeAudio = async (recordedChunks: Blob[], transcribeAudioUrl: string) => {\n const completeBlob = new Blob(recordedChunks, { type: \"audio/mp4\" });\n const formData = new FormData();\n formData.append(\"file\", completeBlob, \"recording.mp4\");\n\n const response = await fetch(transcribeAudioUrl, {\n method: \"POST\",\n body: formData,\n });\n\n if (!response.ok) {\n throw new Error(`Error: ${response.statusText}`);\n }\n\n const transcription = await response.json();\n return transcription.text;\n};\n\nconst playAudioResponse = (text: string, textToSpeechUrl: string, audioContext: AudioContext) => {\n const encodedText = encodeURIComponent(text);\n const url = `${textToSpeechUrl}?text=${encodedText}`;\n\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer))\n .then((audioBuffer) => {\n const source = audioContext.createBufferSource();\n source.buffer = audioBuffer;\n source.connect(audioContext.destination);\n source.start(0);\n })\n .catch((error) => {\n console.error(\"Error with decoding audio data\", error);\n });\n};\n\nexport type PushToTalkState = \"idle\" | \"recording\" | \"transcribing\";\n\nexport type SendFunction = (text: string) => Promise<Message>;\n\nexport const usePushToTalk = ({\n sendFunction,\n inProgress,\n}: {\n sendFunction: SendFunction;\n inProgress: boolean;\n}) => {\n const [pushToTalkState, setPushToTalkState] = useState<PushToTalkState>(\"idle\");\n const mediaStreamRef = useRef<MediaStream | null>(null);\n const audioContextRef = useRef<AudioContext | null>(null);\n const mediaRecorderRef = useRef<MediaRecorder | null>(null);\n const recordedChunks = useRef<Blob[]>([]);\n const 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((message) => message.role === \"assistant\" && message.content);\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;AAAA;AAAA,wBAAwD;AAExD,mBAA8D;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;AA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BAAiB,kBAAmB,EAAE;AAAA,UACpF,CAAO,kBAAkB;AACvB,2BAAe,UAAU,CAAC;AAC1B,+BAAmB,MAAM;AACzB,kBAAM,UAAU,MAAM,aAAa,aAAa;AAChD,yCAA6B,QAAQ,EAAE;AAAA,UACzC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO,MAAM;AACX,oBAAc,gBAAgB;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,8BAAU,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,OAAO,CAAC,YAAY,QAAQ,SAAS,eAAe,QAAQ,OAAO;AAEtE,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":[]}
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;AAAA;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AAI,oBAAoB,aAAa;AACnC;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe;AAAA,QACf,MAAM;AACJ,6BAAmB,cAAc;AAAA,QACnC;AAAA,MACF;AAAA,IACF,OAAO;AACL,oBAAc,gBAAgB;AAC9B,UAAI,oBAAoB,gBAAgB;AACtC,wBAAgB,eAAe,SAAS,QAAQ,iBAAiB,kBAAmB,EAAE;AAAA,UACpF,CAAO,kBAAkB;AACvB,2BAAe,UAAU,CAAC;AAC1B,+BAAmB,MAAM;AACzB,kBAAM,UAAU,MAAM,aAAa,aAAa;AAChD,yCAA6B,QAAQ,EAAE;AAAA,UACzC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO,MAAM;AACX,oBAAc,gBAAgB;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,8BAAU,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,yCAAe,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 {
2
2
  checkMicrophonePermission,
3
3
  requestMicAndPlaybackPermission,
4
4
  usePushToTalk
5
- } from "../chunk-ANO23V2M.mjs";
5
+ } from "../chunk-VOBX4JOA.mjs";
6
6
  import "../chunk-MRXNTQOX.mjs";
7
7
  export {
8
8
  checkMicrophonePermission,
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { CopilotChat } from './components/chat/Chat.js';
5
5
  export { useChatContext } from './components/chat/ChatContext.js';
6
6
  export { useCopilotChatSuggestions } from './hooks/use-copilot-chat-suggestions.js';
7
7
  export { CopilotKitCSSProperties } from './types/css.js';
8
- import '@copilotkit/shared';
8
+ import '@copilotkit/runtime-client-gql';
9
9
  import './components/chat/Modal.js';
10
10
  import 'react';
11
11
  import '@copilotkit/react-core';
package/dist/index.js CHANGED
@@ -517,8 +517,6 @@ var Header = ({ setOpen }) => {
517
517
 
518
518
  // src/components/chat/Messages.tsx
519
519
  var import_react5 = __toESM(require("react"));
520
- var import_nanoid = require("nanoid");
521
- var import_shared = require("@copilotkit/shared");
522
520
 
523
521
  // src/components/chat/Markdown.tsx
524
522
  var import_react4 = require("react");
@@ -990,6 +988,7 @@ var components = {
990
988
 
991
989
  // src/components/chat/Messages.tsx
992
990
  var import_react_core = require("@copilotkit/react-core");
991
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
993
992
  var import_jsx_runtime8 = require("react/jsx-runtime");
994
993
  var Messages = ({ messages, inProgress, children }) => {
995
994
  const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
@@ -1001,10 +1000,13 @@ var Messages = ({ messages, inProgress, children }) => {
1001
1000
  messages = [...initialMessages, ...messages];
1002
1001
  const functionResults = {};
1003
1002
  for (let i = 0; i < messages.length; i++) {
1004
- if (messages[i].role === "assistant" && messages[i].function_call) {
1003
+ if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
1005
1004
  const id = messages[i].id;
1006
- if (i + 1 < messages.length && messages[i + 1].role === "function") {
1007
- functionResults[id] = (0, import_shared.decodeResult)(messages[i + 1].content || "");
1005
+ const resultMessage = messages.find(
1006
+ (message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
1007
+ );
1008
+ if (resultMessage) {
1009
+ functionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
1008
1010
  }
1009
1011
  }
1010
1012
  }
@@ -1021,60 +1023,55 @@ var Messages = ({ messages, inProgress, children }) => {
1021
1023
  }, [messages]);
1022
1024
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitMessages", children: [
1023
1025
  messages.map((message, index) => {
1024
- var _a, _b, _c;
1025
1026
  const isCurrentMessage = index === messages.length - 1;
1026
- if (message.role === "user") {
1027
+ if (message instanceof import_runtime_client_gql.TextMessage && message.role === "user") {
1027
1028
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
1028
- } else if (message.role == "assistant") {
1029
- if (isCurrentMessage && inProgress && !message.content && !message.partialFunctionCall) {
1030
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
1031
- } else if (message.function_call || message.partialFunctionCall) {
1032
- const functionCallName = ((_a = message.function_call) == null ? void 0 : _a.name) || ((_b = message.partialFunctionCall) == null ? void 0 : _b.name);
1033
- if (chatComponentsCache.current !== null && chatComponentsCache.current[functionCallName]) {
1034
- const render = chatComponentsCache.current[functionCallName];
1035
- if (typeof render === "string") {
1036
- if (isCurrentMessage && inProgress) {
1037
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
1038
- context.icons.spinnerIcon,
1039
- " ",
1040
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "inProgressLabel", children: render })
1041
- ] }, index);
1042
- } else {
1043
- return null;
1044
- }
1029
+ } else if (message instanceof import_runtime_client_gql.TextMessage && message.role == "assistant") {
1030
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: isCurrentMessage && inProgress && !message.content ? context.icons.spinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { content: message.content }) }, index);
1031
+ } else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
1032
+ if (chatComponentsCache.current !== null && chatComponentsCache.current[message.name]) {
1033
+ const render = chatComponentsCache.current[message.name];
1034
+ if (typeof render === "string") {
1035
+ if (isCurrentMessage && inProgress) {
1036
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
1037
+ context.icons.spinnerIcon,
1038
+ " ",
1039
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "inProgressLabel", children: render })
1040
+ ] }, index);
1045
1041
  } else {
1046
- const args = message.function_call ? JSON.parse(message.function_call.arguments || "{}") : (_c = message.partialFunctionCall) == null ? void 0 : _c.arguments;
1047
- let status = "inProgress";
1048
- if (functionResults[message.id] !== void 0) {
1049
- status = "complete";
1050
- } else if (message.function_call) {
1051
- status = "executing";
1052
- }
1053
- const toRender = render({
1054
- status,
1055
- args,
1056
- result: functionResults[message.id]
1057
- });
1058
- if (!toRender && status === "complete") {
1059
- return null;
1060
- }
1061
- if (typeof toRender === "string") {
1062
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
1063
- isCurrentMessage && inProgress && context.icons.spinnerIcon,
1064
- " ",
1065
- toRender
1066
- ] }, index);
1067
- } else {
1068
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
1069
- }
1042
+ return null;
1070
1043
  }
1071
- } else if ((!inProgress || !isCurrentMessage) && message.function_call) {
1072
- return null;
1073
1044
  } else {
1074
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
1045
+ const args = message.arguments;
1046
+ let status = "inProgress";
1047
+ if (functionResults[message.id] !== void 0) {
1048
+ status = "complete";
1049
+ } else if (message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending) {
1050
+ status = "executing";
1051
+ }
1052
+ const toRender = render({
1053
+ status,
1054
+ args,
1055
+ result: functionResults[message.id]
1056
+ });
1057
+ if (!toRender && status === "complete") {
1058
+ return null;
1059
+ }
1060
+ if (typeof toRender === "string") {
1061
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
1062
+ isCurrentMessage && inProgress && context.icons.spinnerIcon,
1063
+ " ",
1064
+ toRender
1065
+ ] }, index);
1066
+ } else {
1067
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
1068
+ }
1075
1069
  }
1070
+ } else if (!inProgress || !isCurrentMessage) {
1071
+ return null;
1072
+ } else {
1073
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
1076
1074
  }
1077
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { content: message.content }) }, index);
1078
1075
  }
1079
1076
  }),
1080
1077
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("footer", { ref: messagesEndRef, children })
@@ -1089,11 +1086,12 @@ function makeInitialMessages(initial) {
1089
1086
  initialArray.push(initial);
1090
1087
  }
1091
1088
  }
1092
- return initialArray.map((message) => ({
1093
- id: (0, import_nanoid.nanoid)(),
1094
- role: "assistant",
1095
- content: message
1096
- }));
1089
+ return initialArray.map(
1090
+ (message) => new import_runtime_client_gql.TextMessage({
1091
+ role: import_runtime_client_gql.Role.Assistant,
1092
+ content: message
1093
+ })
1094
+ );
1097
1095
  }
1098
1096
 
1099
1097
  // src/components/chat/Input.tsx
@@ -1150,6 +1148,7 @@ var Textarea_default = AutoResizingTextarea;
1150
1148
 
1151
1149
  // src/hooks/use-push-to-talk.tsx
1152
1150
  var import_react_core2 = require("@copilotkit/react-core");
1151
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1153
1152
  var import_react7 = require("react");
1154
1153
  var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
1155
1154
  if (!mediaStreamRef.current || !audioContextRef.current) {
@@ -1239,7 +1238,9 @@ var usePushToTalk = ({
1239
1238
  const lastMessageIndex = context.messages.findIndex(
1240
1239
  (message) => message.id === startReadingFromMessageId
1241
1240
  );
1242
- const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant" && message.content);
1241
+ const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
1242
+ (message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
1243
+ );
1243
1244
  const text = messagesAfterLast.map((message) => message.content).join("\n");
1244
1245
  playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
1245
1246
  setStartReadingFromMessageId(null);
@@ -1328,6 +1329,7 @@ var ResponseButton = ({ onClick, inProgress }) => {
1328
1329
 
1329
1330
  // src/components/chat/Suggestion.tsx
1330
1331
  var import_react_core4 = require("@copilotkit/react-core");
1332
+ var import_shared = require("@copilotkit/shared");
1331
1333
  var import_jsx_runtime12 = require("react/jsx-runtime");
1332
1334
  function Suggestion({ title, message, onClick, partial, className }) {
1333
1335
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
@@ -1348,7 +1350,13 @@ function Suggestion({ title, message, onClick, partial, className }) {
1348
1350
  }
1349
1351
  var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
1350
1352
  const abortController = abortControllerRef.current;
1351
- const tools = JSON.stringify(context.getChatCompletionFunctionDescriptions(context.entryPoints));
1353
+ const tools = JSON.stringify(
1354
+ Object.values(context.actions).map((action) => ({
1355
+ name: action.name,
1356
+ description: action.description,
1357
+ jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters))
1358
+ }))
1359
+ );
1352
1360
  const allSuggestions = [];
1353
1361
  for (const config of Object.values(chatSuggestionConfiguration)) {
1354
1362
  try {
@@ -1412,7 +1420,8 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
1412
1420
  // src/components/chat/Chat.tsx
1413
1421
  var import_react9 = __toESM(require("react"));
1414
1422
  var import_react_core5 = require("@copilotkit/react-core");
1415
- var import_nanoid2 = require("nanoid");
1423
+ var import_nanoid = require("nanoid");
1424
+ var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1416
1425
  var import_jsx_runtime13 = require("react/jsx-runtime");
1417
1426
  function CopilotChat({
1418
1427
  instructions,
@@ -1484,7 +1493,7 @@ function WrappedCopilotChat({
1484
1493
  var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
1485
1494
  var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
1486
1495
  const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0, import_react_core5.useCopilotChat)({
1487
- id: (0, import_nanoid2.nanoid)(),
1496
+ id: (0, import_nanoid.nanoid)(),
1488
1497
  makeSystemMessage
1489
1498
  });
1490
1499
  const [currentSuggestions, setCurrentSuggestions] = (0, import_react9.useState)([]);
@@ -1521,11 +1530,10 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
1521
1530
  abortSuggestions();
1522
1531
  setCurrentSuggestions([]);
1523
1532
  onSubmitMessage == null ? void 0 : onSubmitMessage(messageContent);
1524
- const message = {
1525
- id: (0, import_nanoid2.nanoid)(),
1533
+ const message = new import_runtime_client_gql3.TextMessage({
1526
1534
  content: messageContent,
1527
- role: "user"
1528
- };
1535
+ role: import_runtime_client_gql3.Role.User
1536
+ });
1529
1537
  appendMessage(message);
1530
1538
  return message;
1531
1539
  });
@@ -1631,7 +1639,7 @@ function CopilotSidebar(props) {
1631
1639
 
1632
1640
  // src/hooks/use-copilot-chat-suggestions.tsx
1633
1641
  var import_react12 = require("react");
1634
- var import_nanoid3 = require("nanoid");
1642
+ var import_nanoid2 = require("nanoid");
1635
1643
  var import_react_core6 = require("@copilotkit/react-core");
1636
1644
  function useCopilotChatSuggestions({
1637
1645
  instructions,
@@ -1641,7 +1649,7 @@ function useCopilotChatSuggestions({
1641
1649
  }, dependencies = []) {
1642
1650
  const context = (0, import_react_core6.useCopilotContext)();
1643
1651
  (0, import_react12.useEffect)(() => {
1644
- const id = (0, import_nanoid3.nanoid)();
1652
+ const id = (0, import_nanoid2.nanoid)();
1645
1653
  context.addChatSuggestionConfiguration(id, {
1646
1654
  instructions,
1647
1655
  minSuggestions,