@meshagent/meshagent-tailwind 0.38.1 → 0.38.3
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/CHANGELOG.md +12 -0
- package/dist/cjs/Chat.d.ts +11 -3
- package/dist/cjs/Chat.js +376 -29
- package/dist/cjs/ChatBotView.d.ts +29 -0
- package/dist/cjs/ChatBotView.js +491 -0
- package/dist/cjs/ChatInput.d.ts +12 -3
- package/dist/cjs/ChatInput.js +143 -44
- package/dist/cjs/ChatThread.d.ts +17 -3
- package/dist/cjs/ChatThread.js +646 -90
- package/dist/cjs/ChatTypingIndicator.d.ts +12 -5
- package/dist/cjs/ChatTypingIndicator.js +104 -13
- package/dist/cjs/FileUploader.d.ts +3 -2
- package/dist/cjs/FileUploader.js +35 -11
- package/dist/cjs/UploadPill.d.ts +2 -2
- package/dist/cjs/UploadPill.js +70 -32
- package/dist/cjs/chat-hooks.d.ts +38 -0
- package/dist/cjs/chat-hooks.js +390 -0
- package/dist/cjs/chat-message.d.ts +11 -0
- package/dist/cjs/chat-message.js +33 -0
- package/dist/cjs/components/ui/button.d.ts +1 -1
- package/dist/cjs/conversation-descriptor.d.ts +59 -0
- package/dist/cjs/conversation-descriptor.js +300 -0
- package/dist/cjs/file-attachment.d.ts +45 -0
- package/dist/cjs/file-attachment.js +171 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/multi-thread-view.d.ts +18 -0
- package/dist/cjs/multi-thread-view.js +88 -0
- package/dist/cjs/tools/ui-toolkit.d.ts +1 -1
- package/dist/cjs/tools/ui-toolkit.js +2 -1
- package/dist/esm/Chat.d.ts +11 -3
- package/dist/esm/Chat.js +378 -31
- package/dist/esm/ChatBotView.d.ts +29 -0
- package/dist/esm/ChatBotView.js +486 -0
- package/dist/esm/ChatInput.d.ts +12 -3
- package/dist/esm/ChatInput.js +143 -34
- package/dist/esm/ChatThread.d.ts +17 -3
- package/dist/esm/ChatThread.js +648 -92
- package/dist/esm/ChatTypingIndicator.d.ts +12 -5
- package/dist/esm/ChatTypingIndicator.js +94 -13
- package/dist/esm/FileUploader.d.ts +3 -2
- package/dist/esm/FileUploader.js +26 -12
- package/dist/esm/UploadPill.d.ts +2 -2
- package/dist/esm/UploadPill.js +60 -32
- package/dist/esm/chat-hooks.d.ts +38 -0
- package/dist/esm/chat-hooks.js +372 -0
- package/dist/esm/chat-message.d.ts +11 -0
- package/dist/esm/chat-message.js +13 -0
- package/dist/esm/components/ui/button.d.ts +1 -1
- package/dist/esm/conversation-descriptor.d.ts +59 -0
- package/dist/esm/conversation-descriptor.js +280 -0
- package/dist/esm/file-attachment.d.ts +45 -0
- package/dist/esm/file-attachment.js +151 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/multi-thread-view.d.ts +18 -0
- package/dist/esm/multi-thread-view.js +68 -0
- package/dist/esm/tools/ui-toolkit.d.ts +1 -1
- package/dist/esm/tools/ui-toolkit.js +2 -1
- package/dist/index.css +1 -1
- package/package.json +3 -3
package/dist/esm/ChatInput.js
CHANGED
|
@@ -1,11 +1,81 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { useRef, useState, useEffect, useMemo, useCallback } from "react";
|
|
3
|
+
import { ArrowUp, LoaderCircle, X } from "lucide-react";
|
|
3
4
|
import { v4 as uuidV4 } from "uuid";
|
|
4
|
-
import { ChatMessage } from "
|
|
5
|
+
import { ChatMessage } from "./chat-message";
|
|
5
6
|
import { Button } from "./components/ui/button";
|
|
6
7
|
import { Textarea } from "./components/ui/textarea";
|
|
7
8
|
import { FileUploader } from "./FileUploader";
|
|
8
9
|
import { UploadPill } from "./UploadPill";
|
|
10
|
+
import { UploadStatus } from "./file-attachment";
|
|
11
|
+
import { cn } from "./lib/utils";
|
|
12
|
+
function useAttachmentStatusVersion(attachments) {
|
|
13
|
+
const [version, setVersion] = useState(0);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const handleChange = () => {
|
|
16
|
+
setVersion((currentVersion) => currentVersion + 1);
|
|
17
|
+
};
|
|
18
|
+
for (const attachment of attachments) {
|
|
19
|
+
attachment.on("change", handleChange);
|
|
20
|
+
}
|
|
21
|
+
return () => {
|
|
22
|
+
for (const attachment of attachments) {
|
|
23
|
+
attachment.off("change", handleChange);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}, [attachments]);
|
|
27
|
+
return version;
|
|
28
|
+
}
|
|
29
|
+
function useAutoResizingTextarea(textareaRef, value) {
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const element = textareaRef.current;
|
|
32
|
+
if (!element) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (value === "") {
|
|
36
|
+
element.style.height = "20px";
|
|
37
|
+
} else {
|
|
38
|
+
element.style.height = "0px";
|
|
39
|
+
element.style.height = `${Math.max(20, Math.min(element.scrollHeight, 160))}px`;
|
|
40
|
+
}
|
|
41
|
+
}, [textareaRef, value]);
|
|
42
|
+
}
|
|
43
|
+
function ComposerActionButton({
|
|
44
|
+
onClick,
|
|
45
|
+
disabled = false,
|
|
46
|
+
showCancelButton = false
|
|
47
|
+
}) {
|
|
48
|
+
if (showCancelButton) {
|
|
49
|
+
return /* @__PURE__ */ jsxs(
|
|
50
|
+
Button,
|
|
51
|
+
{
|
|
52
|
+
type: "button",
|
|
53
|
+
size: "icon",
|
|
54
|
+
variant: "ghost",
|
|
55
|
+
className: cn("relative size-9 rounded-full", disabled && "opacity-55"),
|
|
56
|
+
disabled,
|
|
57
|
+
onClick,
|
|
58
|
+
title: disabled ? "Cancelling" : "Stop",
|
|
59
|
+
children: [
|
|
60
|
+
/* @__PURE__ */ jsx(LoaderCircle, { className: "absolute h-9 w-9 animate-spin text-muted-foreground" }),
|
|
61
|
+
/* @__PURE__ */ jsx("span", { className: "relative inline-flex h-5 w-5 items-center justify-center rounded-full bg-foreground text-background", children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" }) })
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return /* @__PURE__ */ jsx(
|
|
67
|
+
Button,
|
|
68
|
+
{
|
|
69
|
+
type: "button",
|
|
70
|
+
size: "icon",
|
|
71
|
+
className: "size-9 rounded-full shadow-xs",
|
|
72
|
+
disabled,
|
|
73
|
+
onClick,
|
|
74
|
+
title: "Send",
|
|
75
|
+
children: /* @__PURE__ */ jsx(ArrowUp, { className: "h-4 w-4" })
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
9
79
|
function ChatInput({
|
|
10
80
|
onSubmit,
|
|
11
81
|
onFilesSelected,
|
|
@@ -13,61 +83,100 @@ function ChatInput({
|
|
|
13
83
|
setAttachments,
|
|
14
84
|
onTextChange,
|
|
15
85
|
onCancelRequest,
|
|
16
|
-
showCancelButton
|
|
86
|
+
showCancelButton = false,
|
|
87
|
+
placeholder = "Message the room",
|
|
88
|
+
disabled = false,
|
|
89
|
+
clearOnSubmit = true,
|
|
90
|
+
autoFocus = true,
|
|
91
|
+
value: controlledValue,
|
|
92
|
+
defaultValue = "",
|
|
93
|
+
onValueChange
|
|
17
94
|
}) {
|
|
18
|
-
const [
|
|
95
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
96
|
+
const textareaRef = useRef(null);
|
|
97
|
+
const value = controlledValue ?? uncontrolledValue;
|
|
98
|
+
const attachmentStatusVersion = useAttachmentStatusVersion(attachments);
|
|
99
|
+
const setValue = useCallback((nextValue) => {
|
|
100
|
+
if (controlledValue === void 0) {
|
|
101
|
+
setUncontrolledValue(nextValue);
|
|
102
|
+
}
|
|
103
|
+
onValueChange?.(nextValue);
|
|
104
|
+
onTextChange?.(nextValue);
|
|
105
|
+
}, [controlledValue, onTextChange, onValueChange]);
|
|
106
|
+
useAutoResizingTextarea(textareaRef, value);
|
|
107
|
+
const allAttachmentsUploaded = useMemo(
|
|
108
|
+
() => attachments.every((attachment) => attachment.status === UploadStatus.Completed),
|
|
109
|
+
[attachmentStatusVersion, attachments]
|
|
110
|
+
);
|
|
111
|
+
const hasDraft = value.trim() !== "" || attachments.length > 0;
|
|
112
|
+
const canSend = !disabled && hasDraft && allAttachmentsUploaded;
|
|
19
113
|
const handleSend = useCallback(() => {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
114
|
+
const trimmed = value.trim();
|
|
115
|
+
if (!canSend) {
|
|
22
116
|
return;
|
|
23
117
|
}
|
|
24
|
-
onSubmit(new ChatMessage({
|
|
118
|
+
void onSubmit(new ChatMessage({
|
|
25
119
|
id: uuidV4(),
|
|
26
|
-
text:
|
|
27
|
-
attachments: attachments.map((
|
|
120
|
+
text: trimmed,
|
|
121
|
+
attachments: attachments.map((attachment) => attachment.path)
|
|
28
122
|
}));
|
|
123
|
+
if (!clearOnSubmit) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
29
126
|
setValue("");
|
|
30
127
|
setAttachments([]);
|
|
31
|
-
}, [
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
128
|
+
}, [attachments, canSend, clearOnSubmit, onSubmit, setAttachments, setValue, value]);
|
|
129
|
+
const handleKeyDown = useCallback((event) => {
|
|
130
|
+
if (disabled) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
if (showCancelButton) {
|
|
136
|
+
onCancelRequest?.();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
35
139
|
handleSend();
|
|
36
140
|
}
|
|
37
|
-
};
|
|
141
|
+
}, [disabled, handleSend, onCancelRequest, showCancelButton]);
|
|
142
|
+
const handleChange = useCallback((event) => {
|
|
143
|
+
const nextValue = event.currentTarget.value;
|
|
144
|
+
setValue(nextValue);
|
|
145
|
+
}, [setValue]);
|
|
38
146
|
const cancelAttachment = useCallback((attachment) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return /* @__PURE__ */ jsxs("div", { className: "border-t py-3 gap-3 flex flex-col", children: [
|
|
48
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-0 gap-2 flex-wrap", children: attachments.map((attachment) => /* @__PURE__ */ jsx(
|
|
147
|
+
if (disabled) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
setAttachments(attachments.filter((currentAttachment) => currentAttachment !== attachment));
|
|
151
|
+
}, [attachments, disabled, setAttachments]);
|
|
152
|
+
const trailingButton = showCancelButton ? /* @__PURE__ */ jsx(ComposerActionButton, { onClick: onCancelRequest, showCancelButton: true }) : hasDraft ? /* @__PURE__ */ jsx(ComposerActionButton, { onClick: handleSend, disabled: !canSend }) : /* @__PURE__ */ jsx("div", { className: "h-9 w-9 shrink-0" });
|
|
153
|
+
return /* @__PURE__ */ jsx("div", { className: "px-4 pt-2", children: /* @__PURE__ */ jsxs("div", { className: "mx-auto flex w-full max-w-4xl flex-col gap-2 rounded-md border border-input/70 bg-background px-2 py-1 shadow-xs focus-within:border-primary focus-within:[outline:1px_solid_var(--color-primary)]", children: [
|
|
154
|
+
attachments.length > 0 ? /* @__PURE__ */ jsx("div", { className: "flex max-w-full flex-wrap gap-2 px-1 pt-1", children: attachments.map((attachment, index) => /* @__PURE__ */ jsx(
|
|
49
155
|
UploadPill,
|
|
50
156
|
{
|
|
51
157
|
attachment,
|
|
52
158
|
onCancel: cancelAttachment
|
|
53
159
|
},
|
|
54
|
-
attachment.path
|
|
55
|
-
)) }),
|
|
56
|
-
/* @__PURE__ */ jsxs("div", { className: "flex
|
|
57
|
-
/* @__PURE__ */ jsx(FileUploader, { onFilesSelected }),
|
|
160
|
+
`${attachment.path}-${index}`
|
|
161
|
+
)) }) : null,
|
|
162
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
163
|
+
/* @__PURE__ */ jsx(FileUploader, { onFilesSelected, disabled }),
|
|
58
164
|
/* @__PURE__ */ jsx(
|
|
59
165
|
Textarea,
|
|
60
166
|
{
|
|
61
|
-
|
|
62
|
-
|
|
167
|
+
ref: textareaRef,
|
|
168
|
+
autoFocus,
|
|
169
|
+
placeholder,
|
|
170
|
+
className: "min-h-5 max-h-40 flex-1 resize-none border-0 bg-transparent p-0 leading-5 shadow-none focus-visible:border-transparent focus-visible:ring-0",
|
|
171
|
+
readOnly: disabled,
|
|
63
172
|
value,
|
|
64
|
-
onChange:
|
|
65
|
-
onKeyDown
|
|
173
|
+
onChange: handleChange,
|
|
174
|
+
onKeyDown: handleKeyDown
|
|
66
175
|
}
|
|
67
176
|
),
|
|
68
|
-
|
|
177
|
+
trailingButton
|
|
69
178
|
] })
|
|
70
|
-
] });
|
|
179
|
+
] }) });
|
|
71
180
|
}
|
|
72
181
|
export {
|
|
73
182
|
ChatInput
|
package/dist/esm/ChatThread.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
1
2
|
import { Element, RoomClient } from "@meshagent/meshagent";
|
|
2
|
-
export
|
|
3
|
-
export declare function ChatThread({ room, messages, localParticipantName }: {
|
|
3
|
+
export interface ChatThreadProps {
|
|
4
4
|
room: RoomClient;
|
|
5
5
|
messages: Element[];
|
|
6
|
+
isLoading?: boolean;
|
|
6
7
|
localParticipantName: string;
|
|
7
|
-
|
|
8
|
+
path?: string;
|
|
9
|
+
showCompletedToolCalls?: boolean;
|
|
10
|
+
onShowCompletedToolCallsChanged?: (value: boolean) => void;
|
|
11
|
+
typing?: boolean;
|
|
12
|
+
thinking?: boolean;
|
|
13
|
+
threadStatusText?: string | null;
|
|
14
|
+
threadStatusStartedAt?: Date | null;
|
|
15
|
+
threadStatusMode?: string | null;
|
|
16
|
+
onCancelRequest?: () => void;
|
|
17
|
+
emptyStateTitle?: string;
|
|
18
|
+
emptyStateDescription?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function timeAgo(iso: string): string;
|
|
21
|
+
export declare function ChatThread({ room, messages, isLoading, localParticipantName, path, showCompletedToolCalls, onShowCompletedToolCallsChanged, typing, thinking, threadStatusText, threadStatusStartedAt, threadStatusMode, onCancelRequest, emptyStateTitle, emptyStateDescription, }: ChatThreadProps): ReactElement;
|