@meshagent/meshagent-tailwind 0.57.0 → 0.57.1
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 +9 -0
- package/README.md +61 -0
- package/dist/cjs/chat/agent-thread.d.ts +4 -2
- package/dist/cjs/chat/agent-thread.js +79 -44
- package/dist/cjs/chat/chat-input.js +104 -74
- package/dist/cjs/chat/chat-thread-timeline.js +13 -4
- package/dist/cjs/chat/composer-action-button.js +10 -2
- package/dist/cjs/chat/tool-call-status-accumulator.js +57 -48
- package/dist/esm/chat/agent-thread.d.ts +4 -2
- package/dist/esm/chat/agent-thread.js +83 -45
- package/dist/esm/chat/chat-input.js +104 -74
- package/dist/esm/chat/chat-thread-timeline.js +13 -4
- package/dist/esm/chat/composer-action-button.js +10 -2
- package/dist/esm/chat/tool-call-status-accumulator.js +57 -48
- package/package.json +5 -5
|
@@ -139,62 +139,71 @@ class LiveToolCallAccumulator {
|
|
|
139
139
|
return applyPatchStatusInfo({ arguments: call.arguments, deltaText });
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
const maxArgumentDepth = 64;
|
|
143
|
+
const maxArgumentWork = 4096;
|
|
144
|
+
function searchToolArguments(value, pathOnly) {
|
|
145
|
+
const preferredKeys = pathOnly ? ["operation"] : ["patch", "input", "diff"];
|
|
146
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
147
|
+
let remaining = maxArgumentWork;
|
|
148
|
+
let exhausted = false;
|
|
149
|
+
const step = () => {
|
|
150
|
+
if (exhausted || remaining-- <= 0) {
|
|
151
|
+
exhausted = true;
|
|
152
|
+
return false;
|
|
152
153
|
}
|
|
153
|
-
return
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return text;
|
|
160
|
-
}
|
|
154
|
+
return true;
|
|
155
|
+
};
|
|
156
|
+
const find = (current, depth) => {
|
|
157
|
+
if (!step() || depth > maxArgumentDepth) {
|
|
158
|
+
exhausted = true;
|
|
159
|
+
return void 0;
|
|
161
160
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (text != null) {
|
|
165
|
-
return text;
|
|
166
|
-
}
|
|
161
|
+
if (typeof current === "string") {
|
|
162
|
+
return !pathOnly && current.trim() !== "" ? current : void 0;
|
|
167
163
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
164
|
+
if (!isRecord(current) && !Array.isArray(current)) {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
if (seen.has(current)) {
|
|
168
|
+
return void 0;
|
|
169
|
+
}
|
|
170
|
+
seen.add(current);
|
|
171
|
+
if (Array.isArray(current)) {
|
|
172
|
+
for (const child of current) {
|
|
173
|
+
const result = find(child, depth + 1);
|
|
174
|
+
if (exhausted) return void 0;
|
|
175
|
+
if (result != null) return result;
|
|
177
176
|
}
|
|
177
|
+
return void 0;
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const path = value.path;
|
|
183
|
-
if (typeof path === "string" && path.trim() !== "") {
|
|
184
|
-
return path.trim();
|
|
179
|
+
if (pathOnly) {
|
|
180
|
+
const path = current.path;
|
|
181
|
+
if (typeof path === "string" && path.trim() !== "") return path.trim();
|
|
185
182
|
}
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
for (const key of preferredKeys) {
|
|
184
|
+
if (!step()) return void 0;
|
|
185
|
+
const child = current[key];
|
|
186
|
+
if (child == null) continue;
|
|
187
|
+
const result = find(child, depth + 1);
|
|
188
|
+
if (exhausted) return void 0;
|
|
189
|
+
if (result != null) return result;
|
|
189
190
|
}
|
|
190
|
-
for (const
|
|
191
|
-
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
for (const key in current) {
|
|
192
|
+
if (!step()) return void 0;
|
|
193
|
+
if (!Object.prototype.hasOwnProperty.call(current, key) || preferredKeys.includes(key)) continue;
|
|
194
|
+
const result = find(current[key], depth + 1);
|
|
195
|
+
if (exhausted) return void 0;
|
|
196
|
+
if (result != null) return result;
|
|
195
197
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
return void 0;
|
|
199
|
+
};
|
|
200
|
+
return find(value, 0);
|
|
201
|
+
}
|
|
202
|
+
function applyPatchTextFromArguments(value) {
|
|
203
|
+
return searchToolArguments(value, false);
|
|
204
|
+
}
|
|
205
|
+
function applyPatchPathFromArguments(value) {
|
|
206
|
+
return searchToolArguments(value, true);
|
|
198
207
|
}
|
|
199
208
|
function applyPatchPathFromText(patch) {
|
|
200
209
|
const filePattern = /^\*\*\* (?:Update|Add|Delete) File: (.+)$/;
|
|
@@ -2,7 +2,7 @@ import type { ReactElement, ReactNode } from "react";
|
|
|
2
2
|
import type { RoomClient, Tool } from "@meshagent/meshagent";
|
|
3
3
|
import type { AgentMessage, AgentMessageEvent, BaseChatClient, ClientToolkitDescription } from "@meshagent/meshagent-agents";
|
|
4
4
|
import type { AgentUsageSnapshot, ChatThreadItem } from "./chat-thread-timeline.js";
|
|
5
|
-
export { AgentUsageSnapshot, shouldReplaceAgentUsageSnapshot } from "./chat-thread-timeline.js";
|
|
5
|
+
export { AgentUsageSnapshot, shouldReplaceAgentUsageSnapshot, } from "./chat-thread-timeline.js";
|
|
6
6
|
export type { ChatThreadItem } from "./chat-thread-timeline.js";
|
|
7
7
|
import { type ChatInputProps } from "./chat-input.js";
|
|
8
8
|
import { ChatMessage } from "./chat-message.js";
|
|
@@ -104,6 +104,8 @@ export declare function useAgentThreadStatus(): {
|
|
|
104
104
|
interrupt: () => Promise<void>;
|
|
105
105
|
};
|
|
106
106
|
export interface AgentThreadFeedProps {
|
|
107
|
+
/** Presentation-only label for user messages; does not change participant identity. */
|
|
108
|
+
userDisplayName?: string;
|
|
107
109
|
/** Show the built-in progress overlay and reserve its bottom spacing. Defaults to true. */
|
|
108
110
|
showStatusIndicator?: boolean;
|
|
109
111
|
/** Renders application-owned content after a visible feed item without sending it to the agent. */
|
|
@@ -111,7 +113,7 @@ export interface AgentThreadFeedProps {
|
|
|
111
113
|
/** Renders local content before the oldest item, or in place of the empty state. */
|
|
112
114
|
renderUnanchored?: () => ReactNode;
|
|
113
115
|
}
|
|
114
|
-
export declare function AgentThreadFeed({ renderAfterItem, renderUnanchored, showStatusIndicator, }?: AgentThreadFeedProps): ReactElement;
|
|
116
|
+
export declare function AgentThreadFeed({ renderAfterItem, renderUnanchored, showStatusIndicator, userDisplayName, }?: AgentThreadFeedProps): ReactElement;
|
|
115
117
|
export interface AgentThreadInputProps extends Pick<ChatInputProps, "className" | "inputRowClassName" | "textareaClassName" | "leadingButton"> {
|
|
116
118
|
showSubmitButton?: boolean;
|
|
117
119
|
submitButtonComponent?: ChatInputProps["submitButtonComponent"];
|
|
@@ -10,7 +10,10 @@ import {
|
|
|
10
10
|
TurnStarted
|
|
11
11
|
} from "@meshagent/meshagent-agents";
|
|
12
12
|
import { buildChatThreadTimeline, buildMergedChatThreadTimeline } from "./chat-thread-timeline.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
AgentUsageSnapshot,
|
|
15
|
+
shouldReplaceAgentUsageSnapshot
|
|
16
|
+
} from "./chat-thread-timeline.js";
|
|
14
17
|
import { ChevronDown, ChevronRight, Download, FileText, ImageOff, Terminal } from "lucide-react";
|
|
15
18
|
import ReactMarkdown from "react-markdown";
|
|
16
19
|
import rehypeHighlight from "rehype-highlight";
|
|
@@ -278,9 +281,10 @@ function ChatBubble({ text, mine }) {
|
|
|
278
281
|
return /* @__PURE__ */ jsx(
|
|
279
282
|
"div",
|
|
280
283
|
{
|
|
284
|
+
"data-chat-bubble": mine ? "user" : "assistant",
|
|
281
285
|
className: cn(
|
|
282
|
-
"w-fit max-w-[85%] rounded-md px-4 py-3 text-sm leading-6 shadow-xs sm:max-w-2xl",
|
|
283
|
-
mine ? "bg-secondary/85 text-foreground" : "bg-muted/70 text-foreground"
|
|
286
|
+
"chat-message__bubble chat-message__markdown w-fit max-w-[85%] rounded-md px-4 py-3 text-sm leading-6 shadow-xs sm:max-w-2xl",
|
|
287
|
+
mine ? "chat-message__bubble--user bg-secondary/85 text-foreground" : "chat-message__bubble--assistant bg-muted/70 text-foreground"
|
|
284
288
|
),
|
|
285
289
|
children: /* @__PURE__ */ jsx(MarkdownBlock, { text })
|
|
286
290
|
}
|
|
@@ -290,7 +294,16 @@ function ReasoningTrace({ text, className }) {
|
|
|
290
294
|
if (text.trim() === "") {
|
|
291
295
|
return null;
|
|
292
296
|
}
|
|
293
|
-
return /* @__PURE__ */ jsx(
|
|
297
|
+
return /* @__PURE__ */ jsx(
|
|
298
|
+
"div",
|
|
299
|
+
{
|
|
300
|
+
className: cn(
|
|
301
|
+
"chat-message__reasoning chat-message__markdown mr-[50px] ml-1.5 px-4 py-1 text-sm leading-6 text-muted-foreground",
|
|
302
|
+
className
|
|
303
|
+
),
|
|
304
|
+
children: /* @__PURE__ */ jsx(MarkdownBlock, { text })
|
|
305
|
+
}
|
|
306
|
+
);
|
|
294
307
|
}
|
|
295
308
|
function trimShellText(value) {
|
|
296
309
|
if (value == null) {
|
|
@@ -601,7 +614,8 @@ function ThreadMessageView({
|
|
|
601
614
|
agentName,
|
|
602
615
|
chatFeedWidgetsByName,
|
|
603
616
|
onSendMessage,
|
|
604
|
-
forceHideHeader = false
|
|
617
|
+
forceHideHeader = false,
|
|
618
|
+
userDisplayName
|
|
605
619
|
}) {
|
|
606
620
|
if (message.kind === "error") {
|
|
607
621
|
return /* @__PURE__ */ jsx("div", { className: "px-6 py-1 text-center text-sm text-destructive", children: message.text });
|
|
@@ -649,43 +663,59 @@ function ThreadMessageView({
|
|
|
649
663
|
return /* @__PURE__ */ jsx(ToolCallLine, { message });
|
|
650
664
|
}
|
|
651
665
|
const mine = message.role === "user";
|
|
652
|
-
const authorName = message.authorName ??
|
|
653
|
-
const previousAuthor = previous?.
|
|
666
|
+
const authorName = mine ? userDisplayName ?? message.authorName ?? localParticipantName : message.authorName ?? displayParticipantName(agentName);
|
|
667
|
+
const previousAuthor = previous?.role === "user" ? userDisplayName ?? previous.authorName ?? localParticipantName : previous?.authorName ?? displayParticipantName(agentName);
|
|
654
668
|
const shouldShowHeader = !forceHideHeader && (previous?.kind !== "message" || previousAuthor !== authorName);
|
|
655
|
-
return /* @__PURE__ */ jsxs(
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
),
|
|
663
|
-
children: [
|
|
664
|
-
authorName.trim() !== "" ? /* @__PURE__ */ jsx("span", { className: "font-semibold text-foreground", children: displayParticipantName(authorName) }) : null,
|
|
665
|
-
/* @__PURE__ */ jsx("span", { children: timeAgo(message.createdAt) })
|
|
666
|
-
]
|
|
667
|
-
}
|
|
668
|
-
) }) }) : null,
|
|
669
|
-
message.text.trim() !== "" ? /* @__PURE__ */ jsx("div", { className: cn("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ jsx(ChatBubble, { text: message.text, mine }) }) : null,
|
|
670
|
-
message.attachments.length > 0 ? /* @__PURE__ */ jsx("div", { className: cn("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ jsx(
|
|
671
|
-
"div",
|
|
672
|
-
{
|
|
673
|
-
className: cn(
|
|
674
|
-
"flex max-w-[85%] flex-wrap gap-3 px-1 sm:max-w-2xl",
|
|
675
|
-
mine ? "justify-end" : "justify-start"
|
|
676
|
-
),
|
|
677
|
-
children: message.attachments.map((attachment, index) => /* @__PURE__ */ jsx(
|
|
678
|
-
AttachmentView,
|
|
669
|
+
return /* @__PURE__ */ jsxs(
|
|
670
|
+
"div",
|
|
671
|
+
{
|
|
672
|
+
className: cn("chat-message flex flex-col gap-2", mine ? "chat-message--user" : "chat-message--assistant"),
|
|
673
|
+
children: [
|
|
674
|
+
shouldShowHeader ? /* @__PURE__ */ jsx("div", { className: cn("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ jsx("div", { className: cn("max-w-[85%] px-1 sm:max-w-2xl", mine ? "text-right" : "text-left"), children: /* @__PURE__ */ jsxs(
|
|
675
|
+
"div",
|
|
679
676
|
{
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
677
|
+
className: cn(
|
|
678
|
+
"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",
|
|
679
|
+
mine ? "justify-end" : "justify-start"
|
|
680
|
+
),
|
|
681
|
+
children: [
|
|
682
|
+
authorName.trim() !== "" ? /* @__PURE__ */ jsx(
|
|
683
|
+
"span",
|
|
684
|
+
{
|
|
685
|
+
"data-chat-author": mine ? "user" : "assistant",
|
|
686
|
+
className: cn(
|
|
687
|
+
"chat-message__author font-semibold text-foreground",
|
|
688
|
+
mine ? "chat-message__author--user" : "chat-message__author--assistant"
|
|
689
|
+
),
|
|
690
|
+
children: displayParticipantName(authorName)
|
|
691
|
+
}
|
|
692
|
+
) : null,
|
|
693
|
+
/* @__PURE__ */ jsx("span", { children: timeAgo(message.createdAt) })
|
|
694
|
+
]
|
|
695
|
+
}
|
|
696
|
+
) }) }) : null,
|
|
697
|
+
message.text.trim() !== "" ? /* @__PURE__ */ jsx("div", { className: cn("chat-message__content flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ jsx(ChatBubble, { text: message.text, mine }) }) : null,
|
|
698
|
+
message.attachments.length > 0 ? /* @__PURE__ */ jsx("div", { className: cn("flex w-full", mine ? "justify-end" : "justify-start"), children: /* @__PURE__ */ jsx(
|
|
699
|
+
"div",
|
|
700
|
+
{
|
|
701
|
+
className: cn(
|
|
702
|
+
"chat-message__attachments flex max-w-[85%] flex-wrap gap-3 px-1 sm:max-w-2xl",
|
|
703
|
+
mine ? "justify-end" : "justify-start"
|
|
704
|
+
),
|
|
705
|
+
children: message.attachments.map((attachment, index) => /* @__PURE__ */ jsx(
|
|
706
|
+
AttachmentView,
|
|
707
|
+
{
|
|
708
|
+
room,
|
|
709
|
+
path: attachment
|
|
710
|
+
},
|
|
711
|
+
`${message.id}:attachment:${attachment}:${index}`
|
|
712
|
+
))
|
|
713
|
+
}
|
|
714
|
+
) }) : null,
|
|
715
|
+
message.image ? /* @__PURE__ */ jsx("div", { className: "flex w-full justify-start", children: /* @__PURE__ */ jsx(GeneratedImageView, { image: message.image }) }) : null
|
|
716
|
+
]
|
|
717
|
+
}
|
|
718
|
+
);
|
|
689
719
|
}
|
|
690
720
|
function EmptyState({ title, description }) {
|
|
691
721
|
return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex h-full max-w-2xl flex-col items-center justify-center px-6 py-20 text-center", children: [
|
|
@@ -771,7 +801,9 @@ function processClientToolRequests({
|
|
|
771
801
|
}
|
|
772
802
|
replayingClientToolSessions.delete(session);
|
|
773
803
|
const completedRequestIds = new Set(
|
|
774
|
-
buildChatThreadTimeline(session.messages).items.filter(
|
|
804
|
+
buildChatThreadTimeline(session.messages).items.filter(
|
|
805
|
+
(item) => item.kind === "tool_call" && item.toolkit === "client" && (item.state === "completed" || item.state === "failed")
|
|
806
|
+
).map((item) => item.clientToolRequestId ?? item.id)
|
|
775
807
|
);
|
|
776
808
|
for (const request of requests) {
|
|
777
809
|
if (completedRequestIds.has(request.requestId)) {
|
|
@@ -817,7 +849,9 @@ function processClientToolRequests({
|
|
|
817
849
|
});
|
|
818
850
|
session.finishClientToolCall(request.requestId, { responseSent: true });
|
|
819
851
|
} catch (error) {
|
|
820
|
-
session.finishClientToolCall(request.requestId, {
|
|
852
|
+
session.finishClientToolCall(request.requestId, {
|
|
853
|
+
responseSent: false
|
|
854
|
+
});
|
|
821
855
|
updateCall(clientToolCallKey(session.threadPath, request.requestId), {
|
|
822
856
|
status: "failed",
|
|
823
857
|
output: new ErrorContent({ text: describeError(error) })
|
|
@@ -1133,7 +1167,9 @@ function AgentThreadProvider({
|
|
|
1133
1167
|
}, [deferLiveEvents, persistedEvents, session, version]);
|
|
1134
1168
|
const timelineItems = useMemo(
|
|
1135
1169
|
() => (timeline?.items ?? []).map((item) => {
|
|
1136
|
-
const override = session == null ? void 0 : clientToolCallOverrides.get(
|
|
1170
|
+
const override = session == null ? void 0 : clientToolCallOverrides.get(
|
|
1171
|
+
clientToolCallKey(session.threadPath, item.clientToolRequestId ?? item.id)
|
|
1172
|
+
);
|
|
1137
1173
|
if (override == null || item.kind !== "tool_call" || item.state === "completed" || item.state === "failed") {
|
|
1138
1174
|
return item;
|
|
1139
1175
|
}
|
|
@@ -1362,7 +1398,8 @@ function useAgentThreadStatus() {
|
|
|
1362
1398
|
function AgentThreadFeed({
|
|
1363
1399
|
renderAfterItem,
|
|
1364
1400
|
renderUnanchored,
|
|
1365
|
-
showStatusIndicator = true
|
|
1401
|
+
showStatusIndicator = true,
|
|
1402
|
+
userDisplayName
|
|
1366
1403
|
} = {}) {
|
|
1367
1404
|
const {
|
|
1368
1405
|
room,
|
|
@@ -1401,7 +1438,7 @@ function AgentThreadFeed({
|
|
|
1401
1438
|
"div",
|
|
1402
1439
|
{
|
|
1403
1440
|
className: cn(
|
|
1404
|
-
"mx-auto w-full max-w-[912px] px-1 py-3",
|
|
1441
|
+
"chat-scroll__message-content mx-auto w-full max-w-[912px] px-1 py-3",
|
|
1405
1442
|
item.id === firstRenderedItemId ? "pt-6" : null,
|
|
1406
1443
|
item.id === lastRenderedItemId ? showStatusIndicator && statusText ? "pb-24" : "pb-6" : null
|
|
1407
1444
|
),
|
|
@@ -1412,6 +1449,7 @@ function AgentThreadFeed({
|
|
|
1412
1449
|
{
|
|
1413
1450
|
room,
|
|
1414
1451
|
message: item,
|
|
1452
|
+
userDisplayName,
|
|
1415
1453
|
previous: previousItemById.get(item.id) ?? null,
|
|
1416
1454
|
localParticipantName,
|
|
1417
1455
|
agentName,
|
|
@@ -59,13 +59,16 @@ function ChatInput({
|
|
|
59
59
|
const textareaRef = useRef(null);
|
|
60
60
|
const value = controlledValue ?? uncontrolledValue;
|
|
61
61
|
const attachmentStatusVersion = useAttachmentStatusVersion(attachments);
|
|
62
|
-
const setValue = useCallback(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const setValue = useCallback(
|
|
63
|
+
(nextValue) => {
|
|
64
|
+
if (controlledValue === void 0) {
|
|
65
|
+
setUncontrolledValue(nextValue);
|
|
66
|
+
}
|
|
67
|
+
onValueChange?.(nextValue);
|
|
68
|
+
onTextChange?.(nextValue);
|
|
69
|
+
},
|
|
70
|
+
[controlledValue, onTextChange, onValueChange]
|
|
71
|
+
);
|
|
69
72
|
useAutoResizingTextarea(textareaRef, value);
|
|
70
73
|
const allAttachmentsUploaded = useMemo(
|
|
71
74
|
() => attachments.every((attachment) => attachment.status === UploadStatus.Completed),
|
|
@@ -78,83 +81,110 @@ function ChatInput({
|
|
|
78
81
|
if (!canSend) {
|
|
79
82
|
return;
|
|
80
83
|
}
|
|
81
|
-
void onSubmit(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
void onSubmit(
|
|
85
|
+
new ChatMessage({
|
|
86
|
+
id: uuidV4(),
|
|
87
|
+
text: trimmed,
|
|
88
|
+
attachments: attachments.map((attachment) => attachment.path)
|
|
89
|
+
})
|
|
90
|
+
);
|
|
86
91
|
if (!clearOnSubmit) {
|
|
87
92
|
return;
|
|
88
93
|
}
|
|
89
94
|
setValue("");
|
|
90
95
|
setAttachments([]);
|
|
91
96
|
}, [attachments, canSend, clearOnSubmit, onSubmit, setAttachments, setValue, value]);
|
|
92
|
-
const handleKeyDown = useCallback(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (event.key === "Enter" && !event.shiftKey) {
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
if (showCancelButton) {
|
|
99
|
-
onCancelRequest?.();
|
|
97
|
+
const handleKeyDown = useCallback(
|
|
98
|
+
(event) => {
|
|
99
|
+
if (disabled) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
resizeTextarea(event.currentTarget);
|
|
108
|
-
setValue(nextValue);
|
|
109
|
-
}, [setValue]);
|
|
110
|
-
const cancelAttachment = useCallback((attachment) => {
|
|
111
|
-
if (disabled) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
setAttachments(attachments.filter((currentAttachment) => currentAttachment !== attachment));
|
|
115
|
-
}, [attachments, disabled, setAttachments]);
|
|
116
|
-
const trailingButton = showCancelButton ? /* @__PURE__ */ jsx(SubmitButton, { onClick: onCancelRequest, showCancelButton: true, title: "Stop", ariaLabel: "Stop" }) : showSubmitButton ? /* @__PURE__ */ jsx(SubmitButton, { onClick: handleSend, disabled: !canSend, title: "Send", ariaLabel: "Send" }) : null;
|
|
117
|
-
return /* @__PURE__ */ jsxs("div", { className: cn(
|
|
118
|
-
"flex flex-col mx-auto w-full max-w-4xl gap-2",
|
|
119
|
-
"border border-input/70 rounded-md bg-background p-1 shadow-xs",
|
|
120
|
-
"focus-within:border-primary focus-within:[outline:1px_solid_var(--color-primary)]",
|
|
121
|
-
className
|
|
122
|
-
), children: [
|
|
123
|
-
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(
|
|
124
|
-
UploadPill,
|
|
125
|
-
{
|
|
126
|
-
attachment,
|
|
127
|
-
onCancel: cancelAttachment
|
|
128
|
-
},
|
|
129
|
-
`${attachment.path}-${index}`
|
|
130
|
-
)) }) : null,
|
|
131
|
-
/* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-2", !enableFileUpload && "pl-1", inputRowClassName), children: [
|
|
132
|
-
leadingButton,
|
|
133
|
-
enableFileUpload ? /* @__PURE__ */ jsx(FileUploader, { onFilesSelected, disabled }) : null,
|
|
134
|
-
/* @__PURE__ */ jsx(
|
|
135
|
-
"textarea",
|
|
136
|
-
{
|
|
137
|
-
ref: textareaRef,
|
|
138
|
-
rows: 1,
|
|
139
|
-
autoFocus,
|
|
140
|
-
placeholder,
|
|
141
|
-
className: cn(
|
|
142
|
-
"min-h-5 max-h-40",
|
|
143
|
-
"flex-1 resize-none border-0 bg-transparent p-0 leading-5",
|
|
144
|
-
"shadow-none outline-none ring-0 focus:ring-0 focus-visible:ring-0",
|
|
145
|
-
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
146
|
-
"md:text-sm",
|
|
147
|
-
textareaClassName
|
|
148
|
-
),
|
|
149
|
-
readOnly: disabled,
|
|
150
|
-
value,
|
|
151
|
-
onChange: handleChange,
|
|
152
|
-
onKeyDown: handleKeyDown
|
|
102
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
if (showCancelButton) {
|
|
105
|
+
onCancelRequest?.();
|
|
106
|
+
return;
|
|
153
107
|
}
|
|
108
|
+
handleSend();
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[disabled, handleSend, onCancelRequest, showCancelButton]
|
|
112
|
+
);
|
|
113
|
+
const handleChange = useCallback(
|
|
114
|
+
(event) => {
|
|
115
|
+
const nextValue = event.currentTarget.value;
|
|
116
|
+
resizeTextarea(event.currentTarget);
|
|
117
|
+
setValue(nextValue);
|
|
118
|
+
},
|
|
119
|
+
[setValue]
|
|
120
|
+
);
|
|
121
|
+
const cancelAttachment = useCallback(
|
|
122
|
+
(attachment) => {
|
|
123
|
+
if (disabled) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
setAttachments(attachments.filter((currentAttachment) => currentAttachment !== attachment));
|
|
127
|
+
},
|
|
128
|
+
[attachments, disabled, setAttachments]
|
|
129
|
+
);
|
|
130
|
+
const trailingButton = showCancelButton ? /* @__PURE__ */ jsx(SubmitButton, { onClick: onCancelRequest, showCancelButton: true, title: "Stop", ariaLabel: "Stop" }) : showSubmitButton ? /* @__PURE__ */ jsx(SubmitButton, { onClick: handleSend, disabled: !canSend, title: "Send", ariaLabel: "Send" }) : null;
|
|
131
|
+
return /* @__PURE__ */ jsxs(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: cn(
|
|
135
|
+
"chat-composer flex flex-col mx-auto w-full max-w-4xl gap-2",
|
|
136
|
+
"border border-input/70 rounded-md bg-background p-1 shadow-xs",
|
|
137
|
+
"focus-within:border-primary focus-within:[outline:1px_solid_var(--color-primary)]",
|
|
138
|
+
className
|
|
154
139
|
),
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
140
|
+
children: [
|
|
141
|
+
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(
|
|
142
|
+
UploadPill,
|
|
143
|
+
{
|
|
144
|
+
attachment,
|
|
145
|
+
onCancel: cancelAttachment
|
|
146
|
+
},
|
|
147
|
+
`${attachment.path}-${index}`
|
|
148
|
+
)) }) : null,
|
|
149
|
+
/* @__PURE__ */ jsxs(
|
|
150
|
+
"div",
|
|
151
|
+
{
|
|
152
|
+
className: cn(
|
|
153
|
+
"chat-composer__input-row flex items-center gap-2",
|
|
154
|
+
!enableFileUpload && "pl-1",
|
|
155
|
+
inputRowClassName
|
|
156
|
+
),
|
|
157
|
+
children: [
|
|
158
|
+
leadingButton,
|
|
159
|
+
enableFileUpload ? /* @__PURE__ */ jsx(FileUploader, { onFilesSelected, disabled }) : null,
|
|
160
|
+
/* @__PURE__ */ jsx(
|
|
161
|
+
"textarea",
|
|
162
|
+
{
|
|
163
|
+
ref: textareaRef,
|
|
164
|
+
rows: 1,
|
|
165
|
+
autoFocus,
|
|
166
|
+
placeholder,
|
|
167
|
+
className: cn(
|
|
168
|
+
"chat-composer__input min-h-5 max-h-40",
|
|
169
|
+
"flex-1 resize-none border-0 bg-transparent p-0 leading-5",
|
|
170
|
+
"shadow-none outline-none ring-0 focus:ring-0 focus-visible:ring-0",
|
|
171
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
172
|
+
"md:text-sm",
|
|
173
|
+
textareaClassName
|
|
174
|
+
),
|
|
175
|
+
readOnly: disabled,
|
|
176
|
+
value,
|
|
177
|
+
onChange: handleChange,
|
|
178
|
+
onKeyDown: handleKeyDown
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
trailingButton
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
);
|
|
158
188
|
}
|
|
159
189
|
export {
|
|
160
190
|
ChatInput,
|
|
@@ -646,14 +646,23 @@ class AgentUsageSnapshot {
|
|
|
646
646
|
this.usage = Object.freeze({ ...params.usage });
|
|
647
647
|
}
|
|
648
648
|
static fromMessage(message) {
|
|
649
|
-
|
|
649
|
+
if (isTypedMessage(message, AgentUsageUpdated)) {
|
|
650
|
+
return AgentUsageSnapshot.fromPayload(message.toJson());
|
|
651
|
+
}
|
|
652
|
+
return null;
|
|
650
653
|
}
|
|
651
654
|
static fromPayload(payload) {
|
|
652
|
-
if (payload.type !== "meshagent.agent.usage.updated" || typeof payload.thread_id !== "string" || payload.thread_id.trim() === "")
|
|
653
|
-
|
|
655
|
+
if (payload.type !== "meshagent.agent.usage.updated" || typeof payload.thread_id !== "string" || payload.thread_id.trim() === "") {
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
if (payload.context_window == null || typeof payload.context_window !== "object") {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
654
661
|
const context = payload.context_window;
|
|
655
662
|
const usedTokens = integerNumber(context.used_tokens);
|
|
656
|
-
if (usedTokens == null)
|
|
663
|
+
if (usedTokens == null) {
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
657
666
|
const rawUsage = payload.usage != null && typeof payload.usage === "object" ? payload.usage : {};
|
|
658
667
|
return new AgentUsageSnapshot({
|
|
659
668
|
threadPath: payload.thread_id.trim(),
|
|
@@ -18,7 +18,11 @@ function ComposerActionButton({
|
|
|
18
18
|
type: "button",
|
|
19
19
|
size: "icon",
|
|
20
20
|
variant: "ghost",
|
|
21
|
-
className: cn(
|
|
21
|
+
className: cn(
|
|
22
|
+
"chat-composer__action relative size-9 rounded-full",
|
|
23
|
+
disabled ? "opacity-55" : "cursor-pointer",
|
|
24
|
+
className
|
|
25
|
+
),
|
|
22
26
|
disabled,
|
|
23
27
|
onClick,
|
|
24
28
|
title: disabled ? "Cancelling" : "Stop",
|
|
@@ -34,7 +38,11 @@ function ComposerActionButton({
|
|
|
34
38
|
{
|
|
35
39
|
type: "button",
|
|
36
40
|
size: "icon",
|
|
37
|
-
className: cn(
|
|
41
|
+
className: cn(
|
|
42
|
+
"chat-composer__action size-9 rounded-full shadow-xs",
|
|
43
|
+
!disabled && "cursor-pointer",
|
|
44
|
+
className
|
|
45
|
+
),
|
|
38
46
|
disabled,
|
|
39
47
|
onClick,
|
|
40
48
|
title,
|