@copilotkit/react-ui 1.51.4-next.7 → 1.51.4-next.8
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 +9 -0
- package/README.md +18 -12
- package/dist/{chunk-O72ZB5V3.mjs → chunk-2QEDCM6H.mjs} +22 -12
- package/dist/chunk-2QEDCM6H.mjs.map +1 -0
- package/dist/{chunk-54JAUBUJ.mjs → chunk-6SMTHXVA.mjs} +4 -2
- package/dist/chunk-6SMTHXVA.mjs.map +1 -0
- package/dist/{chunk-IEMQ2SQW.mjs → chunk-6TLDRWAD.mjs} +5 -3
- package/dist/{chunk-IEMQ2SQW.mjs.map → chunk-6TLDRWAD.mjs.map} +1 -1
- package/dist/{chunk-UFN2VWSR.mjs → chunk-72FQQMQ2.mjs} +2 -2
- package/dist/chunk-72FQQMQ2.mjs.map +1 -0
- package/dist/{chunk-ELGRNEAO.mjs → chunk-AOUHT4JR.mjs} +4 -2
- package/dist/chunk-AOUHT4JR.mjs.map +1 -0
- package/dist/{chunk-C3GSYRC3.mjs → chunk-BNJX66OH.mjs} +2 -2
- package/dist/{chunk-NRA3CFEE.mjs → chunk-C27LZFA5.mjs} +2 -2
- package/dist/{chunk-FFJHOZX6.mjs → chunk-C7WM7GM3.mjs} +44 -11
- package/dist/chunk-C7WM7GM3.mjs.map +1 -0
- package/dist/{chunk-6TWQUA2Q.mjs → chunk-CNIC5HO5.mjs} +8 -3
- package/dist/chunk-CNIC5HO5.mjs.map +1 -0
- package/dist/chunk-CQCXH5LY.mjs +143 -0
- package/dist/chunk-CQCXH5LY.mjs.map +1 -0
- package/dist/{chunk-RYUCX3ZK.mjs → chunk-DM2V5WTG.mjs} +4 -2
- package/dist/chunk-DM2V5WTG.mjs.map +1 -0
- package/dist/{chunk-JZ3RFQQ6.mjs → chunk-DSHTRV2R.mjs} +16 -4
- package/dist/chunk-DSHTRV2R.mjs.map +1 -0
- package/dist/{chunk-GDSZGYCE.mjs → chunk-EACIYBQH.mjs} +3 -3
- package/dist/{chunk-XWG3L6QC.mjs → chunk-GBAPANZE.mjs} +76 -11
- package/dist/chunk-GBAPANZE.mjs.map +1 -0
- package/dist/{chunk-Q5V6S67N.mjs → chunk-GFE5ZSPV.mjs} +15 -6
- package/dist/chunk-GFE5ZSPV.mjs.map +1 -0
- package/dist/{chunk-VHKHX7GV.mjs → chunk-HHLX4MQN.mjs} +2 -2
- package/dist/{chunk-WNX755OE.mjs → chunk-ICA2EXIX.mjs} +7 -4
- package/dist/chunk-ICA2EXIX.mjs.map +1 -0
- package/dist/{chunk-QIOJXTIQ.mjs → chunk-IWOCQACI.mjs} +12 -3
- package/dist/chunk-IWOCQACI.mjs.map +1 -0
- package/dist/{chunk-BH6PCAAL.mjs → chunk-JYHRHKV5.mjs} +12 -3
- package/dist/chunk-JYHRHKV5.mjs.map +1 -0
- package/dist/{chunk-IK2BPURM.mjs → chunk-LIXN3OVQ.mjs} +12 -7
- package/dist/chunk-LIXN3OVQ.mjs.map +1 -0
- package/dist/{chunk-PD36EMOZ.mjs → chunk-MC6PY7XH.mjs} +75 -54
- package/dist/chunk-MC6PY7XH.mjs.map +1 -0
- package/dist/{chunk-LYYDXL2G.mjs → chunk-OQWEOBRX.mjs} +3 -3
- package/dist/chunk-OQWEOBRX.mjs.map +1 -0
- package/dist/{chunk-LBR23XXF.mjs → chunk-P34CL4LC.mjs} +4 -4
- package/dist/{chunk-F2CDEOFX.mjs → chunk-PF3QBO7V.mjs} +2 -2
- package/dist/chunk-PF3QBO7V.mjs.map +1 -0
- package/dist/{chunk-7CMZ7YPQ.mjs → chunk-PP2A5RP6.mjs} +2 -2
- package/dist/{chunk-7CMZ7YPQ.mjs.map → chunk-PP2A5RP6.mjs.map} +1 -1
- package/dist/{chunk-RKQM2AE5.mjs → chunk-Q64GLWPQ.mjs} +2 -2
- package/dist/{chunk-RKQM2AE5.mjs.map → chunk-Q64GLWPQ.mjs.map} +1 -1
- package/dist/{chunk-OHGUQZJT.mjs → chunk-T4NNQG6T.mjs} +50 -41
- package/dist/chunk-T4NNQG6T.mjs.map +1 -0
- package/dist/{chunk-DBKRAOH7.mjs → chunk-TGM5PKBF.mjs} +16 -6
- package/dist/chunk-TGM5PKBF.mjs.map +1 -0
- package/dist/{chunk-JY2CSDKN.mjs → chunk-YDJ4YUUF.mjs} +22 -16
- package/dist/chunk-YDJ4YUUF.mjs.map +1 -0
- package/dist/components/chat/Button.js +3 -1
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +3 -3
- package/dist/components/chat/Chat.js +285 -132
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +18 -18
- package/dist/components/chat/ChatContext.js +63 -9
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +2 -2
- package/dist/components/chat/CodeBlock.js +20 -6
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +3 -3
- package/dist/components/chat/Header.js +88 -28
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +8 -8
- package/dist/components/chat/Icons.js +75 -10
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +1 -1
- package/dist/components/chat/Input.js +90 -62
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +6 -6
- package/dist/components/chat/Markdown.js +34 -8
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +4 -4
- package/dist/components/chat/Messages.js +59 -16
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +11 -11
- package/dist/components/chat/Modal.js +403 -189
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +27 -27
- package/dist/components/chat/Popup.js +403 -189
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +28 -28
- package/dist/components/chat/PoweredByTag.d.ts +1 -1
- package/dist/components/chat/PoweredByTag.js +3 -1
- package/dist/components/chat/PoweredByTag.js.map +1 -1
- package/dist/components/chat/PoweredByTag.mjs +1 -1
- package/dist/components/chat/Sidebar.js +403 -189
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +28 -28
- package/dist/components/chat/Suggestion.d.ts +1 -1
- package/dist/components/chat/Suggestion.js +13 -2
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +2 -2
- package/dist/components/chat/Suggestions.js +13 -2
- package/dist/components/chat/Suggestions.js.map +1 -1
- package/dist/components/chat/Suggestions.mjs +3 -3
- package/dist/components/chat/Textarea.js +4 -1
- package/dist/components/chat/Textarea.js.map +1 -1
- package/dist/components/chat/Textarea.mjs +1 -1
- package/dist/components/chat/Window.js +3 -1
- package/dist/components/chat/Window.js.map +1 -1
- package/dist/components/chat/Window.mjs +3 -3
- package/dist/components/chat/index.js +403 -189
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +29 -29
- package/dist/components/chat/messages/AssistantMessage.js +37 -9
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +6 -6
- package/dist/components/chat/messages/ErrorMessage.js +65 -31
- package/dist/components/chat/messages/ErrorMessage.js.map +1 -1
- package/dist/components/chat/messages/ErrorMessage.mjs +33 -27
- package/dist/components/chat/messages/ErrorMessage.mjs.map +1 -1
- package/dist/components/chat/messages/ImageRenderer.js +15 -5
- package/dist/components/chat/messages/ImageRenderer.js.map +1 -1
- package/dist/components/chat/messages/ImageRenderer.mjs +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.js +55 -15
- package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.mjs +10 -10
- package/dist/components/chat/messages/RenderMessage.js +55 -15
- package/dist/components/chat/messages/RenderMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderMessage.mjs +9 -9
- package/dist/components/chat/messages/UserMessage.js +3 -1
- package/dist/components/chat/messages/UserMessage.js.map +1 -1
- package/dist/components/chat/messages/UserMessage.mjs +1 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/dev-console/console.js +85 -27
- package/dist/components/dev-console/console.js.map +1 -1
- package/dist/components/dev-console/console.mjs +6 -6
- package/dist/components/dev-console/icons.js +14 -5
- package/dist/components/dev-console/icons.js.map +1 -1
- package/dist/components/dev-console/icons.mjs +1 -1
- package/dist/components/dev-console/index.js +85 -27
- package/dist/components/dev-console/index.js.map +1 -1
- package/dist/components/dev-console/index.mjs +6 -6
- package/dist/components/dev-console/utils.js +21 -15
- package/dist/components/dev-console/utils.js.map +1 -1
- package/dist/components/dev-console/utils.mjs +1 -1
- package/dist/components/help-modal/icons.d.ts +1 -1
- package/dist/components/help-modal/icons.js +11 -2
- package/dist/components/help-modal/icons.js.map +1 -1
- package/dist/components/help-modal/icons.mjs +1 -1
- package/dist/components/help-modal/index.js +8 -1
- package/dist/components/help-modal/index.js.map +1 -1
- package/dist/components/help-modal/index.mjs +2 -2
- package/dist/components/help-modal/modal.js +8 -1
- package/dist/components/help-modal/modal.js.map +1 -1
- package/dist/components/help-modal/modal.mjs +2 -2
- package/dist/components/index.js +403 -189
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +29 -29
- package/dist/hooks/use-copy-to-clipboard.d.ts +1 -1
- package/dist/hooks/use-copy-to-clipboard.js +3 -1
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.mjs +1 -1
- package/dist/hooks/use-push-to-talk.js +17 -10
- package/dist/hooks/use-push-to-talk.js.map +1 -1
- package/dist/hooks/use-push-to-talk.mjs +1 -1
- package/dist/index.js +403 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -34
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/utils.mjs.map +1 -1
- package/package.json +4 -5
- package/src/components/chat/Button.tsx +6 -2
- package/src/components/chat/Chat.tsx +75 -48
- package/src/components/chat/ChatContext.tsx +6 -2
- package/src/components/chat/CodeBlock.tsx +11 -6
- package/src/components/chat/Icons.tsx +45 -10
- package/src/components/chat/Input.tsx +30 -7
- package/src/components/chat/Markdown.tsx +12 -3
- package/src/components/chat/Messages.tsx +24 -8
- package/src/components/chat/Modal.tsx +12 -2
- package/src/components/chat/Popup.tsx +3 -1
- package/src/components/chat/PoweredByTag.tsx +5 -1
- package/src/components/chat/Sidebar.tsx +3 -1
- package/src/components/chat/Suggestion.tsx +6 -1
- package/src/components/chat/Textarea.tsx +15 -3
- package/src/components/chat/messages/AssistantMessage.tsx +12 -4
- package/src/components/chat/messages/ErrorMessage.tsx +3 -1
- package/src/components/chat/messages/ImageRenderer.tsx +17 -5
- package/src/components/chat/messages/LegacyRenderMessage.tsx +4 -1
- package/src/components/chat/messages/UserMessage.tsx +12 -4
- package/src/components/chat/props.ts +13 -3
- package/src/components/dev-console/console.tsx +35 -9
- package/src/components/dev-console/icons.tsx +6 -1
- package/src/components/dev-console/utils.ts +23 -15
- package/src/components/help-modal/icons.tsx +10 -2
- package/src/hooks/use-copy-to-clipboard.tsx +3 -1
- package/src/hooks/use-push-to-talk.tsx +45 -18
- package/src/lib/utils.ts +4 -1
- package/tsconfig.json +1 -1
- package/tsup.config.ts +5 -1
- package/dist/chunk-3W6J75HS.mjs +0 -126
- package/dist/chunk-3W6J75HS.mjs.map +0 -1
- package/dist/chunk-54JAUBUJ.mjs.map +0 -1
- package/dist/chunk-6TWQUA2Q.mjs.map +0 -1
- package/dist/chunk-BH6PCAAL.mjs.map +0 -1
- package/dist/chunk-DBKRAOH7.mjs.map +0 -1
- package/dist/chunk-ELGRNEAO.mjs.map +0 -1
- package/dist/chunk-F2CDEOFX.mjs.map +0 -1
- package/dist/chunk-FFJHOZX6.mjs.map +0 -1
- package/dist/chunk-IK2BPURM.mjs.map +0 -1
- package/dist/chunk-JY2CSDKN.mjs.map +0 -1
- package/dist/chunk-JZ3RFQQ6.mjs.map +0 -1
- package/dist/chunk-LYYDXL2G.mjs.map +0 -1
- package/dist/chunk-O72ZB5V3.mjs.map +0 -1
- package/dist/chunk-OHGUQZJT.mjs.map +0 -1
- package/dist/chunk-PD36EMOZ.mjs.map +0 -1
- package/dist/chunk-Q5V6S67N.mjs.map +0 -1
- package/dist/chunk-QIOJXTIQ.mjs.map +0 -1
- package/dist/chunk-RYUCX3ZK.mjs.map +0 -1
- package/dist/chunk-UFN2VWSR.mjs.map +0 -1
- package/dist/chunk-WNX755OE.mjs.map +0 -1
- package/dist/chunk-XWG3L6QC.mjs.map +0 -1
- /package/dist/{chunk-C3GSYRC3.mjs.map → chunk-BNJX66OH.mjs.map} +0 -0
- /package/dist/{chunk-NRA3CFEE.mjs.map → chunk-C27LZFA5.mjs.map} +0 -0
- /package/dist/{chunk-GDSZGYCE.mjs.map → chunk-EACIYBQH.mjs.map} +0 -0
- /package/dist/{chunk-VHKHX7GV.mjs.map → chunk-HHLX4MQN.mjs.map} +0 -0
- /package/dist/{chunk-LBR23XXF.mjs.map → chunk-P34CL4LC.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 1.51.4-next.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9bc868d]
|
|
8
|
+
- @copilotkit/react-core@1.51.4-next.8
|
|
9
|
+
- @copilotkit/runtime-client-gql@1.51.4-next.8
|
|
10
|
+
- @copilotkit/shared@1.51.4-next.8
|
|
11
|
+
|
|
3
12
|
## 1.51.4-next.7
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
const { visibleMessages, appendMessage, setMessages, ... } = useCopilotChat();
|
|
49
49
|
|
|
50
50
|
// Pre-built components with deep customization options (CSS + pass custom sub-components)
|
|
51
|
-
<CopilotPopup
|
|
52
|
-
instructions={"You are assisting the user as best as you can. Answer in the best way possible given the data you have."}
|
|
53
|
-
labels={{ title: "Popup Assistant", initial: "Need any help?" }}
|
|
51
|
+
<CopilotPopup
|
|
52
|
+
instructions={"You are assisting the user as best as you can. Answer in the best way possible given the data you have."}
|
|
53
|
+
labels={{ title: "Popup Assistant", initial: "Need any help?" }}
|
|
54
54
|
/>
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -71,9 +71,9 @@ useCopilotAction({
|
|
|
71
71
|
|
|
72
72
|
```ts
|
|
73
73
|
// Share state between app and agent
|
|
74
|
-
const { agentState } = useCoAgent({
|
|
75
|
-
name: "basic_agent",
|
|
76
|
-
initialState: { input: "NYC" }
|
|
74
|
+
const { agentState } = useCoAgent({
|
|
75
|
+
name: "basic_agent",
|
|
76
|
+
initialState: { input: "NYC" }
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
// agentic generative UI
|
|
@@ -114,14 +114,20 @@ useCopilotAction({
|
|
|
114
114
|
```ts
|
|
115
115
|
// intermediate agent state streaming (supports both LangGraph.js + LangGraph python)
|
|
116
116
|
const modifiedConfig = copilotKitCustomizeConfig(config, {
|
|
117
|
-
emitIntermediateState: [
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
emitIntermediateState: [
|
|
118
|
+
{
|
|
119
|
+
stateKey: "outline",
|
|
120
|
+
tool: "set_outline",
|
|
121
|
+
toolArgument: "outline",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
122
124
|
});
|
|
123
|
-
const response = await ChatOpenAI({ model: "gpt-4o" }).invoke(
|
|
125
|
+
const response = await ChatOpenAI({ model: "gpt-4o" }).invoke(
|
|
126
|
+
messages,
|
|
127
|
+
modifiedConfig,
|
|
128
|
+
);
|
|
124
129
|
```
|
|
130
|
+
|
|
125
131
|
## 🏆 Featured Examples
|
|
126
132
|
|
|
127
133
|
<p align="center">
|
|
@@ -4,7 +4,10 @@ import {
|
|
|
4
4
|
} from "./chunk-MRXNTQOX.mjs";
|
|
5
5
|
|
|
6
6
|
// src/hooks/use-push-to-talk.tsx
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
useCopilotContext,
|
|
9
|
+
useCopilotMessagesContext
|
|
10
|
+
} from "@copilotkit/react-core";
|
|
8
11
|
import { gqlToAGUI } from "@copilotkit/runtime-client-gql";
|
|
9
12
|
import { useEffect, useRef, useState } from "react";
|
|
10
13
|
var checkMicrophonePermission = () => __async(void 0, null, function* () {
|
|
@@ -34,7 +37,9 @@ var requestMicAndPlaybackPermission = () => __async(void 0, null, function* () {
|
|
|
34
37
|
});
|
|
35
38
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
36
39
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
37
|
-
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({
|
|
40
|
+
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({
|
|
41
|
+
audio: true
|
|
42
|
+
});
|
|
38
43
|
audioContextRef.current = new window.AudioContext();
|
|
39
44
|
yield audioContextRef.current.resume();
|
|
40
45
|
}
|
|
@@ -103,14 +108,15 @@ var usePushToTalk = ({
|
|
|
103
108
|
} else {
|
|
104
109
|
stopRecording(mediaRecorderRef);
|
|
105
110
|
if (pushToTalkState === "transcribing") {
|
|
106
|
-
transcribeAudio(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
transcribeAudio(
|
|
112
|
+
recordedChunks.current,
|
|
113
|
+
context.copilotApiConfig.transcribeAudioUrl
|
|
114
|
+
).then((transcription) => __async(void 0, null, function* () {
|
|
115
|
+
recordedChunks.current = [];
|
|
116
|
+
setPushToTalkState("idle");
|
|
117
|
+
const message = yield sendFunction(transcription);
|
|
118
|
+
setStartReadingFromMessageId(message.id);
|
|
119
|
+
}));
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
return () => {
|
|
@@ -125,7 +131,11 @@ var usePushToTalk = ({
|
|
|
125
131
|
const aguiMessages = gqlToAGUI(context.messages);
|
|
126
132
|
const messagesAfterLast = aguiMessages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant");
|
|
127
133
|
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
128
|
-
playAudioResponse(
|
|
134
|
+
playAudioResponse(
|
|
135
|
+
text,
|
|
136
|
+
context.copilotApiConfig.textToSpeechUrl,
|
|
137
|
+
audioContextRef.current
|
|
138
|
+
);
|
|
129
139
|
setStartReadingFromMessageId(null);
|
|
130
140
|
}
|
|
131
141
|
}, [startReadingFromMessageId, inProgress]);
|
|
@@ -137,4 +147,4 @@ export {
|
|
|
137
147
|
requestMicAndPlaybackPermission,
|
|
138
148
|
usePushToTalk
|
|
139
149
|
};
|
|
140
|
-
//# sourceMappingURL=chunk-
|
|
150
|
+
//# sourceMappingURL=chunk-2QEDCM6H.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-push-to-talk.tsx"],"sourcesContent":["import {\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"@copilotkit/react-core\";\nimport { gqlToAGUI } from \"@copilotkit/runtime-client-gql\";\nimport { Message } from \"@copilotkit/shared\";\nimport { MutableRefObject, useEffect, useRef, useState } from \"react\";\n\nexport const checkMicrophonePermission = async () => {\n try {\n const permissionStatus = await navigator.permissions.query({\n name: \"microphone\" as PermissionName,\n });\n if (permissionStatus.state === \"granted\") {\n return true;\n } else {\n return false;\n }\n } catch (err) {\n console.error(\"Error checking microphone permission\", err);\n }\n};\n\nexport const requestMicAndPlaybackPermission = async () => {\n try {\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n const audioContext = new window.AudioContext();\n await audioContext.resume();\n return { stream, audioContext };\n } catch (err) {\n console.error(\"Error requesting microphone and playback permissions\", err);\n return null;\n }\n};\n\nconst startRecording = async (\n mediaStreamRef: MutableRefObject<MediaStream | null>,\n mediaRecorderRef: MutableRefObject<MediaRecorder | null>,\n audioContextRef: MutableRefObject<AudioContext | null>,\n recordedChunks: Blob[],\n onStop: () => void,\n) => {\n if (!mediaStreamRef.current || !audioContextRef.current) {\n mediaStreamRef.current = await navigator.mediaDevices.getUserMedia({\n audio: true,\n });\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 = (\n mediaRecorderRef: MutableRefObject<MediaRecorder | null>,\n) => {\n if (\n mediaRecorderRef.current &&\n mediaRecorderRef.current.state !== \"inactive\"\n ) {\n mediaRecorderRef.current.stop();\n }\n};\n\nconst transcribeAudio = async (\n recordedChunks: Blob[],\n transcribeAudioUrl: string,\n) => {\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 = (\n text: string,\n textToSpeechUrl: string,\n audioContext: AudioContext,\n) => {\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] =\n 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<\n string | null\n >(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(\n recordedChunks.current,\n context.copilotApiConfig.transcribeAudioUrl!,\n ).then(async (transcription) => {\n recordedChunks.current = [];\n setPushToTalkState(\"idle\");\n const message = await sendFunction(transcription);\n setStartReadingFromMessageId(message.id);\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 aguiMessages = gqlToAGUI(context.messages);\n\n const messagesAfterLast = aguiMessages\n .slice(lastMessageIndex + 1)\n .filter((message) => message.role === \"assistant\");\n\n const text = messagesAfterLast\n .map((message) => message.content)\n .join(\"\\n\");\n playAudioResponse(\n text,\n context.copilotApiConfig.textToSpeechUrl!,\n audioContextRef.current!,\n );\n\n setStartReadingFromMessageId(null);\n }\n }, [startReadingFromMessageId, inProgress]);\n\n return { pushToTalkState, setPushToTalkState };\n};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import * as React from "react";
|
|
3
|
-
function useCopyToClipboard({
|
|
3
|
+
function useCopyToClipboard({
|
|
4
|
+
timeout = 2e3
|
|
5
|
+
}) {
|
|
4
6
|
const [isCopied, setIsCopied] = React.useState(false);
|
|
5
7
|
const copyToClipboard = (value) => {
|
|
6
8
|
var _a;
|
|
@@ -23,4 +25,4 @@ function useCopyToClipboard({ timeout = 2e3 }) {
|
|
|
23
25
|
export {
|
|
24
26
|
useCopyToClipboard
|
|
25
27
|
};
|
|
26
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-6SMTHXVA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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({\n timeout = 2000,\n}: 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,YAAY,WAAW;AAMhB,SAAS,mBAAmB;AAAA,EACjC,UAAU;AACZ,GAA4B;AAC1B,QAAM,CAAC,UAAU,WAAW,IAAU,eAAkB,KAAK;AAE7D,QAAM,kBAAkB,CAAC,UAAkB;AAX7C;AAYI,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":[]}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
ThumbsDownIcon,
|
|
13
13
|
ThumbsUpIcon,
|
|
14
14
|
UploadIcon
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-GBAPANZE.mjs";
|
|
16
16
|
import {
|
|
17
17
|
__spreadValues
|
|
18
18
|
} from "./chunk-MRXNTQOX.mjs";
|
|
@@ -20,7 +20,9 @@ import {
|
|
|
20
20
|
// src/components/chat/ChatContext.tsx
|
|
21
21
|
import React, { useMemo } from "react";
|
|
22
22
|
import { jsx } from "react/jsx-runtime";
|
|
23
|
-
var ChatContext = React.createContext(
|
|
23
|
+
var ChatContext = React.createContext(
|
|
24
|
+
void 0
|
|
25
|
+
);
|
|
24
26
|
function useChatContext() {
|
|
25
27
|
const context = React.useContext(ChatContext);
|
|
26
28
|
if (context === void 0) {
|
|
@@ -90,4 +92,4 @@ export {
|
|
|
90
92
|
useChatContext,
|
|
91
93
|
ChatContextProvider
|
|
92
94
|
};
|
|
93
|
-
//# sourceMappingURL=chunk-
|
|
95
|
+
//# sourceMappingURL=chunk-6TLDRWAD.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/ChatContext.tsx"],"sourcesContent":["import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons from \"./Icons\";\nimport { ThumbsDownIcon, ThumbsUpIcon } from \"./Icons\";\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 * The icons to use for push to talk.\n * @default <PushToTalkIcon />\n */\n\n pushToTalkIcon?: React.ReactNode;\n\n /**\n * The icons to use for copy assistant response\n * @default <CopyIcon />\n */\n\n copyIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs up/response approval.\n * @default <ThumbsUpIcon />\n */\n\n thumbsUpIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs down/response rejection.\n * @default <ThumbsDownIcon />\n */\n\n thumbsDownIcon?: React.ReactNode;\n\n /**\n * The icon to use for the upload button.\n * @default <UploadIcon />\n */\n uploadIcon?: 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 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 /**\n * The label for the copy button.\n * @default \"Copy to clipboard\"\n */\n copyToClipboard?: string;\n\n /**\n * The label for the thumbs up button.\n * @default \"Thumbs up\"\n */\n thumbsUp?: string;\n\n /**\n * The label for the thumbs down button.\n * @default \"Thumbs down\"\n */\n thumbsDown?: string;\n\n /**\n * The text to display when content is copied.\n * @default \"Copied!\"\n */\n copied?: string;\n}\n\ninterface ChatContext {\n labels: Required<CopilotChatLabels>;\n icons: Required<CopilotChatIcons>;\n open: boolean;\n setOpen: (open: boolean) => 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}\n\nexport const ChatContextProvider = ({\n // temperature,\n // instructions,\n // maxFeedback,\n labels,\n icons,\n children,\n open,\n setOpen,\n}: ChatContextProps) => {\n const memoizedLabels = useMemo(\n () => ({\n ...{\n initial: \"\",\n title: \"CopilotKit\",\n placeholder: \"Type a message...\",\n error: \"❌ An error occurred. Please try again.\",\n stopGenerating: \"Stop generating\",\n regenerateResponse: \"Regenerate response\",\n copyToClipboard: \"Copy to clipboard\",\n thumbsUp: \"Thumbs up\",\n thumbsDown: \"Thumbs down\",\n copied: \"Copied!\",\n },\n ...labels,\n }),\n [labels],\n );\n\n const memoizedIcons = useMemo(\n () => ({\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 pushToTalkIcon: DefaultIcons.MicrophoneIcon,\n copyIcon: DefaultIcons.CopyIcon,\n thumbsUpIcon: DefaultIcons.ThumbsUpIcon,\n thumbsDownIcon: DefaultIcons.ThumbsDownIcon,\n uploadIcon: DefaultIcons.UploadIcon,\n },\n ...icons,\n }),\n [icons],\n );\n\n const context = useMemo(\n () => ({\n labels: memoizedLabels,\n icons: memoizedIcons,\n open,\n setOpen,\n }),\n [memoizedLabels, memoizedIcons, open, setOpen],\n );\n\n return <ChatContext.Provider value={context}>{children}</ChatContext.Provider
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/ChatContext.tsx"],"sourcesContent":["import React, { useMemo, useState } from \"react\";\nimport * as DefaultIcons from \"./Icons\";\nimport { ThumbsDownIcon, ThumbsUpIcon } from \"./Icons\";\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 * The icons to use for push to talk.\n * @default <PushToTalkIcon />\n */\n\n pushToTalkIcon?: React.ReactNode;\n\n /**\n * The icons to use for copy assistant response\n * @default <CopyIcon />\n */\n\n copyIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs up/response approval.\n * @default <ThumbsUpIcon />\n */\n\n thumbsUpIcon?: React.ReactNode;\n\n /**\n * The icon to use for thumbs down/response rejection.\n * @default <ThumbsDownIcon />\n */\n\n thumbsDownIcon?: React.ReactNode;\n\n /**\n * The icon to use for the upload button.\n * @default <UploadIcon />\n */\n uploadIcon?: 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 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 /**\n * The label for the copy button.\n * @default \"Copy to clipboard\"\n */\n copyToClipboard?: string;\n\n /**\n * The label for the thumbs up button.\n * @default \"Thumbs up\"\n */\n thumbsUp?: string;\n\n /**\n * The label for the thumbs down button.\n * @default \"Thumbs down\"\n */\n thumbsDown?: string;\n\n /**\n * The text to display when content is copied.\n * @default \"Copied!\"\n */\n copied?: string;\n}\n\ninterface ChatContext {\n labels: Required<CopilotChatLabels>;\n icons: Required<CopilotChatIcons>;\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nexport const ChatContext = React.createContext<ChatContext | undefined>(\n undefined,\n);\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}\n\nexport const ChatContextProvider = ({\n // temperature,\n // instructions,\n // maxFeedback,\n labels,\n icons,\n children,\n open,\n setOpen,\n}: ChatContextProps) => {\n const memoizedLabels = useMemo(\n () => ({\n ...{\n initial: \"\",\n title: \"CopilotKit\",\n placeholder: \"Type a message...\",\n error: \"❌ An error occurred. Please try again.\",\n stopGenerating: \"Stop generating\",\n regenerateResponse: \"Regenerate response\",\n copyToClipboard: \"Copy to clipboard\",\n thumbsUp: \"Thumbs up\",\n thumbsDown: \"Thumbs down\",\n copied: \"Copied!\",\n },\n ...labels,\n }),\n [labels],\n );\n\n const memoizedIcons = useMemo(\n () => ({\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 pushToTalkIcon: DefaultIcons.MicrophoneIcon,\n copyIcon: DefaultIcons.CopyIcon,\n thumbsUpIcon: DefaultIcons.ThumbsUpIcon,\n thumbsDownIcon: DefaultIcons.ThumbsDownIcon,\n uploadIcon: DefaultIcons.UploadIcon,\n },\n ...icons,\n }),\n [icons],\n );\n\n const context = useMemo(\n () => ({\n labels: memoizedLabels,\n icons: memoizedIcons,\n open,\n setOpen,\n }),\n [memoizedLabels, memoizedIcons, open, setOpen],\n );\n\n return (\n <ChatContext.Provider value={context}>{children}</ChatContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,eAAyB;AAyPrC;AAvFG,IAAM,cAAc,MAAM;AAAA,EAC/B;AACF;AAEO,SAAS,iBAA8B;AAC5C,QAAM,UAAU,MAAM,WAAW,WAAW;AAC5C,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAaO,IAAM,sBAAsB,CAAC;AAAA;AAAA;AAAA;AAAA,EAIlC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAwB;AACtB,QAAM,iBAAiB;AAAA,IACrB,MAAO,kCACF;AAAA,MACD,SAAS;AAAA,MACT,OAAO;AAAA,MACP,aAAa;AAAA,MACb,OAAO;AAAA,MACP,gBAAgB;AAAA,MAChB,oBAAoB;AAAA,MACpB,iBAAiB;AAAA,MACjB,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,QAAQ;AAAA,IACV,IACG;AAAA,IAEL,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,gBAAgB;AAAA,IACpB,MAAO,kCACF;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,MAC7B,gBAA6B;AAAA,MAC7B,UAAuB;AAAA,MACvB,cAA2B;AAAA,MAC3B,gBAA6B;AAAA,MAC7B,YAAyB;AAAA,IAC3B,IACG;AAAA,IAEL,CAAC,KAAK;AAAA,EACR;AAEA,QAAM,UAAU;AAAA,IACd,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB,eAAe,MAAM,OAAO;AAAA,EAC/C;AAEA,SACE,oBAAC,YAAY,UAAZ,EAAqB,OAAO,SAAU,UAAS;AAEpD;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useChatContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6TLDRWAD.mjs";
|
|
4
4
|
|
|
5
5
|
// src/components/chat/Button.tsx
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -22,4 +22,4 @@ var Button = ({}) => {
|
|
|
22
22
|
export {
|
|
23
23
|
Button
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-72FQQMQ2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/Button.tsx"],"sourcesContent":["import { ButtonProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\n\nexport const Button = ({}: ButtonProps) => {\n const { open, setOpen, icons } = useChatContext();\n\n return (\n <div onClick={() => setOpen(!open)}>\n <button\n className={`copilotKitButton ${open ? \"open\" : \"\"}`}\n aria-label={open ? \"Close Chat\" : \"Open Chat\"}\n >\n <div className=\"copilotKitButtonIcon copilotKitButtonIconOpen\">\n {icons.openIcon}\n </div>\n <div className=\"copilotKitButtonIcon copilotKitButtonIconClose\">\n {icons.closeIcon}\n </div>\n </button>\n </div>\n );\n};\n"],"mappings":";;;;;AAQM,SAIE,KAJF;AALC,IAAM,SAAS,CAAC,CAAC,MAAmB;AACzC,QAAM,EAAE,MAAM,SAAS,MAAM,IAAI,eAAe;AAEhD,SACE,oBAAC,SAAI,SAAS,MAAM,QAAQ,CAAC,IAAI,GAC/B;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,oBAAoB,OAAO,SAAS;AAAA,MAC/C,cAAY,OAAO,eAAe;AAAA,MAElC;AAAA,4BAAC,SAAI,WAAU,iDACZ,gBAAM,UACT;AAAA,QACA,oBAAC,SAAI,WAAU,kDACZ,gBAAM,WACT;AAAA;AAAA;AAAA,EACF,GACF;AAEJ;","names":[]}
|
|
@@ -5,7 +5,9 @@ import {
|
|
|
5
5
|
// src/components/chat/PoweredByTag.tsx
|
|
6
6
|
import { useState, useEffect } from "react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
function PoweredByTag({
|
|
8
|
+
function PoweredByTag({
|
|
9
|
+
showPoweredBy = true
|
|
10
|
+
}) {
|
|
9
11
|
const [mounted, setMounted] = useState(false);
|
|
10
12
|
const isDark = useDarkMode();
|
|
11
13
|
useEffect(() => {
|
|
@@ -29,4 +31,4 @@ function PoweredByTag({ showPoweredBy = true }) {
|
|
|
29
31
|
export {
|
|
30
32
|
PoweredByTag
|
|
31
33
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-AOUHT4JR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/PoweredByTag.tsx"],"sourcesContent":["import React, { useState, useEffect } from \"react\";\nimport { useDarkMode } from \"../../hooks/use-dark-mode\";\n\nexport function PoweredByTag({\n showPoweredBy = true,\n}: {\n showPoweredBy?: boolean;\n}) {\n const [mounted, setMounted] = useState(false);\n const isDark = useDarkMode();\n\n /*\n note(tylerslaton):\n\n Ensure we only use the isDark computed value after client-side mount.\n This prevents hydration mismatches by using a default color on the\n server and initial client render, then updating to the correct\n dark mode color after hydration is complete.\n */\n useEffect(() => {\n setMounted(true);\n }, []);\n\n if (!showPoweredBy) {\n return null;\n }\n\n const poweredByStyle = {\n visibility: \"visible\",\n display: \"block\",\n position: \"static\",\n textAlign: \"center\",\n fontSize: \"12px\",\n padding: \"3px 0\",\n color: mounted && isDark ? \"rgb(69, 69, 69)\" : \"rgb(214, 214, 214)\",\n };\n\n return (\n <div>\n {/*@ts-expect-error -- expecting position not to be a string, but it can be.*/}\n <p className=\"poweredBy\" style={poweredByStyle}>\n Powered by CopilotKit\n </p>\n </div>\n );\n}\n"],"mappings":";;;;;AAAA,SAAgB,UAAU,iBAAiB;AAwCrC;AArCC,SAAS,aAAa;AAAA,EAC3B,gBAAgB;AAClB,GAEG;AACD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,SAAS,YAAY;AAU3B,YAAU,MAAM;AACd,eAAW,IAAI;AAAA,EACjB,GAAG,CAAC,CAAC;AAEL,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB;AAAA,IACrB,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,UAAU;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,SAAS;AAAA,IACT,OAAO,WAAW,SAAS,oBAAoB;AAAA,EACjD;AAEA,SACE,oBAAC,SAEC,8BAAC,OAAE,WAAU,aAAY,OAAO,gBAAgB,mCAEhD,GACF;AAEJ;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useChatContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6TLDRWAD.mjs";
|
|
4
4
|
|
|
5
5
|
// src/components/chat/Window.tsx
|
|
6
6
|
import React, { useCallback, useEffect } from "react";
|
|
@@ -115,4 +115,4 @@ var preventScroll = (event) => {
|
|
|
115
115
|
export {
|
|
116
116
|
Window
|
|
117
117
|
};
|
|
118
|
-
//# sourceMappingURL=chunk-
|
|
118
|
+
//# sourceMappingURL=chunk-BNJX66OH.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CloseIcon
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JYHRHKV5.mjs";
|
|
4
4
|
|
|
5
5
|
// src/components/help-modal/modal.tsx
|
|
6
6
|
import { useState, useRef, useEffect } from "react";
|
|
@@ -94,4 +94,4 @@ function CopilotKitHelpModal() {
|
|
|
94
94
|
export {
|
|
95
95
|
CopilotKitHelpModal
|
|
96
96
|
};
|
|
97
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-C27LZFA5.mjs.map
|
|
@@ -3,23 +3,26 @@ import {
|
|
|
3
3
|
ChevronDownIcon,
|
|
4
4
|
ExclamationMarkIcon,
|
|
5
5
|
ExclamationMarkTriangleIcon
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-GFE5ZSPV.mjs";
|
|
7
7
|
import {
|
|
8
8
|
getPublishedCopilotKitVersion,
|
|
9
9
|
logActions,
|
|
10
10
|
logMessages,
|
|
11
11
|
logReadables,
|
|
12
12
|
shouldShowDevConsole
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YDJ4YUUF.mjs";
|
|
14
14
|
import {
|
|
15
15
|
CopilotKitHelpModal
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-C27LZFA5.mjs";
|
|
17
17
|
import {
|
|
18
18
|
SmallSpinnerIcon
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-GBAPANZE.mjs";
|
|
20
20
|
|
|
21
21
|
// src/components/dev-console/console.tsx
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
useCopilotContext,
|
|
24
|
+
useCopilotMessagesContext
|
|
25
|
+
} from "@copilotkit/react-core";
|
|
23
26
|
import { useEffect, useRef, useState } from "react";
|
|
24
27
|
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
|
|
25
28
|
import { COPILOTKIT_VERSION } from "@copilotkit/shared";
|
|
@@ -35,7 +38,9 @@ function CopilotDevConsole() {
|
|
|
35
38
|
const [versionStatus, setVersionStatus] = useState("unknown");
|
|
36
39
|
const [latestVersion, setLatestVersion] = useState("");
|
|
37
40
|
const consoleRef = useRef(null);
|
|
38
|
-
const [debugButtonMode, setDebugButtonMode] = useState(
|
|
41
|
+
const [debugButtonMode, setDebugButtonMode] = useState(
|
|
42
|
+
"full"
|
|
43
|
+
);
|
|
39
44
|
const checkForUpdates = (force = false) => {
|
|
40
45
|
setVersionStatus("checking");
|
|
41
46
|
getPublishedCopilotKitVersion(currentVersion, force).then((v) => {
|
|
@@ -176,8 +181,22 @@ function DebugMenuButton({
|
|
|
176
181
|
className: "copilotKitDebugMenu",
|
|
177
182
|
style: { zIndex: 40 },
|
|
178
183
|
children: [
|
|
179
|
-
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
180
|
-
|
|
184
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
185
|
+
"button",
|
|
186
|
+
{
|
|
187
|
+
className: "copilotKitDebugMenuItem",
|
|
188
|
+
onClick: () => logReadables(context),
|
|
189
|
+
children: "Log Readables"
|
|
190
|
+
}
|
|
191
|
+
) }),
|
|
192
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
193
|
+
"button",
|
|
194
|
+
{
|
|
195
|
+
className: "copilotKitDebugMenuItem",
|
|
196
|
+
onClick: () => logActions(context),
|
|
197
|
+
children: "Log Actions"
|
|
198
|
+
}
|
|
199
|
+
) }),
|
|
181
200
|
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
182
201
|
"button",
|
|
183
202
|
{
|
|
@@ -186,9 +205,23 @@ function DebugMenuButton({
|
|
|
186
205
|
children: "Log Messages"
|
|
187
206
|
}
|
|
188
207
|
) }),
|
|
189
|
-
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
208
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
209
|
+
"button",
|
|
210
|
+
{
|
|
211
|
+
className: "copilotKitDebugMenuItem",
|
|
212
|
+
onClick: () => checkForUpdates(true),
|
|
213
|
+
children: "Check for Updates"
|
|
214
|
+
}
|
|
215
|
+
) }),
|
|
190
216
|
/* @__PURE__ */ jsx("hr", {}),
|
|
191
|
-
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
217
|
+
/* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsx(
|
|
218
|
+
"button",
|
|
219
|
+
{
|
|
220
|
+
className: "copilotKitDebugMenuItem",
|
|
221
|
+
onClick: () => setShowDevConsole(false),
|
|
222
|
+
children: "Hide Dev Console"
|
|
223
|
+
}
|
|
224
|
+
) })
|
|
192
225
|
]
|
|
193
226
|
}
|
|
194
227
|
)
|
|
@@ -199,4 +232,4 @@ export {
|
|
|
199
232
|
CopilotDevConsole,
|
|
200
233
|
DebugMenuButton
|
|
201
234
|
};
|
|
202
|
-
//# sourceMappingURL=chunk-
|
|
235
|
+
//# sourceMappingURL=chunk-C7WM7GM3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/dev-console/console.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"@copilotkit/react-core\";\nimport {\n getPublishedCopilotKitVersion,\n logActions,\n logMessages,\n logReadables,\n shouldShowDevConsole,\n} from \"./utils\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport {\n CheckIcon,\n ChevronDownIcon,\n CopilotKitIcon,\n ExclamationMarkIcon,\n ExclamationMarkTriangleIcon,\n} from \"./icons\";\nimport { Menu, MenuButton, MenuItem, MenuItems } from \"@headlessui/react\";\nimport { COPILOTKIT_VERSION } from \"@copilotkit/shared\";\nimport { SmallSpinnerIcon } from \"../chat/Icons\";\nimport { CopilotKitHelpModal } from \"../help-modal\";\n\ntype VersionStatus =\n | \"unknown\"\n | \"checking\"\n | \"latest\"\n | \"update-available\"\n | \"outdated\";\n\nexport function CopilotDevConsole() {\n const currentVersion = COPILOTKIT_VERSION;\n const context = useCopilotContext();\n\n // to prevent hydration errors, ensure that the component renders the same content\n // server-side as it does during the initial client-side render to prevent a hydration\n // mismatch\n // see: https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only\n\n const [showDevConsole, setShowDevConsole] = useState(false);\n\n useEffect(() => {\n setShowDevConsole(shouldShowDevConsole(context.showDevConsole));\n }, [context.showDevConsole]);\n\n const dontRunTwiceInDevMode = useRef(false);\n const [versionStatus, setVersionStatus] = useState<VersionStatus>(\"unknown\");\n const [latestVersion, setLatestVersion] = useState<string>(\"\");\n const consoleRef = useRef<HTMLDivElement>(null);\n const [debugButtonMode, setDebugButtonMode] = useState<\"full\" | \"compact\">(\n \"full\",\n );\n\n const checkForUpdates = (force: boolean = false) => {\n setVersionStatus(\"checking\");\n\n getPublishedCopilotKitVersion(currentVersion, force)\n .then((v) => {\n setLatestVersion(v.latest);\n let versionOk = false;\n\n // match exact version or a version with a letter (e.g. 1.0.0-alpha.1)\n if (v.current === v.latest) {\n versionOk = true;\n } else if (/[a-zA-Z]/.test(v.current)) {\n versionOk = true;\n }\n\n if (versionOk) {\n setVersionStatus(\"latest\");\n } else if (v.severity !== \"low\") {\n setVersionStatus(\"outdated\");\n } else {\n setVersionStatus(\"update-available\");\n }\n })\n .catch((e) => {\n console.error(e);\n setVersionStatus(\"unknown\");\n });\n };\n\n useEffect(() => {\n if (dontRunTwiceInDevMode.current === true) {\n return;\n }\n dontRunTwiceInDevMode.current = true;\n\n checkForUpdates();\n }, []);\n\n if (!showDevConsole) {\n return null;\n }\n return (\n <div\n ref={consoleRef}\n className={\n \"copilotKitDevConsole \" +\n (versionStatus === \"update-available\"\n ? \"copilotKitDevConsoleUpgrade\"\n : \"\") +\n (versionStatus === \"outdated\" ? \"copilotKitDevConsoleWarnOutdated\" : \"\")\n }\n >\n <VersionInfo\n showDevConsole={context.showDevConsole}\n versionStatus={versionStatus}\n currentVersion={currentVersion}\n latestVersion={latestVersion}\n />\n\n <CopilotKitHelpModal />\n\n <DebugMenuButton\n setShowDevConsole={setShowDevConsole}\n checkForUpdates={checkForUpdates}\n mode={debugButtonMode}\n />\n </div>\n );\n}\n\nfunction VersionInfo({\n showDevConsole,\n versionStatus,\n currentVersion,\n latestVersion,\n}: {\n showDevConsole: boolean;\n versionStatus: VersionStatus;\n currentVersion: string;\n latestVersion: string;\n}) {\n const [copyStatus, setCopyStatus] = useState<string>(\"\");\n\n let versionLabel = \"\";\n let versionIcon: any = \"\";\n let currentVersionLabel = currentVersion;\n\n if (versionStatus === \"latest\") {\n versionLabel = \"latest\";\n versionIcon = CheckIcon;\n } else if (versionStatus === \"checking\") {\n versionLabel = \"checking\";\n versionIcon = SmallSpinnerIcon;\n } else if (versionStatus === \"update-available\") {\n versionLabel = \"update available\";\n versionIcon = ExclamationMarkIcon;\n currentVersionLabel = `${currentVersion} → ${latestVersion}`;\n } else if (versionStatus === \"outdated\") {\n versionLabel = \"outdated\";\n versionIcon = ExclamationMarkTriangleIcon;\n currentVersionLabel = `${currentVersion} → ${latestVersion}`;\n }\n\n let asideLabel = \"\";\n if (showDevConsole === true) {\n asideLabel = \"(enabled)\";\n }\n\n const installCommand = [\n `npm install`,\n `@copilotkit/react-core@${latestVersion}`,\n `@copilotkit/react-ui@${latestVersion}`,\n `@copilotkit/react-textarea@${latestVersion}`,\n `&& npm install @copilotkit/runtime@${latestVersion}`,\n ].join(\" \");\n\n const handleCopyClick = () => {\n navigator.clipboard.writeText(installCommand.trim()).then(() => {\n setCopyStatus(\"Command copied to clipboard!\");\n setTimeout(() => setCopyStatus(\"\"), 1000);\n });\n };\n\n if (versionStatus === \"update-available\" || versionStatus === \"outdated\") {\n return (\n <div className=\"copilotKitVersionInfo\">\n <p>\n {currentVersionLabel} {versionIcon}\n </p>\n <button onClick={handleCopyClick}>\n {copyStatus || installCommand}\n </button>\n </div>\n );\n }\n\n return null;\n}\n\nexport default function DebugMenuButton({\n setShowDevConsole,\n checkForUpdates,\n mode,\n}: {\n setShowDevConsole: (show: boolean) => void;\n checkForUpdates: (force: boolean) => void;\n mode: \"full\" | \"compact\";\n}) {\n const context = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n\n return (\n <>\n <Menu>\n <MenuButton\n className={`copilotKitDebugMenuTriggerButton ${mode === \"compact\" ? \"compact\" : \"\"}`}\n >\n {mode == \"compact\" ? \"Debug\" : <>Debug {ChevronDownIcon}</>}\n </MenuButton>\n\n <MenuItems\n transition\n anchor=\"bottom end\"\n className=\"copilotKitDebugMenu\"\n style={{ zIndex: 40 }}\n >\n <MenuItem>\n <button\n className=\"copilotKitDebugMenuItem\"\n onClick={() => logReadables(context)}\n >\n Log Readables\n </button>\n </MenuItem>\n <MenuItem>\n <button\n className=\"copilotKitDebugMenuItem\"\n onClick={() => logActions(context)}\n >\n Log Actions\n </button>\n </MenuItem>\n <MenuItem>\n <button\n className=\"copilotKitDebugMenuItem\"\n onClick={() => logMessages(messagesContext)}\n >\n Log Messages\n </button>\n </MenuItem>\n <MenuItem>\n <button\n className=\"copilotKitDebugMenuItem\"\n onClick={() => checkForUpdates(true)}\n >\n Check for Updates\n </button>\n </MenuItem>\n <hr />\n <MenuItem>\n <button\n className=\"copilotKitDebugMenuItem\"\n onClick={() => setShowDevConsole(false)}\n >\n Hide Dev Console\n </button>\n </MenuItem>\n </MenuItems>\n </Menu>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAQP,SAAgB,WAAW,QAAQ,gBAAgB;AAQnD,SAAS,MAAM,YAAY,UAAU,iBAAiB;AACtD,SAAS,0BAA0B;AA4E/B,SAmHqC,UAzGnC,KAVF;AAjEG,SAAS,oBAAoB;AAClC,QAAM,iBAAiB;AACvB,QAAM,UAAU,kBAAkB;AAOlC,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAS,KAAK;AAE1D,YAAU,MAAM;AACd,sBAAkB,qBAAqB,QAAQ,cAAc,CAAC;AAAA,EAChE,GAAG,CAAC,QAAQ,cAAc,CAAC;AAE3B,QAAM,wBAAwB,OAAO,KAAK;AAC1C,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,SAAS;AAC3E,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAiB,EAAE;AAC7D,QAAM,aAAa,OAAuB,IAAI;AAC9C,QAAM,CAAC,iBAAiB,kBAAkB,IAAI;AAAA,IAC5C;AAAA,EACF;AAEA,QAAM,kBAAkB,CAAC,QAAiB,UAAU;AAClD,qBAAiB,UAAU;AAE3B,kCAA8B,gBAAgB,KAAK,EAChD,KAAK,CAAC,MAAM;AACX,uBAAiB,EAAE,MAAM;AACzB,UAAI,YAAY;AAGhB,UAAI,EAAE,YAAY,EAAE,QAAQ;AAC1B,oBAAY;AAAA,MACd,WAAW,WAAW,KAAK,EAAE,OAAO,GAAG;AACrC,oBAAY;AAA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AAAA,cACpC;AAAA;AAAA,UAED,GACF;AAAA,UACA,oBAAC,YACC;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,SAAS,MAAM,WAAW,OAAO;AAAA,cAClC;AAAA;AAAA,UAED,GACF;AAAA,UACA,oBAAC,YACC;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,SAAS,MAAM,YAAY,eAAe;AAAA,cAC3C;AAAA;AAAA,UAED,GACF;AAAA,UACA,oBAAC,YACC;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,SAAS,MAAM,gBAAgB,IAAI;AAAA,cACpC;AAAA;AAAA,UAED,GACF;AAAA,UACA,oBAAC,QAAG;AAAA,UACJ,oBAAC,YACC;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,SAAS,MAAM,kBAAkB,KAAK;AAAA,cACvC;AAAA;AAAA,UAED,GACF;AAAA;AAAA;AAAA,IACF;AAAA,KACF,GACF;AAEJ;","names":[]}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SmallSpinnerIcon
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GBAPANZE.mjs";
|
|
4
4
|
|
|
5
5
|
// src/components/chat/Suggestion.tsx
|
|
6
6
|
import { useCopilotChatInternal } from "@copilotkit/react-core";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
function Suggestion({
|
|
8
|
+
function Suggestion({
|
|
9
|
+
title,
|
|
10
|
+
onClick,
|
|
11
|
+
partial,
|
|
12
|
+
className
|
|
13
|
+
}) {
|
|
9
14
|
const { isLoading } = useCopilotChatInternal();
|
|
10
15
|
if (!title)
|
|
11
16
|
return null;
|
|
@@ -28,4 +33,4 @@ function Suggestion({ title, onClick, partial, className }) {
|
|
|
28
33
|
export {
|
|
29
34
|
Suggestion
|
|
30
35
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
36
|
+
//# sourceMappingURL=chunk-CNIC5HO5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/Suggestion.tsx"],"sourcesContent":["import { useCopilotChatInternal } from \"@copilotkit/react-core\";\nimport { SmallSpinnerIcon } from \"./Icons\";\n\ninterface SuggestionsProps {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n onClick: () => void;\n}\n\nexport function Suggestion({\n title,\n onClick,\n partial,\n className,\n}: SuggestionsProps) {\n const { isLoading } = useCopilotChatInternal();\n if (!title) return null;\n\n return (\n <button\n disabled={partial || isLoading}\n onClick={(e) => {\n e.preventDefault();\n onClick();\n }}\n className={`suggestion ${className ?? \"\"} ${partial ? \"loading\" : \"\"}`}\n data-test-id=\"suggestion\"\n type=\"button\"\n >\n {partial ? SmallSpinnerIcon : <span>{title}</span>}\n </button>\n );\n}\n"],"mappings":";;;;;AAAA,SAAS,8BAA8B;AA+BH;AApB7B,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAqB;AACnB,QAAM,EAAE,UAAU,IAAI,uBAAuB;AAC7C,MAAI,CAAC;AAAO,WAAO;AAEnB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,WAAW;AAAA,MACrB,SAAS,CAAC,MAAM;AACd,UAAE,eAAe;AACjB,gBAAQ;AAAA,MACV;AAAA,MACA,WAAW,cAAc,gCAAa,MAAM,UAAU,YAAY;AAAA,MAClE,gBAAa;AAAA,MACb,MAAK;AAAA,MAEJ,oBAAU,mBAAmB,oBAAC,UAAM,iBAAM;AAAA;AAAA,EAC7C;AAEJ;","names":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoweredByTag
|
|
3
|
+
} from "./chunk-AOUHT4JR.mjs";
|
|
4
|
+
import {
|
|
5
|
+
Textarea_default
|
|
6
|
+
} from "./chunk-IWOCQACI.mjs";
|
|
7
|
+
import {
|
|
8
|
+
useChatContext
|
|
9
|
+
} from "./chunk-6TLDRWAD.mjs";
|
|
10
|
+
import {
|
|
11
|
+
usePushToTalk
|
|
12
|
+
} from "./chunk-2QEDCM6H.mjs";
|
|
13
|
+
|
|
14
|
+
// src/components/chat/Input.tsx
|
|
15
|
+
import { useMemo, useRef, useState } from "react";
|
|
16
|
+
import {
|
|
17
|
+
useCopilotContext,
|
|
18
|
+
useCopilotChatInternal
|
|
19
|
+
} from "@copilotkit/react-core";
|
|
20
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
var MAX_NEWLINES = 6;
|
|
22
|
+
var Input = ({
|
|
23
|
+
inProgress,
|
|
24
|
+
onSend,
|
|
25
|
+
chatReady = false,
|
|
26
|
+
onStop,
|
|
27
|
+
onUpload,
|
|
28
|
+
hideStopButton = false
|
|
29
|
+
}) => {
|
|
30
|
+
var _a;
|
|
31
|
+
const context = useChatContext();
|
|
32
|
+
const copilotContext = useCopilotContext();
|
|
33
|
+
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
34
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
35
|
+
const textareaRef = useRef(null);
|
|
36
|
+
const [isComposing, setIsComposing] = useState(false);
|
|
37
|
+
const handleDivClick = (event) => {
|
|
38
|
+
var _a2;
|
|
39
|
+
const target = event.target;
|
|
40
|
+
if (target.closest("button"))
|
|
41
|
+
return;
|
|
42
|
+
if (target.tagName === "TEXTAREA")
|
|
43
|
+
return;
|
|
44
|
+
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
45
|
+
};
|
|
46
|
+
const [text, setText] = useState("");
|
|
47
|
+
const send = () => {
|
|
48
|
+
var _a2;
|
|
49
|
+
if (inProgress)
|
|
50
|
+
return;
|
|
51
|
+
onSend(text);
|
|
52
|
+
setText("");
|
|
53
|
+
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
54
|
+
};
|
|
55
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
56
|
+
sendFunction: onSend,
|
|
57
|
+
inProgress
|
|
58
|
+
});
|
|
59
|
+
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
60
|
+
const { buttonIcon, buttonAlt } = useMemo(() => {
|
|
61
|
+
if (!chatReady)
|
|
62
|
+
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
63
|
+
return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
64
|
+
}, [
|
|
65
|
+
isInProgress,
|
|
66
|
+
chatReady,
|
|
67
|
+
hideStopButton,
|
|
68
|
+
context.icons.stopIcon,
|
|
69
|
+
context.icons.sendIcon
|
|
70
|
+
]);
|
|
71
|
+
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
72
|
+
const { interrupt } = useCopilotChatInternal();
|
|
73
|
+
const canSend = useMemo(() => {
|
|
74
|
+
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
75
|
+
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
76
|
+
const canStop = useMemo(() => {
|
|
77
|
+
return isInProgress && !hideStopButton;
|
|
78
|
+
}, [isInProgress, hideStopButton]);
|
|
79
|
+
const sendDisabled = !canSend && !canStop;
|
|
80
|
+
return /* @__PURE__ */ jsxs(
|
|
81
|
+
"div",
|
|
82
|
+
{
|
|
83
|
+
className: `copilotKitInputContainer ${showPoweredBy ? "poweredByContainer" : ""}`,
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsxs("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
86
|
+
/* @__PURE__ */ jsx(
|
|
87
|
+
Textarea_default,
|
|
88
|
+
{
|
|
89
|
+
ref: textareaRef,
|
|
90
|
+
placeholder: context.labels.placeholder,
|
|
91
|
+
autoFocus: false,
|
|
92
|
+
maxRows: MAX_NEWLINES,
|
|
93
|
+
value: text,
|
|
94
|
+
onChange: (event) => setText(event.target.value),
|
|
95
|
+
onCompositionStart: () => setIsComposing(true),
|
|
96
|
+
onCompositionEnd: () => setIsComposing(false),
|
|
97
|
+
onKeyDown: (event) => {
|
|
98
|
+
if (event.key === "Enter" && !event.shiftKey && !isComposing) {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
if (canSend) {
|
|
101
|
+
send();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
/* @__PURE__ */ jsxs("div", { className: "copilotKitInputControls", children: [
|
|
108
|
+
onUpload && /* @__PURE__ */ jsx("button", { onClick: onUpload, className: "copilotKitInputControlButton", children: context.icons.uploadIcon }),
|
|
109
|
+
/* @__PURE__ */ jsx("div", { style: { flexGrow: 1 } }),
|
|
110
|
+
showPushToTalk && /* @__PURE__ */ jsx(
|
|
111
|
+
"button",
|
|
112
|
+
{
|
|
113
|
+
onClick: () => setPushToTalkState(
|
|
114
|
+
pushToTalkState === "idle" ? "recording" : "transcribing"
|
|
115
|
+
),
|
|
116
|
+
className: pushToTalkState === "recording" ? "copilotKitInputControlButton copilotKitPushToTalkRecording" : "copilotKitInputControlButton",
|
|
117
|
+
children: context.icons.pushToTalkIcon
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
/* @__PURE__ */ jsx(
|
|
121
|
+
"button",
|
|
122
|
+
{
|
|
123
|
+
disabled: sendDisabled,
|
|
124
|
+
onClick: isInProgress && !hideStopButton ? onStop : send,
|
|
125
|
+
"data-copilotkit-in-progress": inProgress,
|
|
126
|
+
"data-test-id": inProgress ? "copilot-chat-request-in-progress" : "copilot-chat-ready",
|
|
127
|
+
className: "copilotKitInputControlButton",
|
|
128
|
+
"aria-label": buttonAlt,
|
|
129
|
+
children: buttonIcon
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
] })
|
|
133
|
+
] }),
|
|
134
|
+
/* @__PURE__ */ jsx(PoweredByTag, { showPoweredBy })
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
Input
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=chunk-CQCXH5LY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/Input.tsx"],"sourcesContent":["import React, { useMemo, useRef, useState } from \"react\";\nimport { InputProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport AutoResizingTextarea from \"./Textarea\";\nimport { usePushToTalk } from \"../../hooks/use-push-to-talk\";\nimport {\n useCopilotContext,\n useCopilotChatInternal,\n} from \"@copilotkit/react-core\";\nimport { PoweredByTag } from \"./PoweredByTag\";\n\nconst MAX_NEWLINES = 6;\n\nexport const Input = ({\n inProgress,\n onSend,\n chatReady = false,\n onStop,\n onUpload,\n hideStopButton = false,\n}: InputProps) => {\n const context = useChatContext();\n const copilotContext = useCopilotContext();\n\n const showPoweredBy = !copilotContext.copilotApiConfig?.publicApiKey;\n\n const pushToTalkConfigured =\n copilotContext.copilotApiConfig.textToSpeechUrl !== undefined &&\n copilotContext.copilotApiConfig.transcribeAudioUrl !== undefined;\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const [isComposing, setIsComposing] = useState(false);\n\n const handleDivClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const target = event.target as HTMLElement;\n\n // If the user clicked a button or inside a button, don't focus the textarea\n if (target.closest(\"button\")) return;\n\n // If the user clicked the textarea, do nothing (it's already focused)\n if (target.tagName === \"TEXTAREA\") return;\n\n // Otherwise, focus the textarea\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 // tylerslaton:\n //\n // This scrolls CopilotKit into view always. Reading the commit history, it was likely\n // added to fix a bug but it is causing issues now.\n //\n // For the future, if we want this behavior again, we will need to find a way to do it without\n // forcing CopilotKit to always be in view. This code causes this because focusing an element\n // in most browsers will scroll that element into view.\n //\n // useEffect(() => {\n // if (isVisible) {\n // textareaRef.current?.focus();\n // }\n // }, [isVisible]);\n\n const { pushToTalkState, setPushToTalkState } = usePushToTalk({\n sendFunction: onSend,\n inProgress,\n });\n\n const isInProgress = inProgress || pushToTalkState === \"transcribing\";\n const { buttonIcon, buttonAlt } = useMemo(() => {\n if (!chatReady)\n return { buttonIcon: context.icons.spinnerIcon, buttonAlt: \"Loading\" };\n return isInProgress && !hideStopButton && chatReady\n ? { buttonIcon: context.icons.stopIcon, buttonAlt: \"Stop\" }\n : { buttonIcon: context.icons.sendIcon, buttonAlt: \"Send\" };\n }, [\n isInProgress,\n chatReady,\n hideStopButton,\n context.icons.stopIcon,\n context.icons.sendIcon,\n ]);\n const showPushToTalk =\n pushToTalkConfigured &&\n (pushToTalkState === \"idle\" || pushToTalkState === \"recording\") &&\n !inProgress;\n\n const { interrupt } = useCopilotChatInternal();\n\n const canSend = useMemo(() => {\n return (\n !isInProgress &&\n text.trim().length > 0 &&\n pushToTalkState === \"idle\" &&\n !interrupt\n );\n }, [interrupt, isInProgress, text, pushToTalkState]);\n\n const canStop = useMemo(() => {\n return isInProgress && !hideStopButton;\n }, [isInProgress, hideStopButton]);\n\n const sendDisabled = !canSend && !canStop;\n\n return (\n <div\n className={`copilotKitInputContainer ${showPoweredBy ? \"poweredByContainer\" : \"\"}`}\n >\n <div className=\"copilotKitInput\" onClick={handleDivClick}>\n <AutoResizingTextarea\n ref={textareaRef}\n placeholder={context.labels.placeholder}\n autoFocus={false}\n maxRows={MAX_NEWLINES}\n value={text}\n onChange={(event) => setText(event.target.value)}\n onCompositionStart={() => setIsComposing(true)}\n onCompositionEnd={() => setIsComposing(false)}\n onKeyDown={(event) => {\n if (event.key === \"Enter\" && !event.shiftKey && !isComposing) {\n event.preventDefault();\n if (canSend) {\n send();\n }\n }\n }}\n />\n <div className=\"copilotKitInputControls\">\n {onUpload && (\n <button onClick={onUpload} className=\"copilotKitInputControlButton\">\n {context.icons.uploadIcon}\n </button>\n )}\n\n <div style={{ flexGrow: 1 }} />\n\n {showPushToTalk && (\n <button\n onClick={() =>\n setPushToTalkState(\n pushToTalkState === \"idle\" ? \"recording\" : \"transcribing\",\n )\n }\n className={\n pushToTalkState === \"recording\"\n ? \"copilotKitInputControlButton copilotKitPushToTalkRecording\"\n : \"copilotKitInputControlButton\"\n }\n >\n {context.icons.pushToTalkIcon}\n </button>\n )}\n <button\n disabled={sendDisabled}\n onClick={isInProgress && !hideStopButton ? onStop : send}\n data-copilotkit-in-progress={inProgress}\n data-test-id={\n inProgress\n ? \"copilot-chat-request-in-progress\"\n : \"copilot-chat-ready\"\n }\n className=\"copilotKitInputControlButton\"\n aria-label={buttonAlt}\n >\n {buttonIcon}\n </button>\n </div>\n </div>\n <PoweredByTag showPoweredBy={showPoweredBy} />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAgB,SAAS,QAAQ,gBAAgB;AAKjD;AAAA,EACE;AAAA,EACA;AAAA,OACK;AA4GC,cAkBA,YAlBA;AAzGR,IAAM,eAAe;AAEd,IAAM,QAAQ,CAAC;AAAA,EACpB;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA,iBAAiB;AACnB,MAAkB;AApBlB;AAqBE,QAAM,UAAU,eAAe;AAC/B,QAAM,iBAAiB,kBAAkB;AAEzC,QAAM,gBAAgB,GAAC,oBAAe,qBAAf,mBAAiC;AAExD,QAAM,uBACJ,eAAe,iBAAiB,oBAAoB,UACpD,eAAe,iBAAiB,uBAAuB;AAEzD,QAAM,cAAc,OAA4B,IAAI;AACpD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AAEpD,QAAM,iBAAiB,CAAC,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