@copilotkitnext/react 0.0.16 → 0.0.17
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/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +51 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
useMemo as useMemo2
|
|
13
13
|
} from "react";
|
|
14
14
|
import { twMerge as twMerge3 } from "tailwind-merge";
|
|
15
|
-
import { Plus, Mic, ArrowUp, X, Check } from "lucide-react";
|
|
15
|
+
import { Plus, Mic, ArrowUp, X, Check, Square } from "lucide-react";
|
|
16
16
|
|
|
17
17
|
// src/providers/CopilotChatConfigurationProvider.tsx
|
|
18
18
|
import { createContext, useContext, useMemo, useState } from "react";
|
|
@@ -507,6 +507,8 @@ var SLASH_MENU_ITEM_HEIGHT_PX = 40;
|
|
|
507
507
|
function CopilotChatInput({
|
|
508
508
|
mode = "input",
|
|
509
509
|
onSubmitMessage,
|
|
510
|
+
onStop,
|
|
511
|
+
isRunning = false,
|
|
510
512
|
onStartTranscribe,
|
|
511
513
|
onCancelTranscribe,
|
|
512
514
|
onFinishTranscribe,
|
|
@@ -755,7 +757,11 @@ function CopilotChatInput({
|
|
|
755
757
|
}
|
|
756
758
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
757
759
|
e.preventDefault();
|
|
758
|
-
|
|
760
|
+
if (isProcessing) {
|
|
761
|
+
onStop?.();
|
|
762
|
+
} else {
|
|
763
|
+
send();
|
|
764
|
+
}
|
|
759
765
|
}
|
|
760
766
|
};
|
|
761
767
|
const send = () => {
|
|
@@ -786,12 +792,23 @@ function CopilotChatInput({
|
|
|
786
792
|
isExpanded ? "px-5" : "pr-5"
|
|
787
793
|
)
|
|
788
794
|
});
|
|
795
|
+
const isProcessing = mode !== "transcribe" && isRunning;
|
|
796
|
+
const canSend = resolvedValue.trim().length > 0 && !!onSubmitMessage;
|
|
797
|
+
const canStop = !!onStop;
|
|
798
|
+
const handleSendButtonClick = () => {
|
|
799
|
+
if (isProcessing) {
|
|
800
|
+
onStop?.();
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
send();
|
|
804
|
+
};
|
|
789
805
|
const BoundAudioRecorder = renderSlot(audioRecorder, CopilotChatAudioRecorder, {
|
|
790
806
|
ref: audioRecorderRef
|
|
791
807
|
});
|
|
792
808
|
const BoundSendButton = renderSlot(sendButton, CopilotChatInput.SendButton, {
|
|
793
|
-
onClick:
|
|
794
|
-
disabled: !
|
|
809
|
+
onClick: handleSendButtonClick,
|
|
810
|
+
disabled: isProcessing ? !canStop : !canSend,
|
|
811
|
+
children: isProcessing && canStop ? /* @__PURE__ */ jsx6(Square, { className: "size-[18px] fill-current" }) : void 0
|
|
795
812
|
});
|
|
796
813
|
const BoundStartTranscribeButton = renderSlot(startTranscribeButton, CopilotChatInput.StartTranscribeButton, {
|
|
797
814
|
onClick: onStartTranscribe
|
|
@@ -817,6 +834,8 @@ function CopilotChatInput({
|
|
|
817
834
|
finishTranscribeButton: BoundFinishTranscribeButton,
|
|
818
835
|
addMenuButton: BoundAddMenuButton,
|
|
819
836
|
onSubmitMessage,
|
|
837
|
+
onStop,
|
|
838
|
+
isRunning,
|
|
820
839
|
onStartTranscribe,
|
|
821
840
|
onCancelTranscribe,
|
|
822
841
|
onFinishTranscribe,
|
|
@@ -1131,7 +1150,7 @@ function CopilotChatInput({
|
|
|
1131
1150
|
);
|
|
1132
1151
|
}
|
|
1133
1152
|
((CopilotChatInput2) => {
|
|
1134
|
-
CopilotChatInput2.SendButton = ({ className, ...props }) => /* @__PURE__ */ jsx6("div", { className: "mr-[10px]", children: /* @__PURE__ */ jsx6(
|
|
1153
|
+
CopilotChatInput2.SendButton = ({ className, children, ...props }) => /* @__PURE__ */ jsx6("div", { className: "mr-[10px]", children: /* @__PURE__ */ jsx6(
|
|
1135
1154
|
Button,
|
|
1136
1155
|
{
|
|
1137
1156
|
type: "button",
|
|
@@ -1139,7 +1158,7 @@ function CopilotChatInput({
|
|
|
1139
1158
|
size: "chatInputToolbarIcon",
|
|
1140
1159
|
className,
|
|
1141
1160
|
...props,
|
|
1142
|
-
children: /* @__PURE__ */ jsx6(ArrowUp, { className: "size-[18px]" })
|
|
1161
|
+
children: children ?? /* @__PURE__ */ jsx6(ArrowUp, { className: "size-[18px]" })
|
|
1143
1162
|
}
|
|
1144
1163
|
) });
|
|
1145
1164
|
CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
|
|
@@ -3203,6 +3222,21 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3203
3222
|
},
|
|
3204
3223
|
[agent, copilotkit]
|
|
3205
3224
|
);
|
|
3225
|
+
const stopCurrentRun = useCallback6(() => {
|
|
3226
|
+
if (!agent) {
|
|
3227
|
+
return;
|
|
3228
|
+
}
|
|
3229
|
+
try {
|
|
3230
|
+
copilotkit.stopAgent({ agent });
|
|
3231
|
+
} catch (error) {
|
|
3232
|
+
console.error("CopilotChat: stopAgent failed", error);
|
|
3233
|
+
try {
|
|
3234
|
+
agent.abortRun();
|
|
3235
|
+
} catch (abortError) {
|
|
3236
|
+
console.error("CopilotChat: abortRun fallback failed", abortError);
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
}, [agent, copilotkit]);
|
|
3206
3240
|
const mergedProps = merge(
|
|
3207
3241
|
{
|
|
3208
3242
|
isRunning: agent?.isRunning ?? false,
|
|
@@ -3215,12 +3249,20 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3215
3249
|
...typeof providedMessageView === "string" ? { messageView: { className: providedMessageView } } : providedMessageView !== void 0 ? { messageView: providedMessageView } : {}
|
|
3216
3250
|
}
|
|
3217
3251
|
);
|
|
3252
|
+
const providedStopHandler = providedInputProps?.onStop;
|
|
3253
|
+
const hasMessages = (agent?.messages?.length ?? 0) > 0;
|
|
3254
|
+
const shouldAllowStop = (agent?.isRunning ?? false) && hasMessages;
|
|
3255
|
+
const effectiveStopHandler = shouldAllowStop ? providedStopHandler ?? stopCurrentRun : providedStopHandler;
|
|
3256
|
+
const finalInputProps = {
|
|
3257
|
+
...providedInputProps,
|
|
3258
|
+
onSubmitMessage: onSubmitInput,
|
|
3259
|
+
onStop: effectiveStopHandler,
|
|
3260
|
+
isRunning: agent?.isRunning ?? false
|
|
3261
|
+
};
|
|
3262
|
+
finalInputProps.mode = agent?.isRunning ? "processing" : finalInputProps.mode ?? "input";
|
|
3218
3263
|
const finalProps = merge(mergedProps, {
|
|
3219
3264
|
messages: agent?.messages ?? [],
|
|
3220
|
-
inputProps:
|
|
3221
|
-
onSubmitMessage: onSubmitInput,
|
|
3222
|
-
...providedInputProps
|
|
3223
|
-
}
|
|
3265
|
+
inputProps: finalInputProps
|
|
3224
3266
|
});
|
|
3225
3267
|
const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
|
|
3226
3268
|
return /* @__PURE__ */ jsx18(
|