@meshagent/meshagent-tailwind 0.47.1 → 0.49.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 +18 -0
- package/dist/cjs/chat/agent-thread.d.ts +24 -24
- package/dist/cjs/chat/agent-thread.js +575 -808
- package/dist/cjs/chat/chat-bot-view.d.ts +18 -6
- package/dist/cjs/chat/chat-bot-view.js +29 -7
- package/dist/cjs/chat/chat-feed-widget-view.d.ts +7 -0
- package/dist/cjs/chat/chat-feed-widget-view.js +50 -0
- package/dist/cjs/chat/chat-feed-widget.d.ts +16 -0
- package/dist/cjs/chat/chat-feed-widget.js +51 -0
- package/dist/cjs/chat/chat-hooks.d.ts +2 -2
- package/dist/cjs/chat/chat-input.d.ts +3 -3
- package/dist/cjs/chat/chat-input.js +9 -4
- package/dist/cjs/chat/chat-scroller.d.ts +21 -0
- package/dist/cjs/chat/chat-scroller.js +139 -0
- package/dist/cjs/chat/chat-thread-timeline.d.ts +66 -0
- package/dist/cjs/chat/chat-thread-timeline.js +595 -0
- package/dist/cjs/chat/dataset-agent-thread.d.ts +16 -4
- package/dist/cjs/chat/dataset-agent-thread.js +112 -292
- package/dist/cjs/chat/multi-thread-view.d.ts +8 -3
- package/dist/cjs/chat/multi-thread-view.js +10 -2
- package/dist/cjs/chat/new-chat-thread.d.ts +8 -3
- package/dist/cjs/chat/new-chat-thread.js +63 -24
- package/dist/cjs/chat/thread-view.d.ts +18 -5
- package/dist/cjs/chat/thread-view.js +67 -9
- package/dist/cjs/chat/use-chat-virtualizer.d.ts +47 -0
- package/dist/cjs/chat/use-chat-virtualizer.js +336 -0
- package/dist/cjs/chat/virtualization.d.ts +44 -0
- package/dist/cjs/chat/virtualization.js +143 -0
- package/dist/cjs/components/ui/button.d.ts +2 -2
- package/dist/cjs/components/ui/dialog.d.ts +1 -1
- package/dist/cjs/components/ui/dialog.js +11 -1
- package/dist/cjs/components/ui/form.d.ts +1 -1
- package/dist/cjs/components/ui/portal-container.d.ts +7 -0
- package/dist/cjs/components/ui/portal-container.js +46 -0
- package/dist/cjs/file-preview/file-preview.js +1 -1
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/meetings/meeting-scope.d.ts +2 -1
- package/dist/cjs/meetings/meeting-scope.js +1 -0
- package/dist/cjs/react-syntax-highlighter.d.js +1 -0
- package/dist/esm/chat/agent-thread.d.ts +24 -24
- package/dist/esm/chat/agent-thread.js +574 -838
- package/dist/esm/chat/chat-bot-view.d.ts +18 -6
- package/dist/esm/chat/chat-bot-view.js +29 -7
- package/dist/esm/chat/chat-feed-widget-view.d.ts +7 -0
- package/dist/esm/chat/chat-feed-widget-view.js +30 -0
- package/dist/esm/chat/chat-feed-widget.d.ts +16 -0
- package/dist/esm/chat/chat-feed-widget.js +31 -0
- package/dist/esm/chat/chat-hooks.d.ts +2 -2
- package/dist/esm/chat/chat-input.d.ts +3 -3
- package/dist/esm/chat/chat-input.js +9 -4
- package/dist/esm/chat/chat-scroller.d.ts +21 -0
- package/dist/esm/chat/chat-scroller.js +122 -0
- package/dist/esm/chat/chat-thread-timeline.d.ts +66 -0
- package/dist/esm/chat/chat-thread-timeline.js +605 -0
- package/dist/esm/chat/dataset-agent-thread.d.ts +16 -4
- package/dist/esm/chat/dataset-agent-thread.js +114 -307
- package/dist/esm/chat/multi-thread-view.d.ts +8 -3
- package/dist/esm/chat/multi-thread-view.js +10 -2
- package/dist/esm/chat/new-chat-thread.d.ts +8 -3
- package/dist/esm/chat/new-chat-thread.js +64 -25
- package/dist/esm/chat/thread-view.d.ts +18 -5
- package/dist/esm/chat/thread-view.js +67 -9
- package/dist/esm/chat/use-chat-virtualizer.d.ts +47 -0
- package/dist/esm/chat/use-chat-virtualizer.js +331 -0
- package/dist/esm/chat/virtualization.d.ts +44 -0
- package/dist/esm/chat/virtualization.js +123 -0
- package/dist/esm/components/ui/button.d.ts +2 -2
- package/dist/esm/components/ui/dialog.d.ts +1 -1
- package/dist/esm/components/ui/dialog.js +11 -1
- package/dist/esm/components/ui/form.d.ts +1 -1
- package/dist/esm/components/ui/portal-container.d.ts +7 -0
- package/dist/esm/components/ui/portal-container.js +16 -0
- package/dist/esm/file-preview/file-preview.js +1 -1
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/meetings/meeting-scope.d.ts +2 -1
- package/dist/esm/meetings/meeting-scope.js +1 -0
- package/dist/esm/react-syntax-highlighter.d.js +0 -0
- package/dist/index.css +1 -1
- package/package.json +6 -5
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
2
|
import type { Participant, RoomClient } from "@meshagent/meshagent";
|
|
3
|
-
import type { BaseChatClient, ClientToolkitDescription } from "@meshagent/meshagent-agents";
|
|
4
|
-
import type { AgentToolChoice } from "./agent-thread";
|
|
5
|
-
import type { DatasetThreadRowsLoader } from "./dataset-agent-thread";
|
|
6
|
-
import {
|
|
7
|
-
|
|
3
|
+
import type { AgentMessage, AgentMessageEvent, BaseChatClient, ClientToolkitDescription } from "@meshagent/meshagent-agents";
|
|
4
|
+
import type { AgentToolChoice } from "./agent-thread.js";
|
|
5
|
+
import type { DatasetThreadRowsLoader } from "./dataset-agent-thread.js";
|
|
6
|
+
import type { ChatFeedWidget } from "./chat-feed-widget.js";
|
|
7
|
+
import { ChatThreadDisplayMode } from "./conversation-descriptor.js";
|
|
8
|
+
export { ChatThreadDisplayMode, chatDocumentPath, resolvedThreadListPath, } from "./conversation-descriptor.js";
|
|
8
9
|
export interface ChatBotViewProps {
|
|
9
10
|
room: RoomClient;
|
|
10
11
|
chatClient?: BaseChatClient;
|
|
@@ -33,9 +34,20 @@ export interface ChatBotViewProps {
|
|
|
33
34
|
threadListWidth?: number;
|
|
34
35
|
threadListCollapsedHeight?: number;
|
|
35
36
|
clientToolkits?: ClientToolkitDescription[];
|
|
37
|
+
chatFeedWidgets?: ChatFeedWidget[];
|
|
36
38
|
toolChoice?: AgentToolChoice;
|
|
37
39
|
collapseMessages?: boolean;
|
|
40
|
+
enableFileUpload?: boolean;
|
|
38
41
|
threadSource?: "session" | "dataset";
|
|
39
42
|
rowsLoader?: DatasetThreadRowsLoader;
|
|
43
|
+
persistedEvents?: readonly AgentMessageEvent[];
|
|
44
|
+
loadThread?: boolean;
|
|
45
|
+
injectPersistedEvents?: boolean;
|
|
46
|
+
composerDisabled?: boolean;
|
|
47
|
+
closeThreadOnUnmount?: boolean;
|
|
48
|
+
onPersistedEventsInjectionStarted?: () => void;
|
|
49
|
+
onPersistedEventsInjected?: (error: unknown | null) => void;
|
|
50
|
+
onEventsChanged?: (threadId: string, events: readonly AgentMessageEvent[], latestMessage: AgentMessage | null) => void;
|
|
51
|
+
onThreadStarted?: (threadId: string, events: readonly AgentMessageEvent[]) => Promise<void> | void;
|
|
40
52
|
}
|
|
41
|
-
export declare function ChatBotView({ room, chatClient, disposeChatClient, path, documentPath, agentName, threadDisplayMode, threadDir, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, startNewThreadTitle, startNewThreadDescription, selectedThreadPath, selectedThreadDisplayName, onSelectedThreadPathChanged, onSelectedThreadResolved, onThreadResolved, newThreadResetVersion, showThreadList, threadListWidth, threadListCollapsedHeight, clientToolkits, toolChoice, collapseMessages, threadSource, rowsLoader, }: ChatBotViewProps): ReactElement;
|
|
53
|
+
export declare function ChatBotView({ room, chatClient, disposeChatClient, path, documentPath, agentName, threadDisplayMode, threadDir, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, startNewThreadTitle, startNewThreadDescription, selectedThreadPath, selectedThreadDisplayName, onSelectedThreadPathChanged, onSelectedThreadResolved, onThreadResolved, newThreadResetVersion, showThreadList, threadListWidth, threadListCollapsedHeight, clientToolkits, chatFeedWidgets, toolChoice, collapseMessages, enableFileUpload, threadSource, rowsLoader, persistedEvents, loadThread, injectPersistedEvents, composerDisabled, closeThreadOnUnmount, onPersistedEventsInjectionStarted, onPersistedEventsInjected, onEventsChanged, onThreadStarted, }: ChatBotViewProps): ReactElement;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { MessagingChatClient } from "@meshagent/meshagent-agents";
|
|
4
|
-
import { ChatThreadDisplayMode } from "./conversation-descriptor";
|
|
5
|
-
import { cn } from "../lib/utils";
|
|
6
|
-
import { ThreadListView } from "./thread-list-view";
|
|
7
|
-
import { ThreadView } from "./thread-view";
|
|
4
|
+
import { ChatThreadDisplayMode } from "./conversation-descriptor.js";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
import { ThreadListView } from "./thread-list-view.js";
|
|
7
|
+
import { ThreadView } from "./thread-view.js";
|
|
8
8
|
import {
|
|
9
9
|
ChatThreadDisplayMode as ChatThreadDisplayMode2,
|
|
10
10
|
chatDocumentPath,
|
|
11
11
|
resolvedThreadListPath
|
|
12
|
-
} from "./conversation-descriptor";
|
|
12
|
+
} from "./conversation-descriptor.js";
|
|
13
13
|
const multiThreadLayoutBreakpointPx = 920;
|
|
14
14
|
function normalizePath(path) {
|
|
15
15
|
const normalized = path?.trim();
|
|
@@ -59,10 +59,21 @@ function ChatBotView({
|
|
|
59
59
|
threadListWidth = 280,
|
|
60
60
|
threadListCollapsedHeight = 220,
|
|
61
61
|
clientToolkits,
|
|
62
|
+
chatFeedWidgets,
|
|
62
63
|
toolChoice,
|
|
63
64
|
collapseMessages = true,
|
|
65
|
+
enableFileUpload = false,
|
|
64
66
|
threadSource = "session",
|
|
65
|
-
rowsLoader
|
|
67
|
+
rowsLoader,
|
|
68
|
+
persistedEvents,
|
|
69
|
+
loadThread = true,
|
|
70
|
+
injectPersistedEvents = false,
|
|
71
|
+
composerDisabled = false,
|
|
72
|
+
closeThreadOnUnmount = false,
|
|
73
|
+
onPersistedEventsInjectionStarted,
|
|
74
|
+
onPersistedEventsInjected,
|
|
75
|
+
onEventsChanged,
|
|
76
|
+
onThreadStarted
|
|
66
77
|
}) {
|
|
67
78
|
const isWideLayout = useIsWideLayout(multiThreadLayoutBreakpointPx);
|
|
68
79
|
const resolvedDocumentPath = useMemo(() => normalizePath(documentPath ?? path), [documentPath, path]);
|
|
@@ -149,10 +160,21 @@ function ChatBotView({
|
|
|
149
160
|
onSelectedThreadResolved: emitResolvedThread,
|
|
150
161
|
newThreadResetVersion,
|
|
151
162
|
clientToolkits,
|
|
163
|
+
chatFeedWidgets,
|
|
152
164
|
toolChoice,
|
|
153
165
|
collapseMessages,
|
|
166
|
+
enableFileUpload,
|
|
154
167
|
threadSource,
|
|
155
|
-
rowsLoader
|
|
168
|
+
rowsLoader,
|
|
169
|
+
persistedEvents,
|
|
170
|
+
loadThread,
|
|
171
|
+
injectPersistedEvents,
|
|
172
|
+
composerDisabled,
|
|
173
|
+
closeThreadOnUnmount,
|
|
174
|
+
onPersistedEventsInjectionStarted,
|
|
175
|
+
onPersistedEventsInjected,
|
|
176
|
+
onEventsChanged,
|
|
177
|
+
onThreadStarted
|
|
156
178
|
}
|
|
157
179
|
);
|
|
158
180
|
if (threadDisplayMode !== ChatThreadDisplayMode.MultiThreadComposer) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { ChatFeedWidget, ToolCall } from "./chat-feed-widget.js";
|
|
3
|
+
export declare function ChatFeedWidgetView({ widget, toolCall, fallback, }: {
|
|
4
|
+
widget: ChatFeedWidget;
|
|
5
|
+
toolCall: ToolCall;
|
|
6
|
+
fallback: ReactElement;
|
|
7
|
+
}): ReactElement;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Component } from "react";
|
|
3
|
+
class ChatFeedWidgetErrorBoundary extends Component {
|
|
4
|
+
state = { failed: false };
|
|
5
|
+
static getDerivedStateFromError() {
|
|
6
|
+
return { failed: true };
|
|
7
|
+
}
|
|
8
|
+
componentDidCatch(error, info) {
|
|
9
|
+
console.error("ChatFeedWidget render failed", error, info);
|
|
10
|
+
}
|
|
11
|
+
render() {
|
|
12
|
+
return this.state.failed ? this.props.fallback : this.props.children;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function ChatFeedWidgetRenderer({
|
|
16
|
+
widget,
|
|
17
|
+
toolCall
|
|
18
|
+
}) {
|
|
19
|
+
return widget.render(toolCall);
|
|
20
|
+
}
|
|
21
|
+
function ChatFeedWidgetView({
|
|
22
|
+
widget,
|
|
23
|
+
toolCall,
|
|
24
|
+
fallback
|
|
25
|
+
}) {
|
|
26
|
+
return /* @__PURE__ */ jsx(ChatFeedWidgetErrorBoundary, { fallback, children: /* @__PURE__ */ jsx(ChatFeedWidgetRenderer, { widget, toolCall }) });
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
ChatFeedWidgetView
|
|
30
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { Tool } from "@meshagent/meshagent";
|
|
3
|
+
import type { Content } from "@meshagent/meshagent";
|
|
4
|
+
import { ClientToolkitDescription } from "@meshagent/meshagent-agents";
|
|
5
|
+
import type { AgentThreadSuggestion } from "./agent-thread.js";
|
|
6
|
+
export type ToolCallStatus = "queued" | "in_progress" | "completed" | "failed";
|
|
7
|
+
export interface ToolCall {
|
|
8
|
+
status: ToolCallStatus;
|
|
9
|
+
input: Record<string, unknown>;
|
|
10
|
+
output?: Content;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class ChatFeedWidget extends Tool {
|
|
13
|
+
abstract render(toolCall: ToolCall): ReactElement;
|
|
14
|
+
getFollowUpSuggestions?(toolCall: ToolCall): readonly AgentThreadSuggestion[];
|
|
15
|
+
}
|
|
16
|
+
export declare function resolveClientToolkitDescriptions(clientToolkits: ClientToolkitDescription[] | undefined, chatFeedWidgets: ChatFeedWidget[] | undefined): ClientToolkitDescription[] | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Tool } from "@meshagent/meshagent";
|
|
2
|
+
import { ClientToolkitDescription } from "@meshagent/meshagent-agents";
|
|
3
|
+
class ChatFeedWidget extends Tool {
|
|
4
|
+
}
|
|
5
|
+
function resolveClientToolkitDescriptions(clientToolkits, chatFeedWidgets) {
|
|
6
|
+
if ((clientToolkits?.length ?? 0) === 0 && (chatFeedWidgets?.length ?? 0) === 0) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
const descriptions = [...clientToolkits ?? []];
|
|
10
|
+
const names = new Set(descriptions.map((description) => description.name));
|
|
11
|
+
for (const widget of chatFeedWidgets ?? []) {
|
|
12
|
+
if (names.has(widget.name)) {
|
|
13
|
+
throw new Error(`client tool '${widget.name}' has already been registered`);
|
|
14
|
+
}
|
|
15
|
+
names.add(widget.name);
|
|
16
|
+
descriptions.push(new ClientToolkitDescription({
|
|
17
|
+
name: widget.name,
|
|
18
|
+
title: widget.title,
|
|
19
|
+
description: widget.description,
|
|
20
|
+
inputSchema: widget.inputSchema ?? {
|
|
21
|
+
type: "object",
|
|
22
|
+
additionalProperties: true
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
return descriptions;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
ChatFeedWidget,
|
|
30
|
+
resolveClientToolkitDescriptions
|
|
31
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Element, MeshDocument, Participant, RemoteParticipant, RoomClient } from "@meshagent/meshagent";
|
|
2
|
-
import { ChatMessage } from "./chat-message";
|
|
3
|
-
import type { FileUpload } from "./file-attachment";
|
|
2
|
+
import { ChatMessage } from "./chat-message.js";
|
|
3
|
+
import type { FileUpload } from "./file-attachment.js";
|
|
4
4
|
export interface UseChatThreadProps {
|
|
5
5
|
room: RoomClient;
|
|
6
6
|
path: string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
2
|
import { ChatMessage } from "./chat-message.js";
|
|
3
3
|
import { type FileUpload } from "./file-attachment.js";
|
|
4
|
-
interface ChatInputProps {
|
|
4
|
+
export interface ChatInputProps {
|
|
5
5
|
onSubmit: (message: ChatMessage) => void | Promise<void>;
|
|
6
6
|
onFilesSelected: (files: File[]) => void;
|
|
7
7
|
attachments: FileUpload[];
|
|
8
8
|
setAttachments: (attachments: FileUpload[]) => void;
|
|
9
|
+
enableFileUpload?: boolean;
|
|
9
10
|
onTextChange?: (text: string) => void;
|
|
10
11
|
onCancelRequest?: () => void;
|
|
11
12
|
showCancelButton?: boolean;
|
|
@@ -17,5 +18,4 @@ interface ChatInputProps {
|
|
|
17
18
|
defaultValue?: string;
|
|
18
19
|
onValueChange?: (value: string) => void;
|
|
19
20
|
}
|
|
20
|
-
export declare function ChatInput({ onSubmit, onFilesSelected, attachments, setAttachments, onTextChange, onCancelRequest, showCancelButton, placeholder, disabled, clearOnSubmit, autoFocus, value: controlledValue, defaultValue, onValueChange, }: ChatInputProps): ReactElement;
|
|
21
|
-
export {};
|
|
21
|
+
export declare function ChatInput({ onSubmit, onFilesSelected, attachments, setAttachments, enableFileUpload, onTextChange, onCancelRequest, showCancelButton, placeholder, disabled, clearOnSubmit, autoFocus, value: controlledValue, defaultValue, onValueChange, }: ChatInputProps): ReactElement;
|
|
@@ -35,12 +35,16 @@ function useAutoResizingTextarea(textareaRef, value) {
|
|
|
35
35
|
}
|
|
36
36
|
if (value === "") {
|
|
37
37
|
element.style.height = `${MIN_TEXTAREA_HEIGHT}px`;
|
|
38
|
+
element.style.overflowY = "hidden";
|
|
38
39
|
} else {
|
|
39
40
|
element.style.height = "0px";
|
|
41
|
+
element.style.overflowY = "hidden";
|
|
42
|
+
const contentHeight = element.scrollHeight;
|
|
40
43
|
element.style.height = `${Math.max(
|
|
41
44
|
MIN_TEXTAREA_HEIGHT,
|
|
42
|
-
Math.min(
|
|
45
|
+
Math.min(contentHeight, MAX_TEXTAREA_HEIGHT)
|
|
43
46
|
)}px`;
|
|
47
|
+
element.style.overflowY = contentHeight > MAX_TEXTAREA_HEIGHT ? "auto" : "hidden";
|
|
44
48
|
}
|
|
45
49
|
}, [textareaRef, value]);
|
|
46
50
|
}
|
|
@@ -85,6 +89,7 @@ function ChatInput({
|
|
|
85
89
|
onFilesSelected,
|
|
86
90
|
attachments,
|
|
87
91
|
setAttachments,
|
|
92
|
+
enableFileUpload = false,
|
|
88
93
|
onTextChange,
|
|
89
94
|
onCancelRequest,
|
|
90
95
|
showCancelButton = false,
|
|
@@ -153,7 +158,7 @@ function ChatInput({
|
|
|
153
158
|
}
|
|
154
159
|
setAttachments(attachments.filter((currentAttachment) => currentAttachment !== attachment));
|
|
155
160
|
}, [attachments, disabled, setAttachments]);
|
|
156
|
-
const trailingButton = showCancelButton ? /* @__PURE__ */ jsx(ComposerActionButton, { onClick: onCancelRequest, showCancelButton: true }) :
|
|
161
|
+
const trailingButton = showCancelButton ? /* @__PURE__ */ jsx(ComposerActionButton, { onClick: onCancelRequest, showCancelButton: true }) : /* @__PURE__ */ jsx(ComposerActionButton, { onClick: handleSend, disabled: !canSend });
|
|
157
162
|
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: [
|
|
158
163
|
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(
|
|
159
164
|
UploadPill,
|
|
@@ -163,8 +168,8 @@ function ChatInput({
|
|
|
163
168
|
},
|
|
164
169
|
`${attachment.path}-${index}`
|
|
165
170
|
)) }) : null,
|
|
166
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
167
|
-
/* @__PURE__ */ jsx(FileUploader, { onFilesSelected, disabled }),
|
|
171
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-2", !enableFileUpload && "pl-1"), children: [
|
|
172
|
+
enableFileUpload ? /* @__PURE__ */ jsx(FileUploader, { onFilesSelected, disabled }) : null,
|
|
168
173
|
/* @__PURE__ */ jsx(
|
|
169
174
|
"textarea",
|
|
170
175
|
{
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
export type ChatMessageBase = {
|
|
3
|
+
id: string;
|
|
4
|
+
authorId?: string;
|
|
5
|
+
};
|
|
6
|
+
export type RenderMessageMeta = {
|
|
7
|
+
isCurrentUser: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type ChatScrollerProps<TMessage extends ChatMessageBase> = {
|
|
10
|
+
messages: readonly TMessage[];
|
|
11
|
+
currentUserId: string;
|
|
12
|
+
renderMessage: (message: TMessage, meta: RenderMessageMeta) => ReactNode;
|
|
13
|
+
pageSize?: number;
|
|
14
|
+
overscanPages?: number;
|
|
15
|
+
bottomThresholdPx?: number;
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
getMessageId?: (message: TMessage) => string;
|
|
19
|
+
getMessageAuthorId?: (message: TMessage) => string | undefined;
|
|
20
|
+
};
|
|
21
|
+
export declare function ChatScroller<TMessage extends ChatMessageBase>({ messages, currentUserId, renderMessage, pageSize, overscanPages, bottomThresholdPx, className, style, getMessageId, getMessageAuthorId, }: ChatScrollerProps<TMessage>): import("react").JSX.Element;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
useLayoutEffect,
|
|
4
|
+
useRef
|
|
5
|
+
} from "react";
|
|
6
|
+
import { DEFAULT_OVERSCAN_PAGES, DEFAULT_PAGE_SIZE } from "./virtualization.js";
|
|
7
|
+
import { useChatVirtualizer } from "./use-chat-virtualizer.js";
|
|
8
|
+
function MeasuredPage({
|
|
9
|
+
pageIndex,
|
|
10
|
+
messages,
|
|
11
|
+
currentUserId,
|
|
12
|
+
renderMessage,
|
|
13
|
+
getMessageId,
|
|
14
|
+
getMessageAuthorId,
|
|
15
|
+
onHeightChange
|
|
16
|
+
}) {
|
|
17
|
+
const pageRef = useRef(null);
|
|
18
|
+
useLayoutEffect(() => {
|
|
19
|
+
const pageElement = pageRef.current;
|
|
20
|
+
if (!pageElement) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
const reportHeight = () => {
|
|
24
|
+
const height = pageElement.getBoundingClientRect().height;
|
|
25
|
+
onHeightChange(pageIndex, height);
|
|
26
|
+
};
|
|
27
|
+
reportHeight();
|
|
28
|
+
const resizeObserver = new ResizeObserver(reportHeight);
|
|
29
|
+
resizeObserver.observe(pageElement);
|
|
30
|
+
return () => {
|
|
31
|
+
resizeObserver.disconnect();
|
|
32
|
+
};
|
|
33
|
+
}, [onHeightChange, pageIndex]);
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
className: "chat-scroll__page flex flex-col gap-2 px-3 py-1",
|
|
38
|
+
"data-page-index": pageIndex,
|
|
39
|
+
ref: pageRef,
|
|
40
|
+
children: messages.map((message) => {
|
|
41
|
+
const isCurrentUser = getMessageAuthorId(message) === currentUserId;
|
|
42
|
+
const messageClassName = isCurrentUser ? "chat-scroll__message chat-scroll__message--own flex w-full min-w-0 justify-end" : "chat-scroll__message chat-scroll__message--other flex w-full min-w-0 justify-start";
|
|
43
|
+
return /* @__PURE__ */ jsx(
|
|
44
|
+
"div",
|
|
45
|
+
{
|
|
46
|
+
className: messageClassName,
|
|
47
|
+
"data-message-id": getMessageId(message),
|
|
48
|
+
children: renderMessage(message, { isCurrentUser })
|
|
49
|
+
},
|
|
50
|
+
getMessageId(message)
|
|
51
|
+
);
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function ChatScroller({
|
|
57
|
+
messages,
|
|
58
|
+
currentUserId,
|
|
59
|
+
renderMessage,
|
|
60
|
+
pageSize = DEFAULT_PAGE_SIZE,
|
|
61
|
+
overscanPages = DEFAULT_OVERSCAN_PAGES,
|
|
62
|
+
bottomThresholdPx = 48,
|
|
63
|
+
className,
|
|
64
|
+
style,
|
|
65
|
+
getMessageId = (message) => message.id,
|
|
66
|
+
getMessageAuthorId = (message) => message.authorId
|
|
67
|
+
}) {
|
|
68
|
+
const {
|
|
69
|
+
scrollRef,
|
|
70
|
+
visiblePages,
|
|
71
|
+
spacerHeight,
|
|
72
|
+
windowBottom,
|
|
73
|
+
handleScroll,
|
|
74
|
+
handlePageHeightChange
|
|
75
|
+
} = useChatVirtualizer({
|
|
76
|
+
messages,
|
|
77
|
+
pageSize,
|
|
78
|
+
overscanPages,
|
|
79
|
+
bottomThresholdPx,
|
|
80
|
+
getMessageId
|
|
81
|
+
});
|
|
82
|
+
return /* @__PURE__ */ jsx(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
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]",
|
|
86
|
+
onScroll: handleScroll,
|
|
87
|
+
ref: scrollRef,
|
|
88
|
+
style,
|
|
89
|
+
children: /* @__PURE__ */ jsx(
|
|
90
|
+
"div",
|
|
91
|
+
{
|
|
92
|
+
"aria-hidden": visiblePages.length === 0 ? "true" : void 0,
|
|
93
|
+
className: "chat-scroll__spacer relative min-h-full",
|
|
94
|
+
style: { height: spacerHeight },
|
|
95
|
+
children: /* @__PURE__ */ jsx(
|
|
96
|
+
"div",
|
|
97
|
+
{
|
|
98
|
+
className: "chat-scroll__window absolute right-0 left-0 flex flex-col",
|
|
99
|
+
style: { bottom: windowBottom },
|
|
100
|
+
children: visiblePages.map((page) => /* @__PURE__ */ jsx(
|
|
101
|
+
MeasuredPage,
|
|
102
|
+
{
|
|
103
|
+
currentUserId,
|
|
104
|
+
getMessageAuthorId,
|
|
105
|
+
getMessageId,
|
|
106
|
+
messages: page.items,
|
|
107
|
+
onHeightChange: handlePageHeightChange,
|
|
108
|
+
pageIndex: page.index,
|
|
109
|
+
renderMessage
|
|
110
|
+
},
|
|
111
|
+
page.index
|
|
112
|
+
))
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
ChatScroller
|
|
122
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Content } from "@meshagent/meshagent";
|
|
2
|
+
import { type AgentMessage, AgentMessageEvent, PendingAgentInput } from "@meshagent/meshagent-agents";
|
|
3
|
+
export type ChatThreadItemRole = "user" | "agent";
|
|
4
|
+
export type ChatThreadItemKind = "message" | "reasoning" | "tool_call" | "image_generation" | "event" | "error";
|
|
5
|
+
export interface ChatThreadGeneratedImage {
|
|
6
|
+
uri?: string;
|
|
7
|
+
status?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ChatThreadItem {
|
|
10
|
+
id: string;
|
|
11
|
+
kind: ChatThreadItemKind;
|
|
12
|
+
role: ChatThreadItemRole;
|
|
13
|
+
text: string;
|
|
14
|
+
attachments: string[];
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
authorName?: string;
|
|
17
|
+
phase?: string;
|
|
18
|
+
turnId?: string;
|
|
19
|
+
toolkit?: string;
|
|
20
|
+
tool?: string;
|
|
21
|
+
command?: string;
|
|
22
|
+
argumentsText?: string;
|
|
23
|
+
input?: Record<string, unknown>;
|
|
24
|
+
output?: Content;
|
|
25
|
+
logs?: string[];
|
|
26
|
+
result?: string;
|
|
27
|
+
stdout?: string;
|
|
28
|
+
stderr?: string;
|
|
29
|
+
state?: string;
|
|
30
|
+
failed?: boolean;
|
|
31
|
+
image?: {
|
|
32
|
+
uri?: string;
|
|
33
|
+
status?: string;
|
|
34
|
+
statusDetail?: string;
|
|
35
|
+
images?: ChatThreadGeneratedImage[];
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface ChatThreadTimeline {
|
|
39
|
+
readonly items: readonly ChatThreadItem[];
|
|
40
|
+
readonly usage: AgentUsageSnapshot | null;
|
|
41
|
+
}
|
|
42
|
+
export declare function buildChatThreadTimeline(events: readonly AgentMessageEvent[], pendingInputs?: readonly PendingAgentInput[]): ChatThreadTimeline;
|
|
43
|
+
export declare function buildMergedChatThreadTimeline(persistedEvents: readonly AgentMessageEvent[], liveEvents: readonly AgentMessageEvent[], pendingInputs?: readonly PendingAgentInput[]): ChatThreadTimeline;
|
|
44
|
+
export declare class AgentUsageSnapshot {
|
|
45
|
+
readonly threadPath: string;
|
|
46
|
+
readonly turnId?: string;
|
|
47
|
+
readonly contextUsedTokens: number;
|
|
48
|
+
readonly contextTotalTokens?: number;
|
|
49
|
+
readonly compactionMode?: string;
|
|
50
|
+
readonly compactionThreshold?: number;
|
|
51
|
+
readonly totalTokens?: number;
|
|
52
|
+
readonly usage: Record<string, number>;
|
|
53
|
+
constructor(params: {
|
|
54
|
+
threadPath: string;
|
|
55
|
+
turnId?: string;
|
|
56
|
+
contextUsedTokens: number;
|
|
57
|
+
contextTotalTokens?: number;
|
|
58
|
+
compactionMode?: string;
|
|
59
|
+
compactionThreshold?: number;
|
|
60
|
+
totalTokens?: number;
|
|
61
|
+
usage: Record<string, number>;
|
|
62
|
+
});
|
|
63
|
+
static fromMessage(message: AgentMessage): AgentUsageSnapshot | null;
|
|
64
|
+
static fromPayload(payload: Record<string, unknown>): AgentUsageSnapshot | null;
|
|
65
|
+
}
|
|
66
|
+
export declare function shouldReplaceAgentUsageSnapshot(current: AgentUsageSnapshot | null | undefined, next: AgentUsageSnapshot): boolean;
|