@copilotkitnext/react 0.0.17-alpha.0 → 0.0.18
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 +7 -5
- package/dist/index.d.ts +7 -5
- 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 +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -93,6 +93,8 @@ type CopilotChatInputRestProps = {
|
|
|
93
93
|
toolsMenu?: (ToolsMenuItem | "-")[];
|
|
94
94
|
autoFocus?: boolean;
|
|
95
95
|
onSubmitMessage?: (value: string) => void;
|
|
96
|
+
onStop?: () => void;
|
|
97
|
+
isRunning?: boolean;
|
|
96
98
|
onStartTranscribe?: () => void;
|
|
97
99
|
onCancelTranscribe?: () => void;
|
|
98
100
|
onFinishTranscribe?: () => void;
|
|
@@ -107,7 +109,7 @@ type CopilotChatInputChildrenArgs = CopilotChatInputBaseProps extends {
|
|
|
107
109
|
type CopilotChatInputProps = Omit<CopilotChatInputBaseProps, "children"> & {
|
|
108
110
|
children?: (props: CopilotChatInputChildrenArgs) => React__default.ReactNode;
|
|
109
111
|
};
|
|
110
|
-
declare function CopilotChatInput({ mode, onSubmitMessage, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onAddFile, onChange, value, toolsMenu, autoFocus, textArea, sendButton, startTranscribeButton, cancelTranscribeButton, finishTranscribeButton, addMenuButton, audioRecorder, children, className, ...props }: CopilotChatInputProps): react_jsx_runtime.JSX.Element;
|
|
112
|
+
declare function CopilotChatInput({ mode, onSubmitMessage, onStop, isRunning, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onAddFile, onChange, value, toolsMenu, autoFocus, textArea, sendButton, startTranscribeButton, cancelTranscribeButton, finishTranscribeButton, addMenuButton, audioRecorder, children, className, ...props }: CopilotChatInputProps): react_jsx_runtime.JSX.Element;
|
|
111
113
|
declare namespace CopilotChatInput {
|
|
112
114
|
const SendButton: React__default.FC<React__default.ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
113
115
|
const ToolbarButton: React__default.FC<React__default.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
@@ -456,13 +458,13 @@ interface ReactToolCallRenderer<T> {
|
|
|
456
458
|
}>;
|
|
457
459
|
}
|
|
458
460
|
|
|
459
|
-
type ReactFrontendTool<T extends
|
|
461
|
+
type ReactFrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = FrontendTool<T> & {
|
|
460
462
|
render?: ReactToolCallRenderer<T>["render"];
|
|
461
463
|
};
|
|
462
464
|
|
|
463
|
-
declare function useFrontendTool<T extends
|
|
465
|
+
declare function useFrontendTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactFrontendTool<T>): void;
|
|
464
466
|
|
|
465
|
-
type ReactHumanInTheLoop<T extends
|
|
467
|
+
type ReactHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>> = Omit<FrontendTool<T>, "handler"> & {
|
|
466
468
|
render: React__default.ComponentType<{
|
|
467
469
|
name: string;
|
|
468
470
|
description: string;
|
|
@@ -487,7 +489,7 @@ type ReactHumanInTheLoop<T extends object = Record<string, unknown>> = Omit<Fron
|
|
|
487
489
|
}>;
|
|
488
490
|
};
|
|
489
491
|
|
|
490
|
-
declare function useHumanInTheLoop<T extends
|
|
492
|
+
declare function useHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactHumanInTheLoop<T>): void;
|
|
491
493
|
|
|
492
494
|
declare enum UseAgentUpdate {
|
|
493
495
|
OnMessagesChanged = "OnMessagesChanged",
|
package/dist/index.d.ts
CHANGED
|
@@ -93,6 +93,8 @@ type CopilotChatInputRestProps = {
|
|
|
93
93
|
toolsMenu?: (ToolsMenuItem | "-")[];
|
|
94
94
|
autoFocus?: boolean;
|
|
95
95
|
onSubmitMessage?: (value: string) => void;
|
|
96
|
+
onStop?: () => void;
|
|
97
|
+
isRunning?: boolean;
|
|
96
98
|
onStartTranscribe?: () => void;
|
|
97
99
|
onCancelTranscribe?: () => void;
|
|
98
100
|
onFinishTranscribe?: () => void;
|
|
@@ -107,7 +109,7 @@ type CopilotChatInputChildrenArgs = CopilotChatInputBaseProps extends {
|
|
|
107
109
|
type CopilotChatInputProps = Omit<CopilotChatInputBaseProps, "children"> & {
|
|
108
110
|
children?: (props: CopilotChatInputChildrenArgs) => React__default.ReactNode;
|
|
109
111
|
};
|
|
110
|
-
declare function CopilotChatInput({ mode, onSubmitMessage, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onAddFile, onChange, value, toolsMenu, autoFocus, textArea, sendButton, startTranscribeButton, cancelTranscribeButton, finishTranscribeButton, addMenuButton, audioRecorder, children, className, ...props }: CopilotChatInputProps): react_jsx_runtime.JSX.Element;
|
|
112
|
+
declare function CopilotChatInput({ mode, onSubmitMessage, onStop, isRunning, onStartTranscribe, onCancelTranscribe, onFinishTranscribe, onAddFile, onChange, value, toolsMenu, autoFocus, textArea, sendButton, startTranscribeButton, cancelTranscribeButton, finishTranscribeButton, addMenuButton, audioRecorder, children, className, ...props }: CopilotChatInputProps): react_jsx_runtime.JSX.Element;
|
|
111
113
|
declare namespace CopilotChatInput {
|
|
112
114
|
const SendButton: React__default.FC<React__default.ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
113
115
|
const ToolbarButton: React__default.FC<React__default.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
@@ -456,13 +458,13 @@ interface ReactToolCallRenderer<T> {
|
|
|
456
458
|
}>;
|
|
457
459
|
}
|
|
458
460
|
|
|
459
|
-
type ReactFrontendTool<T extends
|
|
461
|
+
type ReactFrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = FrontendTool<T> & {
|
|
460
462
|
render?: ReactToolCallRenderer<T>["render"];
|
|
461
463
|
};
|
|
462
464
|
|
|
463
|
-
declare function useFrontendTool<T extends
|
|
465
|
+
declare function useFrontendTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactFrontendTool<T>): void;
|
|
464
466
|
|
|
465
|
-
type ReactHumanInTheLoop<T extends
|
|
467
|
+
type ReactHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>> = Omit<FrontendTool<T>, "handler"> & {
|
|
466
468
|
render: React__default.ComponentType<{
|
|
467
469
|
name: string;
|
|
468
470
|
description: string;
|
|
@@ -487,7 +489,7 @@ type ReactHumanInTheLoop<T extends object = Record<string, unknown>> = Omit<Fron
|
|
|
487
489
|
}>;
|
|
488
490
|
};
|
|
489
491
|
|
|
490
|
-
declare function useHumanInTheLoop<T extends
|
|
492
|
+
declare function useHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactHumanInTheLoop<T>): void;
|
|
491
493
|
|
|
492
494
|
declare enum UseAgentUpdate {
|
|
493
495
|
OnMessagesChanged = "OnMessagesChanged",
|
package/dist/index.js
CHANGED
|
@@ -567,6 +567,8 @@ var SLASH_MENU_ITEM_HEIGHT_PX = 40;
|
|
|
567
567
|
function CopilotChatInput({
|
|
568
568
|
mode = "input",
|
|
569
569
|
onSubmitMessage,
|
|
570
|
+
onStop,
|
|
571
|
+
isRunning = false,
|
|
570
572
|
onStartTranscribe,
|
|
571
573
|
onCancelTranscribe,
|
|
572
574
|
onFinishTranscribe,
|
|
@@ -815,7 +817,11 @@ function CopilotChatInput({
|
|
|
815
817
|
}
|
|
816
818
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
817
819
|
e.preventDefault();
|
|
818
|
-
|
|
820
|
+
if (isProcessing) {
|
|
821
|
+
onStop?.();
|
|
822
|
+
} else {
|
|
823
|
+
send();
|
|
824
|
+
}
|
|
819
825
|
}
|
|
820
826
|
};
|
|
821
827
|
const send = () => {
|
|
@@ -846,12 +852,23 @@ function CopilotChatInput({
|
|
|
846
852
|
isExpanded ? "px-5" : "pr-5"
|
|
847
853
|
)
|
|
848
854
|
});
|
|
855
|
+
const isProcessing = mode !== "transcribe" && isRunning;
|
|
856
|
+
const canSend = resolvedValue.trim().length > 0 && !!onSubmitMessage;
|
|
857
|
+
const canStop = !!onStop;
|
|
858
|
+
const handleSendButtonClick = () => {
|
|
859
|
+
if (isProcessing) {
|
|
860
|
+
onStop?.();
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
send();
|
|
864
|
+
};
|
|
849
865
|
const BoundAudioRecorder = renderSlot(audioRecorder, CopilotChatAudioRecorder, {
|
|
850
866
|
ref: audioRecorderRef
|
|
851
867
|
});
|
|
852
868
|
const BoundSendButton = renderSlot(sendButton, CopilotChatInput.SendButton, {
|
|
853
|
-
onClick:
|
|
854
|
-
disabled: !
|
|
869
|
+
onClick: handleSendButtonClick,
|
|
870
|
+
disabled: isProcessing ? !canStop : !canSend,
|
|
871
|
+
children: isProcessing && canStop ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Square, { className: "size-[18px] fill-current" }) : void 0
|
|
855
872
|
});
|
|
856
873
|
const BoundStartTranscribeButton = renderSlot(startTranscribeButton, CopilotChatInput.StartTranscribeButton, {
|
|
857
874
|
onClick: onStartTranscribe
|
|
@@ -877,6 +894,8 @@ function CopilotChatInput({
|
|
|
877
894
|
finishTranscribeButton: BoundFinishTranscribeButton,
|
|
878
895
|
addMenuButton: BoundAddMenuButton,
|
|
879
896
|
onSubmitMessage,
|
|
897
|
+
onStop,
|
|
898
|
+
isRunning,
|
|
880
899
|
onStartTranscribe,
|
|
881
900
|
onCancelTranscribe,
|
|
882
901
|
onFinishTranscribe,
|
|
@@ -1191,7 +1210,7 @@ function CopilotChatInput({
|
|
|
1191
1210
|
);
|
|
1192
1211
|
}
|
|
1193
1212
|
((CopilotChatInput2) => {
|
|
1194
|
-
CopilotChatInput2.SendButton = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "mr-[10px]", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1213
|
+
CopilotChatInput2.SendButton = ({ className, children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "mr-[10px]", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1195
1214
|
Button,
|
|
1196
1215
|
{
|
|
1197
1216
|
type: "button",
|
|
@@ -1199,7 +1218,7 @@ function CopilotChatInput({
|
|
|
1199
1218
|
size: "chatInputToolbarIcon",
|
|
1200
1219
|
className,
|
|
1201
1220
|
...props,
|
|
1202
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.ArrowUp, { className: "size-[18px]" })
|
|
1221
|
+
children: children ?? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.ArrowUp, { className: "size-[18px]" })
|
|
1203
1222
|
}
|
|
1204
1223
|
) });
|
|
1205
1224
|
CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
|
|
@@ -3244,6 +3263,21 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3244
3263
|
},
|
|
3245
3264
|
[agent, copilotkit]
|
|
3246
3265
|
);
|
|
3266
|
+
const stopCurrentRun = (0, import_react22.useCallback)(() => {
|
|
3267
|
+
if (!agent) {
|
|
3268
|
+
return;
|
|
3269
|
+
}
|
|
3270
|
+
try {
|
|
3271
|
+
copilotkit.stopAgent({ agent });
|
|
3272
|
+
} catch (error) {
|
|
3273
|
+
console.error("CopilotChat: stopAgent failed", error);
|
|
3274
|
+
try {
|
|
3275
|
+
agent.abortRun();
|
|
3276
|
+
} catch (abortError) {
|
|
3277
|
+
console.error("CopilotChat: abortRun fallback failed", abortError);
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
}, [agent, copilotkit]);
|
|
3247
3281
|
const mergedProps = (0, import_ts_deepmerge.merge)(
|
|
3248
3282
|
{
|
|
3249
3283
|
isRunning: agent?.isRunning ?? false,
|
|
@@ -3256,12 +3290,20 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3256
3290
|
...typeof providedMessageView === "string" ? { messageView: { className: providedMessageView } } : providedMessageView !== void 0 ? { messageView: providedMessageView } : {}
|
|
3257
3291
|
}
|
|
3258
3292
|
);
|
|
3293
|
+
const providedStopHandler = providedInputProps?.onStop;
|
|
3294
|
+
const hasMessages = (agent?.messages?.length ?? 0) > 0;
|
|
3295
|
+
const shouldAllowStop = (agent?.isRunning ?? false) && hasMessages;
|
|
3296
|
+
const effectiveStopHandler = shouldAllowStop ? providedStopHandler ?? stopCurrentRun : providedStopHandler;
|
|
3297
|
+
const finalInputProps = {
|
|
3298
|
+
...providedInputProps,
|
|
3299
|
+
onSubmitMessage: onSubmitInput,
|
|
3300
|
+
onStop: effectiveStopHandler,
|
|
3301
|
+
isRunning: agent?.isRunning ?? false
|
|
3302
|
+
};
|
|
3303
|
+
finalInputProps.mode = agent?.isRunning ? "processing" : finalInputProps.mode ?? "input";
|
|
3259
3304
|
const finalProps = (0, import_ts_deepmerge.merge)(mergedProps, {
|
|
3260
3305
|
messages: agent?.messages ?? [],
|
|
3261
|
-
inputProps:
|
|
3262
|
-
onSubmitMessage: onSubmitInput,
|
|
3263
|
-
...providedInputProps
|
|
3264
|
-
}
|
|
3306
|
+
inputProps: finalInputProps
|
|
3265
3307
|
});
|
|
3266
3308
|
const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
|
|
3267
3309
|
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|