@copilotkit/react-ui 1.5.1-test-custom-tag-prerelease-1.0 → 1.5.1

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 (288) hide show
  1. package/CHANGELOG.md +61 -6
  2. package/package.json +4 -4
  3. package/dist/chunk-375NVWZM.mjs +0 -21
  4. package/dist/chunk-375NVWZM.mjs.map +0 -1
  5. package/dist/chunk-3E7HY2UN.mjs +0 -85
  6. package/dist/chunk-3E7HY2UN.mjs.map +0 -1
  7. package/dist/chunk-3XAXY2Z3.mjs +0 -18
  8. package/dist/chunk-3XAXY2Z3.mjs.map +0 -1
  9. package/dist/chunk-54JAUBUJ.mjs +0 -26
  10. package/dist/chunk-54JAUBUJ.mjs.map +0 -1
  11. package/dist/chunk-6INMITFA.mjs +0 -18
  12. package/dist/chunk-6INMITFA.mjs.map +0 -1
  13. package/dist/chunk-7II4YL7R.mjs +0 -170
  14. package/dist/chunk-7II4YL7R.mjs.map +0 -1
  15. package/dist/chunk-BH6PCAAL.mjs +0 -81
  16. package/dist/chunk-BH6PCAAL.mjs.map +0 -1
  17. package/dist/chunk-CBBFRI3Q.mjs +0 -81
  18. package/dist/chunk-CBBFRI3Q.mjs.map +0 -1
  19. package/dist/chunk-DCNCY2PL.mjs +0 -304
  20. package/dist/chunk-DCNCY2PL.mjs.map +0 -1
  21. package/dist/chunk-EFZPSZWO.mjs +0 -1
  22. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  23. package/dist/chunk-EMQEEXUB.mjs +0 -97
  24. package/dist/chunk-EMQEEXUB.mjs.map +0 -1
  25. package/dist/chunk-F2W5FD7L.mjs +0 -232
  26. package/dist/chunk-F2W5FD7L.mjs.map +0 -1
  27. package/dist/chunk-FZC7X5PK.mjs +0 -262
  28. package/dist/chunk-FZC7X5PK.mjs.map +0 -1
  29. package/dist/chunk-IU3WTXLQ.mjs +0 -1
  30. package/dist/chunk-IU3WTXLQ.mjs.map +0 -1
  31. package/dist/chunk-KXE2JCUH.mjs +0 -1
  32. package/dist/chunk-KXE2JCUH.mjs.map +0 -1
  33. package/dist/chunk-MMVDU6DF.mjs +0 -1
  34. package/dist/chunk-MMVDU6DF.mjs.map +0 -1
  35. package/dist/chunk-MRFF7GSQ.mjs +0 -1
  36. package/dist/chunk-MRFF7GSQ.mjs.map +0 -1
  37. package/dist/chunk-MRXNTQOX.mjs +0 -59
  38. package/dist/chunk-MRXNTQOX.mjs.map +0 -1
  39. package/dist/chunk-OTPAZXVR.mjs +0 -92
  40. package/dist/chunk-OTPAZXVR.mjs.map +0 -1
  41. package/dist/chunk-PNQVKBPN.mjs +0 -146
  42. package/dist/chunk-PNQVKBPN.mjs.map +0 -1
  43. package/dist/chunk-RJCZRKTV.mjs +0 -106
  44. package/dist/chunk-RJCZRKTV.mjs.map +0 -1
  45. package/dist/chunk-RQNJNK2W.mjs +0 -25
  46. package/dist/chunk-RQNJNK2W.mjs.map +0 -1
  47. package/dist/chunk-RU73BEZM.mjs +0 -41
  48. package/dist/chunk-RU73BEZM.mjs.map +0 -1
  49. package/dist/chunk-S5MBUNGN.mjs +0 -140
  50. package/dist/chunk-S5MBUNGN.mjs.map +0 -1
  51. package/dist/chunk-T26KLXLH.mjs +0 -1
  52. package/dist/chunk-T26KLXLH.mjs.map +0 -1
  53. package/dist/chunk-TI7SY2RI.mjs +0 -164
  54. package/dist/chunk-TI7SY2RI.mjs.map +0 -1
  55. package/dist/chunk-UPTB2MVO.mjs +0 -395
  56. package/dist/chunk-UPTB2MVO.mjs.map +0 -1
  57. package/dist/chunk-UWVGLGFQ.mjs +0 -95
  58. package/dist/chunk-UWVGLGFQ.mjs.map +0 -1
  59. package/dist/chunk-V7W6IM2V.mjs +0 -1
  60. package/dist/chunk-V7W6IM2V.mjs.map +0 -1
  61. package/dist/chunk-VEC45H6Q.mjs +0 -18
  62. package/dist/chunk-VEC45H6Q.mjs.map +0 -1
  63. package/dist/chunk-WB3YULQ4.mjs +0 -1
  64. package/dist/chunk-WB3YULQ4.mjs.map +0 -1
  65. package/dist/chunk-WSMMTZCM.mjs +0 -30
  66. package/dist/chunk-WSMMTZCM.mjs.map +0 -1
  67. package/dist/chunk-YAGE7RCE.mjs +0 -118
  68. package/dist/chunk-YAGE7RCE.mjs.map +0 -1
  69. package/dist/chunk-YQ3D5IQV.mjs +0 -75
  70. package/dist/chunk-YQ3D5IQV.mjs.map +0 -1
  71. package/dist/chunk-YQFVRDNC.mjs +0 -53
  72. package/dist/chunk-YQFVRDNC.mjs.map +0 -1
  73. package/dist/chunk-Z2UZSN3K.mjs +0 -29
  74. package/dist/chunk-Z2UZSN3K.mjs.map +0 -1
  75. package/dist/chunk-ZABXREBH.mjs +0 -65
  76. package/dist/chunk-ZABXREBH.mjs.map +0 -1
  77. package/dist/components/chat/Button.d.ts +0 -7
  78. package/dist/components/chat/Button.js +0 -71
  79. package/dist/components/chat/Button.js.map +0 -1
  80. package/dist/components/chat/Button.mjs +0 -10
  81. package/dist/components/chat/Button.mjs.map +0 -1
  82. package/dist/components/chat/Chat.d.ts +0 -148
  83. package/dist/components/chat/Chat.js +0 -2427
  84. package/dist/components/chat/Chat.js.map +0 -1
  85. package/dist/components/chat/Chat.mjs +0 -34
  86. package/dist/components/chat/Chat.mjs.map +0 -1
  87. package/dist/components/chat/ChatContext.d.ts +0 -105
  88. package/dist/components/chat/ChatContext.js +0 -279
  89. package/dist/components/chat/ChatContext.js.map +0 -1
  90. package/dist/components/chat/ChatContext.mjs +0 -13
  91. package/dist/components/chat/ChatContext.mjs.map +0 -1
  92. package/dist/components/chat/CodeBlock.d.ts +0 -14
  93. package/dist/components/chat/CodeBlock.js +0 -523
  94. package/dist/components/chat/CodeBlock.js.map +0 -1
  95. package/dist/components/chat/CodeBlock.mjs +0 -14
  96. package/dist/components/chat/CodeBlock.mjs.map +0 -1
  97. package/dist/components/chat/Header.d.ts +0 -7
  98. package/dist/components/chat/Header.js +0 -64
  99. package/dist/components/chat/Header.js.map +0 -1
  100. package/dist/components/chat/Header.mjs +0 -10
  101. package/dist/components/chat/Header.mjs.map +0 -1
  102. package/dist/components/chat/Icons.d.ts +0 -18
  103. package/dist/components/chat/Icons.js +0 -321
  104. package/dist/components/chat/Icons.js.map +0 -1
  105. package/dist/components/chat/Icons.mjs +0 -32
  106. package/dist/components/chat/Icons.mjs.map +0 -1
  107. package/dist/components/chat/Input.d.ts +0 -7
  108. package/dist/components/chat/Input.js +0 -324
  109. package/dist/components/chat/Input.js.map +0 -1
  110. package/dist/components/chat/Input.mjs +0 -12
  111. package/dist/components/chat/Input.mjs.map +0 -1
  112. package/dist/components/chat/Markdown.d.ts +0 -8
  113. package/dist/components/chat/Markdown.js +0 -583
  114. package/dist/components/chat/Markdown.js.map +0 -1
  115. package/dist/components/chat/Markdown.mjs +0 -11
  116. package/dist/components/chat/Markdown.mjs.map +0 -1
  117. package/dist/components/chat/Messages.d.ts +0 -12
  118. package/dist/components/chat/Messages.js +0 -217
  119. package/dist/components/chat/Messages.js.map +0 -1
  120. package/dist/components/chat/Messages.mjs +0 -12
  121. package/dist/components/chat/Messages.mjs.map +0 -1
  122. package/dist/components/chat/Modal.d.ts +0 -51
  123. package/dist/components/chat/Modal.js +0 -2626
  124. package/dist/components/chat/Modal.js.map +0 -1
  125. package/dist/components/chat/Modal.mjs +0 -34
  126. package/dist/components/chat/Modal.mjs.map +0 -1
  127. package/dist/components/chat/Popup.d.ts +0 -13
  128. package/dist/components/chat/Popup.js +0 -2637
  129. package/dist/components/chat/Popup.js.map +0 -1
  130. package/dist/components/chat/Popup.mjs +0 -35
  131. package/dist/components/chat/Popup.mjs.map +0 -1
  132. package/dist/components/chat/Response.d.ts +0 -7
  133. package/dist/components/chat/Response.js +0 -64
  134. package/dist/components/chat/Response.js.map +0 -1
  135. package/dist/components/chat/Response.mjs +0 -10
  136. package/dist/components/chat/Response.mjs.map +0 -1
  137. package/dist/components/chat/Sidebar.d.ts +0 -13
  138. package/dist/components/chat/Sidebar.js +0 -2646
  139. package/dist/components/chat/Sidebar.js.map +0 -1
  140. package/dist/components/chat/Sidebar.mjs +0 -35
  141. package/dist/components/chat/Sidebar.mjs.map +0 -1
  142. package/dist/components/chat/Suggestion.d.ts +0 -14
  143. package/dist/components/chat/Suggestion.js +0 -181
  144. package/dist/components/chat/Suggestion.js.map +0 -1
  145. package/dist/components/chat/Suggestion.mjs +0 -11
  146. package/dist/components/chat/Suggestion.mjs.map +0 -1
  147. package/dist/components/chat/Textarea.d.ts +0 -13
  148. package/dist/components/chat/Textarea.js +0 -73
  149. package/dist/components/chat/Textarea.js.map +0 -1
  150. package/dist/components/chat/Textarea.mjs +0 -8
  151. package/dist/components/chat/Textarea.mjs.map +0 -1
  152. package/dist/components/chat/Window.d.ts +0 -7
  153. package/dist/components/chat/Window.js +0 -164
  154. package/dist/components/chat/Window.js.map +0 -1
  155. package/dist/components/chat/Window.mjs +0 -10
  156. package/dist/components/chat/Window.mjs.map +0 -1
  157. package/dist/components/chat/index.d.ts +0 -11
  158. package/dist/components/chat/index.js +0 -2661
  159. package/dist/components/chat/index.js.map +0 -1
  160. package/dist/components/chat/index.mjs +0 -47
  161. package/dist/components/chat/index.mjs.map +0 -1
  162. package/dist/components/chat/messages/RenderActionExecutionMessage.d.ts +0 -7
  163. package/dist/components/chat/messages/RenderActionExecutionMessage.js +0 -131
  164. package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +0 -1
  165. package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +0 -10
  166. package/dist/components/chat/messages/RenderActionExecutionMessage.mjs.map +0 -1
  167. package/dist/components/chat/messages/RenderAgentStateMessage.d.ts +0 -7
  168. package/dist/components/chat/messages/RenderAgentStateMessage.js +0 -111
  169. package/dist/components/chat/messages/RenderAgentStateMessage.js.map +0 -1
  170. package/dist/components/chat/messages/RenderAgentStateMessage.mjs +0 -10
  171. package/dist/components/chat/messages/RenderAgentStateMessage.mjs.map +0 -1
  172. package/dist/components/chat/messages/RenderResultMessage.d.ts +0 -7
  173. package/dist/components/chat/messages/RenderResultMessage.js +0 -64
  174. package/dist/components/chat/messages/RenderResultMessage.js.map +0 -1
  175. package/dist/components/chat/messages/RenderResultMessage.mjs +0 -10
  176. package/dist/components/chat/messages/RenderResultMessage.mjs.map +0 -1
  177. package/dist/components/chat/messages/RenderTextMessage.d.ts +0 -7
  178. package/dist/components/chat/messages/RenderTextMessage.js +0 -629
  179. package/dist/components/chat/messages/RenderTextMessage.js.map +0 -1
  180. package/dist/components/chat/messages/RenderTextMessage.mjs +0 -13
  181. package/dist/components/chat/messages/RenderTextMessage.mjs.map +0 -1
  182. package/dist/components/chat/props.d.ts +0 -46
  183. package/dist/components/chat/props.js +0 -19
  184. package/dist/components/chat/props.js.map +0 -1
  185. package/dist/components/chat/props.mjs +0 -2
  186. package/dist/components/chat/props.mjs.map +0 -1
  187. package/dist/components/dev-console/console.d.ts +0 -10
  188. package/dist/components/dev-console/console.js +0 -720
  189. package/dist/components/dev-console/console.js.map +0 -1
  190. package/dist/components/dev-console/console.mjs +0 -17
  191. package/dist/components/dev-console/console.mjs.map +0 -1
  192. package/dist/components/dev-console/icons.d.ts +0 -9
  193. package/dist/components/dev-console/icons.js +0 -120
  194. package/dist/components/dev-console/icons.js.map +0 -1
  195. package/dist/components/dev-console/icons.mjs +0 -16
  196. package/dist/components/dev-console/icons.mjs.map +0 -1
  197. package/dist/components/dev-console/index.d.ts +0 -5
  198. package/dist/components/dev-console/index.js +0 -720
  199. package/dist/components/dev-console/index.js.map +0 -1
  200. package/dist/components/dev-console/index.mjs +0 -18
  201. package/dist/components/dev-console/index.mjs.map +0 -1
  202. package/dist/components/dev-console/types.d.ts +0 -9
  203. package/dist/components/dev-console/types.js +0 -19
  204. package/dist/components/dev-console/types.js.map +0 -1
  205. package/dist/components/dev-console/types.mjs +0 -1
  206. package/dist/components/dev-console/types.mjs.map +0 -1
  207. package/dist/components/dev-console/utils.d.ts +0 -10
  208. package/dist/components/dev-console/utils.js +0 -188
  209. package/dist/components/dev-console/utils.js.map +0 -1
  210. package/dist/components/dev-console/utils.mjs +0 -16
  211. package/dist/components/dev-console/utils.mjs.map +0 -1
  212. package/dist/components/help-modal/icons.d.ts +0 -9
  213. package/dist/components/help-modal/icons.js +0 -107
  214. package/dist/components/help-modal/icons.js.map +0 -1
  215. package/dist/components/help-modal/icons.mjs +0 -12
  216. package/dist/components/help-modal/icons.mjs.map +0 -1
  217. package/dist/components/help-modal/index.d.ts +0 -2
  218. package/dist/components/help-modal/index.js +0 -255
  219. package/dist/components/help-modal/index.js.map +0 -1
  220. package/dist/components/help-modal/index.mjs +0 -10
  221. package/dist/components/help-modal/index.mjs.map +0 -1
  222. package/dist/components/help-modal/modal.d.ts +0 -5
  223. package/dist/components/help-modal/modal.js +0 -253
  224. package/dist/components/help-modal/modal.js.map +0 -1
  225. package/dist/components/help-modal/modal.mjs +0 -9
  226. package/dist/components/help-modal/modal.mjs.map +0 -1
  227. package/dist/components/index.d.ts +0 -14
  228. package/dist/components/index.js +0 -2665
  229. package/dist/components/index.js.map +0 -1
  230. package/dist/components/index.mjs +0 -54
  231. package/dist/components/index.mjs.map +0 -1
  232. package/dist/context/index.d.ts +0 -2
  233. package/dist/context/index.js +0 -19
  234. package/dist/context/index.js.map +0 -1
  235. package/dist/context/index.mjs +0 -2
  236. package/dist/context/index.mjs.map +0 -1
  237. package/dist/hooks/index.d.ts +0 -1
  238. package/dist/hooks/index.js +0 -55
  239. package/dist/hooks/index.js.map +0 -1
  240. package/dist/hooks/index.mjs +0 -9
  241. package/dist/hooks/index.mjs.map +0 -1
  242. package/dist/hooks/use-copilot-chat-suggestions.d.ts +0 -83
  243. package/dist/hooks/use-copilot-chat-suggestions.js +0 -53
  244. package/dist/hooks/use-copilot-chat-suggestions.js.map +0 -1
  245. package/dist/hooks/use-copilot-chat-suggestions.mjs +0 -8
  246. package/dist/hooks/use-copilot-chat-suggestions.mjs.map +0 -1
  247. package/dist/hooks/use-copy-to-clipboard.d.ts +0 -9
  248. package/dist/hooks/use-copy-to-clipboard.js +0 -60
  249. package/dist/hooks/use-copy-to-clipboard.js.map +0 -1
  250. package/dist/hooks/use-copy-to-clipboard.mjs +0 -8
  251. package/dist/hooks/use-copy-to-clipboard.mjs.map +0 -1
  252. package/dist/hooks/use-push-to-talk.d.ts +0 -19
  253. package/dist/hooks/use-push-to-talk.js +0 -195
  254. package/dist/hooks/use-push-to-talk.js.map +0 -1
  255. package/dist/hooks/use-push-to-talk.mjs +0 -12
  256. package/dist/hooks/use-push-to-talk.mjs.map +0 -1
  257. package/dist/index.css +0 -751
  258. package/dist/index.css.map +0 -1
  259. package/dist/index.d.ts +0 -16
  260. package/dist/index.js +0 -2693
  261. package/dist/index.js.map +0 -1
  262. package/dist/index.mjs +0 -62
  263. package/dist/index.mjs.map +0 -1
  264. package/dist/lib/utils.d.ts +0 -4
  265. package/dist/lib/utils.js +0 -76
  266. package/dist/lib/utils.js.map +0 -1
  267. package/dist/lib/utils.mjs +0 -34
  268. package/dist/lib/utils.mjs.map +0 -1
  269. package/dist/lib/utils.test.d.ts +0 -2
  270. package/dist/lib/utils.test.js +0 -9
  271. package/dist/lib/utils.test.js.map +0 -1
  272. package/dist/lib/utils.test.mjs +0 -7
  273. package/dist/lib/utils.test.mjs.map +0 -1
  274. package/dist/types/css.d.ts +0 -16
  275. package/dist/types/css.js +0 -19
  276. package/dist/types/css.js.map +0 -1
  277. package/dist/types/css.mjs +0 -1
  278. package/dist/types/css.mjs.map +0 -1
  279. package/dist/types/index.d.ts +0 -2
  280. package/dist/types/index.js +0 -19
  281. package/dist/types/index.js.map +0 -1
  282. package/dist/types/index.mjs +0 -2
  283. package/dist/types/index.mjs.map +0 -1
  284. package/dist/types/suggestions.d.ts +0 -8
  285. package/dist/types/suggestions.js +0 -19
  286. package/dist/types/suggestions.js.map +0 -1
  287. package/dist/types/suggestions.mjs +0 -1
  288. package/dist/types/suggestions.mjs.map +0 -1
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/hooks/index.ts
21
- var hooks_exports = {};
22
- __export(hooks_exports, {
23
- useCopilotChatSuggestions: () => useCopilotChatSuggestions
24
- });
25
- module.exports = __toCommonJS(hooks_exports);
26
-
27
- // src/hooks/use-copilot-chat-suggestions.tsx
28
- var import_react = require("react");
29
- var import_react_core = require("@copilotkit/react-core");
30
- var import_shared = require("@copilotkit/shared");
31
- function useCopilotChatSuggestions({
32
- instructions,
33
- className,
34
- minSuggestions = 1,
35
- maxSuggestions = 3
36
- }, dependencies = []) {
37
- const context = (0, import_react_core.useCopilotContext)();
38
- (0, import_react.useEffect)(() => {
39
- const id = (0, import_shared.randomId)();
40
- context.addChatSuggestionConfiguration(id, {
41
- instructions,
42
- minSuggestions,
43
- maxSuggestions,
44
- className
45
- });
46
- return () => {
47
- context.removeChatSuggestionConfiguration(id);
48
- };
49
- }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);
50
- }
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {
53
- useCopilotChatSuggestions
54
- });
55
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/index.ts","../../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["export * from \"./use-copilot-chat-suggestions\";\n","/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * <br/>\n * <img src=\"/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect } from \"react\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { randomId } from \"@copilotkit/shared\";\n\ninterface UseCopilotChatSuggestionsConfiguration {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n}\n\nexport function useCopilotChatSuggestions(\n {\n instructions,\n className,\n minSuggestions = 1,\n maxSuggestions = 3,\n }: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const context = useCopilotContext();\n\n useEffect(() => {\n const id = randomId();\n\n context.addChatSuggestionConfiguration(id, {\n instructions,\n minSuggestions,\n maxSuggestions,\n className,\n });\n\n return () => {\n context.removeChatSuggestionConfiguration(id);\n };\n }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6DA,mBAA0B;AAC1B,wBAAkC;AAClC,oBAAyB;AAuBlB,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,iBAAiB;AACnB,GACA,eAAsB,CAAC,GACvB;AACA,QAAM,cAAU,qCAAkB;AAElC,8BAAU,MAAM;AACd,UAAM,SAAK,wBAAS;AAEpB,YAAQ,+BAA+B,IAAI;AAAA,MACzC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,cAAQ,kCAAkC,EAAE;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,GAAG,cAAc,cAAc,gBAAgB,gBAAgB,SAAS,CAAC;AAC/E;","names":[]}
@@ -1,9 +0,0 @@
1
- import "../chunk-T26KLXLH.mjs";
2
- import {
3
- useCopilotChatSuggestions
4
- } from "../chunk-Z2UZSN3K.mjs";
5
- import "../chunk-MRXNTQOX.mjs";
6
- export {
7
- useCopilotChatSuggestions
8
- };
9
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,83 +0,0 @@
1
- /**
2
- * <Callout type="warning">
3
- * useCopilotChatSuggestions is experimental. The interface is not final and
4
- * can change without notice.
5
- * </Callout>
6
- *
7
- * `useCopilotReadable` is a React hook that provides app-state and other information
8
- * to the Copilot. Optionally, the hook can also handle hierarchical state within your
9
- * application, passing these parent-child relationships to the Copilot.
10
- *
11
- * <br/>
12
- * <img src="/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
13
- *
14
- * ## Usage
15
- *
16
- * ### Install Dependencies
17
- *
18
- * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
19
- *
20
- * ```shell npm2yarn \"@copilotkit/react-ui"\
21
- * npm install @copilotkit/react-core @copilotkit/react-ui
22
- * ```
23
- *
24
- * ### Simple Usage
25
- *
26
- * ```tsx
27
- * import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
28
- *
29
- * export function MyComponent() {
30
- * const [employees, setEmployees] = useState([]);
31
- *
32
- * useCopilotChatSuggestions({
33
- * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,
34
- * });
35
- * }
36
- * ```
37
- *
38
- * ### Dependency Management
39
- *
40
- * ```tsx
41
- * import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
42
- *
43
- * export function MyComponent() {
44
- * useCopilotChatSuggestions(
45
- * {
46
- * instructions: "Suggest the most relevant next actions.",
47
- * },
48
- * [appState],
49
- * );
50
- * }
51
- * ```
52
- *
53
- * In the example above, the suggestions are generated based on the given instructions.
54
- * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
55
- *
56
- * ### Behavior and Lifecycle
57
- *
58
- * The hook registers the configuration with the chat context upon component mount and
59
- * removes it on unmount, ensuring a clean and efficient lifecycle management.
60
- */
61
- interface UseCopilotChatSuggestionsConfiguration {
62
- /**
63
- * A prompt or instructions for the GPT to generate suggestions.
64
- */
65
- instructions: string;
66
- /**
67
- * The minimum number of suggestions to generate. Defaults to `1`.
68
- * @default 1
69
- */
70
- minSuggestions?: number;
71
- /**
72
- * The maximum number of suggestions to generate. Defaults to `3`.
73
- * @default 1
74
- */
75
- maxSuggestions?: number;
76
- /**
77
- * An optional class name to apply to the suggestions.
78
- */
79
- className?: string;
80
- }
81
- declare function useCopilotChatSuggestions({ instructions, className, minSuggestions, maxSuggestions, }: UseCopilotChatSuggestionsConfiguration, dependencies?: any[]): void;
82
-
83
- export { useCopilotChatSuggestions };
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/hooks/use-copilot-chat-suggestions.tsx
21
- var use_copilot_chat_suggestions_exports = {};
22
- __export(use_copilot_chat_suggestions_exports, {
23
- useCopilotChatSuggestions: () => useCopilotChatSuggestions
24
- });
25
- module.exports = __toCommonJS(use_copilot_chat_suggestions_exports);
26
- var import_react = require("react");
27
- var import_react_core = require("@copilotkit/react-core");
28
- var import_shared = require("@copilotkit/shared");
29
- function useCopilotChatSuggestions({
30
- instructions,
31
- className,
32
- minSuggestions = 1,
33
- maxSuggestions = 3
34
- }, dependencies = []) {
35
- const context = (0, import_react_core.useCopilotContext)();
36
- (0, import_react.useEffect)(() => {
37
- const id = (0, import_shared.randomId)();
38
- context.addChatSuggestionConfiguration(id, {
39
- instructions,
40
- minSuggestions,
41
- maxSuggestions,
42
- className
43
- });
44
- return () => {
45
- context.removeChatSuggestionConfiguration(id);
46
- };
47
- }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);
48
- }
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- useCopilotChatSuggestions
52
- });
53
- //# sourceMappingURL=use-copilot-chat-suggestions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * <br/>\n * <img src=\"/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect } from \"react\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { randomId } from \"@copilotkit/shared\";\n\ninterface UseCopilotChatSuggestionsConfiguration {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n}\n\nexport function useCopilotChatSuggestions(\n {\n instructions,\n className,\n minSuggestions = 1,\n maxSuggestions = 3,\n }: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const context = useCopilotContext();\n\n useEffect(() => {\n const id = randomId();\n\n context.addChatSuggestionConfiguration(id, {\n instructions,\n minSuggestions,\n maxSuggestions,\n className,\n });\n\n return () => {\n context.removeChatSuggestionConfiguration(id);\n };\n }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6DA,mBAA0B;AAC1B,wBAAkC;AAClC,oBAAyB;AAuBlB,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,iBAAiB;AACnB,GACA,eAAsB,CAAC,GACvB;AACA,QAAM,cAAU,qCAAkB;AAElC,8BAAU,MAAM;AACd,UAAM,SAAK,wBAAS;AAEpB,YAAQ,+BAA+B,IAAI;AAAA,MACzC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,cAAQ,kCAAkC,EAAE;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,GAAG,cAAc,cAAc,gBAAgB,gBAAgB,SAAS,CAAC;AAC/E;","names":[]}
@@ -1,8 +0,0 @@
1
- import {
2
- useCopilotChatSuggestions
3
- } from "../chunk-Z2UZSN3K.mjs";
4
- import "../chunk-MRXNTQOX.mjs";
5
- export {
6
- useCopilotChatSuggestions
7
- };
8
- //# sourceMappingURL=use-copilot-chat-suggestions.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,9 +0,0 @@
1
- interface useCopyToClipboardProps {
2
- timeout?: number;
3
- }
4
- declare function useCopyToClipboard({ timeout }: useCopyToClipboardProps): {
5
- isCopied: Boolean;
6
- copyToClipboard: (value: string) => void;
7
- };
8
-
9
- export { useCopyToClipboard, useCopyToClipboardProps };
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/hooks/use-copy-to-clipboard.tsx
31
- var use_copy_to_clipboard_exports = {};
32
- __export(use_copy_to_clipboard_exports, {
33
- useCopyToClipboard: () => useCopyToClipboard
34
- });
35
- module.exports = __toCommonJS(use_copy_to_clipboard_exports);
36
- var React = __toESM(require("react"));
37
- function useCopyToClipboard({ timeout = 2e3 }) {
38
- const [isCopied, setIsCopied] = React.useState(false);
39
- const copyToClipboard = (value) => {
40
- var _a;
41
- if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
42
- return;
43
- }
44
- if (!value) {
45
- return;
46
- }
47
- navigator.clipboard.writeText(value).then(() => {
48
- setIsCopied(true);
49
- setTimeout(() => {
50
- setIsCopied(false);
51
- }, timeout);
52
- });
53
- };
54
- return { isCopied, copyToClipboard };
55
- }
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- useCopyToClipboard
59
- });
60
- //# sourceMappingURL=use-copy-to-clipboard.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/use-copy-to-clipboard.tsx"],"sourcesContent":["import * as React from \"react\";\n\nexport interface useCopyToClipboardProps {\n timeout?: number;\n}\n\nexport function useCopyToClipboard({ timeout = 2000 }: useCopyToClipboardProps) {\n const [isCopied, setIsCopied] = React.useState<Boolean>(false);\n\n const copyToClipboard = (value: string) => {\n if (typeof window === \"undefined\" || !navigator.clipboard?.writeText) {\n return;\n }\n\n if (!value) {\n return;\n }\n\n navigator.clipboard.writeText(value).then(() => {\n setIsCopied(true);\n\n setTimeout(() => {\n setIsCopied(false);\n }, timeout);\n });\n };\n\n return { isCopied, copyToClipboard };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAMhB,SAAS,mBAAmB,EAAE,UAAU,IAAK,GAA4B;AAC9E,QAAM,CAAC,UAAU,WAAW,IAAU,eAAkB,KAAK;AAE7D,QAAM,kBAAkB,CAAC,UAAkB;AAT7C;AAUI,QAAI,OAAO,WAAW,eAAe,GAAC,eAAU,cAAV,mBAAqB,YAAW;AACpE;AAAA,IACF;AAEA,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,cAAU,UAAU,UAAU,KAAK,EAAE,KAAK,MAAM;AAC9C,kBAAY,IAAI;AAEhB,iBAAW,MAAM;AACf,oBAAY,KAAK;AAAA,MACnB,GAAG,OAAO;AAAA,IACZ,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,UAAU,gBAAgB;AACrC;","names":[]}
@@ -1,8 +0,0 @@
1
- import {
2
- useCopyToClipboard
3
- } from "../chunk-54JAUBUJ.mjs";
4
- import "../chunk-MRXNTQOX.mjs";
5
- export {
6
- useCopyToClipboard
7
- };
8
- //# sourceMappingURL=use-copy-to-clipboard.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,19 +0,0 @@
1
- import * as React from 'react';
2
- import { Message } from '@copilotkit/runtime-client-gql';
3
-
4
- declare const checkMicrophonePermission: () => Promise<boolean | undefined>;
5
- declare const requestMicAndPlaybackPermission: () => Promise<{
6
- stream: MediaStream;
7
- audioContext: AudioContext;
8
- } | null>;
9
- type PushToTalkState = "idle" | "recording" | "transcribing";
10
- type SendFunction = (text: string) => Promise<Message>;
11
- declare const usePushToTalk: ({ sendFunction, inProgress, }: {
12
- sendFunction: SendFunction;
13
- inProgress: boolean;
14
- }) => {
15
- pushToTalkState: PushToTalkState;
16
- setPushToTalkState: React.Dispatch<React.SetStateAction<PushToTalkState>>;
17
- };
18
-
19
- export { PushToTalkState, SendFunction, checkMicrophonePermission, requestMicAndPlaybackPermission, usePushToTalk };
@@ -1,195 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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
- };
20
- var __export = (target, all) => {
21
- for (var name in all)
22
- __defProp(target, name, { get: all[name], enumerable: true });
23
- };
24
- var __copyProps = (to, from, except, desc) => {
25
- if (from && typeof from === "object" || typeof from === "function") {
26
- for (let key of __getOwnPropNames(from))
27
- if (!__hasOwnProp.call(to, key) && key !== except)
28
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
- }
30
- return to;
31
- };
32
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
- var __async = (__this, __arguments, generator) => {
34
- return new Promise((resolve, reject) => {
35
- var fulfilled = (value) => {
36
- try {
37
- step(generator.next(value));
38
- } catch (e) {
39
- reject(e);
40
- }
41
- };
42
- var rejected = (value) => {
43
- try {
44
- step(generator.throw(value));
45
- } catch (e) {
46
- reject(e);
47
- }
48
- };
49
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
- step((generator = generator.apply(__this, __arguments)).next());
51
- });
52
- };
53
-
54
- // src/hooks/use-push-to-talk.tsx
55
- var use_push_to_talk_exports = {};
56
- __export(use_push_to_talk_exports, {
57
- checkMicrophonePermission: () => checkMicrophonePermission,
58
- requestMicAndPlaybackPermission: () => requestMicAndPlaybackPermission,
59
- usePushToTalk: () => usePushToTalk
60
- });
61
- module.exports = __toCommonJS(use_push_to_talk_exports);
62
- var import_react_core = require("@copilotkit/react-core");
63
- var import_react = require("react");
64
- var checkMicrophonePermission = () => __async(void 0, null, function* () {
65
- try {
66
- const permissionStatus = yield navigator.permissions.query({
67
- name: "microphone"
68
- });
69
- if (permissionStatus.state === "granted") {
70
- return true;
71
- } else {
72
- return false;
73
- }
74
- } catch (err) {
75
- console.error("Error checking microphone permission", err);
76
- }
77
- });
78
- var requestMicAndPlaybackPermission = () => __async(void 0, null, function* () {
79
- try {
80
- const stream = yield navigator.mediaDevices.getUserMedia({ audio: true });
81
- const audioContext = new window.AudioContext();
82
- yield audioContext.resume();
83
- return { stream, audioContext };
84
- } catch (err) {
85
- console.error("Error requesting microphone and playback permissions", err);
86
- return null;
87
- }
88
- });
89
- var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
90
- if (!mediaStreamRef.current || !audioContextRef.current) {
91
- mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
92
- audioContextRef.current = new window.AudioContext();
93
- yield audioContextRef.current.resume();
94
- }
95
- mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
96
- mediaRecorderRef.current.start(1e3);
97
- mediaRecorderRef.current.ondataavailable = (event) => {
98
- recordedChunks.push(event.data);
99
- };
100
- mediaRecorderRef.current.onstop = onStop;
101
- });
102
- var stopRecording = (mediaRecorderRef) => {
103
- if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
104
- mediaRecorderRef.current.stop();
105
- }
106
- };
107
- var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
108
- const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
109
- const formData = new FormData();
110
- formData.append("file", completeBlob, "recording.mp4");
111
- const response = yield fetch(transcribeAudioUrl, {
112
- method: "POST",
113
- body: formData
114
- });
115
- if (!response.ok) {
116
- throw new Error(`Error: ${response.statusText}`);
117
- }
118
- const transcription = yield response.json();
119
- return transcription.text;
120
- });
121
- var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
122
- const encodedText = encodeURIComponent(text);
123
- const url = `${textToSpeechUrl}?text=${encodedText}`;
124
- fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
125
- const source = audioContext.createBufferSource();
126
- source.buffer = audioBuffer;
127
- source.connect(audioContext.destination);
128
- source.start(0);
129
- }).catch((error) => {
130
- console.error("Error with decoding audio data", error);
131
- });
132
- };
133
- var usePushToTalk = ({
134
- sendFunction,
135
- inProgress
136
- }) => {
137
- const [pushToTalkState, setPushToTalkState] = (0, import_react.useState)("idle");
138
- const mediaStreamRef = (0, import_react.useRef)(null);
139
- const audioContextRef = (0, import_react.useRef)(null);
140
- const mediaRecorderRef = (0, import_react.useRef)(null);
141
- const recordedChunks = (0, import_react.useRef)([]);
142
- const generalContext = (0, import_react_core.useCopilotContext)();
143
- const messagesContext = (0, import_react_core.useCopilotMessagesContext)();
144
- const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
145
- const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react.useState)(null);
146
- (0, import_react.useEffect)(() => {
147
- if (pushToTalkState === "recording") {
148
- startRecording(
149
- mediaStreamRef,
150
- mediaRecorderRef,
151
- audioContextRef,
152
- recordedChunks.current,
153
- () => {
154
- setPushToTalkState("transcribing");
155
- }
156
- );
157
- } else {
158
- stopRecording(mediaRecorderRef);
159
- if (pushToTalkState === "transcribing") {
160
- transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
161
- (transcription) => __async(void 0, null, function* () {
162
- recordedChunks.current = [];
163
- setPushToTalkState("idle");
164
- const message = yield sendFunction(transcription);
165
- setStartReadingFromMessageId(message.id);
166
- })
167
- );
168
- }
169
- }
170
- return () => {
171
- stopRecording(mediaRecorderRef);
172
- };
173
- }, [pushToTalkState]);
174
- (0, import_react.useEffect)(() => {
175
- if (inProgress === false && startReadingFromMessageId) {
176
- const lastMessageIndex = context.messages.findIndex(
177
- (message) => message.id === startReadingFromMessageId
178
- );
179
- const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
180
- (message) => message.isTextMessage() && message.role === "assistant"
181
- );
182
- const text = messagesAfterLast.map((message) => message.content).join("\n");
183
- playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
184
- setStartReadingFromMessageId(null);
185
- }
186
- }, [startReadingFromMessageId, inProgress]);
187
- return { pushToTalkState, setPushToTalkState };
188
- };
189
- // Annotate the CommonJS export names for ESM import in node:
190
- 0 && (module.exports = {
191
- checkMicrophonePermission,
192
- requestMicAndPlaybackPermission,
193
- usePushToTalk
194
- });
195
- //# sourceMappingURL=use-push-to-talk.js.map
@@ -1 +0,0 @@
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":"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","names":[]}
@@ -1,12 +0,0 @@
1
- import {
2
- checkMicrophonePermission,
3
- requestMicAndPlaybackPermission,
4
- usePushToTalk
5
- } from "../chunk-S5MBUNGN.mjs";
6
- import "../chunk-MRXNTQOX.mjs";
7
- export {
8
- checkMicrophonePermission,
9
- requestMicAndPlaybackPermission,
10
- usePushToTalk
11
- };
12
- //# sourceMappingURL=use-push-to-talk.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}