@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/{chunk-H7TM5JE6.mjs → chunk-4FIGRRFS.mjs} +8 -8
  3. package/dist/chunk-4FIGRRFS.mjs.map +1 -0
  4. package/dist/{chunk-SPZEI5EN.mjs → chunk-6VYMULPK.mjs} +4 -4
  5. package/dist/{chunk-HIX4HRWU.mjs → chunk-7YQICPBC.mjs} +19 -12
  6. package/dist/chunk-7YQICPBC.mjs.map +1 -0
  7. package/dist/{chunk-RF3KLUPD.mjs → chunk-AAY3WWWC.mjs} +2 -3
  8. package/dist/chunk-AAY3WWWC.mjs.map +1 -0
  9. package/dist/{chunk-U6J5DGOE.mjs → chunk-BNCTYKEP.mjs} +2 -2
  10. package/dist/{chunk-GOTHQ665.mjs → chunk-DP5YVGNX.mjs} +2 -3
  11. package/dist/chunk-DP5YVGNX.mjs.map +1 -0
  12. package/dist/{chunk-TSQVQAAC.mjs → chunk-JQOSF44H.mjs} +2 -2
  13. package/dist/{chunk-WCPLXRZX.mjs → chunk-KFQYJ5R5.mjs} +1 -1
  14. package/dist/chunk-KFQYJ5R5.mjs.map +1 -0
  15. package/dist/{chunk-LT5YTQ4F.mjs → chunk-RS6UPR5N.mjs} +12 -4
  16. package/dist/chunk-RS6UPR5N.mjs.map +1 -0
  17. package/dist/{chunk-YH2STM73.mjs → chunk-RWT7WRG2.mjs} +3 -3
  18. package/dist/chunk-RWT7WRG2.mjs.map +1 -0
  19. package/dist/{chunk-VOBX4JOA.mjs → chunk-S5MBUNGN.mjs} +8 -6
  20. package/dist/chunk-S5MBUNGN.mjs.map +1 -0
  21. package/dist/{chunk-GDNJRSD4.mjs → chunk-SHTMRY45.mjs} +8 -10
  22. package/dist/chunk-SHTMRY45.mjs.map +1 -0
  23. package/dist/{chunk-P47XGGRX.mjs → chunk-TYYJR3LE.mjs} +2 -2
  24. package/dist/{chunk-MA5B5ELM.mjs → chunk-WHSD7DBC.mjs} +2 -3
  25. package/dist/chunk-WHSD7DBC.mjs.map +1 -0
  26. package/dist/components/chat/Chat.js +37 -33
  27. package/dist/components/chat/Chat.js.map +1 -1
  28. package/dist/components/chat/Chat.mjs +11 -11
  29. package/dist/components/chat/Input.js +18 -3
  30. package/dist/components/chat/Input.js.map +1 -1
  31. package/dist/components/chat/Input.mjs +2 -2
  32. package/dist/components/chat/Messages.js +6 -6
  33. package/dist/components/chat/Messages.js.map +1 -1
  34. package/dist/components/chat/Messages.mjs +1 -1
  35. package/dist/components/chat/Modal.js +37 -33
  36. package/dist/components/chat/Modal.js.map +1 -1
  37. package/dist/components/chat/Modal.mjs +12 -12
  38. package/dist/components/chat/Popup.js +37 -33
  39. package/dist/components/chat/Popup.js.map +1 -1
  40. package/dist/components/chat/Popup.mjs +13 -13
  41. package/dist/components/chat/Sidebar.js +37 -33
  42. package/dist/components/chat/Sidebar.js.map +1 -1
  43. package/dist/components/chat/Sidebar.mjs +13 -13
  44. package/dist/components/chat/Suggestion.d.ts +2 -2
  45. package/dist/components/chat/Suggestion.js.map +1 -1
  46. package/dist/components/chat/Suggestion.mjs +1 -1
  47. package/dist/components/chat/index.js +37 -33
  48. package/dist/components/chat/index.js.map +1 -1
  49. package/dist/components/chat/index.mjs +14 -14
  50. package/dist/components/chat/messages/RenderActionExecutionMessage.js +1 -1
  51. package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -1
  52. package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +1 -1
  53. package/dist/components/chat/messages/RenderAgentStateMessage.js +1 -2
  54. package/dist/components/chat/messages/RenderAgentStateMessage.js.map +1 -1
  55. package/dist/components/chat/messages/RenderAgentStateMessage.mjs +1 -1
  56. package/dist/components/chat/messages/RenderResultMessage.js +1 -2
  57. package/dist/components/chat/messages/RenderResultMessage.js.map +1 -1
  58. package/dist/components/chat/messages/RenderResultMessage.mjs +1 -1
  59. package/dist/components/chat/messages/RenderTextMessage.js +1 -2
  60. package/dist/components/chat/messages/RenderTextMessage.js.map +1 -1
  61. package/dist/components/chat/messages/RenderTextMessage.mjs +1 -1
  62. package/dist/components/dev-console/console.js +13 -7
  63. package/dist/components/dev-console/console.js.map +1 -1
  64. package/dist/components/dev-console/console.mjs +2 -2
  65. package/dist/components/dev-console/index.js +13 -7
  66. package/dist/components/dev-console/index.js.map +1 -1
  67. package/dist/components/dev-console/index.mjs +2 -2
  68. package/dist/components/dev-console/utils.d.ts +2 -2
  69. package/dist/components/dev-console/utils.js +4 -6
  70. package/dist/components/dev-console/utils.js.map +1 -1
  71. package/dist/components/dev-console/utils.mjs +1 -1
  72. package/dist/components/index.js +37 -33
  73. package/dist/components/index.js.map +1 -1
  74. package/dist/components/index.mjs +14 -14
  75. package/dist/hooks/use-push-to-talk.js +18 -3
  76. package/dist/hooks/use-push-to-talk.js.map +1 -1
  77. package/dist/hooks/use-push-to-talk.mjs +1 -1
  78. package/dist/index.js +37 -33
  79. package/dist/index.js.map +1 -1
  80. package/dist/index.mjs +14 -14
  81. package/package.json +8 -8
  82. package/src/components/chat/Chat.tsx +9 -2
  83. package/src/components/chat/Messages.tsx +6 -6
  84. package/src/components/chat/Suggestion.tsx +2 -2
  85. package/src/components/chat/messages/RenderActionExecutionMessage.tsx +1 -1
  86. package/src/components/chat/messages/RenderAgentStateMessage.tsx +1 -1
  87. package/src/components/chat/messages/RenderResultMessage.tsx +1 -1
  88. package/src/components/chat/messages/RenderTextMessage.tsx +1 -1
  89. package/src/components/dev-console/console.tsx +6 -2
  90. package/src/components/dev-console/utils.ts +10 -6
  91. package/src/hooks/use-push-to-talk.tsx +5 -3
  92. package/dist/chunk-GDNJRSD4.mjs.map +0 -1
  93. package/dist/chunk-GOTHQ665.mjs.map +0 -1
  94. package/dist/chunk-H7TM5JE6.mjs.map +0 -1
  95. package/dist/chunk-HIX4HRWU.mjs.map +0 -1
  96. package/dist/chunk-LT5YTQ4F.mjs.map +0 -1
  97. package/dist/chunk-MA5B5ELM.mjs.map +0 -1
  98. package/dist/chunk-RF3KLUPD.mjs.map +0 -1
  99. package/dist/chunk-VOBX4JOA.mjs.map +0 -1
  100. package/dist/chunk-WCPLXRZX.mjs.map +0 -1
  101. package/dist/chunk-YH2STM73.mjs.map +0 -1
  102. /package/dist/{chunk-SPZEI5EN.mjs.map → chunk-6VYMULPK.mjs.map} +0 -0
  103. /package/dist/{chunk-U6J5DGOE.mjs.map → chunk-BNCTYKEP.mjs.map} +0 -0
  104. /package/dist/{chunk-TSQVQAAC.mjs.map → chunk-JQOSF44H.mjs.map} +0 -0
  105. /package/dist/{chunk-P47XGGRX.mjs.map → chunk-TYYJR3LE.mjs.map} +0 -0
@@ -2,31 +2,31 @@ import "../chunk-JD7BAH7U.mjs";
2
2
  import "../chunk-MRFF7GSQ.mjs";
3
3
  import {
4
4
  CopilotSidebar
5
- } from "../chunk-P47XGGRX.mjs";
5
+ } from "../chunk-TYYJR3LE.mjs";
6
6
  import "../chunk-WB3YULQ4.mjs";
7
7
  import {
8
8
  CopilotPopup
9
- } from "../chunk-TSQVQAAC.mjs";
10
- import "../chunk-SPZEI5EN.mjs";
9
+ } from "../chunk-JQOSF44H.mjs";
10
+ import "../chunk-6VYMULPK.mjs";
11
11
  import "../chunk-FO7Z5LAL.mjs";
12
12
  import "../chunk-FLV3J3VX.mjs";
13
13
  import "../chunk-YOH25I6N.mjs";
14
14
  import {
15
15
  CopilotChat
16
- } from "../chunk-HIX4HRWU.mjs";
16
+ } from "../chunk-7YQICPBC.mjs";
17
17
  import "../chunk-V7W6IM2V.mjs";
18
- import "../chunk-YH2STM73.mjs";
19
- import "../chunk-RF3KLUPD.mjs";
20
- import "../chunk-GOTHQ665.mjs";
21
- import "../chunk-MA5B5ELM.mjs";
22
- import "../chunk-WCPLXRZX.mjs";
23
- import "../chunk-LT5YTQ4F.mjs";
24
- import "../chunk-H7TM5JE6.mjs";
18
+ import "../chunk-RWT7WRG2.mjs";
19
+ import "../chunk-AAY3WWWC.mjs";
20
+ import "../chunk-DP5YVGNX.mjs";
21
+ import "../chunk-WHSD7DBC.mjs";
22
+ import "../chunk-KFQYJ5R5.mjs";
23
+ import "../chunk-RS6UPR5N.mjs";
24
+ import "../chunk-4FIGRRFS.mjs";
25
25
  import "../chunk-OTPAZXVR.mjs";
26
- import "../chunk-U6J5DGOE.mjs";
26
+ import "../chunk-BNCTYKEP.mjs";
27
27
  import "../chunk-YQFVRDNC.mjs";
28
28
  import "../chunk-YQ3D5IQV.mjs";
29
- import "../chunk-GDNJRSD4.mjs";
29
+ import "../chunk-SHTMRY45.mjs";
30
30
  import "../chunk-XSUSSWDS.mjs";
31
31
  import {
32
32
  useChatContext
@@ -34,7 +34,7 @@ import {
34
34
  import "../chunk-UPTB2MVO.mjs";
35
35
  import "../chunk-FZC7X5PK.mjs";
36
36
  import "../chunk-54JAUBUJ.mjs";
37
- import "../chunk-VOBX4JOA.mjs";
37
+ import "../chunk-S5MBUNGN.mjs";
38
38
  import "../chunk-MRXNTQOX.mjs";
39
39
  export {
40
40
  CopilotChat,
@@ -2,7 +2,21 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
6
20
  var __export = (target, all) => {
7
21
  for (var name in all)
8
22
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -46,7 +60,6 @@ __export(use_push_to_talk_exports, {
46
60
  });
47
61
  module.exports = __toCommonJS(use_push_to_talk_exports);
48
62
  var import_react_core = require("@copilotkit/react-core");
49
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
50
63
  var import_react = require("react");
51
64
  var checkMicrophonePermission = () => __async(void 0, null, function* () {
52
65
  try {
@@ -126,7 +139,9 @@ var usePushToTalk = ({
126
139
  const audioContextRef = (0, import_react.useRef)(null);
127
140
  const mediaRecorderRef = (0, import_react.useRef)(null);
128
141
  const recordedChunks = (0, import_react.useRef)([]);
129
- const context = (0, import_react_core.useCopilotContext)();
142
+ const generalContext = (0, import_react_core.useCopilotContext)();
143
+ const messagesContext = (0, import_react_core.useCopilotMessagesContext)();
144
+ const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
130
145
  const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react.useState)(null);
131
146
  (0, import_react.useEffect)(() => {
132
147
  if (pushToTalkState === "recording") {
@@ -162,7 +177,7 @@ var usePushToTalk = ({
162
177
  (message) => message.id === startReadingFromMessageId
163
178
  );
164
179
  const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
165
- (message) => message instanceof import_runtime_client_gql.TextMessage && message.role === "assistant"
180
+ (message) => message.isTextMessage() && message.role === "assistant"
166
181
  );
167
182
  const text = messagesAfterLast.map((message) => message.content).join("\n");
168
183
  playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
@@ -1 +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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAkC;AAClC,gCAAqC;AACrC,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;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;AAC7C,UAAM,aAAa,OAAO;AAC1B,WAAO,EAAE,QAAQ,aAAa;AAAA,EAChC,SAAS,KAAP;AACA,YAAQ,MAAM,wDAAwD,GAAG;AACzE,WAAO;AAAA,EACT;AACF;AAEA,IAAM,iBAAiB,CACrB,gBACA,kBACA,iBACA,gBACA,WACG;AACH,MAAI,CAAC,eAAe,WAAW,CAAC,gBAAgB,SAAS;AACvD,mBAAe,UAAU,MAAM,UAAU,aAAa,aAAa,EAAE,OAAO,KAAK,CAAC;AAClF,oBAAgB,UAAU,IAAI,OAAO,aAAa;AAClD,UAAM,gBAAgB,QAAQ,OAAO;AAAA,EACvC;AAEA,mBAAiB,UAAU,IAAI,cAAc,eAAe,OAAQ;AACpE,mBAAiB,QAAQ,MAAM,GAAI;AACnC,mBAAiB,QAAQ,kBAAkB,CAAC,UAAU;AAC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C,SAAO,EAAE,iBAAiB,mBAAmB;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../../src/hooks/use-push-to-talk.tsx"],"sourcesContent":["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;AAAA;AAAA,wBAA6D;AAE7D,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;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;AAC7C,UAAM,aAAa,OAAO;AAC1B,WAAO,EAAE,QAAQ,aAAa;AAAA,EAChC,SAAS,KAAP;AACA,YAAQ,MAAM,wDAAwD,GAAG;AACzE,WAAO;AAAA,EACT;AACF;AAEA,IAAM,iBAAiB,CACrB,gBACA,kBACA,iBACA,gBACA,WACG;AACH,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,CAAC,YAAY,QAAQ,OAAO;AAAA,MAC9B;AAEA,YAAM,oBAAoB,QAAQ,SAC/B,MAAM,mBAAmB,CAAC,EAC1B;AAAA,QACC,CAAC,YAAY,QAAQ,cAAc,KAAK,QAAQ,SAAS;AAAA,MAC3D;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-VOBX4JOA.mjs";
5
+ } from "../chunk-S5MBUNGN.mjs";
6
6
  import "../chunk-MRXNTQOX.mjs";
7
7
  export {
8
8
  checkMicrophonePermission,
package/dist/index.js CHANGED
@@ -540,10 +540,10 @@ var Messages = ({
540
540
  messages = [...initialMessages, ...messages];
541
541
  const actionResults = {};
542
542
  for (let i = 0; i < messages.length; i++) {
543
- if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
543
+ if (messages[i].isActionExecutionMessage()) {
544
544
  const id = messages[i].id;
545
545
  const resultMessage = messages.find(
546
- (message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
546
+ (message) => message.isResultMessage() && message.actionExecutionId === id
547
547
  );
548
548
  if (resultMessage) {
549
549
  actionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
@@ -564,7 +564,7 @@ var Messages = ({
564
564
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessages", children: [
565
565
  messages.map((message, index) => {
566
566
  const isCurrentMessage = index === messages.length - 1;
567
- if (message instanceof import_runtime_client_gql.TextMessage) {
567
+ if (message.isTextMessage()) {
568
568
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
569
569
  RenderTextMessage2,
570
570
  {
@@ -575,7 +575,7 @@ var Messages = ({
575
575
  },
576
576
  index
577
577
  );
578
- } else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
578
+ } else if (message.isActionExecutionMessage()) {
579
579
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
580
580
  RenderActionExecutionMessage2,
581
581
  {
@@ -587,7 +587,7 @@ var Messages = ({
587
587
  },
588
588
  index
589
589
  );
590
- } else if (message instanceof import_runtime_client_gql.AgentStateMessage) {
590
+ } else if (message.isAgentStateMessage()) {
591
591
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
592
592
  RenderAgentStateMessage2,
593
593
  {
@@ -598,7 +598,7 @@ var Messages = ({
598
598
  },
599
599
  index
600
600
  );
601
- } else if (message instanceof import_runtime_client_gql.ResultMessage) {
601
+ } else if (message.isResultMessage()) {
602
602
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
603
603
  RenderResultMessage2,
604
604
  {
@@ -685,7 +685,6 @@ var Textarea_default = AutoResizingTextarea;
685
685
 
686
686
  // src/hooks/use-push-to-talk.tsx
687
687
  var import_react_core = require("@copilotkit/react-core");
688
- var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
689
688
  var import_react5 = require("react");
690
689
  var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
691
690
  if (!mediaStreamRef.current || !audioContextRef.current) {
@@ -740,7 +739,9 @@ var usePushToTalk = ({
740
739
  const audioContextRef = (0, import_react5.useRef)(null);
741
740
  const mediaRecorderRef = (0, import_react5.useRef)(null);
742
741
  const recordedChunks = (0, import_react5.useRef)([]);
743
- const context = (0, import_react_core.useCopilotContext)();
742
+ const generalContext = (0, import_react_core.useCopilotContext)();
743
+ const messagesContext = (0, import_react_core.useCopilotMessagesContext)();
744
+ const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
744
745
  const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react5.useState)(null);
745
746
  (0, import_react5.useEffect)(() => {
746
747
  if (pushToTalkState === "recording") {
@@ -776,7 +777,7 @@ var usePushToTalk = ({
776
777
  (message) => message.id === startReadingFromMessageId
777
778
  );
778
779
  const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
779
- (message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
780
+ (message) => message.isTextMessage() && message.role === "assistant"
780
781
  );
781
782
  const text = messagesAfterLast.map((message) => message.content).join("\n");
782
783
  playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
@@ -864,9 +865,6 @@ var ResponseButton = ({ onClick, inProgress }) => {
864
865
  ] });
865
866
  };
866
867
 
867
- // src/components/chat/messages/RenderTextMessage.tsx
868
- var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
869
-
870
868
  // src/components/chat/Markdown.tsx
871
869
  var import_react8 = require("react");
872
870
  var import_react_markdown = __toESM(require("react-markdown"));
@@ -1340,7 +1338,7 @@ var import_jsx_runtime12 = require("react/jsx-runtime");
1340
1338
  function RenderTextMessage(props) {
1341
1339
  const { message, inProgress, index, isCurrentMessage } = props;
1342
1340
  const { icons } = useChatContext();
1343
- if (message instanceof import_runtime_client_gql3.TextMessage) {
1341
+ if (message.isTextMessage()) {
1344
1342
  if (message.role === "user") {
1345
1343
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
1346
1344
  } else if (message.role == "assistant") {
@@ -1350,14 +1348,14 @@ function RenderTextMessage(props) {
1350
1348
  }
1351
1349
 
1352
1350
  // src/components/chat/messages/RenderActionExecutionMessage.tsx
1353
- var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
1351
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
1354
1352
  var import_react_core3 = require("@copilotkit/react-core");
1355
1353
  var import_jsx_runtime13 = require("react/jsx-runtime");
1356
1354
  function RenderActionExecutionMessage(props) {
1357
1355
  const { message, inProgress, index, isCurrentMessage, actionResult } = props;
1358
1356
  const { chatComponentsCache } = (0, import_react_core3.useCopilotContext)();
1359
1357
  const { icons } = useChatContext();
1360
- if (message instanceof import_runtime_client_gql4.ActionExecutionMessage) {
1358
+ if (message.isActionExecutionMessage()) {
1361
1359
  if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
1362
1360
  const render = chatComponentsCache.current.actions[message.name];
1363
1361
  if (typeof render === "string") {
@@ -1375,7 +1373,7 @@ function RenderActionExecutionMessage(props) {
1375
1373
  let status = "inProgress";
1376
1374
  if (actionResult !== void 0) {
1377
1375
  status = "complete";
1378
- } else if (message.status.code !== import_runtime_client_gql4.MessageStatusCode.Pending) {
1376
+ } else if (message.status.code !== import_runtime_client_gql2.MessageStatusCode.Pending) {
1379
1377
  status = "executing";
1380
1378
  }
1381
1379
  try {
@@ -1418,25 +1416,23 @@ function RenderActionExecutionMessage(props) {
1418
1416
  }
1419
1417
 
1420
1418
  // src/components/chat/messages/RenderResultMessage.tsx
1421
- var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
1422
1419
  var import_jsx_runtime14 = require("react/jsx-runtime");
1423
1420
  function RenderResultMessage(props) {
1424
1421
  const { message, inProgress, index, isCurrentMessage } = props;
1425
1422
  const { icons } = useChatContext();
1426
- if (message instanceof import_runtime_client_gql5.ResultMessage && inProgress && isCurrentMessage) {
1423
+ if (message.isResultMessage() && inProgress && isCurrentMessage) {
1427
1424
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: icons.spinnerIcon }, index);
1428
1425
  }
1429
1426
  }
1430
1427
 
1431
1428
  // src/components/chat/messages/RenderAgentStateMessage.tsx
1432
- var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
1433
1429
  var import_react_core4 = require("@copilotkit/react-core");
1434
1430
  var import_jsx_runtime15 = require("react/jsx-runtime");
1435
1431
  function RenderAgentStateMessage(props) {
1436
1432
  const { message, inProgress, index, isCurrentMessage } = props;
1437
1433
  const { chatComponentsCache } = (0, import_react_core4.useCopilotContext)();
1438
1434
  const { icons } = useChatContext();
1439
- if (message instanceof import_runtime_client_gql6.AgentStateMessage) {
1435
+ if (message.isAgentStateMessage()) {
1440
1436
  let render;
1441
1437
  if (chatComponentsCache.current !== null) {
1442
1438
  render = chatComponentsCache.current.coAgentStateRenders[`${message.agentName}-${message.nodeName}`] || chatComponentsCache.current.coAgentStateRenders[`${message.agentName}-global`];
@@ -1489,7 +1485,7 @@ function RenderAgentStateMessage(props) {
1489
1485
  // src/components/chat/Suggestion.tsx
1490
1486
  var import_react_core5 = require("@copilotkit/react-core");
1491
1487
  var import_shared = require("@copilotkit/shared");
1492
- var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
1488
+ var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1493
1489
  var import_jsx_runtime16 = require("react/jsx-runtime");
1494
1490
  function Suggestion({ title, message, onClick, partial, className }) {
1495
1491
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
@@ -1525,7 +1521,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
1525
1521
  context,
1526
1522
  instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " + config.instructions + "\n\n" + numOfSuggestionsInstructions,
1527
1523
  data: "Available tools: " + tools + "\n\n",
1528
- requestType: import_runtime_client_gql7.CopilotRequestType.Task,
1524
+ requestType: import_runtime_client_gql3.CopilotRequestType.Task,
1529
1525
  parameters: [
1530
1526
  {
1531
1527
  name: "suggestions",
@@ -1581,13 +1577,11 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
1581
1577
  // src/components/chat/Chat.tsx
1582
1578
  var import_react11 = __toESM(require("react"));
1583
1579
  var import_react_core8 = require("@copilotkit/react-core");
1584
- var import_runtime_client_gql10 = require("@copilotkit/runtime-client-gql");
1580
+ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
1585
1581
  var import_shared3 = require("@copilotkit/shared");
1586
1582
 
1587
1583
  // src/components/dev-console/utils.ts
1588
1584
  var import_react_core6 = require("@copilotkit/react-core");
1589
- var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
1590
- var import_runtime_client_gql9 = require("@copilotkit/runtime-client-gql");
1591
1585
  function shouldShowDevConsole(showDevConsole) {
1592
1586
  if (typeof showDevConsole === "boolean") {
1593
1587
  return showDevConsole;
@@ -1677,7 +1671,7 @@ function logMessages(context) {
1677
1671
  return;
1678
1672
  }
1679
1673
  const tableData = context.messages.map((message) => {
1680
- if (message instanceof import_runtime_client_gql8.TextMessage) {
1674
+ if (message.isTextMessage()) {
1681
1675
  return {
1682
1676
  id: message.id,
1683
1677
  type: "TextMessage",
@@ -1686,7 +1680,7 @@ function logMessages(context) {
1686
1680
  scope: void 0,
1687
1681
  content: message.content
1688
1682
  };
1689
- } else if (message instanceof import_runtime_client_gql8.ActionExecutionMessage) {
1683
+ } else if (message.isActionExecutionMessage()) {
1690
1684
  return {
1691
1685
  id: message.id,
1692
1686
  type: "ActionExecutionMessage",
@@ -1695,7 +1689,7 @@ function logMessages(context) {
1695
1689
  scope: message.scope,
1696
1690
  content: message.arguments
1697
1691
  };
1698
- } else if (message instanceof import_runtime_client_gql8.ResultMessage) {
1692
+ } else if (message.isResultMessage()) {
1699
1693
  return {
1700
1694
  id: message.id,
1701
1695
  type: "ResultMessage",
@@ -1704,7 +1698,7 @@ function logMessages(context) {
1704
1698
  scope: message.actionExecutionId,
1705
1699
  content: message.result
1706
1700
  };
1707
- } else if (message instanceof import_runtime_client_gql9.AgentStateMessage) {
1701
+ } else if (message.isAgentStateMessage()) {
1708
1702
  return {
1709
1703
  id: message.id,
1710
1704
  type: `AgentStateMessage (running: ${message.running})`,
@@ -1976,6 +1970,7 @@ function DebugMenuButton({
1976
1970
  mode
1977
1971
  }) {
1978
1972
  const context = (0, import_react_core7.useCopilotContext)();
1973
+ const messagesContext = (0, import_react_core7.useCopilotMessagesContext)();
1979
1974
  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: [
1980
1975
  /* @__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: [
1981
1976
  "Debug ",
@@ -1991,7 +1986,14 @@ function DebugMenuButton({
1991
1986
  children: [
1992
1987
  /* @__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" }) }),
1993
1988
  /* @__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" }) }),
1994
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logMessages(context), children: "Log Messages" }) }),
1989
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react10.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1990
+ "button",
1991
+ {
1992
+ className: "copilotKitDebugMenuItem",
1993
+ onClick: () => logMessages(messagesContext),
1994
+ children: "Log Messages"
1995
+ }
1996
+ ) }),
1995
1997
  /* @__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" }) }),
1996
1998
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("hr", {}),
1997
1999
  /* @__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" }) })
@@ -2100,7 +2102,9 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
2100
2102
  (_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
2101
2103
  suggestionsAbortControllerRef.current = null;
2102
2104
  };
2103
- const context = (0, import_react_core8.useCopilotContext)();
2105
+ const generalContext = (0, import_react_core8.useCopilotContext)();
2106
+ const messagesContext = (0, import_react_core8.useCopilotMessagesContext)();
2107
+ const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
2104
2108
  (0, import_react11.useEffect)(() => {
2105
2109
  onInProgress == null ? void 0 : onInProgress(isLoading);
2106
2110
  abortSuggestions();
@@ -2125,9 +2129,9 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
2125
2129
  const sendMessage = (messageContent) => __async(void 0, null, function* () {
2126
2130
  abortSuggestions();
2127
2131
  setCurrentSuggestions([]);
2128
- const message = new import_runtime_client_gql10.TextMessage({
2132
+ const message = new import_runtime_client_gql4.TextMessage({
2129
2133
  content: messageContent,
2130
- role: import_runtime_client_gql10.Role.User
2134
+ role: import_runtime_client_gql4.Role.User
2131
2135
  });
2132
2136
  if (onSubmitMessage) {
2133
2137
  try {