@melony/react 0.1.38 → 0.1.40
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.cjs +85 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -26
- package/dist/index.d.ts +19 -26
- package/dist/index.js +87 -82
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React11 = require('react');
|
|
4
|
+
var melony = require('melony');
|
|
4
5
|
var react = require('nuqs/adapters/react');
|
|
5
6
|
var reactQuery = require('@tanstack/react-query');
|
|
6
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -42,31 +43,6 @@ var React11__namespace = /*#__PURE__*/_interopNamespace(React11);
|
|
|
42
43
|
var ICONS__namespace = /*#__PURE__*/_interopNamespace(ICONS);
|
|
43
44
|
|
|
44
45
|
// src/providers/melony-provider.tsx
|
|
45
|
-
|
|
46
|
-
// src/lib/group-events-to-messages.ts
|
|
47
|
-
function groupEventsToMessages(events) {
|
|
48
|
-
if (events.length === 0) return [];
|
|
49
|
-
const messages = [];
|
|
50
|
-
let currentMessage = null;
|
|
51
|
-
for (const event of events) {
|
|
52
|
-
const role = event.role || "assistant";
|
|
53
|
-
const runId = event.runId;
|
|
54
|
-
if (!currentMessage || currentMessage.role !== role || runId && currentMessage.runId && runId !== currentMessage.runId) {
|
|
55
|
-
currentMessage = {
|
|
56
|
-
role,
|
|
57
|
-
content: [event],
|
|
58
|
-
runId
|
|
59
|
-
};
|
|
60
|
-
messages.push(currentMessage);
|
|
61
|
-
} else {
|
|
62
|
-
currentMessage.content.push(event);
|
|
63
|
-
if (!currentMessage.runId && runId) {
|
|
64
|
-
currentMessage.runId = runId;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return messages;
|
|
69
|
-
}
|
|
70
46
|
var MelonyContext = React11.createContext(
|
|
71
47
|
void 0
|
|
72
48
|
);
|
|
@@ -164,7 +140,7 @@ var MelonyContextProviderInner = ({
|
|
|
164
140
|
const value = React11.useMemo(
|
|
165
141
|
() => ({
|
|
166
142
|
...state,
|
|
167
|
-
messages:
|
|
143
|
+
messages: melony.convertEventsToMessages(state.events),
|
|
168
144
|
sendEvent,
|
|
169
145
|
reset,
|
|
170
146
|
client,
|
|
@@ -1779,12 +1755,39 @@ var Image = ({
|
|
|
1779
1755
|
src,
|
|
1780
1756
|
alt,
|
|
1781
1757
|
size = "sm",
|
|
1758
|
+
groupId,
|
|
1782
1759
|
className,
|
|
1783
1760
|
style
|
|
1784
1761
|
}) => {
|
|
1785
1762
|
const [hasError, setHasError] = React11.useState(false);
|
|
1786
1763
|
const [isLoading, setIsLoading] = React11.useState(true);
|
|
1787
1764
|
const [open, setOpen] = React11.useState(false);
|
|
1765
|
+
const [currentIndex, setCurrentIndex] = React11.useState(0);
|
|
1766
|
+
const [gallery, setGallery] = React11.useState([]);
|
|
1767
|
+
const triggerRef = React11.useRef(null);
|
|
1768
|
+
React11.useEffect(() => {
|
|
1769
|
+
if (open && triggerRef.current) {
|
|
1770
|
+
let parent = triggerRef.current.parentElement;
|
|
1771
|
+
while (parent && parent.parentElement && parent.parentElement.children.length === 1) {
|
|
1772
|
+
parent = parent.parentElement;
|
|
1773
|
+
}
|
|
1774
|
+
const container = parent?.parentElement;
|
|
1775
|
+
if (container) {
|
|
1776
|
+
const foundImgs = Array.from(container.querySelectorAll("img")).map((img) => ({
|
|
1777
|
+
src: img.getAttribute("src") || "",
|
|
1778
|
+
alt: img.getAttribute("alt") || ""
|
|
1779
|
+
})).filter((v, i, a) => a.findIndex((t) => t.src === v.src) === i);
|
|
1780
|
+
setGallery(foundImgs);
|
|
1781
|
+
const idx = foundImgs.findIndex((img) => img.src === src);
|
|
1782
|
+
setCurrentIndex(idx >= 0 ? idx : 0);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
}, [open, src]);
|
|
1786
|
+
const navigate = (dir) => {
|
|
1787
|
+
setCurrentIndex((prev) => (prev + dir + gallery.length) % gallery.length);
|
|
1788
|
+
};
|
|
1789
|
+
const currentImage = gallery[currentIndex] || { src, alt };
|
|
1790
|
+
const hasMultiple = gallery.length > 1;
|
|
1788
1791
|
const sizes = {
|
|
1789
1792
|
sm: "h-11",
|
|
1790
1793
|
md: "h-22",
|
|
@@ -1815,7 +1818,11 @@ var Image = ({
|
|
|
1815
1818
|
/* @__PURE__ */ jsxRuntime.jsx(DialogTrigger, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1816
1819
|
"div",
|
|
1817
1820
|
{
|
|
1818
|
-
|
|
1821
|
+
ref: triggerRef,
|
|
1822
|
+
className: cn(
|
|
1823
|
+
"relative overflow-hidden rounded-md border cursor-pointer",
|
|
1824
|
+
className
|
|
1825
|
+
),
|
|
1819
1826
|
style,
|
|
1820
1827
|
children: [
|
|
1821
1828
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1839,36 +1846,47 @@ var Image = ({
|
|
|
1839
1846
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1840
1847
|
DialogContent,
|
|
1841
1848
|
{
|
|
1842
|
-
className: "max-w-[90vw] max-h-[90vh] p-0 bg-transparent border-none shadow-none",
|
|
1849
|
+
className: "max-w-[90vw] max-h-[90vh] p-0 bg-transparent border-none shadow-none outline-none",
|
|
1843
1850
|
onClick: (e) => e.stopPropagation(),
|
|
1844
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex items-center justify-center", children: [
|
|
1845
|
-
/* @__PURE__ */ jsxRuntime.jsx(DialogClose, { className: "absolute -top-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
"
|
|
1855
|
-
{
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1851
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex items-center justify-center group/lightbox", children: [
|
|
1852
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogClose, { className: "absolute -top-12 right-0 text-white hover:text-gray-300 transition-colors z-50 bg-black/50 rounded-full p-2", children: /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconX, { size: 20 }) }),
|
|
1853
|
+
hasMultiple && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1854
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1855
|
+
"button",
|
|
1856
|
+
{
|
|
1857
|
+
onClick: (e) => {
|
|
1858
|
+
e.stopPropagation();
|
|
1859
|
+
navigate(-1);
|
|
1860
|
+
},
|
|
1861
|
+
className: "absolute left-4 z-50 p-3 bg-black/40 hover:bg-black/60 text-white rounded-full transition-all opacity-0 group-hover/lightbox:opacity-100",
|
|
1862
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconChevronLeft, { size: 28 })
|
|
1863
|
+
}
|
|
1864
|
+
),
|
|
1865
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1866
|
+
"button",
|
|
1867
|
+
{
|
|
1868
|
+
onClick: (e) => {
|
|
1869
|
+
e.stopPropagation();
|
|
1870
|
+
navigate(1);
|
|
1871
|
+
},
|
|
1872
|
+
className: "absolute right-4 z-50 p-3 bg-black/40 hover:bg-black/60 text-white rounded-full transition-all opacity-0 group-hover/lightbox:opacity-100",
|
|
1873
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconChevronRight, { size: 28 })
|
|
1874
|
+
}
|
|
1875
|
+
)
|
|
1876
|
+
] }),
|
|
1864
1877
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1865
1878
|
"img",
|
|
1866
1879
|
{
|
|
1867
|
-
src,
|
|
1868
|
-
alt: alt || "Enlarged image",
|
|
1869
|
-
className: "max-w-full max-h-[
|
|
1880
|
+
src: currentImage.src,
|
|
1881
|
+
alt: currentImage.alt || alt || "Enlarged image",
|
|
1882
|
+
className: "max-w-full max-h-[85vh] object-contain rounded-lg shadow-2xl"
|
|
1870
1883
|
}
|
|
1871
|
-
)
|
|
1884
|
+
),
|
|
1885
|
+
hasMultiple && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute -bottom-10 left-1/2 -translate-x-1/2 text-white bg-black/50 px-3 py-1 rounded-full text-sm font-medium", children: [
|
|
1886
|
+
currentIndex + 1,
|
|
1887
|
+
" / ",
|
|
1888
|
+
gallery.length
|
|
1889
|
+
] })
|
|
1872
1890
|
] })
|
|
1873
1891
|
}
|
|
1874
1892
|
)
|
|
@@ -2833,25 +2851,16 @@ function MessageContent({ events }) {
|
|
|
2833
2851
|
}
|
|
2834
2852
|
function MessageBubble({ message }) {
|
|
2835
2853
|
const isUser = message.role === "user";
|
|
2836
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2854
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex flex-col", isUser ? "items-end" : "items-start"), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2837
2855
|
"div",
|
|
2838
2856
|
{
|
|
2839
2857
|
className: cn(
|
|
2840
|
-
"flex flex-col",
|
|
2841
|
-
isUser ? "
|
|
2858
|
+
"flex flex-col items-start max-w-[85%] rounded-2xl px-4 py-2 space-y-4 whitespace-pre-wrap",
|
|
2859
|
+
isUser ? "bg-primary text-primary-foreground" : "px-0 py-0 text-foreground"
|
|
2842
2860
|
),
|
|
2843
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2844
|
-
"div",
|
|
2845
|
-
{
|
|
2846
|
-
className: cn(
|
|
2847
|
-
"flex flex-col items-start max-w-[85%] rounded-2xl px-4 py-2 space-y-4 whitespace-pre-wrap",
|
|
2848
|
-
isUser ? "bg-primary text-primary-foreground" : "px-0 py-0 text-foreground"
|
|
2849
|
-
),
|
|
2850
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(MessageContent, { events: message.content })
|
|
2851
|
-
}
|
|
2852
|
-
)
|
|
2861
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(MessageContent, { events: message.content })
|
|
2853
2862
|
}
|
|
2854
|
-
);
|
|
2863
|
+
) });
|
|
2855
2864
|
}
|
|
2856
2865
|
function LoadingIndicator({ status }) {
|
|
2857
2866
|
const [isExpanded, setIsExpanded] = React11.useState(false);
|
|
@@ -2891,7 +2900,6 @@ function MessageList({
|
|
|
2891
2900
|
const lastMessage = messages[messages.length - 1];
|
|
2892
2901
|
return lastMessage.content.some((event) => event.type === "text-delta");
|
|
2893
2902
|
}, [messages, isLoading]);
|
|
2894
|
-
console.log("MESSAGES", messages);
|
|
2895
2903
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
2896
2904
|
messages.map((message, index) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message }, index)),
|
|
2897
2905
|
isLoading && !isTextStreaming && /* @__PURE__ */ jsxRuntime.jsx(LoadingIndicator, { status: loadingStatus }),
|
|
@@ -2931,20 +2939,17 @@ function Thread({
|
|
|
2931
2939
|
const handleSubmit = async (state, overrideInput) => {
|
|
2932
2940
|
const text = (overrideInput ?? input).trim();
|
|
2933
2941
|
const hasFiles = state?.files && Array.isArray(state.files) && state.files.length > 0;
|
|
2934
|
-
|
|
2935
|
-
if (!text && !hasFiles && !hasOptions || isLoading) return;
|
|
2942
|
+
if (!text && !hasFiles || isLoading) return;
|
|
2936
2943
|
if (!overrideInput) setInput("");
|
|
2937
|
-
await sendEvent(
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
state
|
|
2943
|
-
|
|
2944
|
-
threadId: activeThreadId ?? void 0
|
|
2945
|
-
}
|
|
2944
|
+
await sendEvent({
|
|
2945
|
+
type: "text",
|
|
2946
|
+
role: "user",
|
|
2947
|
+
data: { content: text || "" },
|
|
2948
|
+
state: {
|
|
2949
|
+
...state,
|
|
2950
|
+
threadId: activeThreadId ?? void 0
|
|
2946
2951
|
}
|
|
2947
|
-
);
|
|
2952
|
+
});
|
|
2948
2953
|
};
|
|
2949
2954
|
const handleStarterPromptClick = (prompt) => {
|
|
2950
2955
|
if (onStarterPromptClick) {
|
|
@@ -3667,7 +3672,7 @@ var CreateThreadNavItem = ({
|
|
|
3667
3672
|
url: "?"
|
|
3668
3673
|
}
|
|
3669
3674
|
},
|
|
3670
|
-
className: cn(className),
|
|
3675
|
+
className: cn(className, "border roudned-lg"),
|
|
3671
3676
|
children: [
|
|
3672
3677
|
/* @__PURE__ */ jsxRuntime.jsx(ICONS.IconPlus, { className: "size-4" }),
|
|
3673
3678
|
"New chat"
|
|
@@ -3722,7 +3727,6 @@ exports.ThreadPopover = ThreadPopover;
|
|
|
3722
3727
|
exports.ThreadProvider = ThreadProvider;
|
|
3723
3728
|
exports.UIRenderer = UIRenderer;
|
|
3724
3729
|
exports.WelcomeScreen = WelcomeScreen;
|
|
3725
|
-
exports.groupEventsToMessages = groupEventsToMessages;
|
|
3726
3730
|
exports.useAuth = useAuth;
|
|
3727
3731
|
exports.useMelony = useMelony;
|
|
3728
3732
|
exports.useScreenSize = useScreenSize;
|