@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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/Chat.d.ts +11 -3
- package/dist/cjs/Chat.js +376 -29
- package/dist/cjs/ChatBotView.d.ts +29 -0
- package/dist/cjs/ChatBotView.js +491 -0
- package/dist/cjs/ChatInput.d.ts +12 -3
- package/dist/cjs/ChatInput.js +143 -44
- package/dist/cjs/ChatThread.d.ts +17 -3
- package/dist/cjs/ChatThread.js +646 -90
- package/dist/cjs/ChatTypingIndicator.d.ts +12 -5
- package/dist/cjs/ChatTypingIndicator.js +104 -13
- package/dist/cjs/FileUploader.d.ts +3 -2
- package/dist/cjs/FileUploader.js +35 -11
- package/dist/cjs/UploadPill.d.ts +2 -2
- package/dist/cjs/UploadPill.js +70 -32
- package/dist/cjs/chat-hooks.d.ts +38 -0
- package/dist/cjs/chat-hooks.js +390 -0
- package/dist/cjs/chat-message.d.ts +11 -0
- package/dist/cjs/chat-message.js +33 -0
- package/dist/cjs/components/ui/button.d.ts +1 -1
- package/dist/cjs/conversation-descriptor.d.ts +59 -0
- package/dist/cjs/conversation-descriptor.js +300 -0
- package/dist/cjs/file-attachment.d.ts +45 -0
- package/dist/cjs/file-attachment.js +171 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/multi-thread-view.d.ts +18 -0
- package/dist/cjs/multi-thread-view.js +88 -0
- package/dist/cjs/tools/ui-toolkit.d.ts +1 -1
- package/dist/cjs/tools/ui-toolkit.js +2 -1
- package/dist/esm/Chat.d.ts +11 -3
- package/dist/esm/Chat.js +378 -31
- package/dist/esm/ChatBotView.d.ts +29 -0
- package/dist/esm/ChatBotView.js +486 -0
- package/dist/esm/ChatInput.d.ts +12 -3
- package/dist/esm/ChatInput.js +143 -34
- package/dist/esm/ChatThread.d.ts +17 -3
- package/dist/esm/ChatThread.js +648 -92
- package/dist/esm/ChatTypingIndicator.d.ts +12 -5
- package/dist/esm/ChatTypingIndicator.js +94 -13
- package/dist/esm/FileUploader.d.ts +3 -2
- package/dist/esm/FileUploader.js +26 -12
- package/dist/esm/UploadPill.d.ts +2 -2
- package/dist/esm/UploadPill.js +60 -32
- package/dist/esm/chat-hooks.d.ts +38 -0
- package/dist/esm/chat-hooks.js +372 -0
- package/dist/esm/chat-message.d.ts +11 -0
- package/dist/esm/chat-message.js +13 -0
- package/dist/esm/components/ui/button.d.ts +1 -1
- package/dist/esm/conversation-descriptor.d.ts +59 -0
- package/dist/esm/conversation-descriptor.js +280 -0
- package/dist/esm/file-attachment.d.ts +45 -0
- package/dist/esm/file-attachment.js +151 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/multi-thread-view.d.ts +18 -0
- package/dist/esm/multi-thread-view.js +68 -0
- package/dist/esm/tools/ui-toolkit.d.ts +1 -1
- package/dist/esm/tools/ui-toolkit.js +2 -1
- package/dist/index.css +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,300 @@
|
|
|
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 conversation_descriptor_exports = {};
|
|
20
|
+
__export(conversation_descriptor_exports, {
|
|
21
|
+
ChatAgentConversationDescriptor: () => ChatAgentConversationDescriptor,
|
|
22
|
+
ChatAgentConversationKind: () => ChatAgentConversationKind,
|
|
23
|
+
ChatThreadDisplayMode: () => ChatThreadDisplayMode,
|
|
24
|
+
chatDocumentPath: () => chatDocumentPath,
|
|
25
|
+
chatThreadDisplayModeFromAnnotation: () => chatThreadDisplayModeFromAnnotation,
|
|
26
|
+
conversationDescriptorForParticipant: () => conversationDescriptorForParticipant,
|
|
27
|
+
defaultThreadDisplayNameFromPath: () => defaultThreadDisplayNameFromPath,
|
|
28
|
+
defaultUntitledThreadName: () => defaultUntitledThreadName,
|
|
29
|
+
normalizedAnnotationString: () => normalizedAnnotationString,
|
|
30
|
+
normalizedThreadDir: () => normalizedThreadDir,
|
|
31
|
+
participantConversationDescriptor: () => participantConversationDescriptor,
|
|
32
|
+
participantDisplayName: () => participantDisplayName,
|
|
33
|
+
participantSupportsChat: () => participantSupportsChat,
|
|
34
|
+
participantSupportsChatOverride: () => participantSupportsChatOverride,
|
|
35
|
+
participantSupportsVoice: () => participantSupportsVoice,
|
|
36
|
+
participantThreadDir: () => participantThreadDir,
|
|
37
|
+
participantThreadListPath: () => participantThreadListPath,
|
|
38
|
+
resolvedThreadListPath: () => resolvedThreadListPath,
|
|
39
|
+
serviceConversationDescriptor: () => serviceConversationDescriptor,
|
|
40
|
+
serviceThreadDir: () => serviceThreadDir,
|
|
41
|
+
serviceThreadListPath: () => serviceThreadListPath
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(conversation_descriptor_exports);
|
|
44
|
+
var import_meshagent = require("@meshagent/meshagent");
|
|
45
|
+
const defaultUntitledThreadName = "New Chat";
|
|
46
|
+
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
47
|
+
var ChatAgentConversationKind = /* @__PURE__ */ ((ChatAgentConversationKind2) => {
|
|
48
|
+
ChatAgentConversationKind2[ChatAgentConversationKind2["Chat"] = 0] = "Chat";
|
|
49
|
+
ChatAgentConversationKind2[ChatAgentConversationKind2["VoiceOnly"] = 1] = "VoiceOnly";
|
|
50
|
+
ChatAgentConversationKind2[ChatAgentConversationKind2["Meeting"] = 2] = "Meeting";
|
|
51
|
+
return ChatAgentConversationKind2;
|
|
52
|
+
})(ChatAgentConversationKind || {});
|
|
53
|
+
var ChatThreadDisplayMode = /* @__PURE__ */ ((ChatThreadDisplayMode2) => {
|
|
54
|
+
ChatThreadDisplayMode2[ChatThreadDisplayMode2["SingleThread"] = 0] = "SingleThread";
|
|
55
|
+
ChatThreadDisplayMode2[ChatThreadDisplayMode2["MultiThreadComposer"] = 1] = "MultiThreadComposer";
|
|
56
|
+
return ChatThreadDisplayMode2;
|
|
57
|
+
})(ChatThreadDisplayMode || {});
|
|
58
|
+
class ChatAgentConversationDescriptor {
|
|
59
|
+
constructor({
|
|
60
|
+
kind,
|
|
61
|
+
chatThreadDisplayMode = 0 /* SingleThread */,
|
|
62
|
+
threadDir = null,
|
|
63
|
+
threadListPath = null
|
|
64
|
+
}) {
|
|
65
|
+
this.kind = kind;
|
|
66
|
+
this.chatThreadDisplayMode = chatThreadDisplayMode;
|
|
67
|
+
this.threadDir = threadDir;
|
|
68
|
+
this.threadListPath = threadListPath;
|
|
69
|
+
}
|
|
70
|
+
static chat({
|
|
71
|
+
chatThreadDisplayMode = 0 /* SingleThread */,
|
|
72
|
+
threadDir = null,
|
|
73
|
+
threadListPath = null
|
|
74
|
+
} = {}) {
|
|
75
|
+
return new ChatAgentConversationDescriptor({
|
|
76
|
+
kind: 0 /* Chat */,
|
|
77
|
+
chatThreadDisplayMode,
|
|
78
|
+
threadDir,
|
|
79
|
+
threadListPath
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
static voiceOnly() {
|
|
83
|
+
return new ChatAgentConversationDescriptor({
|
|
84
|
+
kind: 1 /* VoiceOnly */
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
static meeting() {
|
|
88
|
+
return new ChatAgentConversationDescriptor({
|
|
89
|
+
kind: 2 /* Meeting */
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
kind;
|
|
93
|
+
chatThreadDisplayMode;
|
|
94
|
+
threadDir;
|
|
95
|
+
threadListPath;
|
|
96
|
+
get isChat() {
|
|
97
|
+
return this.kind === 0 /* Chat */;
|
|
98
|
+
}
|
|
99
|
+
get isVoiceOnly() {
|
|
100
|
+
return this.kind === 1 /* VoiceOnly */;
|
|
101
|
+
}
|
|
102
|
+
get isMeeting() {
|
|
103
|
+
return this.kind === 2 /* Meeting */;
|
|
104
|
+
}
|
|
105
|
+
get isMultiThreadChat() {
|
|
106
|
+
return this.isChat && this.chatThreadDisplayMode === 1 /* MultiThreadComposer */;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function firstAgent(service) {
|
|
110
|
+
return service.agents?.[0] ?? null;
|
|
111
|
+
}
|
|
112
|
+
function defaultThreadDocumentDir(agentName) {
|
|
113
|
+
const trimmed = agentName?.trim();
|
|
114
|
+
if (!trimmed) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return `.threads/${trimmed}`;
|
|
118
|
+
}
|
|
119
|
+
function threadListPathFromThreadDir(threadDir) {
|
|
120
|
+
const normalized = normalizedThreadDir(threadDir);
|
|
121
|
+
if (normalized === null) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return `${normalized}/index.threadl`;
|
|
125
|
+
}
|
|
126
|
+
function basename(path) {
|
|
127
|
+
const segments = path.split("/");
|
|
128
|
+
return segments[segments.length - 1] ?? path;
|
|
129
|
+
}
|
|
130
|
+
function participantDisplayName(participant) {
|
|
131
|
+
return normalizedAnnotationString(participant.getAttribute("name"));
|
|
132
|
+
}
|
|
133
|
+
function participantSupportsVoice(participant) {
|
|
134
|
+
return participant.getAttribute("supports_voice") === true;
|
|
135
|
+
}
|
|
136
|
+
function participantSupportsChatOverride(participant) {
|
|
137
|
+
const value = participant.getAttribute("supports_chat");
|
|
138
|
+
return typeof value === "boolean" ? value : null;
|
|
139
|
+
}
|
|
140
|
+
function participantSupportsChat(participant) {
|
|
141
|
+
return participantSupportsChatOverride(participant) ?? true;
|
|
142
|
+
}
|
|
143
|
+
function normalizedAnnotationString(value) {
|
|
144
|
+
if (typeof value !== "string") {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const normalized = value.trim();
|
|
148
|
+
return normalized === "" ? null : normalized;
|
|
149
|
+
}
|
|
150
|
+
function chatThreadDisplayModeFromAnnotation(value) {
|
|
151
|
+
return normalizedAnnotationString(value) === "default-new" ? 1 /* MultiThreadComposer */ : 0 /* SingleThread */;
|
|
152
|
+
}
|
|
153
|
+
function normalizedThreadDir(threadDir) {
|
|
154
|
+
const trimmed = threadDir?.trim();
|
|
155
|
+
if (!trimmed) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return trimmed.replace(/\/+$/u, "");
|
|
159
|
+
}
|
|
160
|
+
function participantThreadDir(participant) {
|
|
161
|
+
return normalizedThreadDir(normalizedAnnotationString(participant.getAttribute("meshagent.chatbot.thread-dir")));
|
|
162
|
+
}
|
|
163
|
+
function participantThreadListPath(participant) {
|
|
164
|
+
const threadListPath = normalizedAnnotationString(participant.getAttribute("meshagent.chatbot.thread-list"));
|
|
165
|
+
return threadListPath ?? threadListPathFromThreadDir(participantThreadDir(participant));
|
|
166
|
+
}
|
|
167
|
+
function participantConversationDescriptor(participant) {
|
|
168
|
+
const supportsVoice = participantSupportsVoice(participant);
|
|
169
|
+
const supportsChat = participantSupportsChatOverride(participant);
|
|
170
|
+
const threadDir = participantThreadDir(participant);
|
|
171
|
+
const threadListPath = participantThreadListPath(participant);
|
|
172
|
+
const hasThreadAnnotations = normalizedAnnotationString(participant.getAttribute("meshagent.chatbot.threading")) !== null || threadDir !== null || threadListPath !== null;
|
|
173
|
+
if (supportsChat === false) {
|
|
174
|
+
return supportsVoice ? ChatAgentConversationDescriptor.voiceOnly() : null;
|
|
175
|
+
}
|
|
176
|
+
if (supportsVoice && supportsChat !== true && !hasThreadAnnotations) {
|
|
177
|
+
return ChatAgentConversationDescriptor.voiceOnly();
|
|
178
|
+
}
|
|
179
|
+
if (hasThreadAnnotations || participantSupportsChat(participant)) {
|
|
180
|
+
return ChatAgentConversationDescriptor.chat({
|
|
181
|
+
chatThreadDisplayMode: chatThreadDisplayModeFromAnnotation(
|
|
182
|
+
participant.getAttribute("meshagent.chatbot.threading")
|
|
183
|
+
),
|
|
184
|
+
threadDir,
|
|
185
|
+
threadListPath
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (supportsVoice) {
|
|
189
|
+
return ChatAgentConversationDescriptor.voiceOnly();
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
function serviceThreadDir(service) {
|
|
194
|
+
return normalizedThreadDir(firstAgent(service)?.annotations?.["meshagent.chatbot.thread-dir"]);
|
|
195
|
+
}
|
|
196
|
+
function serviceThreadListPath(service, { remoteParticipants = [] } = {}) {
|
|
197
|
+
const annotationPath = normalizedAnnotationString(
|
|
198
|
+
firstAgent(service)?.annotations?.["meshagent.chatbot.thread-list"]
|
|
199
|
+
);
|
|
200
|
+
if (annotationPath !== null) {
|
|
201
|
+
return annotationPath;
|
|
202
|
+
}
|
|
203
|
+
const threadDir = serviceThreadDir(service);
|
|
204
|
+
const threadListPath = threadListPathFromThreadDir(threadDir);
|
|
205
|
+
if (threadListPath !== null) {
|
|
206
|
+
return threadListPath;
|
|
207
|
+
}
|
|
208
|
+
const agentName = firstAgent(service)?.name;
|
|
209
|
+
if (!agentName || agentName.trim() === "") {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
for (const participant of remoteParticipants) {
|
|
213
|
+
if (participant.getAttribute("name") === agentName) {
|
|
214
|
+
return participantThreadListPath(participant);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function serviceConversationDescriptor(service, { remoteParticipants = [] } = {}) {
|
|
220
|
+
const type = firstAgent(service)?.annotations?.["meshagent.agent.type"];
|
|
221
|
+
if (type === "VoiceBot") {
|
|
222
|
+
return ChatAgentConversationDescriptor.voiceOnly();
|
|
223
|
+
}
|
|
224
|
+
if (type === "MeetingTranscriber") {
|
|
225
|
+
return ChatAgentConversationDescriptor.meeting();
|
|
226
|
+
}
|
|
227
|
+
if (type !== "ChatBot") {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
return ChatAgentConversationDescriptor.chat({
|
|
231
|
+
chatThreadDisplayMode: chatThreadDisplayModeFromAnnotation(
|
|
232
|
+
firstAgent(service)?.annotations?.["meshagent.chatbot.threading"]
|
|
233
|
+
),
|
|
234
|
+
threadDir: serviceThreadDir(service),
|
|
235
|
+
threadListPath: serviceThreadListPath(service, { remoteParticipants })
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function conversationDescriptorForParticipant(participant, {
|
|
239
|
+
services,
|
|
240
|
+
remoteParticipants
|
|
241
|
+
}) {
|
|
242
|
+
if (!(participant instanceof import_meshagent.RemoteParticipant)) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
const displayName = participantDisplayName(participant);
|
|
246
|
+
if (displayName !== null) {
|
|
247
|
+
for (const service of services) {
|
|
248
|
+
if (firstAgent(service)?.name !== displayName) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const descriptor = serviceConversationDescriptor(service, { remoteParticipants });
|
|
252
|
+
if (descriptor !== null) {
|
|
253
|
+
return descriptor;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return participantConversationDescriptor(participant);
|
|
258
|
+
}
|
|
259
|
+
function resolvedThreadListPath(threadListPath, {
|
|
260
|
+
threadDir,
|
|
261
|
+
agentName
|
|
262
|
+
} = {}) {
|
|
263
|
+
const normalizedPath = normalizedAnnotationString(threadListPath);
|
|
264
|
+
if (normalizedPath !== null) {
|
|
265
|
+
return normalizedPath;
|
|
266
|
+
}
|
|
267
|
+
const normalizedDir = normalizedThreadDir(threadDir);
|
|
268
|
+
if (normalizedDir !== null) {
|
|
269
|
+
return `${normalizedDir}/index.threadl`;
|
|
270
|
+
}
|
|
271
|
+
const defaultThreadDir = defaultThreadDocumentDir(agentName);
|
|
272
|
+
return defaultThreadDir === null ? null : `${defaultThreadDir}/index.threadl`;
|
|
273
|
+
}
|
|
274
|
+
function chatDocumentPath(agentName, {
|
|
275
|
+
threadDir,
|
|
276
|
+
fallbackPath = ".threads/main.thread"
|
|
277
|
+
} = {}) {
|
|
278
|
+
const normalizedDir = normalizedThreadDir(threadDir);
|
|
279
|
+
if (normalizedDir !== null) {
|
|
280
|
+
return `${normalizedDir}/main.thread`;
|
|
281
|
+
}
|
|
282
|
+
const defaultThreadDir = defaultThreadDocumentDir(agentName);
|
|
283
|
+
if (defaultThreadDir !== null) {
|
|
284
|
+
return `${defaultThreadDir}/main.thread`;
|
|
285
|
+
}
|
|
286
|
+
return fallbackPath;
|
|
287
|
+
}
|
|
288
|
+
function defaultThreadDisplayNameFromPath(path) {
|
|
289
|
+
const basenamePath = basename(path);
|
|
290
|
+
const rawName = basenamePath.endsWith(".thread") ? basenamePath.slice(0, -".thread".length) : basenamePath;
|
|
291
|
+
const trimmed = rawName.trim();
|
|
292
|
+
if (!trimmed || uuidPattern.test(trimmed)) {
|
|
293
|
+
return defaultUntitledThreadName;
|
|
294
|
+
}
|
|
295
|
+
const normalized = trimmed.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim();
|
|
296
|
+
if (!normalized) {
|
|
297
|
+
return defaultUntitledThreadName;
|
|
298
|
+
}
|
|
299
|
+
return normalized.split(" ").filter((segment) => segment !== "").map((segment) => segment.length === 1 ? segment.toUpperCase() : `${segment[0]?.toUpperCase() ?? ""}${segment.slice(1)}`).join(" ");
|
|
300
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EventEmitter, RoomClient } from "@meshagent/meshagent";
|
|
2
|
+
export declare enum UploadStatus {
|
|
3
|
+
Initial = "initial",
|
|
4
|
+
Uploading = "uploading",
|
|
5
|
+
Completed = "completed",
|
|
6
|
+
Failed = "failed"
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class FileAttachment extends EventEmitter<void> {
|
|
9
|
+
protected _status: UploadStatus;
|
|
10
|
+
path: string;
|
|
11
|
+
protected constructor({ path, initialStatus, }: {
|
|
12
|
+
path: string;
|
|
13
|
+
initialStatus?: UploadStatus;
|
|
14
|
+
});
|
|
15
|
+
get status(): UploadStatus;
|
|
16
|
+
protected set status(value: UploadStatus);
|
|
17
|
+
protected notifyChange(): void;
|
|
18
|
+
get filename(): string;
|
|
19
|
+
get size(): number;
|
|
20
|
+
get bytesUploaded(): number;
|
|
21
|
+
}
|
|
22
|
+
export type FileUpload = FileAttachment;
|
|
23
|
+
export declare class MeshagentFileUpload extends FileAttachment {
|
|
24
|
+
readonly room: RoomClient;
|
|
25
|
+
readonly dataStream: AsyncIterable<Uint8Array>;
|
|
26
|
+
private readonly _done;
|
|
27
|
+
private readonly _downloadUrl;
|
|
28
|
+
private _resolveDone;
|
|
29
|
+
private _rejectDone;
|
|
30
|
+
private _resolveDownloadUrl;
|
|
31
|
+
private _rejectDownloadUrl;
|
|
32
|
+
private _bytesUploaded;
|
|
33
|
+
private _size;
|
|
34
|
+
constructor(room: RoomClient, path: string, dataStream: AsyncIterable<Uint8Array>, size?: number, autoStart?: boolean);
|
|
35
|
+
static deferred(room: RoomClient, path: string, dataStream: AsyncIterable<Uint8Array>, size?: number): MeshagentFileUpload;
|
|
36
|
+
get bytesUploaded(): number;
|
|
37
|
+
get size(): number;
|
|
38
|
+
set size(value: number);
|
|
39
|
+
get done(): Promise<void>;
|
|
40
|
+
get downloadUrl(): Promise<URL>;
|
|
41
|
+
startUpload(): void;
|
|
42
|
+
private _upload;
|
|
43
|
+
private _trackedStream;
|
|
44
|
+
}
|
|
45
|
+
export declare function fileToAsyncIterable(file: Blob): AsyncIterable<Uint8Array>;
|
|
@@ -0,0 +1,171 @@
|
|
|
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 file_attachment_exports = {};
|
|
20
|
+
__export(file_attachment_exports, {
|
|
21
|
+
FileAttachment: () => FileAttachment,
|
|
22
|
+
MeshagentFileUpload: () => MeshagentFileUpload,
|
|
23
|
+
UploadStatus: () => UploadStatus,
|
|
24
|
+
fileToAsyncIterable: () => fileToAsyncIterable
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(file_attachment_exports);
|
|
27
|
+
var import_meshagent = require("@meshagent/meshagent");
|
|
28
|
+
var UploadStatus = /* @__PURE__ */ ((UploadStatus2) => {
|
|
29
|
+
UploadStatus2["Initial"] = "initial";
|
|
30
|
+
UploadStatus2["Uploading"] = "uploading";
|
|
31
|
+
UploadStatus2["Completed"] = "completed";
|
|
32
|
+
UploadStatus2["Failed"] = "failed";
|
|
33
|
+
return UploadStatus2;
|
|
34
|
+
})(UploadStatus || {});
|
|
35
|
+
class FileAttachment extends import_meshagent.EventEmitter {
|
|
36
|
+
_status;
|
|
37
|
+
path;
|
|
38
|
+
constructor({
|
|
39
|
+
path,
|
|
40
|
+
initialStatus = "initial" /* Initial */
|
|
41
|
+
}) {
|
|
42
|
+
super();
|
|
43
|
+
this.path = path;
|
|
44
|
+
this._status = initialStatus;
|
|
45
|
+
}
|
|
46
|
+
get status() {
|
|
47
|
+
return this._status;
|
|
48
|
+
}
|
|
49
|
+
set status(value) {
|
|
50
|
+
if (this._status !== value) {
|
|
51
|
+
this._status = value;
|
|
52
|
+
this.notifyChange();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
notifyChange() {
|
|
56
|
+
this.emit("change", void 0);
|
|
57
|
+
}
|
|
58
|
+
get filename() {
|
|
59
|
+
return this.path.split("/").pop() ?? "";
|
|
60
|
+
}
|
|
61
|
+
get size() {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
get bytesUploaded() {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class MeshagentFileUpload extends FileAttachment {
|
|
69
|
+
room;
|
|
70
|
+
dataStream;
|
|
71
|
+
_done;
|
|
72
|
+
_downloadUrl;
|
|
73
|
+
_resolveDone;
|
|
74
|
+
_rejectDone;
|
|
75
|
+
_resolveDownloadUrl;
|
|
76
|
+
_rejectDownloadUrl;
|
|
77
|
+
_bytesUploaded = 0;
|
|
78
|
+
_size;
|
|
79
|
+
constructor(room, path, dataStream, size = 0, autoStart = true) {
|
|
80
|
+
super({ path });
|
|
81
|
+
this.room = room;
|
|
82
|
+
this.dataStream = dataStream;
|
|
83
|
+
this._size = size;
|
|
84
|
+
this._done = new Promise((resolve, reject) => {
|
|
85
|
+
this._resolveDone = resolve;
|
|
86
|
+
this._rejectDone = reject;
|
|
87
|
+
});
|
|
88
|
+
this._downloadUrl = new Promise((resolve, reject) => {
|
|
89
|
+
this._resolveDownloadUrl = resolve;
|
|
90
|
+
this._rejectDownloadUrl = reject;
|
|
91
|
+
});
|
|
92
|
+
if (autoStart) {
|
|
93
|
+
this.startUpload();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
static deferred(room, path, dataStream, size = 0) {
|
|
97
|
+
return new MeshagentFileUpload(room, path, dataStream, size, false);
|
|
98
|
+
}
|
|
99
|
+
get bytesUploaded() {
|
|
100
|
+
return this._bytesUploaded;
|
|
101
|
+
}
|
|
102
|
+
get size() {
|
|
103
|
+
return this._size;
|
|
104
|
+
}
|
|
105
|
+
set size(value) {
|
|
106
|
+
this._size = value;
|
|
107
|
+
}
|
|
108
|
+
get done() {
|
|
109
|
+
return this._done;
|
|
110
|
+
}
|
|
111
|
+
get downloadUrl() {
|
|
112
|
+
return this._downloadUrl;
|
|
113
|
+
}
|
|
114
|
+
startUpload() {
|
|
115
|
+
if (this.status !== "initial" /* Initial */) {
|
|
116
|
+
throw new Error("upload already started or completed");
|
|
117
|
+
}
|
|
118
|
+
void this._upload();
|
|
119
|
+
}
|
|
120
|
+
async _upload() {
|
|
121
|
+
try {
|
|
122
|
+
this.status = "uploading" /* Uploading */;
|
|
123
|
+
const trackedStream = this._trackedStream();
|
|
124
|
+
await this.room.storage.uploadStream(this.path, trackedStream, {
|
|
125
|
+
overwrite: true,
|
|
126
|
+
size: this.size > 0 ? this.size : null
|
|
127
|
+
});
|
|
128
|
+
this._resolveDone();
|
|
129
|
+
this.status = "completed" /* Completed */;
|
|
130
|
+
const url = await this.room.storage.downloadUrl(this.path);
|
|
131
|
+
this._resolveDownloadUrl(new URL(url));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
this.status = "failed" /* Failed */;
|
|
134
|
+
this._rejectDone(error);
|
|
135
|
+
this._rejectDownloadUrl(error);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async *_trackedStream() {
|
|
139
|
+
for await (const chunk of this.dataStream) {
|
|
140
|
+
yield chunk;
|
|
141
|
+
this._bytesUploaded += chunk.length;
|
|
142
|
+
this.notifyChange();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function* fileToAsyncIterable(file) {
|
|
147
|
+
const chunkSize = 64 * 1024;
|
|
148
|
+
if (typeof file.stream === "function") {
|
|
149
|
+
const reader = file.stream().getReader();
|
|
150
|
+
try {
|
|
151
|
+
while (true) {
|
|
152
|
+
const { done, value } = await reader.read();
|
|
153
|
+
if (done) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (value != null) {
|
|
157
|
+
yield value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} finally {
|
|
161
|
+
reader.releaseLock();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
let offset = 0;
|
|
165
|
+
while (offset < file.size) {
|
|
166
|
+
const chunk = file.slice(offset, offset + chunkSize);
|
|
167
|
+
const buffer = await chunk.arrayBuffer();
|
|
168
|
+
yield new Uint8Array(buffer);
|
|
169
|
+
offset += chunkSize;
|
|
170
|
+
}
|
|
171
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export * from './Chat';
|
|
2
|
+
export * from './ChatBotView';
|
|
2
3
|
export * from './ChatInput';
|
|
3
4
|
export * from './ChatThread';
|
|
4
5
|
export * from './ChatTypingIndicator';
|
|
5
6
|
export * from './FileUploader';
|
|
7
|
+
export * from './chat-message';
|
|
8
|
+
export * from './conversation-descriptor';
|
|
9
|
+
export * from './file-attachment';
|
|
10
|
+
export * from './multi-thread-view';
|
package/dist/cjs/index.js
CHANGED
|
@@ -16,7 +16,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var index_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(index_exports);
|
|
18
18
|
__reExport(index_exports, require("./Chat"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./ChatBotView"), module.exports);
|
|
19
20
|
__reExport(index_exports, require("./ChatInput"), module.exports);
|
|
20
21
|
__reExport(index_exports, require("./ChatThread"), module.exports);
|
|
21
22
|
__reExport(index_exports, require("./ChatTypingIndicator"), module.exports);
|
|
22
23
|
__reExport(index_exports, require("./FileUploader"), module.exports);
|
|
24
|
+
__reExport(index_exports, require("./chat-message"), module.exports);
|
|
25
|
+
__reExport(index_exports, require("./conversation-descriptor"), module.exports);
|
|
26
|
+
__reExport(index_exports, require("./file-attachment"), module.exports);
|
|
27
|
+
__reExport(index_exports, require("./multi-thread-view"), module.exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { RoomClient } from "@meshagent/meshagent";
|
|
3
|
+
export type MultiThreadContentBuilder = (threadPath: string) => ReactElement;
|
|
4
|
+
export interface MultiThreadViewProps {
|
|
5
|
+
room: RoomClient;
|
|
6
|
+
agentName: string;
|
|
7
|
+
builder: MultiThreadContentBuilder;
|
|
8
|
+
toolkit?: string;
|
|
9
|
+
tool?: string;
|
|
10
|
+
selectedThreadPath?: string | null;
|
|
11
|
+
onSelectedThreadPathChanged?: (path: string | null) => void;
|
|
12
|
+
onSelectedThreadResolved?: (path: string | null, displayName: string | null) => void;
|
|
13
|
+
newThreadResetVersion?: number;
|
|
14
|
+
centerComposer?: boolean;
|
|
15
|
+
emptyStateTitle?: string;
|
|
16
|
+
emptyStateDescription?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function MultiThreadView({ room, agentName, builder, toolkit, tool, selectedThreadPath, onSelectedThreadPathChanged, onSelectedThreadResolved, newThreadResetVersion, centerComposer, emptyStateTitle, emptyStateDescription, }: MultiThreadViewProps): ReactElement;
|
|
@@ -0,0 +1,88 @@
|
|
|
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 multi_thread_view_exports = {};
|
|
20
|
+
__export(multi_thread_view_exports, {
|
|
21
|
+
MultiThreadView: () => MultiThreadView
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(multi_thread_view_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_Chat = require("./Chat");
|
|
27
|
+
function normalizeSelectedThreadPath(path) {
|
|
28
|
+
const normalized = path?.trim();
|
|
29
|
+
return normalized ? normalized : null;
|
|
30
|
+
}
|
|
31
|
+
function MultiThreadView({
|
|
32
|
+
room,
|
|
33
|
+
agentName,
|
|
34
|
+
builder,
|
|
35
|
+
toolkit = "chat",
|
|
36
|
+
tool = "new_thread",
|
|
37
|
+
selectedThreadPath,
|
|
38
|
+
onSelectedThreadPathChanged,
|
|
39
|
+
onSelectedThreadResolved,
|
|
40
|
+
newThreadResetVersion = 0,
|
|
41
|
+
centerComposer = true,
|
|
42
|
+
emptyStateTitle,
|
|
43
|
+
emptyStateDescription
|
|
44
|
+
}) {
|
|
45
|
+
const controlledSelectedThreadPath = selectedThreadPath !== void 0 ? normalizeSelectedThreadPath(selectedThreadPath) : void 0;
|
|
46
|
+
const [internalSelectedThreadPath, setInternalSelectedThreadPath] = (0, import_react.useState)(() => controlledSelectedThreadPath ?? null);
|
|
47
|
+
(0, import_react.useEffect)(() => {
|
|
48
|
+
if (controlledSelectedThreadPath === void 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
setInternalSelectedThreadPath(controlledSelectedThreadPath);
|
|
52
|
+
}, [controlledSelectedThreadPath]);
|
|
53
|
+
(0, import_react.useEffect)(() => {
|
|
54
|
+
if (controlledSelectedThreadPath !== void 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setInternalSelectedThreadPath(null);
|
|
58
|
+
}, [agentName, controlledSelectedThreadPath, room]);
|
|
59
|
+
const activeSelectedThreadPath = controlledSelectedThreadPath ?? internalSelectedThreadPath;
|
|
60
|
+
const composerKey = (0, import_react.useMemo)(
|
|
61
|
+
() => `new-thread-${agentName.trim()}-${newThreadResetVersion}`,
|
|
62
|
+
[agentName, newThreadResetVersion]
|
|
63
|
+
);
|
|
64
|
+
if (activeSelectedThreadPath !== null) {
|
|
65
|
+
return builder(activeSelectedThreadPath);
|
|
66
|
+
}
|
|
67
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
68
|
+
import_Chat.Chat,
|
|
69
|
+
{
|
|
70
|
+
room,
|
|
71
|
+
agentName,
|
|
72
|
+
toolkit,
|
|
73
|
+
tool,
|
|
74
|
+
centerComposer,
|
|
75
|
+
emptyStateTitle,
|
|
76
|
+
emptyStateDescription,
|
|
77
|
+
onThreadResolved: (path, displayName) => {
|
|
78
|
+
const normalizedPath = normalizeSelectedThreadPath(path);
|
|
79
|
+
if (controlledSelectedThreadPath === void 0) {
|
|
80
|
+
setInternalSelectedThreadPath(normalizedPath);
|
|
81
|
+
}
|
|
82
|
+
onSelectedThreadPathChanged?.(normalizedPath);
|
|
83
|
+
onSelectedThreadResolved?.(normalizedPath, displayName);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
composerKey
|
|
87
|
+
);
|
|
88
|
+
}
|
package/dist/esm/Chat.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { Participant, RoomClient } from "@meshagent/meshagent";
|
|
2
3
|
export interface ChatProps {
|
|
3
4
|
room: RoomClient;
|
|
4
|
-
path
|
|
5
|
+
path?: string;
|
|
5
6
|
participants?: Participant[];
|
|
7
|
+
agentName?: string;
|
|
8
|
+
toolkit?: string;
|
|
9
|
+
tool?: string;
|
|
10
|
+
centerComposer?: boolean;
|
|
11
|
+
emptyStateTitle?: string;
|
|
12
|
+
emptyStateDescription?: string;
|
|
13
|
+
onThreadResolved?: (path: string | null, displayName: string | null) => void;
|
|
6
14
|
}
|
|
7
|
-
export declare function Chat({ room, path, participants }: ChatProps):
|
|
15
|
+
export declare function Chat({ room, path, participants, agentName, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, onThreadResolved, }: ChatProps): ReactElement;
|