@paymanai/payman-ask-sdk 4.0.17 → 4.0.19
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +36 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -4
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +966 -24
- package/dist/index.native.js.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1077,6 +1077,9 @@ async function cancelUserAction(config, userActionId) {
|
|
|
1077
1077
|
async function resendUserAction(config, userActionId) {
|
|
1078
1078
|
return sendUserActionRequest(config, userActionId, "resend");
|
|
1079
1079
|
}
|
|
1080
|
+
async function expireUserAction(config, userActionId) {
|
|
1081
|
+
return sendUserActionRequest(config, userActionId, "expired");
|
|
1082
|
+
}
|
|
1080
1083
|
var EMPTY_USER_ACTION_STATE = { prompts: [], notifications: [] };
|
|
1081
1084
|
function upsertPrompt(prompts, req) {
|
|
1082
1085
|
const active = { ...req, status: "pending" };
|
|
@@ -1368,6 +1371,19 @@ function useChatV2(config, callbacks = {}) {
|
|
|
1368
1371
|
},
|
|
1369
1372
|
[setPromptStatus]
|
|
1370
1373
|
);
|
|
1374
|
+
const expireUserAction2 = useCallback(
|
|
1375
|
+
async (userActionId) => {
|
|
1376
|
+
setPromptStatus(userActionId, "expired");
|
|
1377
|
+
try {
|
|
1378
|
+
await expireUserAction(configRef.current, userActionId);
|
|
1379
|
+
} catch (error) {
|
|
1380
|
+
if (error instanceof UserActionStaleError) return;
|
|
1381
|
+
callbacksRef.current.onError?.(error);
|
|
1382
|
+
throw error;
|
|
1383
|
+
}
|
|
1384
|
+
},
|
|
1385
|
+
[setPromptStatus]
|
|
1386
|
+
);
|
|
1371
1387
|
const dismissNotification = useCallback((id) => {
|
|
1372
1388
|
setUserActionState((prev) => ({
|
|
1373
1389
|
...prev,
|
|
@@ -1447,6 +1463,7 @@ function useChatV2(config, callbacks = {}) {
|
|
|
1447
1463
|
submitUserAction: submitUserAction2,
|
|
1448
1464
|
cancelUserAction: cancelUserAction2,
|
|
1449
1465
|
resendUserAction: resendUserAction2,
|
|
1466
|
+
expireUserAction: expireUserAction2,
|
|
1450
1467
|
dismissNotification
|
|
1451
1468
|
};
|
|
1452
1469
|
}
|
|
@@ -4630,6 +4647,7 @@ var MessageListV2 = forwardRef(
|
|
|
4630
4647
|
onSubmitUserAction,
|
|
4631
4648
|
onCancelUserAction,
|
|
4632
4649
|
onResendUserAction,
|
|
4650
|
+
onExpireUserAction,
|
|
4633
4651
|
onDismissNotification,
|
|
4634
4652
|
onSubmitFeedback,
|
|
4635
4653
|
typingSpeed = 4
|
|
@@ -4641,6 +4659,7 @@ var MessageListV2 = forwardRef(
|
|
|
4641
4659
|
const isNearBottomRef = useRef(true);
|
|
4642
4660
|
const [showScrollBtn, setShowScrollBtn] = useState(false);
|
|
4643
4661
|
const [expiredPromptViewState, setExpiredPromptViewState] = useState({});
|
|
4662
|
+
const expiredUserActionIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
4644
4663
|
const prevCountRef = useRef(messages.length);
|
|
4645
4664
|
const pauseStickUntilUserMessageRef = useRef(false);
|
|
4646
4665
|
const followingBottomRef = useRef(true);
|
|
@@ -4678,7 +4697,7 @@ var MessageListV2 = forwardRef(
|
|
|
4678
4697
|
].join(PROMPT_KEY_SEPARATOR);
|
|
4679
4698
|
}, [isStreaming, messages, notifications, userActionPrompts]);
|
|
4680
4699
|
const handleUserActionExpired = useCallback(
|
|
4681
|
-
(promptKey) => {
|
|
4700
|
+
(promptKey, userActionId) => {
|
|
4682
4701
|
setExpiredPromptViewState((prev) => {
|
|
4683
4702
|
if (prev[promptKey]) return prev;
|
|
4684
4703
|
return {
|
|
@@ -4686,8 +4705,13 @@ var MessageListV2 = forwardRef(
|
|
|
4686
4705
|
[promptKey]: { baseline: messageActivityFingerprint, hidden: false }
|
|
4687
4706
|
};
|
|
4688
4707
|
});
|
|
4708
|
+
if (!expiredUserActionIdsRef.current.has(userActionId)) {
|
|
4709
|
+
expiredUserActionIdsRef.current.add(userActionId);
|
|
4710
|
+
void onExpireUserAction?.(userActionId)?.catch(() => {
|
|
4711
|
+
});
|
|
4712
|
+
}
|
|
4689
4713
|
},
|
|
4690
|
-
[messageActivityFingerprint]
|
|
4714
|
+
[messageActivityFingerprint, onExpireUserAction]
|
|
4691
4715
|
);
|
|
4692
4716
|
useEffect(() => {
|
|
4693
4717
|
setExpiredPromptViewState((prev) => {
|
|
@@ -4706,6 +4730,12 @@ var MessageListV2 = forwardRef(
|
|
|
4706
4730
|
}, [messageActivityFingerprint]);
|
|
4707
4731
|
useEffect(() => {
|
|
4708
4732
|
const livePromptKeys = new Set((userActionPrompts ?? []).map(getPromptViewKey));
|
|
4733
|
+
const liveUserActionIds = new Set((userActionPrompts ?? []).map((p) => p.userActionId));
|
|
4734
|
+
for (const userActionId of expiredUserActionIdsRef.current) {
|
|
4735
|
+
if (!liveUserActionIds.has(userActionId)) {
|
|
4736
|
+
expiredUserActionIdsRef.current.delete(userActionId);
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4709
4739
|
setExpiredPromptViewState((prev) => {
|
|
4710
4740
|
let changed = false;
|
|
4711
4741
|
const next = {};
|
|
@@ -4871,7 +4901,7 @@ var MessageListV2 = forwardRef(
|
|
|
4871
4901
|
onSubmit: onSubmitUserAction ?? noop,
|
|
4872
4902
|
onCancel: onCancelUserAction ?? noop,
|
|
4873
4903
|
onResend: onResendUserAction ?? noop,
|
|
4874
|
-
onExpired: () => handleUserActionExpired(promptKey)
|
|
4904
|
+
onExpired: () => handleUserActionExpired(promptKey, prompt.userActionId)
|
|
4875
4905
|
},
|
|
4876
4906
|
promptKey
|
|
4877
4907
|
);
|
|
@@ -6083,6 +6113,7 @@ var PaymanChatInner = forwardRef(function PaymanChatInner2({
|
|
|
6083
6113
|
const submitUserAction2 = chat.submitUserAction ?? NOOP_ASYNC;
|
|
6084
6114
|
const cancelUserAction2 = chat.cancelUserAction ?? NOOP_ASYNC;
|
|
6085
6115
|
const resendUserAction2 = chat.resendUserAction ?? NOOP_ASYNC;
|
|
6116
|
+
const expireUserAction2 = chat.expireUserAction ?? NOOP_ASYNC;
|
|
6086
6117
|
const dismissNotification = chat.dismissNotification ?? NOOP;
|
|
6087
6118
|
const isUserActionSupported = typeof chat.submitUserAction === "function" && typeof chat.cancelUserAction === "function" && typeof chat.resendUserAction === "function";
|
|
6088
6119
|
const {
|
|
@@ -6483,6 +6514,7 @@ var PaymanChatInner = forwardRef(function PaymanChatInner2({
|
|
|
6483
6514
|
onSubmitUserAction: isUserActionSupported ? submitUserAction2 : void 0,
|
|
6484
6515
|
onCancelUserAction: isUserActionSupported ? cancelUserAction2 : void 0,
|
|
6485
6516
|
onResendUserAction: isUserActionSupported ? resendUserAction2 : void 0,
|
|
6517
|
+
onExpireUserAction: isUserActionSupported ? expireUserAction2 : void 0,
|
|
6486
6518
|
onDismissNotification: dismissNotification,
|
|
6487
6519
|
onSubmitFeedback: handleSubmitFeedback
|
|
6488
6520
|
}
|
|
@@ -6566,6 +6598,6 @@ var PaymanChat = forwardRef(
|
|
|
6566
6598
|
}
|
|
6567
6599
|
);
|
|
6568
6600
|
|
|
6569
|
-
export { PaymanChat, PaymanChatContext, UserActionStaleError, cancelUserAction, captureSentryError, cn, formatDate, resendUserAction, submitUserAction, useChatV2, usePaymanChat, useVoice };
|
|
6601
|
+
export { PaymanChat, PaymanChatContext, UserActionStaleError, cancelUserAction, captureSentryError, cn, expireUserAction, formatDate, resendUserAction, submitUserAction, useChatV2, usePaymanChat, useVoice };
|
|
6570
6602
|
//# sourceMappingURL=index.mjs.map
|
|
6571
6603
|
//# sourceMappingURL=index.mjs.map
|