@copilotkit/react-core 1.59.2 → 1.59.3

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.
@@ -764,7 +764,7 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
764
764
  }
765
765
  if (e.key === "Enter" && !e.shiftKey) {
766
766
  e.preventDefault();
767
- if (isProcessing) onStop?.();
767
+ if (isProcessing && !canSend) onStop?.();
768
768
  else send();
769
769
  }
770
770
  };
@@ -7123,6 +7123,10 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
7123
7123
  const [transcriptionError, setTranscriptionError] = useState(null);
7124
7124
  const [isTranscribing, setIsTranscribing] = useState(false);
7125
7125
  const { attachments: selectedAttachments, enabled: attachmentsEnabled, dragOver, fileInputRef, containerRef: chatContainerRef, handleFileUpload, handleDragOver, handleDragLeave, handleDrop, removeAttachment, consumeAttachments } = useAttachments({ config: attachmentsConfig });
7126
+ const selectedAttachmentsRef = useRef(selectedAttachments);
7127
+ useEffect(() => {
7128
+ selectedAttachmentsRef.current = selectedAttachments;
7129
+ }, [selectedAttachments]);
7126
7130
  const isTranscriptionEnabled = copilotkit.audioFileTranscriptionEnabled;
7127
7131
  const isMediaRecorderSupported = typeof window !== "undefined" && typeof MediaRecorder !== "undefined";
7128
7132
  const { messageView: providedMessageView, suggestionView: providedSuggestionView, onStop: providedStopHandler, ...restProps } = props;
@@ -7159,8 +7163,21 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
7159
7163
  hasExplicitThreadId
7160
7164
  ]);
7161
7165
  const onSubmitInput = useCallback(async (value) => {
7162
- if (selectedAttachments.some((a) => a.status === "uploading")) {
7163
- console.error("[CopilotKit] Cannot send while attachments are uploading");
7166
+ if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
7167
+ console.error("[CopilotKit] Cannot send while attachments are uploading (pre-await guard)");
7168
+ setTranscriptionError("Cannot send while attachments are uploading.");
7169
+ return;
7170
+ }
7171
+ setInputValue("");
7172
+ if (agent.isRunning && "activeRunCompletionPromise" in agent && agent.activeRunCompletionPromise) try {
7173
+ await agent.activeRunCompletionPromise;
7174
+ } catch (error) {
7175
+ console.error("CopilotChat: in-flight run rejected while queuing send", error);
7176
+ }
7177
+ if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
7178
+ console.error("[CopilotKit] Cannot send while attachments are uploading (post-await re-check)");
7179
+ setTranscriptionError("Cannot send while attachments are uploading.");
7180
+ setInputValue(value);
7164
7181
  return;
7165
7182
  }
7166
7183
  const readyAttachments = consumeAttachments();
@@ -7188,17 +7205,12 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
7188
7205
  role: "user",
7189
7206
  content: value
7190
7207
  });
7191
- setInputValue("");
7192
7208
  try {
7193
7209
  await copilotkit.runAgent({ agent });
7194
7210
  } catch (error) {
7195
7211
  console.error("CopilotChat: runAgent failed", error);
7196
7212
  }
7197
- }, [
7198
- agent,
7199
- selectedAttachments,
7200
- consumeAttachments
7201
- ]);
7213
+ }, [agent, consumeAttachments]);
7202
7214
  const handleSelectSuggestion = useCallback(async (suggestion) => {
7203
7215
  agent.addMessage({
7204
7216
  id: randomUUID(),
@@ -10087,4 +10099,4 @@ function validateProps(props) {
10087
10099
 
10088
10100
  //#endregion
10089
10101
  export { createA2UIMessageRenderer as $, IntelligenceIndicator as A, useInterrupt as B, CopilotChatToggleButton as C, CopilotChatView_default as D, CopilotChat as E, CopilotChatAttachmentRenderer as F, useAgent as G, useSuggestions as H, CopilotChatAssistantMessage_default as I, useFrontendTool as J, useHumanInTheLoop as K, CopilotChatToolCallsView as L, CopilotChatSuggestionPill as M, CopilotChatReasoningMessage_default as N, CopilotChatAttachmentQueue as O, CopilotChatUserMessage_default as P, useAgentContext as Q, useAttachments as R, CopilotModalHeader as S, DefaultOpenIcon as T, useCapabilities as U, useConfigureSuggestions as V, UseAgentUpdate as W, useRenderCustomMessages as X, useRenderActivityMessage as Y, CopilotKitProvider as Z, WildcardToolCallRender as _, ThreadsProvider as a, CopilotKitInspector as at, CopilotPopupView as b, CoAgentStateRendersProvider as c, useRenderTool as ct, shouldShowDevConsole as d, CopilotKitCoreReact as dt, SandboxFunctionsContext as et, useToast as f, CopilotChatInput_default as ft, useCopilotContext as g, useCopilotChatConfiguration as gt, CopilotContext as h, CopilotChatConfigurationProvider as ht, ThreadsContext as i, MCPAppsActivityType as it, CopilotChatSuggestionView as j, CopilotChatMessageView as k, useCoAgentStateRenders as l, defineToolCallRenderer as lt, useCopilotMessagesContext as m, CopilotChatAudioRecorder as mt, defaultCopilotContextCategories as n, MCPAppsActivityContentSchema as nt, useThreads as o, useRenderToolCall as ot, CopilotMessagesContext as p, AudioRecorderError as pt, useComponent as q, CoAgentStateRenderBridge as r, MCPAppsActivityRenderer as rt, CoAgentStateRendersContext as s, useDefaultRenderTool as st, CopilotKit as t, useSandboxFunctions as tt, useAsyncCallback as u, useCopilotKit as ut, CopilotPopup as v, DefaultCloseIcon as w, CopilotSidebarView as x, CopilotSidebar as y, useThreads$1 as z };
10090
- //# sourceMappingURL=copilotkit-B5RsC6la.mjs.map
10102
+ //# sourceMappingURL=copilotkit-BRNy5UvX.mjs.map