@meshagent/meshagent-tailwind 0.38.2 → 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.
Files changed (61) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/Chat.d.ts +11 -3
  3. package/dist/cjs/Chat.js +376 -29
  4. package/dist/cjs/ChatBotView.d.ts +29 -0
  5. package/dist/cjs/ChatBotView.js +491 -0
  6. package/dist/cjs/ChatInput.d.ts +12 -3
  7. package/dist/cjs/ChatInput.js +143 -44
  8. package/dist/cjs/ChatThread.d.ts +17 -3
  9. package/dist/cjs/ChatThread.js +646 -90
  10. package/dist/cjs/ChatTypingIndicator.d.ts +12 -5
  11. package/dist/cjs/ChatTypingIndicator.js +104 -13
  12. package/dist/cjs/FileUploader.d.ts +3 -2
  13. package/dist/cjs/FileUploader.js +35 -11
  14. package/dist/cjs/UploadPill.d.ts +2 -2
  15. package/dist/cjs/UploadPill.js +70 -32
  16. package/dist/cjs/chat-hooks.d.ts +38 -0
  17. package/dist/cjs/chat-hooks.js +390 -0
  18. package/dist/cjs/chat-message.d.ts +11 -0
  19. package/dist/cjs/chat-message.js +33 -0
  20. package/dist/cjs/components/ui/button.d.ts +1 -1
  21. package/dist/cjs/conversation-descriptor.d.ts +59 -0
  22. package/dist/cjs/conversation-descriptor.js +300 -0
  23. package/dist/cjs/file-attachment.d.ts +45 -0
  24. package/dist/cjs/file-attachment.js +171 -0
  25. package/dist/cjs/index.d.ts +5 -0
  26. package/dist/cjs/index.js +5 -0
  27. package/dist/cjs/multi-thread-view.d.ts +18 -0
  28. package/dist/cjs/multi-thread-view.js +88 -0
  29. package/dist/cjs/tools/ui-toolkit.d.ts +1 -1
  30. package/dist/cjs/tools/ui-toolkit.js +2 -1
  31. package/dist/esm/Chat.d.ts +11 -3
  32. package/dist/esm/Chat.js +378 -31
  33. package/dist/esm/ChatBotView.d.ts +29 -0
  34. package/dist/esm/ChatBotView.js +486 -0
  35. package/dist/esm/ChatInput.d.ts +12 -3
  36. package/dist/esm/ChatInput.js +143 -34
  37. package/dist/esm/ChatThread.d.ts +17 -3
  38. package/dist/esm/ChatThread.js +648 -92
  39. package/dist/esm/ChatTypingIndicator.d.ts +12 -5
  40. package/dist/esm/ChatTypingIndicator.js +94 -13
  41. package/dist/esm/FileUploader.d.ts +3 -2
  42. package/dist/esm/FileUploader.js +26 -12
  43. package/dist/esm/UploadPill.d.ts +2 -2
  44. package/dist/esm/UploadPill.js +60 -32
  45. package/dist/esm/chat-hooks.d.ts +38 -0
  46. package/dist/esm/chat-hooks.js +372 -0
  47. package/dist/esm/chat-message.d.ts +11 -0
  48. package/dist/esm/chat-message.js +13 -0
  49. package/dist/esm/components/ui/button.d.ts +1 -1
  50. package/dist/esm/conversation-descriptor.d.ts +59 -0
  51. package/dist/esm/conversation-descriptor.js +280 -0
  52. package/dist/esm/file-attachment.d.ts +45 -0
  53. package/dist/esm/file-attachment.js +151 -0
  54. package/dist/esm/index.d.ts +5 -0
  55. package/dist/esm/index.js +5 -0
  56. package/dist/esm/multi-thread-view.d.ts +18 -0
  57. package/dist/esm/multi-thread-view.js +68 -0
  58. package/dist/esm/tools/ui-toolkit.d.ts +1 -1
  59. package/dist/esm/tools/ui-toolkit.js +2 -1
  60. package/dist/index.css +1 -1
  61. package/package.json +3 -3
@@ -1,11 +1,81 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import React, { useCallback } from "react";
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 "@meshagent/meshagent-react";
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 [value, setValue] = React.useState("");
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 trimmed2 = value.trim();
21
- if (attachments.length === 0 && !trimmed2) {
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: trimmed2,
27
- attachments: attachments.map((file) => file.path)
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
- }, [value, onSubmit, attachments]);
32
- const onKeyDown = (e) => {
33
- if (e.key === "Enter" && !e.shiftKey) {
34
- e.preventDefault();
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
- setAttachments(attachments.filter((f) => f.path !== attachment.path));
40
- }, [attachments, setAttachments]);
41
- const _onChange = useCallback((e) => {
42
- setValue(e.currentTarget.value);
43
- onTextChange?.(e.currentTarget.value);
44
- }, [onTextChange]);
45
- const trimmed = value.trim();
46
- const disabled = !trimmed && attachments.length === 0;
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 flex-0 gap-3", children: [
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
- placeholder: "Type a message and press Enter",
62
- className: "flex-1 resize-none h-20",
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: _onChange,
65
- onKeyDown
173
+ onChange: handleChange,
174
+ onKeyDown: handleKeyDown
66
175
  }
67
176
  ),
68
- showCancelButton === true ? /* @__PURE__ */ jsx(Button, { onClick: onCancelRequest, children: "Cancel" }) : /* @__PURE__ */ jsx(Button, { onClick: handleSend, disabled, children: "Send" })
177
+ trailingButton
69
178
  ] })
70
- ] });
179
+ ] }) });
71
180
  }
72
181
  export {
73
182
  ChatInput
@@ -1,7 +1,21 @@
1
+ import type { ReactElement } from "react";
1
2
  import { Element, RoomClient } from "@meshagent/meshagent";
2
- export declare function timeAgo(iso: string): string;
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
- }): import("react/jsx-runtime").JSX.Element;
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;