@meshagent/meshagent-tailwind 0.55.1 → 0.56.0
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 +20 -0
- package/README.md +34 -3
- package/dist/cjs/chat/agent-thread.d.ts +42 -7
- package/dist/cjs/chat/agent-thread.js +422 -183
- package/dist/cjs/chat/chat-input-state.d.ts +2 -0
- package/dist/cjs/chat/chat-input-state.js +41 -0
- package/dist/cjs/chat/chat-input.d.ts +14 -2
- package/dist/cjs/chat/chat-input.js +41 -76
- package/dist/cjs/chat/chat-scroller.js +45 -43
- package/dist/cjs/chat/chat-thread-timeline.d.ts +2 -0
- package/dist/cjs/chat/chat-thread-timeline.js +83 -10
- package/dist/cjs/chat/composer-action-button.d.ts +11 -0
- package/dist/cjs/chat/composer-action-button.js +68 -0
- package/dist/cjs/chat/use-chat-virtualizer.d.ts +14 -17
- package/dist/cjs/chat/use-chat-virtualizer.js +288 -222
- package/dist/cjs/chat/virtualization.d.ts +0 -5
- package/dist/cjs/chat/virtualization.js +4 -6
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/esm/chat/agent-thread.d.ts +42 -7
- package/dist/esm/chat/agent-thread.js +424 -186
- package/dist/esm/chat/chat-input-state.d.ts +2 -0
- package/dist/esm/chat/chat-input-state.js +21 -0
- package/dist/esm/chat/chat-input.d.ts +14 -2
- package/dist/esm/chat/chat-input.js +41 -76
- package/dist/esm/chat/chat-scroller.js +46 -44
- package/dist/esm/chat/chat-thread-timeline.d.ts +2 -0
- package/dist/esm/chat/chat-thread-timeline.js +83 -10
- package/dist/esm/chat/composer-action-button.d.ts +11 -0
- package/dist/esm/chat/composer-action-button.js +48 -0
- package/dist/esm/chat/use-chat-virtualizer.d.ts +14 -17
- package/dist/esm/chat/use-chat-virtualizer.js +290 -226
- package/dist/esm/chat/virtualization.d.ts +0 -5
- package/dist/esm/chat/virtualization.js +4 -6
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/index.css +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var chat_input_state_exports = {};
|
|
20
|
+
__export(chat_input_state_exports, {
|
|
21
|
+
useAttachmentStatusVersion: () => useAttachmentStatusVersion
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(chat_input_state_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
function useAttachmentStatusVersion(attachments) {
|
|
26
|
+
const [version, setVersion] = (0, import_react.useState)(0);
|
|
27
|
+
(0, import_react.useEffect)(() => {
|
|
28
|
+
const handleChange = () => {
|
|
29
|
+
setVersion((currentVersion) => currentVersion + 1);
|
|
30
|
+
};
|
|
31
|
+
for (const attachment of attachments) {
|
|
32
|
+
attachment.on("change", handleChange);
|
|
33
|
+
}
|
|
34
|
+
return () => {
|
|
35
|
+
for (const attachment of attachments) {
|
|
36
|
+
attachment.off("change", handleChange);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}, [attachments]);
|
|
40
|
+
return version;
|
|
41
|
+
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import type { ReactElement } from "react";
|
|
1
|
+
import type { ComponentType, ReactElement, ReactNode, RefObject } from "react";
|
|
2
2
|
import { ChatMessage } from "./chat-message.js";
|
|
3
3
|
import { type FileUpload } from "./file-attachment.js";
|
|
4
|
+
import { type ComposerActionButtonProps } from "./composer-action-button.js";
|
|
4
5
|
export interface ChatInputProps {
|
|
6
|
+
/** Classes for the outer composer wrapper. */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Classes for the row containing the buttons and textarea. */
|
|
9
|
+
inputRowClassName?: string;
|
|
10
|
+
/** Classes for the textarea. */
|
|
11
|
+
textareaClassName?: string;
|
|
12
|
+
/** Optional content before the file uploader and textarea. */
|
|
13
|
+
leadingButton?: ReactNode;
|
|
5
14
|
onSubmit: (message: ChatMessage) => void | Promise<void>;
|
|
6
15
|
onFilesSelected: (files: File[]) => void;
|
|
7
16
|
attachments: FileUpload[];
|
|
@@ -10,6 +19,8 @@ export interface ChatInputProps {
|
|
|
10
19
|
onTextChange?: (text: string) => void;
|
|
11
20
|
onCancelRequest?: () => void;
|
|
12
21
|
showCancelButton?: boolean;
|
|
22
|
+
showSubmitButton?: boolean;
|
|
23
|
+
submitButtonComponent?: ComponentType<ComposerActionButtonProps>;
|
|
13
24
|
placeholder?: string;
|
|
14
25
|
disabled?: boolean;
|
|
15
26
|
clearOnSubmit?: boolean;
|
|
@@ -18,4 +29,5 @@ export interface ChatInputProps {
|
|
|
18
29
|
defaultValue?: string;
|
|
19
30
|
onValueChange?: (value: string) => void;
|
|
20
31
|
}
|
|
21
|
-
export declare function
|
|
32
|
+
export declare function useAutoResizingTextarea(textareaRef: RefObject<HTMLTextAreaElement | null>, value: string): void;
|
|
33
|
+
export declare function ChatInput({ className, inputRowClassName, textareaClassName, leadingButton, onSubmit, onFilesSelected, attachments, setAttachments, enableFileUpload, onTextChange, onCancelRequest, showCancelButton, showSubmitButton, submitButtonComponent: SubmitButton, placeholder, disabled, clearOnSubmit, autoFocus, value: controlledValue, defaultValue, onValueChange, }: ChatInputProps): ReactElement;
|
|
@@ -18,96 +18,49 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var chat_input_exports = {};
|
|
20
20
|
__export(chat_input_exports, {
|
|
21
|
-
ChatInput: () => ChatInput
|
|
21
|
+
ChatInput: () => ChatInput,
|
|
22
|
+
useAutoResizingTextarea: () => useAutoResizingTextarea
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(chat_input_exports);
|
|
24
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
26
|
var import_react = require("react");
|
|
26
|
-
var import_lucide_react = require("lucide-react");
|
|
27
27
|
var import_uuid = require("uuid");
|
|
28
28
|
var import_chat_message = require("./chat-message.js");
|
|
29
|
-
var import_button = require("../components/ui/button.js");
|
|
30
29
|
var import_file_uploader = require("./file-uploader.js");
|
|
31
30
|
var import_upload_pill = require("./upload-pill.js");
|
|
32
31
|
var import_file_attachment = require("./file-attachment.js");
|
|
33
32
|
var import_utils = require("../lib/utils.js");
|
|
33
|
+
var import_composer_action_button = require("./composer-action-button.js");
|
|
34
|
+
var import_chat_input_state = require("./chat-input-state.js");
|
|
34
35
|
const MIN_TEXTAREA_HEIGHT = 20;
|
|
35
36
|
const MAX_TEXTAREA_HEIGHT = 160;
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}, [attachments]);
|
|
51
|
-
return version;
|
|
37
|
+
function resizeTextarea(element) {
|
|
38
|
+
if (element.value === "") {
|
|
39
|
+
element.style.height = `${MIN_TEXTAREA_HEIGHT}px`;
|
|
40
|
+
element.style.overflowY = "hidden";
|
|
41
|
+
} else {
|
|
42
|
+
element.style.height = "0px";
|
|
43
|
+
element.style.overflowY = "hidden";
|
|
44
|
+
const contentHeight = element.scrollHeight;
|
|
45
|
+
const height = Math.max(MIN_TEXTAREA_HEIGHT, Math.min(contentHeight, MAX_TEXTAREA_HEIGHT));
|
|
46
|
+
element.style.height = `${height}px`;
|
|
47
|
+
element.style.overflowY = contentHeight > MAX_TEXTAREA_HEIGHT ? "auto" : "hidden";
|
|
48
|
+
}
|
|
52
49
|
}
|
|
53
50
|
function useAutoResizingTextarea(textareaRef, value) {
|
|
54
|
-
(0, import_react.
|
|
51
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
55
52
|
const element = textareaRef.current;
|
|
56
53
|
if (!element) {
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
element.style.height = `${MIN_TEXTAREA_HEIGHT}px`;
|
|
61
|
-
element.style.overflowY = "hidden";
|
|
62
|
-
} else {
|
|
63
|
-
element.style.height = "0px";
|
|
64
|
-
element.style.overflowY = "hidden";
|
|
65
|
-
const contentHeight = element.scrollHeight;
|
|
66
|
-
element.style.height = `${Math.max(
|
|
67
|
-
MIN_TEXTAREA_HEIGHT,
|
|
68
|
-
Math.min(contentHeight, MAX_TEXTAREA_HEIGHT)
|
|
69
|
-
)}px`;
|
|
70
|
-
element.style.overflowY = contentHeight > MAX_TEXTAREA_HEIGHT ? "auto" : "hidden";
|
|
71
|
-
}
|
|
56
|
+
resizeTextarea(element);
|
|
72
57
|
}, [textareaRef, value]);
|
|
73
58
|
}
|
|
74
|
-
function ComposerActionButton({
|
|
75
|
-
onClick,
|
|
76
|
-
disabled = false,
|
|
77
|
-
showCancelButton = false
|
|
78
|
-
}) {
|
|
79
|
-
if (showCancelButton) {
|
|
80
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
81
|
-
import_button.Button,
|
|
82
|
-
{
|
|
83
|
-
type: "button",
|
|
84
|
-
size: "icon",
|
|
85
|
-
variant: "ghost",
|
|
86
|
-
className: (0, import_utils.cn)("relative size-9 rounded-full", disabled ? "opacity-55" : "cursor-pointer"),
|
|
87
|
-
disabled,
|
|
88
|
-
onClick,
|
|
89
|
-
title: disabled ? "Cancelling" : "Stop",
|
|
90
|
-
children: [
|
|
91
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.LoaderCircle, { className: "absolute h-9 w-9 animate-spin text-muted-foreground" }),
|
|
92
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "relative inline-flex h-5 w-5 items-center justify-center rounded-full bg-foreground text-background", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.X, { className: "h-3 w-3" }) })
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
98
|
-
import_button.Button,
|
|
99
|
-
{
|
|
100
|
-
type: "button",
|
|
101
|
-
size: "icon",
|
|
102
|
-
className: (0, import_utils.cn)("size-9 rounded-full shadow-xs", !disabled && "cursor-pointer"),
|
|
103
|
-
disabled,
|
|
104
|
-
onClick,
|
|
105
|
-
title: "Send",
|
|
106
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ArrowUp, { className: "h-4 w-4" })
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
59
|
function ChatInput({
|
|
60
|
+
className,
|
|
61
|
+
inputRowClassName,
|
|
62
|
+
textareaClassName,
|
|
63
|
+
leadingButton,
|
|
111
64
|
onSubmit,
|
|
112
65
|
onFilesSelected,
|
|
113
66
|
attachments,
|
|
@@ -116,6 +69,8 @@ function ChatInput({
|
|
|
116
69
|
onTextChange,
|
|
117
70
|
onCancelRequest,
|
|
118
71
|
showCancelButton = false,
|
|
72
|
+
showSubmitButton = true,
|
|
73
|
+
submitButtonComponent: SubmitButton = import_composer_action_button.ComposerActionButton,
|
|
119
74
|
placeholder = "Message the room",
|
|
120
75
|
disabled = false,
|
|
121
76
|
clearOnSubmit = true,
|
|
@@ -127,7 +82,7 @@ function ChatInput({
|
|
|
127
82
|
const [uncontrolledValue, setUncontrolledValue] = (0, import_react.useState)(defaultValue);
|
|
128
83
|
const textareaRef = (0, import_react.useRef)(null);
|
|
129
84
|
const value = controlledValue ?? uncontrolledValue;
|
|
130
|
-
const attachmentStatusVersion = useAttachmentStatusVersion(attachments);
|
|
85
|
+
const attachmentStatusVersion = (0, import_chat_input_state.useAttachmentStatusVersion)(attachments);
|
|
131
86
|
const setValue = (0, import_react.useCallback)((nextValue) => {
|
|
132
87
|
if (controlledValue === void 0) {
|
|
133
88
|
setUncontrolledValue(nextValue);
|
|
@@ -173,6 +128,7 @@ function ChatInput({
|
|
|
173
128
|
}, [disabled, handleSend, onCancelRequest, showCancelButton]);
|
|
174
129
|
const handleChange = (0, import_react.useCallback)((event) => {
|
|
175
130
|
const nextValue = event.currentTarget.value;
|
|
131
|
+
resizeTextarea(event.currentTarget);
|
|
176
132
|
setValue(nextValue);
|
|
177
133
|
}, [setValue]);
|
|
178
134
|
const cancelAttachment = (0, import_react.useCallback)((attachment) => {
|
|
@@ -181,8 +137,13 @@ function ChatInput({
|
|
|
181
137
|
}
|
|
182
138
|
setAttachments(attachments.filter((currentAttachment) => currentAttachment !== attachment));
|
|
183
139
|
}, [attachments, disabled, setAttachments]);
|
|
184
|
-
const trailingButton = showCancelButton ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
185
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.
|
|
140
|
+
const trailingButton = showCancelButton ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubmitButton, { onClick: onCancelRequest, showCancelButton: true, title: "Stop", ariaLabel: "Stop" }) : showSubmitButton ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubmitButton, { onClick: handleSend, disabled: !canSend, title: "Send", ariaLabel: "Send" }) : null;
|
|
141
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_utils.cn)(
|
|
142
|
+
"flex flex-col mx-auto w-full max-w-4xl gap-2",
|
|
143
|
+
"border border-input/70 rounded-md bg-background p-1 shadow-xs",
|
|
144
|
+
"focus-within:border-primary focus-within:[outline:1px_solid_var(--color-primary)]",
|
|
145
|
+
className
|
|
146
|
+
), children: [
|
|
186
147
|
attachments.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex max-w-full flex-wrap gap-2 px-1 pt-1", children: attachments.map((attachment, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
187
148
|
import_upload_pill.UploadPill,
|
|
188
149
|
{
|
|
@@ -191,19 +152,23 @@ function ChatInput({
|
|
|
191
152
|
},
|
|
192
153
|
`${attachment.path}-${index}`
|
|
193
154
|
)) }) : null,
|
|
194
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_utils.cn)("flex items-center gap-2", !enableFileUpload && "pl-1"), children: [
|
|
155
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_utils.cn)("flex items-center gap-2", !enableFileUpload && "pl-1", inputRowClassName), children: [
|
|
156
|
+
leadingButton,
|
|
195
157
|
enableFileUpload ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_file_uploader.FileUploader, { onFilesSelected, disabled }) : null,
|
|
196
158
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
197
159
|
"textarea",
|
|
198
160
|
{
|
|
199
161
|
ref: textareaRef,
|
|
162
|
+
rows: 1,
|
|
200
163
|
autoFocus,
|
|
201
164
|
placeholder,
|
|
202
165
|
className: (0, import_utils.cn)(
|
|
203
166
|
"min-h-5 max-h-40",
|
|
204
167
|
"flex-1 resize-none border-0 bg-transparent p-0 leading-5",
|
|
205
|
-
"shadow-none outline-none ring-0 focus:ring-0 focus-visible:ring-0
|
|
206
|
-
"
|
|
168
|
+
"shadow-none outline-none ring-0 focus:ring-0 focus-visible:ring-0",
|
|
169
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
170
|
+
"md:text-sm",
|
|
171
|
+
textareaClassName
|
|
207
172
|
),
|
|
208
173
|
readOnly: disabled,
|
|
209
174
|
value,
|
|
@@ -213,5 +178,5 @@ function ChatInput({
|
|
|
213
178
|
),
|
|
214
179
|
trailingButton
|
|
215
180
|
] })
|
|
216
|
-
] })
|
|
181
|
+
] });
|
|
217
182
|
}
|
|
@@ -32,29 +32,17 @@ function MeasuredPage({
|
|
|
32
32
|
renderMessage,
|
|
33
33
|
getMessageId,
|
|
34
34
|
getMessageAuthorId,
|
|
35
|
-
|
|
35
|
+
registerPage
|
|
36
36
|
}) {
|
|
37
37
|
const pageRef = (0, import_react.useRef)(null);
|
|
38
38
|
(0, import_react.useLayoutEffect)(() => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
const reportHeight = () => {
|
|
44
|
-
const height = pageElement.getBoundingClientRect().height;
|
|
45
|
-
onHeightChange(pageIndex, height);
|
|
46
|
-
};
|
|
47
|
-
reportHeight();
|
|
48
|
-
const resizeObserver = new ResizeObserver(reportHeight);
|
|
49
|
-
resizeObserver.observe(pageElement);
|
|
50
|
-
return () => {
|
|
51
|
-
resizeObserver.disconnect();
|
|
52
|
-
};
|
|
53
|
-
}, [onHeightChange, pageIndex]);
|
|
39
|
+
const element = pageRef.current;
|
|
40
|
+
return element ? registerPage(pageIndex, element) : void 0;
|
|
41
|
+
}, [registerPage, pageIndex]);
|
|
54
42
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
55
43
|
"div",
|
|
56
44
|
{
|
|
57
|
-
className: "chat-scroll__page flex flex-col gap-2 px-3 py-1",
|
|
45
|
+
className: "chat-scroll__page flex shrink-0 flex-col gap-2 px-3 py-1",
|
|
58
46
|
"data-page-index": pageIndex,
|
|
59
47
|
ref: pageRef,
|
|
60
48
|
children: messages.map((message) => {
|
|
@@ -88,10 +76,10 @@ function ChatScroller({
|
|
|
88
76
|
const {
|
|
89
77
|
scrollRef,
|
|
90
78
|
visiblePages,
|
|
91
|
-
|
|
92
|
-
windowBottom,
|
|
79
|
+
spacerHeights,
|
|
93
80
|
handleScroll,
|
|
94
|
-
|
|
81
|
+
handleScrollIntent,
|
|
82
|
+
registerPage
|
|
95
83
|
} = (0, import_use_chat_virtualizer.useChatVirtualizer)({
|
|
96
84
|
messages,
|
|
97
85
|
pageSize,
|
|
@@ -104,34 +92,48 @@ function ChatScroller({
|
|
|
104
92
|
{
|
|
105
93
|
className: className ? "chat-scroll relative box-border h-full min-h-0 overflow-y-auto overscroll-contain [overflow-anchor:none] " + className : "chat-scroll relative box-border h-full min-h-0 overflow-y-auto overscroll-contain [overflow-anchor:none]",
|
|
106
94
|
onScroll: handleScroll,
|
|
95
|
+
onWheelCapture: handleScrollIntent,
|
|
96
|
+
onTouchMoveCapture: handleScrollIntent,
|
|
97
|
+
onPointerDownCapture: (event) => {
|
|
98
|
+
if (event.target === event.currentTarget) {
|
|
99
|
+
handleScrollIntent();
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
onKeyDownCapture: (event) => {
|
|
103
|
+
if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End", " "].includes(event.key)) {
|
|
104
|
+
handleScrollIntent();
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
107
|
ref: scrollRef,
|
|
108
108
|
style,
|
|
109
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.
|
|
109
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
110
110
|
"div",
|
|
111
111
|
{
|
|
112
112
|
"aria-hidden": visiblePages.length === 0 ? "true" : void 0,
|
|
113
|
-
className: "chat-scroll__spacer
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
113
|
+
className: "chat-scroll__spacer flex min-h-full flex-col justify-end",
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "aria-hidden": "true", className: "shrink-0", style: { height: spacerHeights.top } }),
|
|
116
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
117
|
+
"div",
|
|
118
|
+
{
|
|
119
|
+
className: "chat-scroll__window flex shrink-0 flex-col",
|
|
120
|
+
children: visiblePages.map((page) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
121
|
+
MeasuredPage,
|
|
122
|
+
{
|
|
123
|
+
currentUserId,
|
|
124
|
+
getMessageAuthorId,
|
|
125
|
+
getMessageId,
|
|
126
|
+
messages: page.items,
|
|
127
|
+
registerPage,
|
|
128
|
+
pageIndex: page.index,
|
|
129
|
+
renderMessage
|
|
130
|
+
},
|
|
131
|
+
page.index
|
|
132
|
+
))
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "aria-hidden": "true", className: "shrink-0", style: { height: spacerHeights.bottom } })
|
|
136
|
+
]
|
|
135
137
|
}
|
|
136
138
|
)
|
|
137
139
|
}
|
|
@@ -18,6 +18,8 @@ export interface ChatThreadItem {
|
|
|
18
18
|
turnId?: string;
|
|
19
19
|
toolkit?: string;
|
|
20
20
|
tool?: string;
|
|
21
|
+
/** Execution request associated with this lifecycle row. */
|
|
22
|
+
clientToolRequestId?: string;
|
|
21
23
|
command?: string;
|
|
22
24
|
argumentsText?: string;
|
|
23
25
|
input?: Record<string, unknown>;
|
|
@@ -42,7 +42,10 @@ function inputContent(message) {
|
|
|
42
42
|
attachments.push(item.url);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
return {
|
|
45
|
+
return {
|
|
46
|
+
text: textParts.join("\n"),
|
|
47
|
+
attachments
|
|
48
|
+
};
|
|
46
49
|
}
|
|
47
50
|
function inputItemFromMessage(message, createdAt) {
|
|
48
51
|
if (isTypedMessage(message, import_meshagent_agents.StartThread) || isTypedMessage(message, import_meshagent_agents.TurnStart) || isTypedMessage(message, import_meshagent_agents.TurnSteer)) {
|
|
@@ -233,7 +236,7 @@ function turnEndedErrorItem(message, createdAt) {
|
|
|
233
236
|
turnId
|
|
234
237
|
};
|
|
235
238
|
}
|
|
236
|
-
function
|
|
239
|
+
function buildRawChatThreadTimeline(events, pendingInputs = []) {
|
|
237
240
|
const items = /* @__PURE__ */ new Map();
|
|
238
241
|
let usage = null;
|
|
239
242
|
for (const event of events) {
|
|
@@ -372,11 +375,12 @@ function buildChatThreadTimeline(events, pendingInputs = []) {
|
|
|
372
375
|
failed: existing?.failed
|
|
373
376
|
});
|
|
374
377
|
} else if (isTypedMessage(message, import_meshagent_agents.AgentClientToolCallRequested)) {
|
|
378
|
+
const existing = items.get(message.requestId);
|
|
375
379
|
upsertItem(items, {
|
|
376
380
|
id: message.requestId,
|
|
377
381
|
kind: "tool_call",
|
|
378
382
|
role: "agent",
|
|
379
|
-
text: `Waiting for client tool ${toolCallLabel(message)}`,
|
|
383
|
+
text: existing?.text ?? `Waiting for client tool ${toolCallLabel(message)}`,
|
|
380
384
|
attachments: [],
|
|
381
385
|
createdAt,
|
|
382
386
|
turnId: message.turnId,
|
|
@@ -384,7 +388,7 @@ function buildChatThreadTimeline(events, pendingInputs = []) {
|
|
|
384
388
|
tool: message.tool,
|
|
385
389
|
argumentsText: formatJsonValue(message.arguments),
|
|
386
390
|
input: message.arguments,
|
|
387
|
-
state: "queued"
|
|
391
|
+
state: existing?.state ?? "queued"
|
|
388
392
|
});
|
|
389
393
|
} else if (isTypedMessage(message, import_meshagent_agents.AgentSecretRequested)) {
|
|
390
394
|
const prompt = message.prompt?.trim();
|
|
@@ -430,9 +434,69 @@ function buildChatThreadTimeline(events, pendingInputs = []) {
|
|
|
430
434
|
usage
|
|
431
435
|
};
|
|
432
436
|
}
|
|
437
|
+
function clientToolInputKey(input) {
|
|
438
|
+
return JSON.stringify(input, (_key, value) => {
|
|
439
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
440
|
+
return value;
|
|
441
|
+
}
|
|
442
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)));
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
function mergeClientToolRequests(items, events) {
|
|
446
|
+
const requests = /* @__PURE__ */ new Map();
|
|
447
|
+
const lifecycleIds = /* @__PURE__ */ new Set();
|
|
448
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
449
|
+
const consumedRequests = /* @__PURE__ */ new Set();
|
|
450
|
+
const matchesScope = (item, request) => item.turnId === request.turnId && item.toolkit === request.toolkit && item.tool === request.tool;
|
|
451
|
+
const pair = (item, request) => {
|
|
452
|
+
replacements.set(item.id, {
|
|
453
|
+
...item,
|
|
454
|
+
clientToolRequestId: request.requestId,
|
|
455
|
+
input: item.input ?? request.arguments,
|
|
456
|
+
argumentsText: item.argumentsText ?? formatJsonValue(request.arguments)
|
|
457
|
+
});
|
|
458
|
+
consumedRequests.add(request.requestId);
|
|
459
|
+
};
|
|
460
|
+
for (const { message } of events) {
|
|
461
|
+
if (isTypedMessage(message, import_meshagent_agents.AgentClientToolCallRequested) && message.toolkit === "client") {
|
|
462
|
+
requests.set(message.requestId, message);
|
|
463
|
+
}
|
|
464
|
+
if (isTypedMessage(message, import_meshagent_agents.AgentToolCallPending) || isTypedMessage(message, import_meshagent_agents.AgentToolCallInProgress) || isTypedMessage(message, import_meshagent_agents.AgentToolCallStarted) || isTypedMessage(message, import_meshagent_agents.AgentToolCallEnded)) {
|
|
465
|
+
lifecycleIds.add(message.itemId);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const lifecycles = items.filter((item) => item.toolkit === "client" && lifecycleIds.has(item.id));
|
|
469
|
+
for (const item of lifecycles) {
|
|
470
|
+
const request = requests.get(item.id);
|
|
471
|
+
if (request && matchesScope(item, request)) {
|
|
472
|
+
pair(item, request);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for (const request of requests.values()) {
|
|
476
|
+
const item = lifecycles.find(
|
|
477
|
+
(candidate) => !replacements.has(candidate.id) && matchesScope(candidate, request) && candidate.input != null && clientToolInputKey(candidate.input) === clientToolInputKey(request.arguments)
|
|
478
|
+
);
|
|
479
|
+
if (!consumedRequests.has(request.requestId) && item) {
|
|
480
|
+
pair(item, request);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
for (const request of requests.values()) {
|
|
484
|
+
const candidates = lifecycles.filter((item2) => !replacements.has(item2.id) && matchesScope(item2, request));
|
|
485
|
+
const peers = [...requests.values()].filter((other) => !consumedRequests.has(other.requestId) && other.turnId === request.turnId && other.toolkit === request.toolkit && other.tool === request.tool);
|
|
486
|
+
const item = candidates[0];
|
|
487
|
+
if (!consumedRequests.has(request.requestId) && candidates.length === 1 && peers.length === 1 && item.input == null) {
|
|
488
|
+
pair(item, request);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return items.filter((item) => !consumedRequests.has(item.id) || replacements.has(item.id)).map((item) => replacements.get(item.id) ?? item);
|
|
492
|
+
}
|
|
493
|
+
function buildChatThreadTimeline(events, pendingInputs = []) {
|
|
494
|
+
const timeline = buildRawChatThreadTimeline(events, pendingInputs);
|
|
495
|
+
return { ...timeline, items: mergeClientToolRequests(timeline.items, events) };
|
|
496
|
+
}
|
|
433
497
|
function buildMergedChatThreadTimeline(persistedEvents, liveEvents, pendingInputs = []) {
|
|
434
|
-
const persisted =
|
|
435
|
-
const live =
|
|
498
|
+
const persisted = buildRawChatThreadTimeline(persistedEvents);
|
|
499
|
+
const live = buildRawChatThreadTimeline(liveEvents, pendingInputs);
|
|
436
500
|
const items = persisted.items.map((item) => ({ ...item }));
|
|
437
501
|
const indexes = new Map(items.map((item, index) => [item.id, index]));
|
|
438
502
|
for (const liveItem of live.items) {
|
|
@@ -448,7 +512,10 @@ function buildMergedChatThreadTimeline(persistedEvents, liveEvents, pendingInput
|
|
|
448
512
|
if (live.usage != null && shouldReplaceAgentUsageSnapshot(usage, live.usage)) {
|
|
449
513
|
usage = live.usage;
|
|
450
514
|
}
|
|
451
|
-
return {
|
|
515
|
+
return {
|
|
516
|
+
items: mergeClientToolRequests(items, [...persistedEvents, ...liveEvents]),
|
|
517
|
+
usage
|
|
518
|
+
};
|
|
452
519
|
}
|
|
453
520
|
function mergeChatThreadItem(persisted, live) {
|
|
454
521
|
if (persisted.kind !== live.kind || persisted.role !== live.role) {
|
|
@@ -523,9 +590,13 @@ function sumUsageKeys(rawUsage, names) {
|
|
|
523
590
|
let total = 0;
|
|
524
591
|
let found = false;
|
|
525
592
|
for (const [key, value] of Object.entries(rawUsage)) {
|
|
526
|
-
if (![...names].some((name) => key === name || key.endsWith(`.${name}`)))
|
|
593
|
+
if (![...names].some((name) => key === name || key.endsWith(`.${name}`))) {
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
527
596
|
const numeric = finiteNumber(value);
|
|
528
|
-
if (numeric == null)
|
|
597
|
+
if (numeric == null) {
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
529
600
|
total += numeric;
|
|
530
601
|
found = true;
|
|
531
602
|
}
|
|
@@ -533,7 +604,9 @@ function sumUsageKeys(rawUsage, names) {
|
|
|
533
604
|
}
|
|
534
605
|
function usageTotalTokens(rawUsage) {
|
|
535
606
|
const explicit = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["total_tokens"]));
|
|
536
|
-
if (explicit != null)
|
|
607
|
+
if (explicit != null) {
|
|
608
|
+
return explicit;
|
|
609
|
+
}
|
|
537
610
|
const input = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["input_tokens", "audio_input_tokens", "image_input_tokens", "cache_creation_input_tokens", "cache_read_input_tokens"]));
|
|
538
611
|
const output = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["output_tokens", "audio_output_tokens", "image_output_tokens"]));
|
|
539
612
|
const cached = sumUsageKeys(rawUsage, /* @__PURE__ */ new Set(["cached_tokens", "audio_cached_tokens", "image_cached_tokens"]));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
export interface ComposerActionButtonProps {
|
|
3
|
+
onClick?: () => void;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
showCancelButton?: boolean;
|
|
6
|
+
className?: string;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
title?: string;
|
|
9
|
+
ariaLabel?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function ComposerActionButton({ onClick, disabled, showCancelButton, className, icon, title, ariaLabel, }: ComposerActionButtonProps): ReactElement;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var composer_action_button_exports = {};
|
|
20
|
+
__export(composer_action_button_exports, {
|
|
21
|
+
ComposerActionButton: () => ComposerActionButton
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(composer_action_button_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_lucide_react = require("lucide-react");
|
|
26
|
+
var import_button = require("../components/ui/button.js");
|
|
27
|
+
var import_utils = require("../lib/utils.js");
|
|
28
|
+
function ComposerActionButton({
|
|
29
|
+
onClick,
|
|
30
|
+
disabled = false,
|
|
31
|
+
showCancelButton = false,
|
|
32
|
+
className,
|
|
33
|
+
icon,
|
|
34
|
+
title = "Send",
|
|
35
|
+
ariaLabel = title
|
|
36
|
+
}) {
|
|
37
|
+
if (showCancelButton) {
|
|
38
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
39
|
+
import_button.Button,
|
|
40
|
+
{
|
|
41
|
+
type: "button",
|
|
42
|
+
size: "icon",
|
|
43
|
+
variant: "ghost",
|
|
44
|
+
className: (0, import_utils.cn)("relative size-9 rounded-full", disabled ? "opacity-55" : "cursor-pointer", className),
|
|
45
|
+
disabled,
|
|
46
|
+
onClick,
|
|
47
|
+
title: disabled ? "Cancelling" : "Stop",
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.LoaderCircle, { className: "absolute h-9 w-9 animate-spin text-muted-foreground" }),
|
|
50
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "relative inline-flex h-5 w-5 items-center justify-center rounded-full bg-foreground text-background", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.X, { className: "h-3 w-3" }) })
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
56
|
+
import_button.Button,
|
|
57
|
+
{
|
|
58
|
+
type: "button",
|
|
59
|
+
size: "icon",
|
|
60
|
+
className: (0, import_utils.cn)("size-9 rounded-full shadow-xs", !disabled && "cursor-pointer", className),
|
|
61
|
+
disabled,
|
|
62
|
+
onClick,
|
|
63
|
+
title,
|
|
64
|
+
"aria-label": ariaLabel,
|
|
65
|
+
children: icon ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ArrowUp, { className: "h-4 w-4" })
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
}
|