@paymanai/payman-ask-sdk 1.2.13 → 1.2.15
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 +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.js +30 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -22
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +1 -12
- package/dist/index.native.js.map +1 -1
- package/dist/styles.css +6 -0
- package/dist/styles.css.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useChat, useVoice } from '@paymanai/payman-typescript-ask-sdk';
|
|
2
2
|
export { cancelUserAction, generateId, resendUserAction, streamWorkflowEvents, submitUserAction, useChat, useVoice } from '@paymanai/payman-typescript-ask-sdk';
|
|
3
|
-
import { createContext,
|
|
3
|
+
import { createContext, forwardRef, useState, useRef, useMemo, useImperativeHandle, useEffect, useCallback, useLayoutEffect, useContext } from 'react';
|
|
4
4
|
import { clsx } from 'clsx';
|
|
5
5
|
import { twMerge } from 'tailwind-merge';
|
|
6
6
|
import { motion, AnimatePresence } from 'framer-motion';
|
|
@@ -70,6 +70,8 @@ function ChatInput({
|
|
|
70
70
|
isRecording = false
|
|
71
71
|
}) {
|
|
72
72
|
const textareaRef = useRef(null);
|
|
73
|
+
const containerRef = useRef(null);
|
|
74
|
+
const prevWaitingRef = useRef(isWaitingForResponse);
|
|
73
75
|
useEffect(() => {
|
|
74
76
|
if (textareaRef.current) {
|
|
75
77
|
textareaRef.current.style.height = "auto";
|
|
@@ -81,6 +83,21 @@ function ChatInput({
|
|
|
81
83
|
)}px`;
|
|
82
84
|
}
|
|
83
85
|
}, [value]);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
requestAnimationFrame(() => {
|
|
88
|
+
textareaRef.current?.focus();
|
|
89
|
+
});
|
|
90
|
+
}, []);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
const wasWaiting = prevWaitingRef.current;
|
|
93
|
+
prevWaitingRef.current = isWaitingForResponse;
|
|
94
|
+
if (wasWaiting && !isWaitingForResponse) {
|
|
95
|
+
requestAnimationFrame(() => {
|
|
96
|
+
textareaRef.current?.focus();
|
|
97
|
+
containerRef.current?.scrollIntoView({ block: "end", behavior: "smooth" });
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}, [isWaitingForResponse]);
|
|
84
101
|
const handleKeyDown = (e) => {
|
|
85
102
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
86
103
|
e.preventDefault();
|
|
@@ -88,7 +105,6 @@ function ChatInput({
|
|
|
88
105
|
}
|
|
89
106
|
};
|
|
90
107
|
const isInputDisabled = disabled || isWaitingForResponse;
|
|
91
|
-
const showPauseButton = isWaitingForResponse && onPause;
|
|
92
108
|
const showVoiceButton = enableVoice && onVoicePress != null;
|
|
93
109
|
const isVoiceButtonDisabled = isWaitingForResponse || !voiceAvailable || !isSessionParamsConfigured;
|
|
94
110
|
const canSend = !isInputDisabled && !!value.trim();
|
|
@@ -100,6 +116,7 @@ function ChatInput({
|
|
|
100
116
|
return /* @__PURE__ */ jsx(
|
|
101
117
|
"div",
|
|
102
118
|
{
|
|
119
|
+
ref: containerRef,
|
|
103
120
|
className: cn("flex-shrink-0 w-full", className),
|
|
104
121
|
style: { flexShrink: 0 },
|
|
105
122
|
children: /* @__PURE__ */ jsx("div", { className: "px-3 pb-3 pt-1.5 w-full", children: /* @__PURE__ */ jsx("div", { className: "relative w-full max-w-2xl mx-auto", children: /* @__PURE__ */ jsxs(
|
|
@@ -169,22 +186,7 @@ function ChatInput({
|
|
|
169
186
|
]
|
|
170
187
|
}
|
|
171
188
|
),
|
|
172
|
-
|
|
173
|
-
"button",
|
|
174
|
-
{
|
|
175
|
-
type: "button",
|
|
176
|
-
onClick: onPause,
|
|
177
|
-
className: cn(
|
|
178
|
-
"flex items-center justify-center",
|
|
179
|
-
"w-8 h-8 rounded-full",
|
|
180
|
-
"payman-chat-input-btn-pause",
|
|
181
|
-
"hover:opacity-90 active:scale-95",
|
|
182
|
-
"transition-all duration-150"
|
|
183
|
-
),
|
|
184
|
-
"aria-label": "Stop response",
|
|
185
|
-
children: /* @__PURE__ */ jsx(Square, { className: "w-3.5 h-3.5", fill: "currentColor" })
|
|
186
|
-
}
|
|
187
|
-
) : /* @__PURE__ */ jsx(
|
|
189
|
+
/* @__PURE__ */ jsx(
|
|
188
190
|
"button",
|
|
189
191
|
{
|
|
190
192
|
type: "button",
|
|
@@ -611,7 +613,7 @@ function markdownComponents(_isError) {
|
|
|
611
613
|
tbody: ({ children }) => /* @__PURE__ */ jsx("tbody", { className: "[&_tr:last-child]:border-0", children }),
|
|
612
614
|
tr: ({ children }) => /* @__PURE__ */ jsx("tr", { className: "border-b transition-colors payman-agent-tr", children }),
|
|
613
615
|
th: ({ children }) => /* @__PURE__ */ jsx("th", { className: "h-10 px-3 text-left align-middle font-medium whitespace-nowrap text-xs", children }),
|
|
614
|
-
td: ({ children }) => /* @__PURE__ */ jsx("td", { className: "p-3 align-middle text-sm", children })
|
|
616
|
+
td: ({ children }) => /* @__PURE__ */ jsx("td", { className: "p-3 align-middle text-sm whitespace-nowrap", children })
|
|
615
617
|
};
|
|
616
618
|
}
|
|
617
619
|
function UserMessage({
|
|
@@ -1443,7 +1445,7 @@ var DEFAULT_USER_ACTION_STATE = {
|
|
|
1443
1445
|
};
|
|
1444
1446
|
var NOOP_ASYNC = async () => {
|
|
1445
1447
|
};
|
|
1446
|
-
|
|
1448
|
+
var PaymanChat = forwardRef(function PaymanChat2({
|
|
1447
1449
|
config,
|
|
1448
1450
|
callbacks = {},
|
|
1449
1451
|
className,
|
|
@@ -1452,7 +1454,7 @@ function PaymanChat({
|
|
|
1452
1454
|
onLoadMoreMessages,
|
|
1453
1455
|
isLoadingMoreMessages = false,
|
|
1454
1456
|
hasMoreMessages = false
|
|
1455
|
-
}) {
|
|
1457
|
+
}, ref) {
|
|
1456
1458
|
const [inputValue, setInputValue] = useState("");
|
|
1457
1459
|
const prevInputValueRef = useRef(inputValue);
|
|
1458
1460
|
const chat = useChat(config, callbacks);
|
|
@@ -1515,6 +1517,13 @@ function PaymanChat({
|
|
|
1515
1517
|
isWaitingForResponse
|
|
1516
1518
|
]
|
|
1517
1519
|
);
|
|
1520
|
+
useImperativeHandle(ref, () => ({
|
|
1521
|
+
resetSession,
|
|
1522
|
+
clearMessages,
|
|
1523
|
+
cancelStream,
|
|
1524
|
+
getSessionId,
|
|
1525
|
+
getMessages
|
|
1526
|
+
}), [resetSession, clearMessages, cancelStream, getSessionId, getMessages]);
|
|
1518
1527
|
const { onExecutionTraceClick } = callbacks;
|
|
1519
1528
|
const {
|
|
1520
1529
|
placeholder = "Type your message...",
|
|
@@ -1666,7 +1675,7 @@ function PaymanChat({
|
|
|
1666
1675
|
]
|
|
1667
1676
|
}
|
|
1668
1677
|
) });
|
|
1669
|
-
}
|
|
1678
|
+
});
|
|
1670
1679
|
|
|
1671
1680
|
export { PaymanChat, PaymanChatContext, cn, formatDate, usePaymanChat };
|
|
1672
1681
|
//# sourceMappingURL=index.mjs.map
|