@copilotkit/react-core 1.56.0 → 1.56.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{copilotkit-Dv8zU8_U.d.cts → copilotkit-BtP7w7cT.d.cts} +10 -1
  2. package/dist/{copilotkit-Dv8zU8_U.d.cts.map → copilotkit-BtP7w7cT.d.cts.map} +1 -1
  3. package/dist/{copilotkit-f2Uq0RwG.d.mts → copilotkit-CCbxm6JM.d.mts} +10 -1
  4. package/dist/{copilotkit-f2Uq0RwG.d.mts.map → copilotkit-CCbxm6JM.d.mts.map} +1 -1
  5. package/dist/{copilotkit-Cvb6WpAX.cjs → copilotkit-CSJw5BG8.cjs} +32 -17
  6. package/dist/copilotkit-CSJw5BG8.cjs.map +1 -0
  7. package/dist/{copilotkit-BebqQrYT.mjs → copilotkit-Cj2ZIxVr.mjs} +32 -17
  8. package/dist/copilotkit-Cj2ZIxVr.mjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.cts +1 -1
  11. package/dist/index.d.mts +1 -1
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.umd.js +14 -6
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/v2/index.cjs +1 -1
  16. package/dist/v2/index.d.cts +1 -1
  17. package/dist/v2/index.d.mts +1 -1
  18. package/dist/v2/index.mjs +1 -1
  19. package/dist/v2/index.umd.js +32 -17
  20. package/dist/v2/index.umd.js.map +1 -1
  21. package/package.json +6 -6
  22. package/src/components/CopilotListeners.tsx +15 -4
  23. package/src/components/__tests__/CopilotListeners.test.tsx +38 -0
  24. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +4 -4
  25. package/src/v2/components/chat/CopilotChatInput.tsx +21 -2
  26. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.tsx +72 -0
  27. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +38 -0
  28. package/src/v2/components/ui/button.tsx +12 -11
  29. package/src/v2/hooks/__tests__/use-render-custom-messages.test.tsx +55 -0
  30. package/src/v2/hooks/use-render-custom-messages.tsx +1 -1
  31. package/src/v2/hooks/use-render-tool-call.tsx +3 -0
  32. package/src/v2/hooks/use-render-tool.tsx +3 -0
  33. package/src/v2/types/defineToolCallRenderer.ts +3 -0
  34. package/src/v2/types/react-tool-call-renderer.ts +3 -0
  35. package/dist/copilotkit-BebqQrYT.mjs.map +0 -1
  36. package/dist/copilotkit-Cvb6WpAX.cjs.map +0 -1
@@ -269,8 +269,9 @@ const buttonVariants = cva("cpk:inline-flex cpk:items-center cpk:justify-center
269
269
  size: "default"
270
270
  }
271
271
  });
272
- function Button({ className, variant, size, asChild = false, ...props }) {
272
+ const Button = React$1.forwardRef(function Button({ className, variant, size, asChild = false, ...props }, ref) {
273
273
  return /* @__PURE__ */ jsx(asChild ? Slot : "button", {
274
+ ref,
274
275
  "data-slot": "button",
275
276
  className: cn(buttonVariants({
276
277
  variant,
@@ -279,7 +280,7 @@ function Button({ className, variant, size, asChild = false, ...props }) {
279
280
  })),
280
281
  ...props
281
282
  });
282
- }
283
+ });
283
284
 
284
285
  //#endregion
285
286
  //#region src/v2/components/ui/tooltip.tsx
@@ -721,6 +722,7 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
721
722
  });
722
723
  }, [clearInputValue]);
723
724
  const handleKeyDown = (e) => {
725
+ if (e.nativeEvent.isComposing || e.keyCode === 229) return;
724
726
  if (commandQuery !== null && mode === "input") {
725
727
  if (e.key === "ArrowDown") {
726
728
  if (filteredCommands.length > 0) {
@@ -768,10 +770,8 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
768
770
  const trimmed = resolvedValue.trim();
769
771
  if (!trimmed) return;
770
772
  onSubmitMessage(trimmed);
771
- if (!isControlled) {
772
- setInternalValue("");
773
- onChange?.("");
774
- }
773
+ if (!isControlled) setInternalValue("");
774
+ onChange?.("");
775
775
  if (inputRef.current) inputRef.current.focus();
776
776
  };
777
777
  const BoundTextArea = renderSlot(textArea, CopilotChatInput.TextArea, {
@@ -779,6 +779,12 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
779
779
  value: resolvedValue,
780
780
  onChange: handleChange,
781
781
  onKeyDown: handleKeyDown,
782
+ onCompositionStart: () => {
783
+ isComposingRef.current = true;
784
+ },
785
+ onCompositionEnd: () => {
786
+ isComposingRef.current = false;
787
+ },
782
788
  autoFocus,
783
789
  className: twMerge("cpk:w-full cpk:py-3", isExpanded ? "cpk:px-5" : "cpk:pr-5")
784
790
  });
@@ -853,9 +859,10 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
853
859
  const target = e.target;
854
860
  if (target.tagName !== "BUTTON" && !target.closest("button") && inputRef.current && mode === "input") inputRef.current.focus();
855
861
  };
862
+ const isComposingRef = useRef(false);
856
863
  const ensureMeasurements = useCallback(() => {
857
864
  const textarea = inputRef.current;
858
- if (!textarea) return;
865
+ if (!textarea || isComposingRef.current) return;
859
866
  const previousValue = textarea.value;
860
867
  const previousHeight = textarea.style.height;
861
868
  textarea.style.height = "auto";
@@ -3403,18 +3410,21 @@ const ToolCallRenderer = React.memo(function ToolCallRenderer({ toolCall, toolMe
3403
3410
  const toolName = toolCall.function.name;
3404
3411
  if (toolMessage) return /* @__PURE__ */ jsx(RenderComponent, {
3405
3412
  name: toolName,
3413
+ toolCallId: toolCall.id,
3406
3414
  args,
3407
3415
  status: ToolCallStatus.Complete,
3408
3416
  result: toolMessage.content
3409
3417
  });
3410
3418
  else if (isExecuting) return /* @__PURE__ */ jsx(RenderComponent, {
3411
3419
  name: toolName,
3420
+ toolCallId: toolCall.id,
3412
3421
  args,
3413
3422
  status: ToolCallStatus.Executing,
3414
3423
  result: void 0
3415
3424
  });
3416
3425
  else return /* @__PURE__ */ jsx(RenderComponent, {
3417
3426
  name: toolName,
3427
+ toolCallId: toolCall.id,
3418
3428
  args,
3419
3429
  status: ToolCallStatus.InProgress,
3420
3430
  result: void 0
@@ -3671,7 +3681,7 @@ function useRenderCustomMessages() {
3671
3681
  const runId = resolvedRunId ?? `missing-run-id:${message.id}`;
3672
3682
  const registryAgent = copilotkit.getAgent(agentId);
3673
3683
  const agent = getThreadClone(registryAgent, threadId) ?? registryAgent;
3674
- if (!agent) throw new Error("Agent not found");
3684
+ if (!agent) return null;
3675
3685
  const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
3676
3686
  const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
3677
3687
  const messageIndex = rawMessageIndex >= 0 ? rawMessageIndex : 0;
@@ -4841,10 +4851,10 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
4841
4851
  if (message.content) return await copyToClipboard(message.content);
4842
4852
  return false;
4843
4853
  } });
4844
- const boundThumbsUpButton = renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp });
4845
- const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown });
4846
- const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud });
4847
- const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate });
4854
+ const boundThumbsUpButton = renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp ? () => onThumbsUp(message) : void 0 });
4855
+ const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
4856
+ const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
4857
+ const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
4848
4858
  const boundToolbar = renderSlot(toolbar, CopilotChatAssistantMessage.Toolbar, { children: /* @__PURE__ */ jsxs("div", {
4849
4859
  className: "cpk:flex cpk:items-center cpk:gap-1",
4850
4860
  children: [
@@ -9013,12 +9023,17 @@ const usePredictStateSubscription = (agent) => {
9013
9023
  };
9014
9024
  }, [agent, getSubscriber]);
9015
9025
  };
9016
- function CopilotListeners() {
9017
- const { copilotkit } = useCopilotKit();
9026
+ function CopilotListenersAgentSubscription() {
9018
9027
  const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
9019
- const { setBannerError } = useToast();
9020
9028
  const { agent } = useAgent({ agentId: resolvedAgentId });
9021
9029
  usePredictStateSubscription(agent);
9030
+ return null;
9031
+ }
9032
+ function CopilotListeners() {
9033
+ const { copilotkit } = useCopilotKit();
9034
+ const { setBannerError } = useToast();
9035
+ const hasAgents = Object.keys(copilotkit.agents ?? {}).length > 0;
9036
+ const hasRuntime = copilotkit.runtimeUrl !== void 0;
9022
9037
  useEffect(() => {
9023
9038
  const subscription = copilotkit.subscribe({ onError: ({ error, code, context }) => {
9024
9039
  if (error.name === "AbortError" || error.message === "Fetch is aborted" || error.message === "signal is aborted without reason" || error.message === "component unmounted" || !error.message) return;
@@ -9040,7 +9055,7 @@ function CopilotListeners() {
9040
9055
  subscription.unsubscribe();
9041
9056
  };
9042
9057
  }, [copilotkit?.subscribe]);
9043
- return null;
9058
+ return hasAgents || hasRuntime ? /* @__PURE__ */ jsx(CopilotListenersAgentSubscription, {}) : null;
9044
9059
  }
9045
9060
 
9046
9061
  //#endregion
@@ -9553,4 +9568,4 @@ function validateProps(props) {
9553
9568
 
9554
9569
  //#endregion
9555
9570
  export { CopilotKitProvider as $, CopilotChatSuggestionView as A, useConfigureSuggestions as B, CopilotChatToggleButton as C, CopilotChatView_default as D, CopilotChat as E, CopilotChatAssistantMessage_default as F, useRenderTool as G, useCapabilities as H, CopilotChatToolCallsView as I, useRenderActivityMessage as J, useComponent as K, useAttachments as L, CopilotChatReasoningMessage_default as M, CopilotChatUserMessage_default as N, CopilotChatAttachmentQueue as O, CopilotChatAttachmentRenderer as P, useRenderToolCall as Q, useThreads$1 as R, CopilotModalHeader as S, DefaultOpenIcon as T, useHumanInTheLoop as U, useSuggestions as V, useDefaultRenderTool as W, UseAgentUpdate as X, useRenderCustomMessages as Y, useAgent as Z, WildcardToolCallRender as _, ThreadsProvider as a, SandboxFunctionsContext as at, CopilotPopupView as b, CoAgentStateRendersProvider as c, MCPAppsActivityRenderer as ct, shouldShowDevConsole as d, CopilotChatInput_default as dt, useCopilotKit as et, useToast as f, AudioRecorderError as ft, useCopilotContext as g, CopilotContext as h, useCopilotChatConfiguration as ht, ThreadsContext as i, createA2UIMessageRenderer as it, CopilotChatSuggestionPill as j, CopilotChatMessageView as k, useCoAgentStateRenders as l, MCPAppsActivityType as lt, useCopilotMessagesContext as m, CopilotChatConfigurationProvider as mt, defaultCopilotContextCategories as n, useAgentContext as nt, useThreads as o, useSandboxFunctions as ot, CopilotMessagesContext as p, CopilotChatAudioRecorder as pt, useFrontendTool as q, CoAgentStateRenderBridge as r, defineToolCallRenderer as rt, CoAgentStateRendersContext as s, MCPAppsActivityContentSchema as st, CopilotKit as t, CopilotKitCoreReact as tt, useAsyncCallback as u, CopilotKitInspector as ut, CopilotPopup as v, DefaultCloseIcon as w, CopilotSidebarView as x, CopilotSidebar as y, useInterrupt as z };
9556
- //# sourceMappingURL=copilotkit-BebqQrYT.mjs.map
9571
+ //# sourceMappingURL=copilotkit-Cj2ZIxVr.mjs.map