@copilotkit/react-ui 1.3.0 → 1.3.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/CHANGELOG.md +10 -0
- package/dist/chunk-54JAUBUJ.mjs +26 -0
- package/dist/chunk-54JAUBUJ.mjs.map +1 -0
- package/dist/chunk-5HHVL5WK.mjs +29 -0
- package/dist/chunk-5HHVL5WK.mjs.map +1 -0
- package/dist/chunk-B2KQEX2R.mjs +91 -0
- package/dist/chunk-B2KQEX2R.mjs.map +1 -0
- package/dist/chunk-BJPGMY3I.mjs +70 -0
- package/dist/chunk-BJPGMY3I.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +1 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-FL4ETWFB.mjs +21 -0
- package/dist/chunk-FL4ETWFB.mjs.map +1 -0
- package/dist/chunk-FLV3J3VX.mjs +18 -0
- package/dist/chunk-FLV3J3VX.mjs.map +1 -0
- package/dist/chunk-FO7Z5LAL.mjs +118 -0
- package/dist/chunk-FO7Z5LAL.mjs.map +1 -0
- package/dist/chunk-FOZVHL73.mjs +171 -0
- package/dist/chunk-FOZVHL73.mjs.map +1 -0
- package/dist/chunk-FZC7X5PK.mjs +262 -0
- package/dist/chunk-FZC7X5PK.mjs.map +1 -0
- package/dist/chunk-H7TM5JE6.mjs +146 -0
- package/dist/chunk-H7TM5JE6.mjs.map +1 -0
- package/dist/chunk-HR36Y2FQ.mjs +167 -0
- package/dist/chunk-HR36Y2FQ.mjs.map +1 -0
- package/dist/chunk-I4QG2ZZU.mjs +220 -0
- package/dist/chunk-I4QG2ZZU.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +1 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +1 -0
- package/dist/chunk-JD7BAH7U.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/chunk-MRFF7GSQ.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +59 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-OTPAZXVR.mjs +92 -0
- package/dist/chunk-OTPAZXVR.mjs.map +1 -0
- package/dist/chunk-QOEAEMUQ.mjs +30 -0
- package/dist/chunk-QOEAEMUQ.mjs.map +1 -0
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/chunk-T26KLXLH.mjs.map +1 -0
- package/dist/chunk-U6J5DGOE.mjs +83 -0
- package/dist/chunk-U6J5DGOE.mjs.map +1 -0
- package/dist/chunk-UPTB2MVO.mjs +395 -0
- package/dist/chunk-UPTB2MVO.mjs.map +1 -0
- package/dist/chunk-V7W6IM2V.mjs +1 -0
- package/dist/chunk-V7W6IM2V.mjs.map +1 -0
- package/dist/chunk-VOBX4JOA.mjs +138 -0
- package/dist/chunk-VOBX4JOA.mjs.map +1 -0
- package/dist/chunk-WB3YULQ4.mjs +1 -0
- package/dist/chunk-WB3YULQ4.mjs.map +1 -0
- package/dist/chunk-WCPLXRZX.mjs +106 -0
- package/dist/chunk-WCPLXRZX.mjs.map +1 -0
- package/dist/chunk-XSUSSWDS.mjs +18 -0
- package/dist/chunk-XSUSSWDS.mjs.map +1 -0
- package/dist/chunk-YOH25I6N.mjs +25 -0
- package/dist/chunk-YOH25I6N.mjs.map +1 -0
- package/dist/chunk-YQ3D5IQV.mjs +75 -0
- package/dist/chunk-YQ3D5IQV.mjs.map +1 -0
- package/dist/chunk-YQFVRDNC.mjs +53 -0
- package/dist/chunk-YQFVRDNC.mjs.map +1 -0
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +6 -30
- package/dist/components/chat/Button.mjs.map +1 -1
- package/dist/components/chat/Chat.d.ts +1 -1
- package/dist/components/chat/Chat.js +6 -3
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +20 -1851
- package/dist/components/chat/Chat.mjs.map +1 -1
- package/dist/components/chat/ChatContext.d.ts +1 -1
- package/dist/components/chat/ChatContext.mjs +7 -228
- package/dist/components/chat/ChatContext.mjs.map +1 -1
- package/dist/components/chat/CodeBlock.js +2 -1
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +8 -482
- package/dist/components/chat/CodeBlock.mjs.map +1 -1
- package/dist/components/chat/Header.mjs +6 -23
- package/dist/components/chat/Header.mjs.map +1 -1
- package/dist/components/chat/Icons.mjs +16 -271
- package/dist/components/chat/Icons.mjs.map +1 -1
- package/dist/components/chat/Input.js +4 -2
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +8 -255
- package/dist/components/chat/Input.mjs.map +1 -1
- package/dist/components/chat/Markdown.js +2 -1
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +7 -546
- package/dist/components/chat/Markdown.mjs.map +1 -1
- package/dist/components/chat/Messages.js +2 -1
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +8 -723
- package/dist/components/chat/Messages.mjs.map +1 -1
- package/dist/components/chat/Modal.d.ts +1 -1
- package/dist/components/chat/Modal.js +6 -3
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +22 -2052
- package/dist/components/chat/Modal.mjs.map +1 -1
- package/dist/components/chat/Popup.js +6 -3
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +23 -2061
- package/dist/components/chat/Popup.mjs.map +1 -1
- package/dist/components/chat/Response.mjs +6 -23
- package/dist/components/chat/Response.mjs.map +1 -1
- package/dist/components/chat/Sidebar.js +6 -3
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +23 -2072
- package/dist/components/chat/Sidebar.mjs.map +1 -1
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +5 -152
- package/dist/components/chat/Suggestion.mjs.map +1 -1
- package/dist/components/chat/Textarea.js.map +1 -1
- package/dist/components/chat/Textarea.mjs +4 -48
- package/dist/components/chat/Textarea.mjs.map +1 -1
- package/dist/components/chat/Window.js.map +1 -1
- package/dist/components/chat/Window.mjs +6 -125
- package/dist/components/chat/Window.mjs.map +1 -1
- package/dist/components/chat/index.js +6 -3
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +31 -2078
- package/dist/components/chat/index.mjs.map +1 -1
- package/dist/components/chat/props.d.ts +1 -1
- package/dist/components/chat/props.mjs +1 -0
- package/dist/components/dev-console/console.js.map +1 -1
- package/dist/components/dev-console/console.mjs +8 -478
- package/dist/components/dev-console/console.mjs.map +1 -1
- package/dist/components/dev-console/icons.mjs +8 -83
- package/dist/components/dev-console/icons.mjs.map +1 -1
- package/dist/components/dev-console/index.js.map +1 -1
- package/dist/components/dev-console/index.mjs +10 -476
- package/dist/components/dev-console/index.mjs.map +1 -1
- package/dist/components/dev-console/types.d.ts +1 -1
- package/dist/components/dev-console/utils.js.map +1 -1
- package/dist/components/dev-console/utils.mjs +8 -154
- package/dist/components/dev-console/utils.mjs.map +1 -1
- package/dist/components/index.js +6 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +32 -2078
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.mjs +1 -0
- package/dist/hooks/index.mjs +5 -24
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +4 -24
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +1 -1
- package/dist/hooks/use-copy-to-clipboard.mjs +4 -21
- package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -1
- package/dist/hooks/use-push-to-talk.d.ts +1 -1
- package/dist/hooks/use-push-to-talk.js.map +1 -1
- package/dist/hooks/use-push-to-talk.mjs +6 -148
- package/dist/hooks/use-push-to-talk.mjs.map +1 -1
- package/dist/index.css +747 -1
- package/dist/index.css.map +1 -0
- package/dist/index.js +6 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -2110
- package/dist/index.mjs.map +1 -1
- package/dist/lib/utils.mjs +3 -20
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/lib/utils.test.d.ts +1 -1
- package/dist/types/css.d.ts +1 -1
- package/dist/types/index.mjs +1 -0
- package/dist/types/suggestions.d.ts +1 -1
- package/package.json +11 -19
- package/src/components/chat/Chat.tsx +4 -1
- package/src/components/chat/Popup.tsx +4 -1
- package/src/components/chat/Sidebar.tsx +3 -1
- package/tsup.config.ts +15 -59
- package/dist/components/chat/Button.d.mts +0 -7
- package/dist/components/chat/Chat.d.mts +0 -87
- package/dist/components/chat/ChatContext.d.mts +0 -105
- package/dist/components/chat/CodeBlock.d.mts +0 -14
- package/dist/components/chat/Header.d.mts +0 -7
- package/dist/components/chat/Icons.d.mts +0 -18
- package/dist/components/chat/Input.d.mts +0 -7
- package/dist/components/chat/Markdown.d.mts +0 -8
- package/dist/components/chat/Messages.d.mts +0 -7
- package/dist/components/chat/Modal.d.mts +0 -51
- package/dist/components/chat/Popup.d.mts +0 -13
- package/dist/components/chat/Response.d.mts +0 -7
- package/dist/components/chat/Sidebar.d.mts +0 -13
- package/dist/components/chat/Suggestion.d.mts +0 -14
- package/dist/components/chat/Textarea.d.mts +0 -13
- package/dist/components/chat/Window.d.mts +0 -7
- package/dist/components/chat/index.d.mts +0 -11
- package/dist/components/chat/props.d.mts +0 -35
- package/dist/components/dev-console/console.d.mts +0 -10
- package/dist/components/dev-console/icons.d.mts +0 -9
- package/dist/components/dev-console/index.d.mts +0 -5
- package/dist/components/dev-console/types.d.mts +0 -9
- package/dist/components/dev-console/utils.d.mts +0 -10
- package/dist/components/index.d.mts +0 -11
- package/dist/context/index.d.mts +0 -2
- package/dist/hooks/index.d.mts +0 -1
- package/dist/hooks/use-copilot-chat-suggestions.d.mts +0 -83
- package/dist/hooks/use-copy-to-clipboard.d.mts +0 -9
- package/dist/hooks/use-push-to-talk.d.mts +0 -19
- package/dist/index.d.mts +0 -13
- package/dist/lib/utils.d.mts +0 -4
- package/dist/lib/utils.test.d.mts +0 -2
- package/dist/types/css.d.mts +0 -16
- package/dist/types/index.d.mts +0 -2
- package/dist/types/suggestions.d.mts +0 -8
|
@@ -1,151 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/hooks/use-push-to-talk.tsx
|
|
23
|
-
import { useCopilotContext } from "@copilotkit/react-core";
|
|
24
|
-
import { TextMessage } from "@copilotkit/runtime-client-gql";
|
|
25
|
-
import { useEffect, useRef, useState } from "react";
|
|
26
|
-
var checkMicrophonePermission = () => __async(void 0, null, function* () {
|
|
27
|
-
try {
|
|
28
|
-
const permissionStatus = yield navigator.permissions.query({
|
|
29
|
-
name: "microphone"
|
|
30
|
-
});
|
|
31
|
-
if (permissionStatus.state === "granted") {
|
|
32
|
-
return true;
|
|
33
|
-
} else {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error("Error checking microphone permission", err);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
var requestMicAndPlaybackPermission = () => __async(void 0, null, function* () {
|
|
41
|
-
try {
|
|
42
|
-
const stream = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
43
|
-
const audioContext = new window.AudioContext();
|
|
44
|
-
yield audioContext.resume();
|
|
45
|
-
return { stream, audioContext };
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.error("Error requesting microphone and playback permissions", err);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
52
|
-
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
53
|
-
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
54
|
-
audioContextRef.current = new window.AudioContext();
|
|
55
|
-
yield audioContextRef.current.resume();
|
|
56
|
-
}
|
|
57
|
-
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
58
|
-
mediaRecorderRef.current.start(1e3);
|
|
59
|
-
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
60
|
-
recordedChunks.push(event.data);
|
|
61
|
-
};
|
|
62
|
-
mediaRecorderRef.current.onstop = onStop;
|
|
63
|
-
});
|
|
64
|
-
var stopRecording = (mediaRecorderRef) => {
|
|
65
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
66
|
-
mediaRecorderRef.current.stop();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
|
|
70
|
-
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
71
|
-
const formData = new FormData();
|
|
72
|
-
formData.append("file", completeBlob, "recording.mp4");
|
|
73
|
-
const response = yield fetch(transcribeAudioUrl, {
|
|
74
|
-
method: "POST",
|
|
75
|
-
body: formData
|
|
76
|
-
});
|
|
77
|
-
if (!response.ok) {
|
|
78
|
-
throw new Error(`Error: ${response.statusText}`);
|
|
79
|
-
}
|
|
80
|
-
const transcription = yield response.json();
|
|
81
|
-
return transcription.text;
|
|
82
|
-
});
|
|
83
|
-
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
84
|
-
const encodedText = encodeURIComponent(text);
|
|
85
|
-
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
86
|
-
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
87
|
-
const source = audioContext.createBufferSource();
|
|
88
|
-
source.buffer = audioBuffer;
|
|
89
|
-
source.connect(audioContext.destination);
|
|
90
|
-
source.start(0);
|
|
91
|
-
}).catch((error) => {
|
|
92
|
-
console.error("Error with decoding audio data", error);
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
var usePushToTalk = ({
|
|
96
|
-
sendFunction,
|
|
97
|
-
inProgress
|
|
98
|
-
}) => {
|
|
99
|
-
const [pushToTalkState, setPushToTalkState] = useState("idle");
|
|
100
|
-
const mediaStreamRef = useRef(null);
|
|
101
|
-
const audioContextRef = useRef(null);
|
|
102
|
-
const mediaRecorderRef = useRef(null);
|
|
103
|
-
const recordedChunks = useRef([]);
|
|
104
|
-
const context = useCopilotContext();
|
|
105
|
-
const [startReadingFromMessageId, setStartReadingFromMessageId] = useState(null);
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
if (pushToTalkState === "recording") {
|
|
108
|
-
startRecording(
|
|
109
|
-
mediaStreamRef,
|
|
110
|
-
mediaRecorderRef,
|
|
111
|
-
audioContextRef,
|
|
112
|
-
recordedChunks.current,
|
|
113
|
-
() => {
|
|
114
|
-
setPushToTalkState("transcribing");
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
} else {
|
|
118
|
-
stopRecording(mediaRecorderRef);
|
|
119
|
-
if (pushToTalkState === "transcribing") {
|
|
120
|
-
transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
|
|
121
|
-
(transcription) => __async(void 0, null, function* () {
|
|
122
|
-
recordedChunks.current = [];
|
|
123
|
-
setPushToTalkState("idle");
|
|
124
|
-
const message = yield sendFunction(transcription);
|
|
125
|
-
setStartReadingFromMessageId(message.id);
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return () => {
|
|
131
|
-
stopRecording(mediaRecorderRef);
|
|
132
|
-
};
|
|
133
|
-
}, [pushToTalkState]);
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
if (inProgress === false && startReadingFromMessageId) {
|
|
136
|
-
const lastMessageIndex = context.messages.findIndex(
|
|
137
|
-
(message) => message.id === startReadingFromMessageId
|
|
138
|
-
);
|
|
139
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
140
|
-
(message) => message instanceof TextMessage && message.role === "assistant"
|
|
141
|
-
);
|
|
142
|
-
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
143
|
-
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
144
|
-
setStartReadingFromMessageId(null);
|
|
145
|
-
}
|
|
146
|
-
}, [startReadingFromMessageId, inProgress]);
|
|
147
|
-
return { pushToTalkState, setPushToTalkState };
|
|
148
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
checkMicrophonePermission,
|
|
3
|
+
requestMicAndPlaybackPermission,
|
|
4
|
+
usePushToTalk
|
|
5
|
+
} from "../chunk-VOBX4JOA.mjs";
|
|
6
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
149
7
|
export {
|
|
150
8
|
checkMicrophonePermission,
|
|
151
9
|
requestMicAndPlaybackPermission,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|