@paymanai/payman-ask-sdk 4.0.18 → 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.mjs CHANGED
@@ -846,17 +846,6 @@ function useStreamManagerV2(config, callbacks, setMessages, setIsWaitingForRespo
846
846
  signal: abortController.signal,
847
847
  onEvent: (event) => {
848
848
  if (abortController.signal.aborted) return;
849
- try {
850
- const et = event?.eventType;
851
- if (et === "RUN_IN_PROGRESS" || et === "INTENT_PROGRESS" || et === "THINKING_DELTA") {
852
- const len = (event.partialText ?? event.text ?? "").length;
853
- console.log(`[stream] ${et} (+${len} chars)`);
854
- } else {
855
- console.log(`[stream] ${et ?? "?"}:`, JSON.stringify(event));
856
- }
857
- } catch {
858
- console.log("[stream] (unserializable event)", event?.eventType);
859
- }
860
849
  processStreamEventV2(event, state);
861
850
  if (state.lastUserAction) {
862
851
  callbacksRef.current.onUserActionRequired?.(state.lastUserAction);
@@ -1088,6 +1077,9 @@ async function cancelUserAction(config, userActionId) {
1088
1077
  async function resendUserAction(config, userActionId) {
1089
1078
  return sendUserActionRequest(config, userActionId, "resend");
1090
1079
  }
1080
+ async function expireUserAction(config, userActionId) {
1081
+ return sendUserActionRequest(config, userActionId, "expired");
1082
+ }
1091
1083
  var EMPTY_USER_ACTION_STATE = { prompts: [], notifications: [] };
1092
1084
  function upsertPrompt(prompts, req) {
1093
1085
  const active = { ...req, status: "pending" };
@@ -1379,6 +1371,19 @@ function useChatV2(config, callbacks = {}) {
1379
1371
  },
1380
1372
  [setPromptStatus]
1381
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
+ );
1382
1387
  const dismissNotification = useCallback((id) => {
1383
1388
  setUserActionState((prev) => ({
1384
1389
  ...prev,
@@ -1458,6 +1463,7 @@ function useChatV2(config, callbacks = {}) {
1458
1463
  submitUserAction: submitUserAction2,
1459
1464
  cancelUserAction: cancelUserAction2,
1460
1465
  resendUserAction: resendUserAction2,
1466
+ expireUserAction: expireUserAction2,
1461
1467
  dismissNotification
1462
1468
  };
1463
1469
  }
@@ -4641,6 +4647,7 @@ var MessageListV2 = forwardRef(
4641
4647
  onSubmitUserAction,
4642
4648
  onCancelUserAction,
4643
4649
  onResendUserAction,
4650
+ onExpireUserAction,
4644
4651
  onDismissNotification,
4645
4652
  onSubmitFeedback,
4646
4653
  typingSpeed = 4
@@ -4652,6 +4659,7 @@ var MessageListV2 = forwardRef(
4652
4659
  const isNearBottomRef = useRef(true);
4653
4660
  const [showScrollBtn, setShowScrollBtn] = useState(false);
4654
4661
  const [expiredPromptViewState, setExpiredPromptViewState] = useState({});
4662
+ const expiredUserActionIdsRef = useRef(/* @__PURE__ */ new Set());
4655
4663
  const prevCountRef = useRef(messages.length);
4656
4664
  const pauseStickUntilUserMessageRef = useRef(false);
4657
4665
  const followingBottomRef = useRef(true);
@@ -4689,7 +4697,7 @@ var MessageListV2 = forwardRef(
4689
4697
  ].join(PROMPT_KEY_SEPARATOR);
4690
4698
  }, [isStreaming, messages, notifications, userActionPrompts]);
4691
4699
  const handleUserActionExpired = useCallback(
4692
- (promptKey) => {
4700
+ (promptKey, userActionId) => {
4693
4701
  setExpiredPromptViewState((prev) => {
4694
4702
  if (prev[promptKey]) return prev;
4695
4703
  return {
@@ -4697,8 +4705,13 @@ var MessageListV2 = forwardRef(
4697
4705
  [promptKey]: { baseline: messageActivityFingerprint, hidden: false }
4698
4706
  };
4699
4707
  });
4708
+ if (!expiredUserActionIdsRef.current.has(userActionId)) {
4709
+ expiredUserActionIdsRef.current.add(userActionId);
4710
+ void onExpireUserAction?.(userActionId)?.catch(() => {
4711
+ });
4712
+ }
4700
4713
  },
4701
- [messageActivityFingerprint]
4714
+ [messageActivityFingerprint, onExpireUserAction]
4702
4715
  );
4703
4716
  useEffect(() => {
4704
4717
  setExpiredPromptViewState((prev) => {
@@ -4717,6 +4730,12 @@ var MessageListV2 = forwardRef(
4717
4730
  }, [messageActivityFingerprint]);
4718
4731
  useEffect(() => {
4719
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
+ }
4720
4739
  setExpiredPromptViewState((prev) => {
4721
4740
  let changed = false;
4722
4741
  const next = {};
@@ -4882,7 +4901,7 @@ var MessageListV2 = forwardRef(
4882
4901
  onSubmit: onSubmitUserAction ?? noop,
4883
4902
  onCancel: onCancelUserAction ?? noop,
4884
4903
  onResend: onResendUserAction ?? noop,
4885
- onExpired: () => handleUserActionExpired(promptKey)
4904
+ onExpired: () => handleUserActionExpired(promptKey, prompt.userActionId)
4886
4905
  },
4887
4906
  promptKey
4888
4907
  );
@@ -6094,6 +6113,7 @@ var PaymanChatInner = forwardRef(function PaymanChatInner2({
6094
6113
  const submitUserAction2 = chat.submitUserAction ?? NOOP_ASYNC;
6095
6114
  const cancelUserAction2 = chat.cancelUserAction ?? NOOP_ASYNC;
6096
6115
  const resendUserAction2 = chat.resendUserAction ?? NOOP_ASYNC;
6116
+ const expireUserAction2 = chat.expireUserAction ?? NOOP_ASYNC;
6097
6117
  const dismissNotification = chat.dismissNotification ?? NOOP;
6098
6118
  const isUserActionSupported = typeof chat.submitUserAction === "function" && typeof chat.cancelUserAction === "function" && typeof chat.resendUserAction === "function";
6099
6119
  const {
@@ -6494,6 +6514,7 @@ var PaymanChatInner = forwardRef(function PaymanChatInner2({
6494
6514
  onSubmitUserAction: isUserActionSupported ? submitUserAction2 : void 0,
6495
6515
  onCancelUserAction: isUserActionSupported ? cancelUserAction2 : void 0,
6496
6516
  onResendUserAction: isUserActionSupported ? resendUserAction2 : void 0,
6517
+ onExpireUserAction: isUserActionSupported ? expireUserAction2 : void 0,
6497
6518
  onDismissNotification: dismissNotification,
6498
6519
  onSubmitFeedback: handleSubmitFeedback
6499
6520
  }
@@ -6577,6 +6598,6 @@ var PaymanChat = forwardRef(
6577
6598
  }
6578
6599
  );
6579
6600
 
6580
- 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 };
6581
6602
  //# sourceMappingURL=index.mjs.map
6582
6603
  //# sourceMappingURL=index.mjs.map