@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 +3 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +60 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -27
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js.map +1 -1
- package/package.json +2 -2
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
|
-
|
|
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.
|
|
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:
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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(
|