@copilotkit/react-ui 1.68.1 → 1.68.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.
package/dist/index.mjs CHANGED
@@ -1394,6 +1394,36 @@ const Markdown = ({ content, components, remarkPlugins, rehypePlugins, ...rest }
1394
1394
  });
1395
1395
  };
1396
1396
 
1397
+ //#endregion
1398
+ //#region src/components/chat/feedback.ts
1399
+ /**
1400
+ * The feedback state a click on `kind` transitions to.
1401
+ *
1402
+ * Clicking the button that is already active retracts the feedback, so the
1403
+ * click deactivates it; every other click applies feedback.
1404
+ */
1405
+ function isActivatingClick(current, kind) {
1406
+ return current !== kind;
1407
+ }
1408
+ /**
1409
+ * Applies a feedback click to the message-id keyed map.
1410
+ *
1411
+ * A deactivating click removes the entry entirely rather than storing a falsy
1412
+ * value, so `messageFeedback[id]` stays absent for "no feedback given".
1413
+ */
1414
+ function applyFeedbackClick(previous, messageId, kind, isActive) {
1415
+ if (!isActive) {
1416
+ if (!(messageId in previous)) return previous;
1417
+ const { [messageId]: _retracted, ...rest } = previous;
1418
+ return rest;
1419
+ }
1420
+ if (previous[messageId] === kind) return previous;
1421
+ return {
1422
+ ...previous,
1423
+ [messageId]: kind
1424
+ };
1425
+ }
1426
+
1397
1427
  //#endregion
1398
1428
  //#region src/components/chat/messages/AssistantMessage.tsx
1399
1429
  const AssistantMessage = (props) => {
@@ -1413,10 +1443,10 @@ const AssistantMessage = (props) => {
1413
1443
  if (onRegenerate) onRegenerate();
1414
1444
  };
1415
1445
  const handleThumbsUp = () => {
1416
- if (onThumbsUp && message) onThumbsUp(message);
1446
+ if (onThumbsUp && message) onThumbsUp(message, isActivatingClick(feedback, "thumbsUp"));
1417
1447
  };
1418
1448
  const handleThumbsDown = () => {
1419
- if (onThumbsDown && message) onThumbsDown(message);
1449
+ if (onThumbsDown && message) onThumbsDown(message, isActivatingClick(feedback, "thumbsDown"));
1420
1450
  };
1421
1451
  const LoadingIcon = () => /* @__PURE__ */ jsx("span", {
1422
1452
  "data-testid": "copilot-loading-cursor",
@@ -2473,21 +2503,18 @@ function CopilotChat({ instructions, suggestions = "auto", onSubmitMessage, make
2473
2503
  triggerChatError(error, "dropUpload", error);
2474
2504
  }
2475
2505
  };
2476
- const handleThumbsUp = (message) => {
2477
- if (onThumbsUp) onThumbsUp(message);
2478
- setMessageFeedback((prev) => ({
2479
- ...prev,
2480
- [message.id]: "thumbsUp"
2481
- }));
2482
- triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
2506
+ const recordFeedback = (message, kind, isActive) => {
2507
+ const nextActive = isActive ?? true;
2508
+ setMessageFeedback((prev) => applyFeedbackClick(prev, message.id, kind, nextActive));
2509
+ if (nextActive) triggerObservabilityHook("onFeedbackGiven", message.id, kind);
2510
+ };
2511
+ const handleThumbsUp = (message, isActive) => {
2512
+ onThumbsUp?.(message, isActive ?? true);
2513
+ recordFeedback(message, "thumbsUp", isActive);
2483
2514
  };
2484
- const handleThumbsDown = (message) => {
2485
- if (onThumbsDown) onThumbsDown(message);
2486
- setMessageFeedback((prev) => ({
2487
- ...prev,
2488
- [message.id]: "thumbsDown"
2489
- }));
2490
- triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2515
+ const handleThumbsDown = (message, isActive) => {
2516
+ onThumbsDown?.(message, isActive ?? true);
2517
+ recordFeedback(message, "thumbsDown", isActive);
2491
2518
  };
2492
2519
  return /* @__PURE__ */ jsx(WrappedCopilotChat, {
2493
2520
  icons,