@paymanai/payman-ask-sdk 1.2.12 → 1.2.14

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/README.md CHANGED
@@ -41,6 +41,7 @@ function MyApp() {
41
41
  streamEndpoint: "/api/playground/ask/stream", // Important!
42
42
  },
43
43
  workflowName: "my-workflow",
44
+ userId: "user-123", // Required for chatStore and activeStreamStore
44
45
  workflowVersion: 1,
45
46
  stage: "DEV",
46
47
  sessionParams: {
@@ -66,6 +67,7 @@ function MyApp() {
66
67
  authToken: "your-api-key", // API key with stage configured
67
68
  },
68
69
  workflowName: "my-workflow",
70
+ userId: "user-123", // Required for chatStore and activeStreamStore
69
71
  stage: "PROD",
70
72
  sessionParams: {
71
73
  id: "user-123",
@@ -109,6 +111,7 @@ function MyApp() {
109
111
  |----------|------|----------|-------------|
110
112
  | `api` | `APIConfig` | ✅ | API configuration |
111
113
  | `workflowName` | `string` | ✅ | Workflow name |
114
+ | `userId` | `string` | ✅ | User ID for chatStore and activeStreamStore (context store messages management) |
112
115
  | `workflowVersion` | `number` | | Workflow version (default: 1) |
113
116
  | `stage` | `WorkflowStage` | | Stage (DEV/SANDBOX/PROD) |
114
117
  | `sessionParams` | `SessionParams` | | User session info |
package/dist/index.d.mts CHANGED
@@ -71,6 +71,8 @@ type ChatConfig = {
71
71
  api: APIConfig;
72
72
  /** Workflow name */
73
73
  workflowName: string;
74
+ /** User ID for chatStore and activeStreamStore — required for context store messages management */
75
+ userId?: string;
74
76
  /** Workflow version */
75
77
  workflowVersion?: number;
76
78
  /** Stage/Environment */
@@ -163,6 +165,12 @@ type PaymanChatProps = {
163
165
  style?: React__default.CSSProperties;
164
166
  /** Custom children to render (e.g., header) */
165
167
  children?: React__default.ReactNode;
168
+ /** Called when the user scrolls to the top — use to load older messages */
169
+ onLoadMoreMessages?: () => void;
170
+ /** Show a loading spinner at the top of the list while fetching older messages */
171
+ isLoadingMoreMessages?: boolean;
172
+ /** Whether there are more messages to load (hides the spinner/trigger when false) */
173
+ hasMoreMessages?: boolean;
166
174
  };
167
175
  type ChatInputProps = {
168
176
  /** Input value */
@@ -251,6 +259,12 @@ type MessageListProps = {
251
259
  }) => void;
252
260
  /** Custom class name */
253
261
  className?: string;
262
+ /** Called when the user scrolls to the top — use to load older messages */
263
+ onLoadMoreMessages?: () => void;
264
+ /** Show a loading spinner at the top while fetching older messages */
265
+ isLoadingMoreMessages?: boolean;
266
+ /** Whether there are more messages to load */
267
+ hasMoreMessages?: boolean;
254
268
  };
255
269
  type MessageRowProps = {
256
270
  /** Message to display */
@@ -395,7 +409,7 @@ type UserActionModalProps = {
395
409
  clearOtpTrigger: number;
396
410
  };
397
411
 
398
- declare function PaymanChat({ config, callbacks, className, style, children, }: PaymanChatProps): react_jsx_runtime.JSX.Element;
412
+ declare function PaymanChat({ config, callbacks, className, style, children, onLoadMoreMessages, isLoadingMoreMessages, hasMoreMessages, }: PaymanChatProps): react_jsx_runtime.JSX.Element;
399
413
 
400
414
  interface PaymanChatContextValue {
401
415
  /**
@@ -406,6 +420,10 @@ interface PaymanChatContextValue {
406
420
  * Clear all messages without resetting session ID
407
421
  */
408
422
  clearMessages: () => void;
423
+ /**
424
+ * Prepend older messages to the top of the list (e.g. from history pagination)
425
+ */
426
+ prependMessages: (messages: MessageDisplay[]) => void;
409
427
  /**
410
428
  * Cancel current streaming operation
411
429
  */
package/dist/index.d.ts CHANGED
@@ -71,6 +71,8 @@ type ChatConfig = {
71
71
  api: APIConfig;
72
72
  /** Workflow name */
73
73
  workflowName: string;
74
+ /** User ID for chatStore and activeStreamStore — required for context store messages management */
75
+ userId?: string;
74
76
  /** Workflow version */
75
77
  workflowVersion?: number;
76
78
  /** Stage/Environment */
@@ -163,6 +165,12 @@ type PaymanChatProps = {
163
165
  style?: React__default.CSSProperties;
164
166
  /** Custom children to render (e.g., header) */
165
167
  children?: React__default.ReactNode;
168
+ /** Called when the user scrolls to the top — use to load older messages */
169
+ onLoadMoreMessages?: () => void;
170
+ /** Show a loading spinner at the top of the list while fetching older messages */
171
+ isLoadingMoreMessages?: boolean;
172
+ /** Whether there are more messages to load (hides the spinner/trigger when false) */
173
+ hasMoreMessages?: boolean;
166
174
  };
167
175
  type ChatInputProps = {
168
176
  /** Input value */
@@ -251,6 +259,12 @@ type MessageListProps = {
251
259
  }) => void;
252
260
  /** Custom class name */
253
261
  className?: string;
262
+ /** Called when the user scrolls to the top — use to load older messages */
263
+ onLoadMoreMessages?: () => void;
264
+ /** Show a loading spinner at the top while fetching older messages */
265
+ isLoadingMoreMessages?: boolean;
266
+ /** Whether there are more messages to load */
267
+ hasMoreMessages?: boolean;
254
268
  };
255
269
  type MessageRowProps = {
256
270
  /** Message to display */
@@ -395,7 +409,7 @@ type UserActionModalProps = {
395
409
  clearOtpTrigger: number;
396
410
  };
397
411
 
398
- declare function PaymanChat({ config, callbacks, className, style, children, }: PaymanChatProps): react_jsx_runtime.JSX.Element;
412
+ declare function PaymanChat({ config, callbacks, className, style, children, onLoadMoreMessages, isLoadingMoreMessages, hasMoreMessages, }: PaymanChatProps): react_jsx_runtime.JSX.Element;
399
413
 
400
414
  interface PaymanChatContextValue {
401
415
  /**
@@ -406,6 +420,10 @@ interface PaymanChatContextValue {
406
420
  * Clear all messages without resetting session ID
407
421
  */
408
422
  clearMessages: () => void;
423
+ /**
424
+ * Prepend older messages to the top of the list (e.g. from history pagination)
425
+ */
426
+ prependMessages: (messages: MessageDisplay[]) => void;
409
427
  /**
410
428
  * Cancel current streaming operation
411
429
  */
package/dist/index.js CHANGED
@@ -771,6 +771,7 @@ function MessageRowSkeleton({
771
771
  );
772
772
  }
773
773
  var SCROLL_THRESHOLD = 150;
774
+ var LOAD_MORE_THRESHOLD = 80;
774
775
  function MessageList({
775
776
  messages,
776
777
  isLoading = false,
@@ -790,12 +791,17 @@ function MessageList({
790
791
  streamingStepsText,
791
792
  completedStepsText,
792
793
  onExecutionTraceClick,
793
- className
794
+ className,
795
+ onLoadMoreMessages,
796
+ isLoadingMoreMessages = false,
797
+ hasMoreMessages = false
794
798
  }) {
795
799
  const scrollRef = react.useRef(null);
796
800
  const isNearBottomRef = react.useRef(true);
797
801
  const [showScrollBtn, setShowScrollBtn] = react.useState(false);
798
802
  const prevMessageCountRef = react.useRef(messages.length);
803
+ const scrollHeightBeforePrependRef = react.useRef(null);
804
+ const firstMessageIdRef = react.useRef(messages[0]?.id);
799
805
  const getDistanceFromBottom = react.useCallback(() => {
800
806
  const el = scrollRef.current;
801
807
  if (!el) return 0;
@@ -807,11 +813,27 @@ function MessageList({
807
813
  el.scrollTo({ top: el.scrollHeight, behavior });
808
814
  }, []);
809
815
  const handleScroll = react.useCallback(() => {
816
+ const el = scrollRef.current;
817
+ if (!el) return;
810
818
  const distance = getDistanceFromBottom();
811
819
  const nearBottom = distance <= SCROLL_THRESHOLD;
812
820
  isNearBottomRef.current = nearBottom;
813
821
  setShowScrollBtn(!nearBottom);
814
- }, [getDistanceFromBottom]);
822
+ if (el.scrollTop <= LOAD_MORE_THRESHOLD && hasMoreMessages && !isLoadingMoreMessages && onLoadMoreMessages) {
823
+ scrollHeightBeforePrependRef.current = el.scrollHeight;
824
+ onLoadMoreMessages();
825
+ }
826
+ }, [getDistanceFromBottom, hasMoreMessages, isLoadingMoreMessages, onLoadMoreMessages]);
827
+ react.useLayoutEffect(() => {
828
+ const el = scrollRef.current;
829
+ const prevHeight = scrollHeightBeforePrependRef.current;
830
+ const newFirstId = messages[0]?.id;
831
+ if (el && prevHeight !== null && newFirstId !== firstMessageIdRef.current) {
832
+ el.scrollTop = el.scrollHeight - prevHeight;
833
+ scrollHeightBeforePrependRef.current = null;
834
+ }
835
+ firstMessageIdRef.current = newFirstId;
836
+ }, [messages]);
815
837
  react.useEffect(() => {
816
838
  const prevCount = prevMessageCountRef.current;
817
839
  prevMessageCountRef.current = messages.length;
@@ -922,34 +944,37 @@ function MessageList({
922
944
  className
923
945
  ),
924
946
  children: [
925
- /* @__PURE__ */ jsxRuntime.jsx(
947
+ /* @__PURE__ */ jsxRuntime.jsxs(
926
948
  "div",
927
949
  {
928
950
  className: cn(
929
951
  "space-y-4",
930
952
  layout === "centered" ? "max-w-2xl mx-auto px-4 py-6" : "p-4"
931
953
  ),
932
- children: messages.map((message) => /* @__PURE__ */ jsxRuntime.jsx(
933
- MessageRow,
934
- {
935
- message,
936
- stage,
937
- animated,
938
- showAgentName,
939
- agentName,
940
- showAvatars,
941
- showUserAvatar,
942
- showAssistantAvatar,
943
- layout,
944
- showTimestamps,
945
- showExecutionSteps,
946
- showStreamingDot,
947
- streamingStepsText,
948
- completedStepsText,
949
- onExecutionTraceClick
950
- },
951
- message.id
952
- ))
954
+ children: [
955
+ isLoadingMoreMessages && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-5 rounded-full border-2 border-muted-foreground/30 border-t-muted-foreground animate-spin" }) }),
956
+ messages.map((message) => /* @__PURE__ */ jsxRuntime.jsx(
957
+ MessageRow,
958
+ {
959
+ message,
960
+ stage,
961
+ animated,
962
+ showAgentName,
963
+ agentName,
964
+ showAvatars,
965
+ showUserAvatar,
966
+ showAssistantAvatar,
967
+ layout,
968
+ showTimestamps,
969
+ showExecutionSteps,
970
+ showStreamingDot,
971
+ streamingStepsText,
972
+ completedStepsText,
973
+ onExecutionTraceClick
974
+ },
975
+ message.id
976
+ ))
977
+ ]
953
978
  }
954
979
  ),
955
980
  showScrollBtn && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sticky bottom-0 z-20 flex justify-center pb-3 -mt-11", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1429,7 +1454,10 @@ function PaymanChat({
1429
1454
  callbacks = {},
1430
1455
  className,
1431
1456
  style,
1432
- children
1457
+ children,
1458
+ onLoadMoreMessages,
1459
+ isLoadingMoreMessages = false,
1460
+ hasMoreMessages = false
1433
1461
  }) {
1434
1462
  const [inputValue, setInputValue] = react.useState("");
1435
1463
  const prevInputValueRef = react.useRef(inputValue);
@@ -1440,6 +1468,7 @@ function PaymanChat({
1440
1468
  isWaitingForResponse,
1441
1469
  resetSession,
1442
1470
  clearMessages,
1471
+ prependMessages,
1443
1472
  cancelStream,
1444
1473
  getSessionId,
1445
1474
  getMessages
@@ -1476,6 +1505,7 @@ function PaymanChat({
1476
1505
  () => ({
1477
1506
  resetSession,
1478
1507
  clearMessages,
1508
+ prependMessages,
1479
1509
  cancelStream,
1480
1510
  getSessionId,
1481
1511
  getMessages,
@@ -1484,6 +1514,7 @@ function PaymanChat({
1484
1514
  [
1485
1515
  resetSession,
1486
1516
  clearMessages,
1517
+ prependMessages,
1487
1518
  cancelStream,
1488
1519
  getSessionId,
1489
1520
  getMessages,
@@ -1601,7 +1632,10 @@ function PaymanChat({
1601
1632
  showStreamingDot,
1602
1633
  streamingStepsText,
1603
1634
  completedStepsText,
1604
- onExecutionTraceClick
1635
+ onExecutionTraceClick,
1636
+ onLoadMoreMessages,
1637
+ isLoadingMoreMessages,
1638
+ hasMoreMessages
1605
1639
  }
1606
1640
  ),
1607
1641
  hasAskPermission && /* @__PURE__ */ jsxRuntime.jsx(