@copilotkit/react-ui 0.36.0-mme-push-to-talk.0 → 0.36.0-mme-pre.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.
- package/.turbo/turbo-build.log +174 -167
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-DMAQBCTX.mjs → chunk-4MKP23AD.mjs} +6 -4
- package/dist/chunk-4MKP23AD.mjs.map +1 -0
- package/dist/{chunk-UVMROYDT.mjs → chunk-6XLZXLM5.mjs} +5 -5
- package/dist/{chunk-UVMROYDT.mjs.map → chunk-6XLZXLM5.mjs.map} +1 -1
- package/dist/{chunk-XYM43AHP.mjs → chunk-7FES2IQA.mjs} +3 -3
- package/dist/chunk-ANO23V2M.mjs +135 -0
- package/dist/chunk-ANO23V2M.mjs.map +1 -0
- package/dist/{chunk-DRNCOXZO.mjs → chunk-BL65ZC6L.mjs} +28 -7
- package/dist/chunk-BL65ZC6L.mjs.map +1 -0
- package/dist/{chunk-PGZDQT74.mjs → chunk-CE7PJAAO.mjs} +2 -2
- package/dist/{chunk-FWTPMPSN.mjs → chunk-FZC7X5PK.mjs} +23 -3
- package/dist/{chunk-FWTPMPSN.mjs.map → chunk-FZC7X5PK.mjs.map} +1 -1
- package/dist/{chunk-Z45ZEXJW.mjs → chunk-LTCJCXCP.mjs} +5 -8
- package/dist/chunk-LTCJCXCP.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/{chunk-SKC7AJIV.mjs → chunk-MRXNTQOX.mjs} +1 -3
- package/dist/{chunk-MWFHYCQB.mjs → chunk-PAQWLSA4.mjs} +2 -2
- package/dist/chunk-RT2XG2T7.mjs +25 -0
- package/dist/chunk-RT2XG2T7.mjs.map +1 -0
- package/dist/chunk-T3JTSIHT.mjs +93 -0
- package/dist/chunk-T3JTSIHT.mjs.map +1 -0
- package/dist/{chunk-A7J4KGLP.mjs → chunk-UPTB2MVO.mjs} +2 -2
- package/dist/{chunk-KZME7C5S.mjs → chunk-VUZA5AFH.mjs} +8 -11
- package/dist/chunk-VUZA5AFH.mjs.map +1 -0
- package/dist/{chunk-XWWMYJJF.mjs → chunk-XRODMID5.mjs} +5 -5
- package/dist/{chunk-XWWMYJJF.mjs.map → chunk-XRODMID5.mjs.map} +1 -1
- package/dist/{chunk-ZKLK3M77.mjs → chunk-YQ3D5IQV.mjs} +3 -3
- package/dist/{chunk-WM6BS77F.mjs → chunk-YQFVRDNC.mjs} +2 -2
- package/dist/{chunk-WM6BS77F.mjs.map → chunk-YQFVRDNC.mjs.map} +1 -1
- package/dist/chunk-ZO3GLN23.mjs +137 -0
- package/dist/chunk-ZO3GLN23.mjs.map +1 -0
- package/dist/components/chat/Button.d.ts +1 -1
- package/dist/components/chat/Button.js +2 -30
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +4 -4
- package/dist/components/chat/Chat.d.ts +66 -47
- package/dist/components/chat/Chat.js +274 -430
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +16 -17
- package/dist/components/chat/ChatContext.d.ts +17 -22
- package/dist/components/chat/ChatContext.js +23 -8
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +3 -3
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +3 -3
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +4 -4
- package/dist/components/chat/Icons.d.ts +6 -5
- package/dist/components/chat/Icons.js +21 -0
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +4 -2
- package/dist/components/chat/Input.js +147 -9
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +6 -5
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +4 -4
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +6 -6
- package/dist/components/chat/Modal.d.ts +50 -0
- package/dist/components/chat/Modal.js +1584 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +23 -0
- package/dist/components/chat/Popup.d.ts +6 -5
- package/dist/components/chat/Popup.js +288 -249
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +16 -15
- package/dist/components/chat/Response.js.map +1 -1
- package/dist/components/chat/Response.mjs +4 -4
- package/dist/components/chat/Sidebar.d.ts +6 -5
- package/dist/components/chat/Sidebar.js +290 -251
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +16 -15
- package/dist/components/chat/Suggestion.d.ts +1 -2
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +3 -3
- package/dist/components/chat/Textarea.d.ts +4 -4
- package/dist/components/chat/Textarea.js +1 -1
- package/dist/components/chat/Textarea.js.map +1 -1
- package/dist/components/chat/Textarea.mjs +2 -2
- package/dist/components/chat/Window.mjs +1 -1
- package/dist/components/chat/index.d.ts +2 -1
- package/dist/components/chat/index.js +294 -253
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +23 -19
- package/dist/components/chat/props.d.ts +1 -3
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +294 -253
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +23 -19
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +6 -31
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +2 -22
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +26 -4
- package/dist/hooks/use-copilot-chat-suggestions.js +6 -31
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +2 -22
- package/dist/hooks/use-copy-to-clipboard.mjs +1 -1
- package/dist/hooks/use-push-to-talk.d.ts +19 -0
- package/dist/hooks/use-push-to-talk.js +177 -0
- package/dist/hooks/use-push-to-talk.js.map +1 -0
- package/dist/hooks/use-push-to-talk.mjs +12 -0
- package/dist/hooks/use-push-to-talk.mjs.map +1 -0
- package/dist/index.css +60 -8
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +300 -258
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -24
- package/dist/lib/utils.mjs +1 -1
- package/dist/types/suggestions.d.ts +1 -21
- package/dist/types/suggestions.js.map +1 -1
- package/package.json +6 -6
- package/src/components/chat/Button.tsx +2 -35
- package/src/components/chat/Chat.tsx +126 -255
- package/src/components/chat/ChatContext.tsx +8 -22
- package/src/components/chat/Icons.tsx +17 -0
- package/src/components/chat/Input.tsx +37 -5
- package/src/components/chat/Modal.tsx +115 -0
- package/src/components/chat/Popup.tsx +3 -3
- package/src/components/chat/Sidebar.tsx +4 -4
- package/src/components/chat/Suggestion.tsx +6 -2
- package/src/components/chat/Textarea.tsx +1 -1
- package/src/components/chat/index.tsx +1 -0
- package/src/components/chat/props.ts +1 -3
- package/src/css/input.css +18 -8
- package/src/css/panel.css +38 -0
- package/src/css/window.css +3 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +31 -5
- package/src/hooks/use-push-to-talk.tsx +162 -0
- package/src/styles.css +1 -0
- package/src/types/suggestions.ts +0 -24
- package/dist/chunk-5ASYNEHX.mjs +0 -53
- package/dist/chunk-5ASYNEHX.mjs.map +0 -1
- package/dist/chunk-DMAQBCTX.mjs.map +0 -1
- package/dist/chunk-DRNCOXZO.mjs.map +0 -1
- package/dist/chunk-JPX5ODUX.mjs +0 -266
- package/dist/chunk-JPX5ODUX.mjs.map +0 -1
- package/dist/chunk-KZME7C5S.mjs.map +0 -1
- package/dist/chunk-PEDSZYHE.mjs +0 -36
- package/dist/chunk-PEDSZYHE.mjs.map +0 -1
- package/dist/chunk-UGQQ4WEQ.mjs +0 -1
- package/dist/chunk-Z45ZEXJW.mjs.map +0 -1
- package/dist/components/chat/audio.d.ts +0 -7
- package/dist/components/chat/audio.js +0 -77
- package/dist/components/chat/audio.js.map +0 -1
- package/dist/components/chat/audio.mjs +0 -10
- package/src/components/chat/audio.ts +0 -26
- /package/dist/{chunk-XYM43AHP.mjs.map → chunk-7FES2IQA.mjs.map} +0 -0
- /package/dist/{chunk-PGZDQT74.mjs.map → chunk-CE7PJAAO.mjs.map} +0 -0
- /package/dist/{chunk-SKC7AJIV.mjs.map → chunk-MRFF7GSQ.mjs.map} +0 -0
- /package/dist/{chunk-UGQQ4WEQ.mjs.map → chunk-MRXNTQOX.mjs.map} +0 -0
- /package/dist/{chunk-MWFHYCQB.mjs.map → chunk-PAQWLSA4.mjs.map} +0 -0
- /package/dist/{chunk-A7J4KGLP.mjs.map → chunk-UPTB2MVO.mjs.map} +0 -0
- /package/dist/{chunk-ZKLK3M77.mjs.map → chunk-YQ3D5IQV.mjs.map} +0 -0
- /package/dist/components/chat/{audio.mjs.map → Modal.mjs.map} +0 -0
package/dist/chunk-5ASYNEHX.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useChatContext
|
|
3
|
-
} from "./chunk-KZME7C5S.mjs";
|
|
4
|
-
|
|
5
|
-
// src/components/chat/Button.tsx
|
|
6
|
-
import { useEffect, useRef, useState } from "react";
|
|
7
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
var Button = ({ open, setOpen, pushToTalk, setPushToTalk }) => {
|
|
9
|
-
const context = useChatContext();
|
|
10
|
-
const timerRef = useRef(null);
|
|
11
|
-
const [isLongPress, setIsLongPress] = useState(false);
|
|
12
|
-
const handleMouseDown = () => {
|
|
13
|
-
timerRef.current = setTimeout(() => {
|
|
14
|
-
setPushToTalk(true);
|
|
15
|
-
setIsLongPress(true);
|
|
16
|
-
}, 500);
|
|
17
|
-
};
|
|
18
|
-
const handleMouseUp = () => {
|
|
19
|
-
if (timerRef.current) {
|
|
20
|
-
clearTimeout(timerRef.current);
|
|
21
|
-
setPushToTalk(false);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const handleClick = () => {
|
|
25
|
-
if (!isLongPress) {
|
|
26
|
-
setOpen(!open);
|
|
27
|
-
} else {
|
|
28
|
-
setIsLongPress(false);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
document.addEventListener("mouseup", handleMouseUp);
|
|
33
|
-
return () => {
|
|
34
|
-
document.removeEventListener("mouseup", handleMouseUp);
|
|
35
|
-
};
|
|
36
|
-
}, []);
|
|
37
|
-
return /* @__PURE__ */ jsx("div", { onClick: handleClick, onMouseDown: handleMouseDown, children: /* @__PURE__ */ jsxs(
|
|
38
|
-
"button",
|
|
39
|
-
{
|
|
40
|
-
className: `copilotKitButton ${open ? "open" : ""}`,
|
|
41
|
-
"aria-label": open ? "Close Chat" : "Open Chat",
|
|
42
|
-
children: [
|
|
43
|
-
/* @__PURE__ */ jsx("div", { className: "copilotKitButtonIcon copilotKitButtonIconOpen", children: context.icons.openIcon }),
|
|
44
|
-
/* @__PURE__ */ jsx("div", { className: "copilotKitButtonIcon copilotKitButtonIconClose", children: context.icons.closeIcon })
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
) });
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export {
|
|
51
|
-
Button
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=chunk-5ASYNEHX.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/Button.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { ButtonProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\n\nexport const Button = ({ open, setOpen, pushToTalk, setPushToTalk }: ButtonProps) => {\n const context = useChatContext();\n const timerRef = useRef<NodeJS.Timeout | null>(null);\n const [isLongPress, setIsLongPress] = useState(false);\n\n const handleMouseDown = () => {\n timerRef.current = setTimeout(() => {\n setPushToTalk(true);\n setIsLongPress(true);\n }, 500); // 500ms for long press\n };\n\n const handleMouseUp = () => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n setPushToTalk(false);\n }\n };\n\n const handleClick = () => {\n if (!isLongPress) {\n setOpen(!open);\n } else {\n setIsLongPress(false);\n }\n };\n\n // we want to handle the mouse up event event outside of the button component\n useEffect(() => {\n document.addEventListener(\"mouseup\", handleMouseUp);\n return () => {\n document.removeEventListener(\"mouseup\", handleMouseUp);\n };\n }, []);\n\n return (\n <div onClick={handleClick} onMouseDown={handleMouseDown}>\n <button\n className={`copilotKitButton ${open ? \"open\" : \"\"}`}\n aria-label={open ? \"Close Chat\" : \"Open Chat\"}\n >\n <div className=\"copilotKitButtonIcon copilotKitButtonIconOpen\">\n {context.icons.openIcon}\n </div>\n <div className=\"copilotKitButtonIcon copilotKitButtonIconClose\">\n {context.icons.closeIcon}\n </div>\n </button>\n </div>\n );\n};\n"],"mappings":";;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgB;AAyCtC,SAIE,KAJF;AArCC,IAAM,SAAS,CAAC,EAAE,MAAM,SAAS,YAAY,cAAc,MAAmB;AACnF,QAAM,UAAU,eAAe;AAC/B,QAAM,WAAW,OAA8B,IAAI;AACnD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AAEpD,QAAM,kBAAkB,MAAM;AAC5B,aAAS,UAAU,WAAW,MAAM;AAClC,oBAAc,IAAI;AAClB,qBAAe,IAAI;AAAA,IACrB,GAAG,GAAG;AAAA,EACR;AAEA,QAAM,gBAAgB,MAAM;AAC1B,QAAI,SAAS,SAAS;AACpB,mBAAa,SAAS,OAAO;AAC7B,oBAAc,KAAK;AAAA,IACrB;AAAA,EACF;AAEA,QAAM,cAAc,MAAM;AACxB,QAAI,CAAC,aAAa;AAChB,cAAQ,CAAC,IAAI;AAAA,IACf,OAAO;AACL,qBAAe,KAAK;AAAA,IACtB;AAAA,EACF;AAGA,YAAU,MAAM;AACd,aAAS,iBAAiB,WAAW,aAAa;AAClD,WAAO,MAAM;AACX,eAAS,oBAAoB,WAAW,aAAa;AAAA,IACvD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SACE,oBAAC,SAAI,SAAS,aAAa,aAAa,iBACtC;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,oBAAoB,OAAO,SAAS;AAAA,MAC/C,cAAY,OAAO,eAAe;AAAA,MAElC;AAAA,4BAAC,SAAI,WAAU,iDACZ,kBAAQ,MAAM,UACjB;AAAA,QACA,oBAAC,SAAI,WAAU,kDACZ,kBAAQ,MAAM,WACjB;AAAA;AAAA;AAAA,EACF,GACF;AAEJ;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/Suggestion.tsx"],"sourcesContent":["import { CopilotContextParams, extract } from \"@copilotkit/react-core\";\nimport { SuggestionsProps } from \"./props\";\nimport { SmallSpinnerIcon } from \"./Icons\";\nimport { CopilotChatSuggestion, CopilotChatSuggestionConfiguration } from \"../../types/suggestions\";\n\nexport function Suggestion({ title, message, onClick, partial, className }: SuggestionsProps) {\n return (\n <button\n disabled={partial}\n onClick={(e) => {\n e.preventDefault();\n onClick(message);\n }}\n className={className || \"suggestion\"}\n >\n {partial && SmallSpinnerIcon}\n <span>{title}</span>\n </button>\n );\n}\n\nexport const reloadSuggestions = async (\n context: CopilotContextParams,\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },\n setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,\n abortControllerRef: React.MutableRefObject<AbortController | null>,\n) => {\n const abortController = abortControllerRef.current;\n const tools = JSON.stringify(context.getChatCompletionFunctionDescriptions(context.entryPoints));\n\n const allSuggestions: CopilotChatSuggestion[] = [];\n\n for (const config of Object.values(chatSuggestionConfiguration)) {\n try {\n const numOfSuggestionsInstructions =\n config.minSuggestions === 0\n ? `Produce up to ${config.maxSuggestions} suggestions. ` +\n `If there are no highly relevant suggestions you can think of, provide an empty array.`\n : `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;\n const result = await extract({\n context,\n instructions:\n \"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. \" +\n config.instructions +\n \"\\n\\n\" +\n numOfSuggestionsInstructions,\n data: \"Available tools: \" + tools + \"\\n\\n\",\n parameters: [\n {\n name: \"suggestions\",\n type: \"object[]\",\n attributes: [\n {\n name: \"title\",\n description:\n \"The title of the suggestion. This is shown as a button and should be short.\",\n type: \"string\",\n },\n {\n name: \"message\",\n description:\n \"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.\",\n type: \"string\",\n },\n ],\n },\n ],\n include: {\n messages: true,\n readable: true,\n },\n abortSignal: abortController?.signal,\n stream: ({ status, args }) => {\n const suggestions = args.suggestions || [];\n const newSuggestions: CopilotChatSuggestion[] = [];\n for (let i = 0; i < suggestions.length; i++) {\n // if GPT provides too many suggestions, limit the number of suggestions\n if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {\n break;\n }\n const { title, message } = suggestions[i];\n\n // If this is the last suggestion and the status is not complete, mark it as partial\n const partial = i == suggestions.length - 1 && status !== \"complete\";\n\n newSuggestions.push({\n title,\n message,\n partial,\n className: config.className,\n });\n }\n setCurrentSuggestions([...allSuggestions, ...newSuggestions]);\n },\n });\n allSuggestions.push(...result.suggestions);\n } catch (error) {\n console.error(\"Error loading suggestions\", error);\n }\n }\n\n if (abortControllerRef.current === abortController) {\n abortControllerRef.current = null;\n }\n};\n"],"mappings":";;;;;;;;AAAA,SAA+B,eAAe;AAO1C,SASE,KATF;AAFG,SAAS,WAAW,EAAE,OAAO,SAAS,SAAS,SAAS,UAAU,GAAqB;AAC5F,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU;AAAA,MACV,SAAS,CAAC,MAAM;AACd,UAAE,eAAe;AACjB,gBAAQ,OAAO;AAAA,MACjB;AAAA,MACA,WAAW,aAAa;AAAA,MAEvB;AAAA,mBAAW;AAAA,QACZ,oBA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,cACA,WAAW,OAAO;AAAA,YACpB,CAAC;AAAA,UACH;AACA,gCAAsB,CAAC,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAAA,QAC9D;AAAA,MACF,CAAC;AACD,qBAAe,KAAK,GAAG,OAAO,WAAW;AAAA,IAC3C,SAAS,OAAP;AACA,cAAQ,MAAM,6BAA6B,KAAK;AAAA,IAClD;AAAA,EACF;AAEA,MAAI,mBAAmB,YAAY,iBAAiB;AAClD,uBAAmB,UAAU;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/Input.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { InputProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport AutoResizingTextarea from \"./Textarea\";\n\nexport const Input = ({ inProgress, onSend, isVisible = false }: InputProps) => {\n const context = useChatContext();\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {\n // Check if the clicked element is not the textarea itself\n if (event.target !== event.currentTarget) return;\n\n textareaRef.current?.focus();\n };\n\n const [text, setText] = useState(\"\");\n const send = () => {\n if (inProgress) return;\n onSend(text);\n setText(\"\");\n\n textareaRef.current?.focus();\n };\n\n useEffect(() => {\n if (isVisible) {\n textareaRef.current?.focus();\n }\n }, [isVisible]);\n\n const icon = inProgress ? context.icons.activityIcon : context.icons.sendIcon;\n const disabled = inProgress || text.length === 0;\n\n return (\n <div className=\"copilotKitInput\" onClick={handleDivClick}>\n <button className=\"copilotKitSendButton\" disabled={disabled} onClick={send}>\n {icon}\n </button>\n <AutoResizingTextarea\n ref={textareaRef}\n placeholder={context.labels.placeholder}\n autoFocus={true}\n maxRows={5}\n value={text}\n onChange={(event) => setText(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n send();\n }\n }}\n />\n </div>\n );\n};\n"],"mappings":";;;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
-
import {
|
|
2
|
-
Window
|
|
3
|
-
} from "./chunk-B7DNOYVQ.mjs";
|
|
4
|
-
import {
|
|
5
|
-
requestMicAndPlaybackPermission
|
|
6
|
-
} from "./chunk-PEDSZYHE.mjs";
|
|
7
|
-
import {
|
|
8
|
-
Input
|
|
9
|
-
} from "./chunk-DRNCOXZO.mjs";
|
|
10
|
-
import {
|
|
11
|
-
Messages
|
|
12
|
-
} from "./chunk-XYM43AHP.mjs";
|
|
13
|
-
import {
|
|
14
|
-
ResponseButton
|
|
15
|
-
} from "./chunk-PGZDQT74.mjs";
|
|
16
|
-
import {
|
|
17
|
-
Suggestion,
|
|
18
|
-
reloadSuggestions
|
|
19
|
-
} from "./chunk-DMAQBCTX.mjs";
|
|
20
|
-
import {
|
|
21
|
-
Button
|
|
22
|
-
} from "./chunk-5ASYNEHX.mjs";
|
|
23
|
-
import {
|
|
24
|
-
Header
|
|
25
|
-
} from "./chunk-MWFHYCQB.mjs";
|
|
26
|
-
import {
|
|
27
|
-
ChatContextProvider
|
|
28
|
-
} from "./chunk-KZME7C5S.mjs";
|
|
29
|
-
import {
|
|
30
|
-
__async,
|
|
31
|
-
__objRest,
|
|
32
|
-
__restKey,
|
|
33
|
-
__spreadProps,
|
|
34
|
-
__spreadValues
|
|
35
|
-
} from "./chunk-SKC7AJIV.mjs";
|
|
36
|
-
|
|
37
|
-
// src/components/chat/Chat.tsx
|
|
38
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
39
|
-
import {
|
|
40
|
-
useCopilotChat,
|
|
41
|
-
useCopilotContext
|
|
42
|
-
} from "@copilotkit/react-core";
|
|
43
|
-
import { nanoid } from "nanoid";
|
|
44
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
45
|
-
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
46
|
-
var CopilotChat = ({
|
|
47
|
-
instructions,
|
|
48
|
-
defaultOpen = false,
|
|
49
|
-
clickOutsideToClose = true,
|
|
50
|
-
hitEscapeToClose = true,
|
|
51
|
-
onSetOpen,
|
|
52
|
-
onSubmitMessage,
|
|
53
|
-
shortcut = "/",
|
|
54
|
-
icons,
|
|
55
|
-
labels,
|
|
56
|
-
makeSystemMessage,
|
|
57
|
-
showResponseButton = true,
|
|
58
|
-
onInProgress,
|
|
59
|
-
Window: Window2 = Window,
|
|
60
|
-
Button: Button2 = Button,
|
|
61
|
-
Header: Header2 = Header,
|
|
62
|
-
Messages: Messages2 = Messages,
|
|
63
|
-
Input: Input2 = Input,
|
|
64
|
-
ResponseButton: ResponseButton2 = ResponseButton,
|
|
65
|
-
className,
|
|
66
|
-
children
|
|
67
|
-
}) => {
|
|
68
|
-
const { visibleMessages, append, reload, stop, isLoading, input, setInput } = useCopilotChat({
|
|
69
|
-
id: nanoid(),
|
|
70
|
-
makeSystemMessage,
|
|
71
|
-
additionalInstructions: instructions
|
|
72
|
-
});
|
|
73
|
-
const [currentSuggestions, setCurrentSuggestions] = React.useState([]);
|
|
74
|
-
const suggestionsAbortControllerRef = useRef(null);
|
|
75
|
-
const debounceTimerRef = useRef();
|
|
76
|
-
const abortSuggestions = () => {
|
|
77
|
-
var _a;
|
|
78
|
-
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
79
|
-
suggestionsAbortControllerRef.current = null;
|
|
80
|
-
};
|
|
81
|
-
const context = useCopilotContext();
|
|
82
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState({});
|
|
83
|
-
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
84
|
-
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
85
|
-
};
|
|
86
|
-
const removeChatSuggestion = (id) => {
|
|
87
|
-
setChatSuggestionConfiguration((prev) => {
|
|
88
|
-
const _a = prev, { [id]: _ } = _a, rest = __objRest(_a, [__restKey(id)]);
|
|
89
|
-
return rest;
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
94
|
-
abortSuggestions();
|
|
95
|
-
debounceTimerRef.current = setTimeout(
|
|
96
|
-
() => {
|
|
97
|
-
if (!isLoading && Object.keys(chatSuggestionConfiguration).length !== 0) {
|
|
98
|
-
suggestionsAbortControllerRef.current = new AbortController();
|
|
99
|
-
reloadSuggestions(
|
|
100
|
-
context,
|
|
101
|
-
chatSuggestionConfiguration,
|
|
102
|
-
setCurrentSuggestions,
|
|
103
|
-
suggestionsAbortControllerRef
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT
|
|
108
|
-
);
|
|
109
|
-
return () => {
|
|
110
|
-
clearTimeout(debounceTimerRef.current);
|
|
111
|
-
};
|
|
112
|
-
}, [isLoading, chatSuggestionConfiguration]);
|
|
113
|
-
const setOpen = (open) => {
|
|
114
|
-
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
115
|
-
setOpenState(open);
|
|
116
|
-
};
|
|
117
|
-
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
118
|
-
abortSuggestions();
|
|
119
|
-
setCurrentSuggestions([]);
|
|
120
|
-
onSubmitMessage == null ? void 0 : onSubmitMessage(messageContent);
|
|
121
|
-
const message = {
|
|
122
|
-
id: nanoid(),
|
|
123
|
-
content: messageContent,
|
|
124
|
-
role: "user"
|
|
125
|
-
};
|
|
126
|
-
append(message);
|
|
127
|
-
return message;
|
|
128
|
-
});
|
|
129
|
-
const [openState, setOpenState] = React.useState(defaultOpen);
|
|
130
|
-
const [pushToTalkState, setPushToTalkState] = React.useState(false);
|
|
131
|
-
const mediaStreamRef = useRef(null);
|
|
132
|
-
const audioContextRef = useRef(null);
|
|
133
|
-
const mediaRecorderRef = useRef(null);
|
|
134
|
-
const [lastMessageIdBeforeAudio, setLastMessageIdBeforeAudio] = useState(null);
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
if (pushToTalkState) {
|
|
137
|
-
console.log("HERE");
|
|
138
|
-
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
139
|
-
setPushToTalkState(false);
|
|
140
|
-
requestMicAndPlaybackPermission().then((res) => {
|
|
141
|
-
if (res) {
|
|
142
|
-
mediaStreamRef.current = res.stream;
|
|
143
|
-
audioContextRef.current = res.audioContext;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
} else {
|
|
147
|
-
console.log("Recording started");
|
|
148
|
-
const recordedChunks = [];
|
|
149
|
-
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
150
|
-
mediaRecorderRef.current.start(1e3);
|
|
151
|
-
mediaRecorderRef.current.ondataavailable = (event) => __async(void 0, null, function* () {
|
|
152
|
-
console.log("Recorded audio: ", event.data);
|
|
153
|
-
recordedChunks.push(event.data);
|
|
154
|
-
});
|
|
155
|
-
mediaRecorderRef.current.onstop = () => __async(void 0, null, function* () {
|
|
156
|
-
console.log("Recording stopped");
|
|
157
|
-
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
158
|
-
const formData = new FormData();
|
|
159
|
-
formData.append("file", completeBlob, "recording.mp4");
|
|
160
|
-
const response = yield fetch(context.copilotApiConfig.transcribeAudioUrl, {
|
|
161
|
-
method: "POST",
|
|
162
|
-
body: formData
|
|
163
|
-
});
|
|
164
|
-
if (!response.ok) {
|
|
165
|
-
throw new Error(`Error: ${response.statusText}`);
|
|
166
|
-
}
|
|
167
|
-
const transcription = yield response.json();
|
|
168
|
-
const message = yield sendMessage(transcription.text);
|
|
169
|
-
setLastMessageIdBeforeAudio(message.id);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
174
|
-
mediaRecorderRef.current.stop();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return () => {
|
|
178
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
179
|
-
mediaRecorderRef.current.stop();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}, [pushToTalkState]);
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
if (lastMessageIdBeforeAudio && !isLoading) {
|
|
185
|
-
if (audioContextRef.current) {
|
|
186
|
-
const lastMessageIndex = context.messages.findIndex(
|
|
187
|
-
(message) => message.id === lastMessageIdBeforeAudio
|
|
188
|
-
);
|
|
189
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant" && message.content);
|
|
190
|
-
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
191
|
-
const encodedText = encodeURIComponent(text);
|
|
192
|
-
const url = `${context.copilotApiConfig.textToSpeechUrl}?text=${encodedText}`;
|
|
193
|
-
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContextRef.current.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
194
|
-
const source = audioContextRef.current.createBufferSource();
|
|
195
|
-
source.buffer = audioBuffer;
|
|
196
|
-
source.connect(audioContextRef.current.destination);
|
|
197
|
-
source.start(0);
|
|
198
|
-
}).catch((error) => {
|
|
199
|
-
console.error("Error with decoding audio data", error);
|
|
200
|
-
});
|
|
201
|
-
setLastMessageIdBeforeAudio(null);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, [isLoading]);
|
|
205
|
-
return /* @__PURE__ */ jsxs(
|
|
206
|
-
ChatContextProvider,
|
|
207
|
-
{
|
|
208
|
-
icons,
|
|
209
|
-
labels,
|
|
210
|
-
open: openState,
|
|
211
|
-
setOpen: setOpenState,
|
|
212
|
-
addChatSuggestionConfiguration,
|
|
213
|
-
removeChatSuggestionConfiguration: removeChatSuggestion,
|
|
214
|
-
children: [
|
|
215
|
-
children,
|
|
216
|
-
/* @__PURE__ */ jsxs("div", { className, children: [
|
|
217
|
-
/* @__PURE__ */ jsx(
|
|
218
|
-
Button2,
|
|
219
|
-
{
|
|
220
|
-
open: openState,
|
|
221
|
-
setOpen,
|
|
222
|
-
pushToTalk: pushToTalkState,
|
|
223
|
-
setPushToTalk: setPushToTalkState
|
|
224
|
-
}
|
|
225
|
-
),
|
|
226
|
-
/* @__PURE__ */ jsxs(
|
|
227
|
-
Window2,
|
|
228
|
-
{
|
|
229
|
-
open: openState,
|
|
230
|
-
setOpen,
|
|
231
|
-
clickOutsideToClose,
|
|
232
|
-
shortcut,
|
|
233
|
-
hitEscapeToClose,
|
|
234
|
-
children: [
|
|
235
|
-
/* @__PURE__ */ jsx(Header2, { open: openState, setOpen }),
|
|
236
|
-
/* @__PURE__ */ jsxs(Messages2, { messages: visibleMessages, inProgress: isLoading, children: [
|
|
237
|
-
currentSuggestions.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
238
|
-
/* @__PURE__ */ jsx("h6", { children: "Suggested:" }),
|
|
239
|
-
/* @__PURE__ */ jsx("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ jsx(
|
|
240
|
-
Suggestion,
|
|
241
|
-
{
|
|
242
|
-
title: suggestion.title,
|
|
243
|
-
message: suggestion.message,
|
|
244
|
-
partial: suggestion.partial,
|
|
245
|
-
className: suggestion.className,
|
|
246
|
-
onClick: (message) => sendMessage(message)
|
|
247
|
-
},
|
|
248
|
-
index
|
|
249
|
-
)) })
|
|
250
|
-
] }),
|
|
251
|
-
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ jsx(ResponseButton2, { onClick: isLoading ? stop : reload, inProgress: isLoading })
|
|
252
|
-
] }),
|
|
253
|
-
/* @__PURE__ */ jsx(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible: openState })
|
|
254
|
-
]
|
|
255
|
-
}
|
|
256
|
-
)
|
|
257
|
-
] })
|
|
258
|
-
]
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
export {
|
|
264
|
-
CopilotChat
|
|
265
|
-
};
|
|
266
|
-
//# sourceMappingURL=chunk-JPX5ODUX.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/Chat.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { CopilotChatIcons, ChatContextProvider, CopilotChatLabels } from \"./ChatContext\";\nimport {\n SystemMessageFunction,\n extract,\n useCopilotChat,\n useCopilotContext,\n} from \"@copilotkit/react-core\";\nimport {\n ButtonProps,\n HeaderProps,\n WindowProps,\n MessagesProps,\n InputProps,\n ResponseButtonProps,\n SuggestionsProps,\n} from \"./props\";\nimport { Window as DefaultWindow } from \"./Window\";\nimport { Button as DefaultButton } from \"./Button\";\nimport { Header as DefaultHeader } from \"./Header\";\nimport { Messages as DefaultMessages } from \"./Messages\";\nimport { Input as DefaultInput } from \"./Input\";\nimport { nanoid } from \"nanoid\";\nimport { ResponseButton as DefaultResponseButton } from \"./Response\";\nimport { Suggestion, reloadSuggestions } from \"./Suggestion\";\nimport { CopilotChatSuggestion, CopilotChatSuggestionConfiguration } from \"../../types/suggestions\";\nimport { requestMicAndPlaybackPermission } from \"./audio\";\nimport { Message } from \"@copilotkit/shared\";\n\n/**\n * Props for CopilotChat component.\n */\nexport interface CopilotChatProps {\n /**\n * Custom instructions to be added to the system message. Use this property to\n * provide additional context or guidance to the language model, influencing\n * its responses. These instructions can include specific directions,\n * preferences, or criteria that the model should consider when generating\n * its output, thereby tailoring the conversation more precisely to the\n * user's needs or the application's requirements.\n */\n instructions?: string;\n\n /**\n * Whether the chat window should be open by default.\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * If the chat window should close when the user clicks outside of it.\n * @default true\n */\n clickOutsideToClose?: boolean;\n\n /**\n * If the chat window should close when the user hits the Escape key.\n * @default true\n */\n hitEscapeToClose?: boolean;\n\n /**\n * A callback that gets called when the chat window opens or closes.\n */\n onSetOpen?: (open: boolean) => void;\n\n /**\n * A callback that gets called when the in progress state changes.\n */\n onInProgress?: (inProgress: boolean) => void;\n\n /**\n * A callback that gets called when a new message it submitted.\n */\n onSubmitMessage?: (message: string) => void;\n\n /**\n * The shortcut key to open the chat window.\n * Uses Command-[shortcut] on a Mac and Ctrl-[shortcut] on Windows.\n * @default \"/\"\n */\n shortcut?: string;\n\n /**\n * Icons can be used to set custom icons for the chat window.\n */\n icons?: CopilotChatIcons;\n\n /**\n * Labels can be used to set custom labels for the chat window.\n */\n labels?: CopilotChatLabels;\n\n /**\n * A function that takes in context string and instructions and returns\n * the system message to include in the chat request.\n * Use this to completely override the system message, when providing\n * instructions is not enough.\n */\n makeSystemMessage?: SystemMessageFunction;\n\n /**\n * Whether to show the response button.\n * @default true\n */\n showResponseButton?: boolean;\n\n /**\n * A custom Window component to use instead of the default.\n */\n Window?: React.ComponentType<WindowProps>;\n\n /**\n * A custom Button component to use instead of the default.\n */\n Button?: React.ComponentType<ButtonProps>;\n\n /**\n * A custom Header component to use instead of the default.\n */\n Header?: React.ComponentType<HeaderProps>;\n\n /**\n * A custom Messages component to use instead of the default.\n */\n Messages?: React.ComponentType<MessagesProps>;\n\n /**\n * A custom Input component to use instead of the default.\n */\n Input?: React.ComponentType<InputProps>;\n\n /**\n * A custom ResponseButton component to use instead of the default.\n */\n ResponseButton?: React.ComponentType<ResponseButtonProps>;\n\n /**\n * A class name to apply to the root element.\n */\n className?: string;\n\n /**\n * Children to render.\n */\n children?: React.ReactNode;\n}\n\nconst SUGGESTIONS_DEBOUNCE_TIMEOUT = 1000;\n\nexport const CopilotChat = ({\n instructions,\n defaultOpen = false,\n clickOutsideToClose = true,\n hitEscapeToClose = true,\n onSetOpen,\n onSubmitMessage,\n shortcut = \"/\",\n icons,\n labels,\n makeSystemMessage,\n showResponseButton = true,\n onInProgress,\n Window = DefaultWindow,\n Button = DefaultButton,\n Header = DefaultHeader,\n Messages = DefaultMessages,\n Input = DefaultInput,\n ResponseButton = DefaultResponseButton,\n className,\n children,\n}: CopilotChatProps) => {\n const { visibleMessages, append, reload, stop, isLoading, input, setInput } = useCopilotChat({\n id: nanoid(),\n makeSystemMessage,\n additionalInstructions: instructions,\n });\n\n const [currentSuggestions, setCurrentSuggestions] = React.useState<CopilotChatSuggestion[]>([]);\n const suggestionsAbortControllerRef = useRef<AbortController | null>(null);\n const debounceTimerRef = useRef<any>();\n\n const abortSuggestions = () => {\n suggestionsAbortControllerRef.current?.abort();\n suggestionsAbortControllerRef.current = null;\n };\n\n const context = useCopilotContext();\n\n const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState<{\n [key: string]: CopilotChatSuggestionConfiguration;\n }>({});\n\n const addChatSuggestionConfiguration = (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => {\n setChatSuggestionConfiguration((prev) => ({ ...prev, [id]: suggestion }));\n };\n\n const removeChatSuggestion = (id: string) => {\n setChatSuggestionConfiguration((prev) => {\n const { [id]: _, ...rest } = prev;\n return rest;\n });\n };\n\n useEffect(() => {\n onInProgress?.(isLoading);\n\n abortSuggestions();\n\n debounceTimerRef.current = setTimeout(\n () => {\n if (!isLoading && Object.keys(chatSuggestionConfiguration).length !== 0) {\n suggestionsAbortControllerRef.current = new AbortController();\n reloadSuggestions(\n context,\n chatSuggestionConfiguration,\n setCurrentSuggestions,\n suggestionsAbortControllerRef,\n );\n }\n },\n currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT,\n );\n\n return () => {\n clearTimeout(debounceTimerRef.current);\n };\n }, [isLoading, chatSuggestionConfiguration]);\n\n const setOpen = (open: boolean) => {\n onSetOpen?.(open);\n setOpenState(open);\n };\n\n const sendMessage = async (messageContent: string) => {\n abortSuggestions();\n setCurrentSuggestions([]);\n onSubmitMessage?.(messageContent);\n const message: Message = {\n id: nanoid(),\n content: messageContent,\n role: \"user\",\n };\n append(message);\n return message;\n };\n\n const [openState, setOpenState] = React.useState(defaultOpen);\n const [pushToTalkState, setPushToTalkState] = React.useState(false);\n const mediaStreamRef = useRef<MediaStream | null>(null);\n const audioContextRef = useRef<AudioContext | null>(null);\n const mediaRecorderRef = useRef<MediaRecorder | null>(null);\n const [lastMessageIdBeforeAudio, setLastMessageIdBeforeAudio] = useState<string | null>(null);\n\n useEffect(() => {\n if (pushToTalkState) {\n console.log(\"HERE\");\n if (!mediaStreamRef.current || !audioContextRef.current) {\n setPushToTalkState(false);\n requestMicAndPlaybackPermission().then((res) => {\n if (res) {\n mediaStreamRef.current = res.stream;\n audioContextRef.current = res.audioContext;\n }\n });\n } else {\n console.log(\"Recording started\");\n const recordedChunks: Blob[] = [];\n\n mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);\n mediaRecorderRef.current.start(1000);\n mediaRecorderRef.current.ondataavailable = async (event) => {\n console.log(\"Recorded audio: \", event.data);\n recordedChunks.push(event.data);\n };\n mediaRecorderRef.current.onstop = async () => {\n console.log(\"Recording stopped\");\n const completeBlob = new Blob(recordedChunks, { type: \"audio/mp4\" });\n\n const formData = new FormData();\n formData.append(\"file\", completeBlob, \"recording.mp4\");\n\n const response = await fetch(context.copilotApiConfig.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 const message = await sendMessage(transcription.text);\n setLastMessageIdBeforeAudio(message.id);\n };\n }\n } else {\n if (mediaRecorderRef.current && mediaRecorderRef.current.state !== \"inactive\") {\n mediaRecorderRef.current.stop();\n }\n }\n\n return () => {\n if (mediaRecorderRef.current && mediaRecorderRef.current.state !== \"inactive\") {\n mediaRecorderRef.current.stop();\n }\n };\n }, [pushToTalkState]);\n\n useEffect(() => {\n if (lastMessageIdBeforeAudio && !isLoading) {\n if (audioContextRef.current) {\n const lastMessageIndex = context.messages.findIndex(\n (message) => message.id === lastMessageIdBeforeAudio,\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 const encodedText = encodeURIComponent(text);\n const url = `${context.copilotApiConfig.textToSpeechUrl}?text=${encodedText}`;\n\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((arrayBuffer) => audioContextRef.current!.decodeAudioData(arrayBuffer))\n .then((audioBuffer) => {\n const source = audioContextRef.current!.createBufferSource();\n source.buffer = audioBuffer;\n source.connect(audioContextRef.current!.destination);\n source.start(0);\n })\n .catch((error) => {\n console.error(\"Error with decoding audio data\", error);\n });\n\n setLastMessageIdBeforeAudio(null);\n }\n }\n }, [isLoading]);\n\n return (\n <ChatContextProvider\n icons={icons}\n labels={labels}\n open={openState}\n setOpen={setOpenState}\n addChatSuggestionConfiguration={addChatSuggestionConfiguration}\n removeChatSuggestionConfiguration={removeChatSuggestion}\n >\n {children}\n <div className={className}>\n <Button\n open={openState}\n setOpen={setOpen}\n pushToTalk={pushToTalkState}\n setPushToTalk={setPushToTalkState}\n ></Button>\n <Window\n open={openState}\n setOpen={setOpen}\n clickOutsideToClose={clickOutsideToClose}\n shortcut={shortcut}\n hitEscapeToClose={hitEscapeToClose}\n >\n <Header open={openState} setOpen={setOpen} />\n <Messages messages={visibleMessages} inProgress={isLoading}>\n {currentSuggestions.length > 0 && (\n <div>\n <h6>Suggested:</h6>\n <div className=\"suggestions\">\n {currentSuggestions.map((suggestion, index) => (\n <Suggestion\n key={index}\n title={suggestion.title}\n message={suggestion.message}\n partial={suggestion.partial}\n className={suggestion.className}\n onClick={(message) => sendMessage(message)}\n />\n ))}\n </div>\n </div>\n )}\n {showResponseButton && visibleMessages.length > 0 && (\n <ResponseButton onClick={isLoading ? stop : reload} inProgress={isLoading} />\n )}\n </Messages>\n <Input inProgress={isLoading} onSend={sendMessage} isVisible={openState} />\n </Window>\n </div>\n </ChatContextProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,WAAW,QAAQ,gBAAgB;AAEnD;AAAA,EAGE;AAAA,EACA;AAAA,OACK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AA,qCAAmB,SAAS,KAC3B,qBAAC,SACC;AAAA,wCAAC,QAAG,wBAAU;AAAA,oBACd,oBAAC,SAAI,WAAU,eACZ,6BAAmB,IAAI,CAAC,YAAY,UACnC;AAAA,sBAAC;AAAA;AAAA,wBAEC,OAAO,WAAW;AAAA,wBAClB,SAAS,WAAW;AAAA,wBACpB,SAAS,WAAW;AAAA,wBACpB,WAAW,WAAW;AAAA,wBACtB,SAAS,CAAC,YAAY,YAAY,OAAO;AAAA;AAAA,sBALpC;AAAA,oBAMP,CACD,GACH;AAAA,qBACF;AAAA,kBAED,sBAAsB,gBAAgB,SAAS,KAC9C,oBAACE,iBAAA,EAAe,SAAS,YAAY,OAAO,QAAQ,YAAY,WAAW;AAAA,mBAE/E;AAAA,gBACA,oBAACD,QAAA,EAAM,YAAY,WAAW,QAAQ,aAAa,WAAW,WAAW;AAAA;AAAA;AAAA,UAC3E;AAAA,WACF;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["Window","Button","Header","Messages","Input","ResponseButton"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/ChatContext.tsx"],"sourcesContent":["import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons from \"./Icons\";\nimport { CopilotChatSuggestion, CopilotChatSuggestionConfiguration } from \"../../types/suggestions\";\n\n/**\n * Icons for CopilotChat component.\n */\nexport interface CopilotChatIcons {\n /**\n * The icon to use for the open chat button.\n * @default <OpenIcon />\n */\n openIcon?: React.ReactNode;\n\n /**\n * The icon to use for the close chat button.\n * @default <CloseIcon />\n */\n closeIcon?: React.ReactNode;\n\n /**\n * The icon to use for the close chat button in the header.\n * @default <HeaderCloseIcon />\n */\n headerCloseIcon?: React.ReactNode;\n\n /**\n * The icon to use for the send button.\n * @default <SendIcon />\n */\n sendIcon?: React.ReactNode;\n\n /**\n * The icon to use for the activity indicator.\n * @default <ActivityIcon />\n */\n activityIcon?: React.ReactNode;\n\n /**\n * The icon to use for the spinner.\n * @default <SpinnerIcon />\n */\n spinnerIcon?: React.ReactNode;\n\n /**\n * The icon to use for the stop button.\n * @default <StopIcon />\n */\n stopIcon?: React.ReactNode;\n\n /**\n * The icon to use for the regenerate button.\n * @default <RegenerateIcon />\n */\n regenerateIcon?: React.ReactNode;\n}\n\n/**\n * Labels for CopilotChat component.\n */\nexport interface CopilotChatLabels {\n /**\n * The initial message(s) to display in the chat window.\n */\n initial?: string | string[];\n\n /**\n * The title to display in the header.\n * @default \"CopilotKit\"\n */\n title?: string;\n\n /**\n * The placeholder to display in the input.\n * @default \"Type a message...\"\n */\n placeholder?: string;\n\n /**\n * The message to display while the chat GPT is \"thinking\".\n * @default \"Thinking...\"\n */\n thinking?: string;\n\n /**\n * The message to display when an error occurs.\n * @default \"❌ An error occurred. Please try again.\"\n */\n error?: string;\n\n /**\n * The label to display on the stop button.\n * @default \"Stop generating\"\n */\n stopGenerating?: string;\n\n /**\n * The label to display on the regenerate button.\n * @default \"Regenerate response\"\n */\n regenerateResponse?: string;\n}\n\ninterface ChatContext {\n labels: Required<CopilotChatLabels>;\n icons: Required<CopilotChatIcons>;\n open: boolean;\n setOpen: (open: boolean) => void;\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n}\n\nexport const ChatContext = React.createContext<ChatContext | undefined>(undefined);\n\nexport function useChatContext(): ChatContext {\n const context = React.useContext(ChatContext);\n if (context === undefined) {\n throw new Error(\n \"Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?\",\n );\n }\n return context;\n}\n\ninterface ChatContextProps {\n // temperature?: number;\n // instructions?: string;\n // maxFeedback?: number;\n labels?: CopilotChatLabels;\n icons?: CopilotChatIcons;\n children?: React.ReactNode;\n open: boolean;\n setOpen: (open: boolean) => void;\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n}\n\nexport const ChatContextProvider = ({\n // temperature,\n // instructions,\n // maxFeedback,\n labels,\n icons,\n children,\n open,\n setOpen,\n addChatSuggestionConfiguration,\n removeChatSuggestionConfiguration,\n}: ChatContextProps) => {\n const context = {\n labels: {\n ...{\n initial: \"\",\n title: \"CopilotKit\",\n placeholder: \"Type a message...\",\n thinking: \"Thinking...\",\n error: \"❌ An error occurred. Please try again.\",\n stopGenerating: \"Stop generating\",\n regenerateResponse: \"Regenerate response\",\n },\n ...labels,\n },\n\n icons: {\n ...{\n openIcon: DefaultIcons.OpenIcon,\n closeIcon: DefaultIcons.CloseIcon,\n headerCloseIcon: DefaultIcons.HeaderCloseIcon,\n sendIcon: DefaultIcons.SendIcon,\n activityIcon: DefaultIcons.ActivityIcon,\n spinnerIcon: DefaultIcons.SpinnerIcon,\n stopIcon: DefaultIcons.StopIcon,\n regenerateIcon: DefaultIcons.RegenerateIcon,\n },\n icons,\n },\n open,\n setOpen,\n addChatSuggestionConfiguration,\n removeChatSuggestionConfiguration,\n };\n return <ChatContext.Provider value={context}>{children}</ChatContext.Provider>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,OAAO,WAAkC;AA2LhC;AAxEF,IAAM,cAAc,MAAM,cAAuC,MAAS;AAE1E,SAAS,iBAA8B;AAC5C,QAAM,UAAU,MAAM,WAAW,WAAW;AAC5C,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAkBO,IAAM,sBAAsB,CAAC;AAAA;AAAA;AAAA;AAAA,EAIlC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAwB;AACtB,QAAM,UAAU;AAAA,IACd,QAAQ,kCACH;AAAA,MACD,SAAS;AAAA,MACT,OAAO;AAAA,MACP,aAAa;AAAA,MACb,UAAU;AAAA,MACV,OAAO;AAAA,MACP,gBAAgB;AAAA,MAChB,oBAAoB;AAAA,IACtB,IACG;AAAA,IAGL,OAAO,iCACF;AAAA,MACD,UAAuB;AAAA,MACvB,WAAwB;AAAA,MACxB,iBAA8B;AAAA,MAC9B,UAAuB;AAAA,MACvB,cAA2B;AAAA,MAC3B,aAA0B;AAAA,MAC1B,UAAuB;AAAA,MACvB,gBAA6B;AAAA,IAC/B,IAVK;AAAA,MAWL;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,oBAAC,YAAY,UAAZ,EAAqB,OAAO,SAAU,UAAS;AACzD;","names":[]}
|
package/dist/chunk-PEDSZYHE.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__async
|
|
3
|
-
} from "./chunk-SKC7AJIV.mjs";
|
|
4
|
-
|
|
5
|
-
// src/components/chat/audio.ts
|
|
6
|
-
var checkMicrophonePermission = () => __async(void 0, null, function* () {
|
|
7
|
-
try {
|
|
8
|
-
const permissionStatus = yield navigator.permissions.query({
|
|
9
|
-
name: "microphone"
|
|
10
|
-
});
|
|
11
|
-
if (permissionStatus.state === "granted") {
|
|
12
|
-
return true;
|
|
13
|
-
} else {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
} catch (err) {
|
|
17
|
-
console.error("Error checking microphone permission", err);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
var requestMicAndPlaybackPermission = () => __async(void 0, null, function* () {
|
|
21
|
-
try {
|
|
22
|
-
const stream = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
23
|
-
const audioContext = new window.AudioContext();
|
|
24
|
-
yield audioContext.resume();
|
|
25
|
-
return { stream, audioContext };
|
|
26
|
-
} catch (err) {
|
|
27
|
-
console.error("Error requesting microphone and playback permissions", err);
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
checkMicrophonePermission,
|
|
34
|
-
requestMicAndPlaybackPermission
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=chunk-PEDSZYHE.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/audio.ts"],"sourcesContent":["export 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"],"mappings":";;;;;AAAO,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;","names":[]}
|
package/dist/chunk-UGQQ4WEQ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-UGQQ4WEQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["/**\n * A hook for providing suggestions to the user in the Copilot chat.\n *\n * <img src=\"/images/useCopilotChatSuggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * <img referrerPolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be\" />\n *\n * `useCopilotChatSuggestions` integrates auto-generated chat suggestions into your application in the context of your\n * app's state. It dynamically manages suggestions based on provided configurations and\n * dependencies.\n *\n * <RequestExample>\n * ```jsx useCopilotChatSuggestions Example\n * import { useCopilotChatSuggestions }\n * from \"@copilotkit/react-ui\";\n *\n * useCopilotChatSuggestions({\n * instructions: \"Your instructions for suggestions.\",\n * })\n * ```\n * </RequestExample>\n *\n * ## Basic Setup\n *\n * To incorporate this hook into your React components, start by importing it:\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n * ```\n *\n * Then, use it in your component to initiate suggestion functionality:\n *\n * ```tsx\n * useCopilotChatSuggestions({\n * instructions: \"Your instructions for suggestions.\",\n * });\n * ```\n *\n * ## Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\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 { useChatContext } from \"../components\";\nimport { nanoid } from \"nanoid\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/suggestions\";\n\nexport function useCopilotChatSuggestions(\n {\n instructions,\n className,\n minSuggestions = 1,\n maxSuggestions = 3,\n }: CopilotChatSuggestionConfiguration,\n dependencies: any[] = [],\n) {\n const chatContext = useChatContext();\n\n useEffect(() => {\n const id = nanoid();\n\n chatContext.addChatSuggestionConfiguration(id, {\n instructions,\n minSuggestions,\n maxSuggestions,\n className,\n });\n\n return () => {\n chatContext.removeChatSuggestionConfiguration(id);\n };\n }, dependencies);\n}\n"],"mappings":";;;;;AA4DA,SAAS,iBAAiB;AAE1B,SAAS,cAAc;AAGhB,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,iBAAiB;AACnB,GACA,eAAsB,CAAC,GACvB;AACA,QAAM,cAAc,eAAe;AAEnC,YAAU,MAAM;AACd,UAAM,KAAK,OAAO;AAElB,gBAAY,+BAA+B,IAAI;AAAA,MAC7C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,kBAAY,kCAAkC,EAAE;AAAA,IAClD;AAAA,EACF,GAAG,YAAY;AACjB;","names":[]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
declare const checkMicrophonePermission: () => Promise<boolean | undefined>;
|
|
2
|
-
declare const requestMicAndPlaybackPermission: () => Promise<{
|
|
3
|
-
stream: MediaStream;
|
|
4
|
-
audioContext: AudioContext;
|
|
5
|
-
} | null>;
|
|
6
|
-
|
|
7
|
-
export { checkMicrophonePermission, requestMicAndPlaybackPermission };
|
|
@@ -1,77 +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
|
-
var __async = (__this, __arguments, generator) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
var fulfilled = (value) => {
|
|
22
|
-
try {
|
|
23
|
-
step(generator.next(value));
|
|
24
|
-
} catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var rejected = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.throw(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/components/chat/audio.ts
|
|
41
|
-
var audio_exports = {};
|
|
42
|
-
__export(audio_exports, {
|
|
43
|
-
checkMicrophonePermission: () => checkMicrophonePermission,
|
|
44
|
-
requestMicAndPlaybackPermission: () => requestMicAndPlaybackPermission
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(audio_exports);
|
|
47
|
-
var checkMicrophonePermission = () => __async(void 0, null, function* () {
|
|
48
|
-
try {
|
|
49
|
-
const permissionStatus = yield navigator.permissions.query({
|
|
50
|
-
name: "microphone"
|
|
51
|
-
});
|
|
52
|
-
if (permissionStatus.state === "granted") {
|
|
53
|
-
return true;
|
|
54
|
-
} else {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
} catch (err) {
|
|
58
|
-
console.error("Error checking microphone permission", err);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
var requestMicAndPlaybackPermission = () => __async(void 0, null, function* () {
|
|
62
|
-
try {
|
|
63
|
-
const stream = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
64
|
-
const audioContext = new window.AudioContext();
|
|
65
|
-
yield audioContext.resume();
|
|
66
|
-
return { stream, audioContext };
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error("Error requesting microphone and playback permissions", err);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
checkMicrophonePermission,
|
|
75
|
-
requestMicAndPlaybackPermission
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=audio.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/chat/audio.ts"],"sourcesContent":["export 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,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;","names":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
checkMicrophonePermission,
|
|
3
|
-
requestMicAndPlaybackPermission
|
|
4
|
-
} from "../../chunk-PEDSZYHE.mjs";
|
|
5
|
-
import "../../chunk-SKC7AJIV.mjs";
|
|
6
|
-
export {
|
|
7
|
-
checkMicrophonePermission,
|
|
8
|
-
requestMicAndPlaybackPermission
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=audio.mjs.map
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export const checkMicrophonePermission = async () => {
|
|
2
|
-
try {
|
|
3
|
-
const permissionStatus = await navigator.permissions.query({
|
|
4
|
-
name: "microphone" as PermissionName,
|
|
5
|
-
});
|
|
6
|
-
if (permissionStatus.state === "granted") {
|
|
7
|
-
return true;
|
|
8
|
-
} else {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
} catch (err) {
|
|
12
|
-
console.error("Error checking microphone permission", err);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const requestMicAndPlaybackPermission = async () => {
|
|
17
|
-
try {
|
|
18
|
-
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
19
|
-
const audioContext = new window.AudioContext();
|
|
20
|
-
await audioContext.resume();
|
|
21
|
-
return { stream, audioContext };
|
|
22
|
-
} catch (err) {
|
|
23
|
-
console.error("Error requesting microphone and playback permissions", err);
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|