@paymanai/payman-ask-sdk 4.0.7 → 4.0.9

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
@@ -2023,6 +2023,16 @@ function useTypingEffect(targetText, enabled, speed = RESPONSE_SPEED, initialDis
2023
2023
  isTyping
2024
2024
  };
2025
2025
  }
2026
+ function getFeedbackState(message) {
2027
+ const feedback = message.feedback;
2028
+ if (feedback === "up" || feedback === "down") return feedback;
2029
+ if (feedback && typeof feedback === "object") {
2030
+ const value = feedback.feedback;
2031
+ if (!value) return null;
2032
+ return value === "POSITIVE" ? "up" : "down";
2033
+ }
2034
+ return null;
2035
+ }
2026
2036
  function AssistantMessageV2({
2027
2037
  message,
2028
2038
  onImageClick,
@@ -2032,21 +2042,11 @@ function AssistantMessageV2({
2032
2042
  typingSpeed = 4
2033
2043
  }) {
2034
2044
  const [copied, setCopied] = useState(false);
2035
- const [activeFeedback, setActiveFeedback] = useState(null);
2045
+ const [activeFeedback, setActiveFeedback] = useState(
2046
+ () => getFeedbackState(message)
2047
+ );
2036
2048
  const [reasonModalOpen, setReasonModalOpen] = useState(false);
2037
2049
  const canSubmitFeedback = !!onSubmitFeedback && !!message.executionId;
2038
- const handlePositiveFeedback = () => {
2039
- if (!canSubmitFeedback || activeFeedback === "up") return;
2040
- const previous = activeFeedback;
2041
- setActiveFeedback("up");
2042
- Promise.resolve(
2043
- onSubmitFeedback?.({
2044
- messageId: message.id,
2045
- executionId: message.executionId,
2046
- feedback: "POSITIVE"
2047
- })
2048
- ).catch(() => setActiveFeedback(previous));
2049
- };
2050
2050
  const [toast, setToast] = useState(null);
2051
2051
  const copyResetTimerRef = useRef(null);
2052
2052
  const toastTimerRef = useRef(null);
@@ -2054,8 +2054,12 @@ function AssistantMessageV2({
2054
2054
  const showTraceAction = (actions?.trace ?? true) && !!onExecutionTraceClick;
2055
2055
  const showThumbsUp = actions?.thumbsUp ?? true;
2056
2056
  const showThumbsDown = actions?.thumbsDown ?? true;
2057
+ const hydratedFeedback = message.feedback;
2057
2058
  const hasEverStreamed = useRef(!!message.isStreaming);
2058
2059
  if (message.isStreaming) hasEverStreamed.current = true;
2060
+ useEffect(() => {
2061
+ setActiveFeedback(getFeedbackState(message));
2062
+ }, [hydratedFeedback, message.id]);
2059
2063
  useEffect(() => {
2060
2064
  return () => {
2061
2065
  if (copyResetTimerRef.current) clearTimeout(copyResetTimerRef.current);
@@ -2121,6 +2125,21 @@ function AssistantMessageV2({
2121
2125
  setToast({ label, tone });
2122
2126
  toastTimerRef.current = setTimeout(() => setToast(null), 1800);
2123
2127
  };
2128
+ const handlePositiveFeedback = () => {
2129
+ if (!canSubmitFeedback || activeFeedback === "up") return;
2130
+ const previous = activeFeedback;
2131
+ setActiveFeedback("up");
2132
+ Promise.resolve(
2133
+ onSubmitFeedback?.({
2134
+ messageId: message.id,
2135
+ executionId: message.executionId,
2136
+ feedback: "POSITIVE"
2137
+ })
2138
+ ).then(() => showToast("Thank you for your feedback", "success")).catch(() => {
2139
+ setActiveFeedback(previous);
2140
+ showToast("Could not send feedback", "error");
2141
+ });
2142
+ };
2124
2143
  const handleCopy = async () => {
2125
2144
  try {
2126
2145
  if (!navigator.clipboard?.writeText) {
@@ -2267,7 +2286,13 @@ function AssistantMessageV2({
2267
2286
  activeFeedback === "up" && "payman-v2-assistant-msg-action-btn-active"
2268
2287
  ),
2269
2288
  "aria-label": "Good response",
2270
- children: /* @__PURE__ */ jsx(ThumbsUp, { style: { width: 15, height: 15 } })
2289
+ children: /* @__PURE__ */ jsx(
2290
+ ThumbsUp,
2291
+ {
2292
+ fill: activeFeedback === "up" ? "currentColor" : "none",
2293
+ style: { width: 15, height: 15 }
2294
+ }
2295
+ )
2271
2296
  }
2272
2297
  ) }),
2273
2298
  showThumbsDown && canSubmitFeedback && /* @__PURE__ */ jsx(ActionTooltipV2, { label: "Bad response", children: /* @__PURE__ */ jsx(
@@ -2279,7 +2304,13 @@ function AssistantMessageV2({
2279
2304
  activeFeedback === "down" && "payman-v2-assistant-msg-action-btn-active"
2280
2305
  ),
2281
2306
  "aria-label": "Bad response",
2282
- children: /* @__PURE__ */ jsx(ThumbsDown, { style: { width: 15, height: 15 } })
2307
+ children: /* @__PURE__ */ jsx(
2308
+ ThumbsDown,
2309
+ {
2310
+ fill: activeFeedback === "down" ? "currentColor" : "none",
2311
+ style: { width: 15, height: 15 }
2312
+ }
2313
+ )
2283
2314
  }
2284
2315
  ) }),
2285
2316
  showTraceAction && /* @__PURE__ */ jsx(ActionTooltipV2, { label: "Trace", children: /* @__PURE__ */ jsx(
@@ -2306,6 +2337,7 @@ function AssistantMessageV2({
2306
2337
  details
2307
2338
  });
2308
2339
  setActiveFeedback("down");
2340
+ showToast("Thank you for your feedback", "success");
2309
2341
  }
2310
2342
  }
2311
2343
  )