@paymanai/payman-ask-sdk 4.0.8 → 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.js +47 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2049,6 +2049,16 @@ function useTypingEffect(targetText, enabled, speed = RESPONSE_SPEED, initialDis
|
|
|
2049
2049
|
isTyping
|
|
2050
2050
|
};
|
|
2051
2051
|
}
|
|
2052
|
+
function getFeedbackState(message) {
|
|
2053
|
+
const feedback = message.feedback;
|
|
2054
|
+
if (feedback === "up" || feedback === "down") return feedback;
|
|
2055
|
+
if (feedback && typeof feedback === "object") {
|
|
2056
|
+
const value = feedback.feedback;
|
|
2057
|
+
if (!value) return null;
|
|
2058
|
+
return value === "POSITIVE" ? "up" : "down";
|
|
2059
|
+
}
|
|
2060
|
+
return null;
|
|
2061
|
+
}
|
|
2052
2062
|
function AssistantMessageV2({
|
|
2053
2063
|
message,
|
|
2054
2064
|
onImageClick,
|
|
@@ -2058,21 +2068,11 @@ function AssistantMessageV2({
|
|
|
2058
2068
|
typingSpeed = 4
|
|
2059
2069
|
}) {
|
|
2060
2070
|
const [copied, setCopied] = react.useState(false);
|
|
2061
|
-
const [activeFeedback, setActiveFeedback] = react.useState(
|
|
2071
|
+
const [activeFeedback, setActiveFeedback] = react.useState(
|
|
2072
|
+
() => getFeedbackState(message)
|
|
2073
|
+
);
|
|
2062
2074
|
const [reasonModalOpen, setReasonModalOpen] = react.useState(false);
|
|
2063
2075
|
const canSubmitFeedback = !!onSubmitFeedback && !!message.executionId;
|
|
2064
|
-
const handlePositiveFeedback = () => {
|
|
2065
|
-
if (!canSubmitFeedback || activeFeedback === "up") return;
|
|
2066
|
-
const previous = activeFeedback;
|
|
2067
|
-
setActiveFeedback("up");
|
|
2068
|
-
Promise.resolve(
|
|
2069
|
-
onSubmitFeedback?.({
|
|
2070
|
-
messageId: message.id,
|
|
2071
|
-
executionId: message.executionId,
|
|
2072
|
-
feedback: "POSITIVE"
|
|
2073
|
-
})
|
|
2074
|
-
).catch(() => setActiveFeedback(previous));
|
|
2075
|
-
};
|
|
2076
2076
|
const [toast, setToast] = react.useState(null);
|
|
2077
2077
|
const copyResetTimerRef = react.useRef(null);
|
|
2078
2078
|
const toastTimerRef = react.useRef(null);
|
|
@@ -2080,8 +2080,12 @@ function AssistantMessageV2({
|
|
|
2080
2080
|
const showTraceAction = (actions?.trace ?? true) && !!onExecutionTraceClick;
|
|
2081
2081
|
const showThumbsUp = actions?.thumbsUp ?? true;
|
|
2082
2082
|
const showThumbsDown = actions?.thumbsDown ?? true;
|
|
2083
|
+
const hydratedFeedback = message.feedback;
|
|
2083
2084
|
const hasEverStreamed = react.useRef(!!message.isStreaming);
|
|
2084
2085
|
if (message.isStreaming) hasEverStreamed.current = true;
|
|
2086
|
+
react.useEffect(() => {
|
|
2087
|
+
setActiveFeedback(getFeedbackState(message));
|
|
2088
|
+
}, [hydratedFeedback, message.id]);
|
|
2085
2089
|
react.useEffect(() => {
|
|
2086
2090
|
return () => {
|
|
2087
2091
|
if (copyResetTimerRef.current) clearTimeout(copyResetTimerRef.current);
|
|
@@ -2147,6 +2151,21 @@ function AssistantMessageV2({
|
|
|
2147
2151
|
setToast({ label, tone });
|
|
2148
2152
|
toastTimerRef.current = setTimeout(() => setToast(null), 1800);
|
|
2149
2153
|
};
|
|
2154
|
+
const handlePositiveFeedback = () => {
|
|
2155
|
+
if (!canSubmitFeedback || activeFeedback === "up") return;
|
|
2156
|
+
const previous = activeFeedback;
|
|
2157
|
+
setActiveFeedback("up");
|
|
2158
|
+
Promise.resolve(
|
|
2159
|
+
onSubmitFeedback?.({
|
|
2160
|
+
messageId: message.id,
|
|
2161
|
+
executionId: message.executionId,
|
|
2162
|
+
feedback: "POSITIVE"
|
|
2163
|
+
})
|
|
2164
|
+
).then(() => showToast("Thank you for your feedback", "success")).catch(() => {
|
|
2165
|
+
setActiveFeedback(previous);
|
|
2166
|
+
showToast("Could not send feedback", "error");
|
|
2167
|
+
});
|
|
2168
|
+
};
|
|
2150
2169
|
const handleCopy = async () => {
|
|
2151
2170
|
try {
|
|
2152
2171
|
if (!navigator.clipboard?.writeText) {
|
|
@@ -2293,7 +2312,13 @@ function AssistantMessageV2({
|
|
|
2293
2312
|
activeFeedback === "up" && "payman-v2-assistant-msg-action-btn-active"
|
|
2294
2313
|
),
|
|
2295
2314
|
"aria-label": "Good response",
|
|
2296
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2315
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2316
|
+
lucideReact.ThumbsUp,
|
|
2317
|
+
{
|
|
2318
|
+
fill: activeFeedback === "up" ? "currentColor" : "none",
|
|
2319
|
+
style: { width: 15, height: 15 }
|
|
2320
|
+
}
|
|
2321
|
+
)
|
|
2297
2322
|
}
|
|
2298
2323
|
) }),
|
|
2299
2324
|
showThumbsDown && canSubmitFeedback && /* @__PURE__ */ jsxRuntime.jsx(ActionTooltipV2, { label: "Bad response", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2305,7 +2330,13 @@ function AssistantMessageV2({
|
|
|
2305
2330
|
activeFeedback === "down" && "payman-v2-assistant-msg-action-btn-active"
|
|
2306
2331
|
),
|
|
2307
2332
|
"aria-label": "Bad response",
|
|
2308
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2333
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2334
|
+
lucideReact.ThumbsDown,
|
|
2335
|
+
{
|
|
2336
|
+
fill: activeFeedback === "down" ? "currentColor" : "none",
|
|
2337
|
+
style: { width: 15, height: 15 }
|
|
2338
|
+
}
|
|
2339
|
+
)
|
|
2309
2340
|
}
|
|
2310
2341
|
) }),
|
|
2311
2342
|
showTraceAction && /* @__PURE__ */ jsxRuntime.jsx(ActionTooltipV2, { label: "Trace", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2332,6 +2363,7 @@ function AssistantMessageV2({
|
|
|
2332
2363
|
details
|
|
2333
2364
|
});
|
|
2334
2365
|
setActiveFeedback("down");
|
|
2366
|
+
showToast("Thank you for your feedback", "success");
|
|
2335
2367
|
}
|
|
2336
2368
|
}
|
|
2337
2369
|
)
|