@copilotkit/react-core 1.56.0 → 1.56.2

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
@@ -299,8 +299,9 @@ const buttonVariants = (0, class_variance_authority.cva)("cpk:inline-flex cpk:it
299
299
  size: "default"
300
300
  }
301
301
  });
302
- function Button({ className, variant, size, asChild = false, ...props }) {
302
+ const Button = react.forwardRef(function Button({ className, variant, size, asChild = false, ...props }, ref) {
303
303
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? _radix_ui_react_slot.Slot : "button", {
304
+ ref,
304
305
  "data-slot": "button",
305
306
  className: cn(buttonVariants({
306
307
  variant,
@@ -309,7 +310,7 @@ function Button({ className, variant, size, asChild = false, ...props }) {
309
310
  })),
310
311
  ...props
311
312
  });
312
- }
313
+ });
313
314
 
314
315
  //#endregion
315
316
  //#region src/v2/components/ui/tooltip.tsx
@@ -751,6 +752,7 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
751
752
  });
752
753
  }, [clearInputValue]);
753
754
  const handleKeyDown = (e) => {
755
+ if (e.nativeEvent.isComposing || e.keyCode === 229) return;
754
756
  if (commandQuery !== null && mode === "input") {
755
757
  if (e.key === "ArrowDown") {
756
758
  if (filteredCommands.length > 0) {
@@ -798,10 +800,8 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
798
800
  const trimmed = resolvedValue.trim();
799
801
  if (!trimmed) return;
800
802
  onSubmitMessage(trimmed);
801
- if (!isControlled) {
802
- setInternalValue("");
803
- onChange?.("");
804
- }
803
+ if (!isControlled) setInternalValue("");
804
+ onChange?.("");
805
805
  if (inputRef.current) inputRef.current.focus();
806
806
  };
807
807
  const BoundTextArea = renderSlot(textArea, CopilotChatInput.TextArea, {
@@ -809,6 +809,12 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
809
809
  value: resolvedValue,
810
810
  onChange: handleChange,
811
811
  onKeyDown: handleKeyDown,
812
+ onCompositionStart: () => {
813
+ isComposingRef.current = true;
814
+ },
815
+ onCompositionEnd: () => {
816
+ isComposingRef.current = false;
817
+ },
812
818
  autoFocus,
813
819
  className: (0, tailwind_merge.twMerge)("cpk:w-full cpk:py-3", isExpanded ? "cpk:px-5" : "cpk:pr-5")
814
820
  });
@@ -883,9 +889,10 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
883
889
  const target = e.target;
884
890
  if (target.tagName !== "BUTTON" && !target.closest("button") && inputRef.current && mode === "input") inputRef.current.focus();
885
891
  };
892
+ const isComposingRef = (0, react.useRef)(false);
886
893
  const ensureMeasurements = (0, react.useCallback)(() => {
887
894
  const textarea = inputRef.current;
888
- if (!textarea) return;
895
+ if (!textarea || isComposingRef.current) return;
889
896
  const previousValue = textarea.value;
890
897
  const previousHeight = textarea.style.height;
891
898
  textarea.style.height = "auto";
@@ -3433,18 +3440,21 @@ const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall
3433
3440
  const toolName = toolCall.function.name;
3434
3441
  if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
3435
3442
  name: toolName,
3443
+ toolCallId: toolCall.id,
3436
3444
  args,
3437
3445
  status: _copilotkit_core.ToolCallStatus.Complete,
3438
3446
  result: toolMessage.content
3439
3447
  });
3440
3448
  else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
3441
3449
  name: toolName,
3450
+ toolCallId: toolCall.id,
3442
3451
  args,
3443
3452
  status: _copilotkit_core.ToolCallStatus.Executing,
3444
3453
  result: void 0
3445
3454
  });
3446
3455
  else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
3447
3456
  name: toolName,
3457
+ toolCallId: toolCall.id,
3448
3458
  args,
3449
3459
  status: _copilotkit_core.ToolCallStatus.InProgress,
3450
3460
  result: void 0
@@ -3701,7 +3711,7 @@ function useRenderCustomMessages() {
3701
3711
  const runId = resolvedRunId ?? `missing-run-id:${message.id}`;
3702
3712
  const registryAgent = copilotkit.getAgent(agentId);
3703
3713
  const agent = getThreadClone(registryAgent, threadId) ?? registryAgent;
3704
- if (!agent) throw new Error("Agent not found");
3714
+ if (!agent) return null;
3705
3715
  const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
3706
3716
  const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
3707
3717
  const messageIndex = rawMessageIndex >= 0 ? rawMessageIndex : 0;
@@ -4871,10 +4881,10 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
4871
4881
  if (message.content) return await (0, _copilotkit_shared.copyToClipboard)(message.content);
4872
4882
  return false;
4873
4883
  } });
4874
- const boundThumbsUpButton = renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp });
4875
- const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown });
4876
- const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud });
4877
- const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate });
4884
+ const boundThumbsUpButton = renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp ? () => onThumbsUp(message) : void 0 });
4885
+ const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
4886
+ const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
4887
+ const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
4878
4888
  const boundToolbar = renderSlot(toolbar, CopilotChatAssistantMessage.Toolbar, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4879
4889
  className: "cpk:flex cpk:items-center cpk:gap-1",
4880
4890
  children: [
@@ -9043,12 +9053,17 @@ const usePredictStateSubscription = (agent) => {
9043
9053
  };
9044
9054
  }, [agent, getSubscriber]);
9045
9055
  };
9046
- function CopilotListeners() {
9047
- const { copilotkit } = useCopilotKit();
9056
+ function CopilotListenersAgentSubscription() {
9048
9057
  const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
9049
- const { setBannerError } = useToast();
9050
9058
  const { agent } = useAgent({ agentId: resolvedAgentId });
9051
9059
  usePredictStateSubscription(agent);
9060
+ return null;
9061
+ }
9062
+ function CopilotListeners() {
9063
+ const { copilotkit } = useCopilotKit();
9064
+ const { setBannerError } = useToast();
9065
+ const hasAgents = Object.keys(copilotkit.agents ?? {}).length > 0;
9066
+ const hasRuntime = copilotkit.runtimeUrl !== void 0;
9052
9067
  (0, react.useEffect)(() => {
9053
9068
  const subscription = copilotkit.subscribe({ onError: ({ error, code, context }) => {
9054
9069
  if (error.name === "AbortError" || error.message === "Fetch is aborted" || error.message === "signal is aborted without reason" || error.message === "component unmounted" || !error.message) return;
@@ -9070,7 +9085,7 @@ function CopilotListeners() {
9070
9085
  subscription.unsubscribe();
9071
9086
  };
9072
9087
  }, [copilotkit?.subscribe]);
9073
- return null;
9088
+ return hasAgents || hasRuntime ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotListenersAgentSubscription, {}) : null;
9074
9089
  }
9075
9090
 
9076
9091
  //#endregion
@@ -10002,4 +10017,4 @@ Object.defineProperty(exports, 'useToast', {
10002
10017
  return useToast;
10003
10018
  }
10004
10019
  });
10005
- //# sourceMappingURL=copilotkit-Cvb6WpAX.cjs.map
10020
+ //# sourceMappingURL=copilotkit-CSJw5BG8.cjs.map