@meshagent/meshagent-tailwind 0.44.11 → 0.44.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +47 -0
  3. package/dist/cjs/chat/chat-bot-view.d.ts +4 -1
  4. package/dist/cjs/chat/chat-bot-view.js +20 -52
  5. package/dist/cjs/chat/dataset-agent-thread.d.ts +35 -0
  6. package/dist/cjs/chat/dataset-agent-thread.js +429 -0
  7. package/dist/cjs/chat/realtime-audio-output.d.ts +44 -0
  8. package/dist/cjs/chat/realtime-audio-output.js +326 -0
  9. package/dist/cjs/chat/thread-list-view.js +18 -1
  10. package/dist/cjs/chat/thread-view.d.ts +32 -0
  11. package/dist/cjs/chat/thread-view.js +157 -0
  12. package/dist/cjs/index.d.ts +3 -0
  13. package/dist/cjs/index.js +3 -0
  14. package/dist/cjs/meetings/controls.js +8 -15
  15. package/dist/cjs/meetings/lobby.d.ts +1 -1
  16. package/dist/cjs/meetings/lobby.js +10 -6
  17. package/dist/cjs/meetings/meeting-scope.d.ts +3 -0
  18. package/dist/cjs/meetings/meeting-scope.js +25 -4
  19. package/dist/cjs/meetings/meeting-view.d.ts +4 -0
  20. package/dist/cjs/meetings/meeting-view.js +4 -10
  21. package/dist/cjs/meetings/meetings.d.ts +1 -0
  22. package/dist/cjs/meetings/meetings.js +1 -0
  23. package/dist/cjs/meetings/voice-agent-caller.d.ts +11 -0
  24. package/dist/cjs/meetings/voice-agent-caller.js +133 -0
  25. package/dist/esm/chat/chat-bot-view.d.ts +4 -1
  26. package/dist/esm/chat/chat-bot-view.js +23 -55
  27. package/dist/esm/chat/dataset-agent-thread.d.ts +35 -0
  28. package/dist/esm/chat/dataset-agent-thread.js +426 -0
  29. package/dist/esm/chat/realtime-audio-output.d.ts +44 -0
  30. package/dist/esm/chat/realtime-audio-output.js +310 -0
  31. package/dist/esm/chat/thread-list-view.js +18 -1
  32. package/dist/esm/chat/thread-view.d.ts +32 -0
  33. package/dist/esm/chat/thread-view.js +137 -0
  34. package/dist/esm/index.d.ts +3 -0
  35. package/dist/esm/index.js +3 -0
  36. package/dist/esm/meetings/controls.js +8 -15
  37. package/dist/esm/meetings/lobby.d.ts +1 -1
  38. package/dist/esm/meetings/lobby.js +10 -8
  39. package/dist/esm/meetings/meeting-scope.d.ts +3 -0
  40. package/dist/esm/meetings/meeting-scope.js +25 -4
  41. package/dist/esm/meetings/meeting-view.d.ts +4 -0
  42. package/dist/esm/meetings/meeting-view.js +4 -10
  43. package/dist/esm/meetings/meetings.d.ts +1 -0
  44. package/dist/esm/meetings/meetings.js +1 -0
  45. package/dist/esm/meetings/voice-agent-caller.d.ts +11 -0
  46. package/dist/esm/meetings/voice-agent-caller.js +113 -0
  47. package/dist/index.css +2 -2
  48. package/package.json +5 -4
@@ -0,0 +1,426 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import {
4
+ AgentMessage,
5
+ AgentTextContentDelta,
6
+ AgentTextContentEnded,
7
+ AgentTextContentStarted,
8
+ AgentReasoningContentDelta,
9
+ AgentReasoningContentEnded,
10
+ AgentReasoningContentStarted,
11
+ AgentToolCallEnded,
12
+ AgentToolCallPending,
13
+ AgentToolCallStarted,
14
+ BaseChatClient,
15
+ MessagingChatClient,
16
+ ThreadLoaded,
17
+ agentThreadOpenType,
18
+ agentThreadCloseType,
19
+ TurnStart
20
+ } from "@meshagent/meshagent-agents";
21
+ import { AgentThread } from "./agent-thread.js";
22
+ class DatasetReplayChatClient extends BaseChatClient {
23
+ upstream;
24
+ shouldStopUpstream;
25
+ eventPump;
26
+ stopped = false;
27
+ constructor({ upstream, shouldStopUpstream }) {
28
+ super();
29
+ this.upstream = upstream;
30
+ this.shouldStopUpstream = shouldStopUpstream;
31
+ }
32
+ agentParticipant() {
33
+ return this.upstream.agentParticipant();
34
+ }
35
+ localParticipantName() {
36
+ return this.upstream.localParticipantName();
37
+ }
38
+ async start() {
39
+ this.stopped = false;
40
+ await this.upstream.start();
41
+ if (this.eventPump == null) {
42
+ this.eventPump = this.pumpUpstreamEvents();
43
+ }
44
+ }
45
+ async stop() {
46
+ this.stopped = true;
47
+ if (this.shouldStopUpstream) {
48
+ await this.upstream.stop();
49
+ }
50
+ }
51
+ async sendAgentMessage(message, options) {
52
+ if (message.type === agentThreadOpenType || message.type === agentThreadCloseType) {
53
+ return;
54
+ }
55
+ await this.upstream.sendAgentMessage(message, options);
56
+ }
57
+ replayMessages(messages) {
58
+ for (const message of messages) {
59
+ this.handleAgentMessage(message, { createdAt: dateFromString(message.createdAt) ?? void 0 });
60
+ }
61
+ }
62
+ markThreadLoaded(path) {
63
+ this.handleAgentMessage(new ThreadLoaded({ threadId: path }));
64
+ }
65
+ async pumpUpstreamEvents() {
66
+ try {
67
+ for await (const event of this.upstream.events) {
68
+ if (this.stopped) {
69
+ return;
70
+ }
71
+ this.handleAgentMessage(event.message, {
72
+ createdAt: event.createdAt,
73
+ attachment: event.attachment
74
+ });
75
+ }
76
+ } finally {
77
+ this.eventPump = void 0;
78
+ }
79
+ }
80
+ }
81
+ function DatasetAgentThread({
82
+ room,
83
+ path,
84
+ chatClient,
85
+ disposeChatClient = false,
86
+ agentName,
87
+ rowsLoader,
88
+ emptyStateTitle,
89
+ emptyStateDescription,
90
+ clientToolkits,
91
+ toolChoice,
92
+ collapseMessages,
93
+ retryMissingTableMs = 500
94
+ }) {
95
+ const [loadError, setLoadError] = useState(null);
96
+ const normalizedPath = path.trim();
97
+ const activeRowsLoader = useMemo(() => rowsLoader ?? defaultRowsLoader(room), [room, rowsLoader]);
98
+ const upstreamChatClient = useMemo(
99
+ () => chatClient ?? new MessagingChatClient({ room, agentName }),
100
+ [agentName, chatClient, room]
101
+ );
102
+ const replayChatClient = useMemo(
103
+ () => new DatasetReplayChatClient({
104
+ upstream: upstreamChatClient,
105
+ shouldStopUpstream: chatClient == null || disposeChatClient
106
+ }),
107
+ [chatClient, disposeChatClient, upstreamChatClient]
108
+ );
109
+ useEffect(() => {
110
+ let cancelled = false;
111
+ let retryTimer;
112
+ const loadRows = async () => {
113
+ if (normalizedPath === "") {
114
+ setLoadError("thread path cannot be empty");
115
+ replayChatClient.markThreadLoaded(normalizedPath);
116
+ return;
117
+ }
118
+ let ref;
119
+ try {
120
+ ref = parseDatasetThreadRef(normalizedPath);
121
+ } catch (error) {
122
+ setLoadError(describeError(error));
123
+ replayChatClient.markThreadLoaded(normalizedPath);
124
+ return;
125
+ }
126
+ try {
127
+ setLoadError(null);
128
+ const messages = await loadDatasetThreadMessages(activeRowsLoader, {
129
+ path: normalizedPath,
130
+ namespace: ref.namespace,
131
+ table: ref.table
132
+ });
133
+ if (cancelled) {
134
+ return;
135
+ }
136
+ replayChatClient.replayMessages(messages);
137
+ replayChatClient.markThreadLoaded(normalizedPath);
138
+ } catch (error) {
139
+ if (cancelled) {
140
+ return;
141
+ }
142
+ if (isDatasetTableNotFoundError(error)) {
143
+ retryTimer = setTimeout(() => {
144
+ void loadRows();
145
+ }, retryMissingTableMs);
146
+ return;
147
+ }
148
+ setLoadError(describeError(error));
149
+ replayChatClient.markThreadLoaded(normalizedPath);
150
+ }
151
+ };
152
+ void loadRows();
153
+ return () => {
154
+ cancelled = true;
155
+ if (retryTimer !== void 0) {
156
+ clearTimeout(retryTimer);
157
+ }
158
+ };
159
+ }, [activeRowsLoader, normalizedPath, replayChatClient, retryMissingTableMs]);
160
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full min-h-0 flex-1 flex-col", children: [
161
+ loadError === null ? null : /* @__PURE__ */ jsx("div", { className: "px-4 pt-3", children: /* @__PURE__ */ jsx("div", { className: "mx-auto w-full max-w-[912px] whitespace-pre-wrap rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive", children: loadError }) }),
162
+ /* @__PURE__ */ jsx(
163
+ AgentThread,
164
+ {
165
+ room,
166
+ path: normalizedPath,
167
+ chatClient: replayChatClient,
168
+ disposeChatClient: true,
169
+ agentName,
170
+ emptyStateTitle,
171
+ emptyStateDescription,
172
+ clientToolkits,
173
+ toolChoice,
174
+ collapseMessages
175
+ }
176
+ )
177
+ ] });
178
+ }
179
+ function RoomDatasetAgentThread(props) {
180
+ return /* @__PURE__ */ jsx(DatasetAgentThread, { ...props });
181
+ }
182
+ function parseDatasetThreadRef(path) {
183
+ const normalized = path.trim().replace(/\/+$/u, "");
184
+ const prefix = "dataset://";
185
+ if (!normalized.startsWith(prefix)) {
186
+ throw new TypeError("dataset thread path must start with dataset://");
187
+ }
188
+ const body = normalized.slice(prefix.length);
189
+ const parts = body.split("/").map((part) => part.trim()).filter((part) => part !== "");
190
+ const table = parts[parts.length - 1];
191
+ if (table == null || table === "") {
192
+ throw new TypeError("dataset thread path must include a table name");
193
+ }
194
+ return {
195
+ namespace: parts.slice(0, -1),
196
+ table
197
+ };
198
+ }
199
+ function defaultRowsLoader(room) {
200
+ return async function* loadRows({ namespace, table }) {
201
+ for await (const chunk of room.datasets.searchStream({ table, namespace })) {
202
+ yield rowsFromTable(chunk);
203
+ }
204
+ };
205
+ }
206
+ async function loadDatasetThreadMessages(loader, args) {
207
+ const rows = [];
208
+ const loaded = await loader(args);
209
+ if (isAsyncIterable(loaded)) {
210
+ for await (const chunk of loaded) {
211
+ rows.push(...chunk);
212
+ }
213
+ } else {
214
+ rows.push(...loaded);
215
+ }
216
+ return rows.filter((row) => rowData(row) !== null).sort(compareDatasetThreadRows).flatMap((row) => messagesFromDatasetRow(row, args.path));
217
+ }
218
+ function rowsFromTable(table) {
219
+ const tableLike = table;
220
+ if (typeof tableLike.toArray !== "function") {
221
+ return [];
222
+ }
223
+ return tableLike.toArray().map((row) => row != null && typeof row === "object" ? { ...row } : {});
224
+ }
225
+ function messagesFromDatasetRow(row, path) {
226
+ const data = rowData(row);
227
+ if (data === null) {
228
+ return [];
229
+ }
230
+ const agentMessage = agentMessageFromPayload(data);
231
+ if (agentMessage !== null) {
232
+ return [agentMessage];
233
+ }
234
+ const kind = stringValue(data.kind);
235
+ if (kind === "message" || kind === "file") {
236
+ const text = stringValue(data.text) ?? "";
237
+ const attachments = kind === "file" ? stringList(data.urls) : stringList(data.attachments);
238
+ if (text.trim() === "" && attachments.length === 0) {
239
+ return [];
240
+ }
241
+ const role = stringValue(data.role);
242
+ if (role === "user") {
243
+ return [new TurnStart({
244
+ threadId: path,
245
+ messageId: rowItemId(row),
246
+ senderName: stringValue(data.sender_name),
247
+ createdAt: rowCreatedAt(row).toISOString(),
248
+ content: [
249
+ ...text.trim() === "" ? [] : [{ type: "text", text }],
250
+ ...attachments.map((url) => ({ type: "file", url }))
251
+ ]
252
+ })];
253
+ }
254
+ return [
255
+ new AgentTextContentStarted({
256
+ threadId: path,
257
+ itemId: rowItemId(row),
258
+ turnId: rowTurnId(row),
259
+ phase: stringValue(data.phase),
260
+ createdAt: rowCreatedAt(row).toISOString()
261
+ }),
262
+ ...text.trim() === "" ? [] : [new AgentTextContentDelta({
263
+ threadId: path,
264
+ itemId: rowItemId(row),
265
+ turnId: rowTurnId(row),
266
+ phase: stringValue(data.phase),
267
+ text,
268
+ createdAt: rowCreatedAt(row).toISOString()
269
+ })],
270
+ new AgentTextContentEnded({
271
+ threadId: path,
272
+ itemId: rowItemId(row),
273
+ turnId: rowTurnId(row),
274
+ phase: stringValue(data.phase),
275
+ createdAt: rowCreatedAt(row).toISOString()
276
+ })
277
+ ];
278
+ }
279
+ if (kind === "reasoning") {
280
+ const text = stringValue(data.text) ?? "";
281
+ if (text.trim() === "") {
282
+ return [];
283
+ }
284
+ return [
285
+ new AgentReasoningContentStarted({
286
+ threadId: path,
287
+ itemId: rowItemId(row),
288
+ turnId: rowTurnId(row),
289
+ createdAt: rowCreatedAt(row).toISOString()
290
+ }),
291
+ new AgentReasoningContentDelta({
292
+ threadId: path,
293
+ itemId: rowItemId(row),
294
+ turnId: rowTurnId(row),
295
+ text,
296
+ createdAt: rowCreatedAt(row).toISOString()
297
+ }),
298
+ new AgentReasoningContentEnded({
299
+ threadId: path,
300
+ itemId: rowItemId(row),
301
+ turnId: rowTurnId(row),
302
+ createdAt: rowCreatedAt(row).toISOString()
303
+ })
304
+ ];
305
+ }
306
+ if (kind === "tool_call") {
307
+ const toolkit = stringValue(data.toolkit) ?? "";
308
+ const tool = stringValue(data.tool) ?? "tool";
309
+ const status = stringValue(data.status);
310
+ const message = toolCallIsFinished(status) ? new AgentToolCallEnded({
311
+ threadId: path,
312
+ itemId: rowItemId(row),
313
+ turnId: rowTurnId(row),
314
+ toolkit,
315
+ tool,
316
+ arguments: objectValue(data.arguments) ?? void 0,
317
+ createdAt: rowCreatedAt(row).toISOString(),
318
+ error: stringValue(data.error_message) == null ? void 0 : { message: stringValue(data.error_message) }
319
+ }) : toolCallIsPending(status) ? new AgentToolCallPending({
320
+ threadId: path,
321
+ itemId: rowItemId(row),
322
+ turnId: rowTurnId(row),
323
+ toolkit,
324
+ tool,
325
+ arguments: objectValue(data.arguments) ?? void 0,
326
+ createdAt: rowCreatedAt(row).toISOString()
327
+ }) : new AgentToolCallStarted({
328
+ threadId: path,
329
+ itemId: rowItemId(row),
330
+ turnId: rowTurnId(row),
331
+ toolkit,
332
+ tool,
333
+ arguments: objectValue(data.arguments) ?? void 0,
334
+ createdAt: rowCreatedAt(row).toISOString()
335
+ });
336
+ return [message];
337
+ }
338
+ return [];
339
+ }
340
+ function agentMessageFromPayload(payload) {
341
+ if (typeof payload.type !== "string" || payload.type.trim() === "") {
342
+ return null;
343
+ }
344
+ try {
345
+ return AgentMessage.fromJson(payload);
346
+ } catch {
347
+ return null;
348
+ }
349
+ }
350
+ function rowData(row) {
351
+ return objectValue(row.data);
352
+ }
353
+ function compareDatasetThreadRows(left, right) {
354
+ const sequenceOrder = numberValue(left.sequence) - numberValue(right.sequence);
355
+ if (sequenceOrder !== 0) {
356
+ return sequenceOrder;
357
+ }
358
+ const timestampOrder = rowCreatedAt(left).getTime() - rowCreatedAt(right).getTime();
359
+ if (timestampOrder !== 0) {
360
+ return timestampOrder;
361
+ }
362
+ return rowItemId(left).localeCompare(rowItemId(right));
363
+ }
364
+ function rowItemId(row) {
365
+ return stringValue(row.item_id) ?? `row:${stringValue(row.sequence) ?? ""}:${stringValue(row.timestamp) ?? stringValue(row.created_at) ?? ""}`;
366
+ }
367
+ function rowTurnId(row) {
368
+ return stringValue(row.turn_id) ?? rowItemId(row);
369
+ }
370
+ function rowCreatedAt(row) {
371
+ return dateFromString(stringValue(row.timestamp) ?? stringValue(row.created_at)) ?? /* @__PURE__ */ new Date(0);
372
+ }
373
+ function dateFromString(value) {
374
+ if (value == null || value.trim() === "") {
375
+ return null;
376
+ }
377
+ const parsed = new Date(value);
378
+ return Number.isNaN(parsed.getTime()) ? null : parsed;
379
+ }
380
+ function isDatasetTableNotFoundError(error) {
381
+ const values = [
382
+ error instanceof Error ? error.message : void 0,
383
+ typeof error === "object" && error !== null ? stringValue(error.code) : void 0
384
+ ].filter((value) => value != null);
385
+ return values.some((value) => {
386
+ const normalized = value.trim().toLowerCase();
387
+ return normalized.includes("not found") || normalized.includes("not_found") || normalized.includes("does not exist");
388
+ });
389
+ }
390
+ function describeError(error) {
391
+ if (error instanceof Error && error.message.trim() !== "") {
392
+ return error.message;
393
+ }
394
+ return String(error);
395
+ }
396
+ function isAsyncIterable(value) {
397
+ return value != null && typeof value === "object" && Symbol.asyncIterator in value;
398
+ }
399
+ function objectValue(value) {
400
+ return value != null && typeof value === "object" && !Array.isArray(value) ? value : null;
401
+ }
402
+ function stringValue(value) {
403
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
404
+ }
405
+ function stringList(value) {
406
+ if (!Array.isArray(value)) {
407
+ return [];
408
+ }
409
+ return value.filter((entry) => typeof entry === "string" && entry.trim() !== "").map((entry) => entry.trim());
410
+ }
411
+ function numberValue(value) {
412
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
413
+ }
414
+ function toolCallIsPending(status) {
415
+ const normalized = status?.trim().toLowerCase();
416
+ return normalized === "pending" || normalized === "queued";
417
+ }
418
+ function toolCallIsFinished(status) {
419
+ const normalized = status?.trim().toLowerCase();
420
+ return normalized === "completed" || normalized === "failed" || normalized === "error";
421
+ }
422
+ export {
423
+ DatasetAgentThread,
424
+ RoomDatasetAgentThread,
425
+ parseDatasetThreadRef
426
+ };
@@ -0,0 +1,44 @@
1
+ import type { ChatThreadSession } from "@meshagent/meshagent-agents";
2
+ export type RealtimeAudioOutputState = "idle" | "starting" | "playing" | "completed" | "stopped" | "error";
3
+ export interface RealtimeAudioOutputStartOptions {
4
+ sampleRate: number;
5
+ channels: number;
6
+ }
7
+ export interface RealtimeAudioOutputAppendOptions {
8
+ mimeType?: string;
9
+ }
10
+ export interface RealtimeAudioOutput {
11
+ start(options: RealtimeAudioOutputStartOptions): Promise<void>;
12
+ append(pcm: Uint8Array, options?: RealtimeAudioOutputAppendOptions): Promise<void>;
13
+ complete(): Promise<void>;
14
+ stop(): Promise<void>;
15
+ dispose(): Promise<void>;
16
+ }
17
+ export interface UseRealtimeAudioOutputOptions {
18
+ sampleRate?: number;
19
+ channels?: number;
20
+ createOutput?: () => RealtimeAudioOutput;
21
+ }
22
+ export interface UseRealtimeAudioOutputResult {
23
+ state: RealtimeAudioOutputState;
24
+ error: unknown;
25
+ start: (options?: Partial<RealtimeAudioOutputStartOptions>) => Promise<void>;
26
+ append: (pcm: Uint8Array, options?: RealtimeAudioOutputAppendOptions) => Promise<void>;
27
+ complete: () => Promise<void>;
28
+ stop: () => Promise<void>;
29
+ dispose: () => Promise<void>;
30
+ }
31
+ export interface UseAgentRealtimeAudioOutputOptions extends UseRealtimeAudioOutputOptions {
32
+ enabled?: boolean;
33
+ }
34
+ export declare function createRealtimeAudioOutput(): RealtimeAudioOutput;
35
+ export declare function useRealtimeAudioOutput({ sampleRate, channels, createOutput, }?: UseRealtimeAudioOutputOptions): UseRealtimeAudioOutputResult;
36
+ export declare function useAgentRealtimeAudioOutput(session: ChatThreadSession | null | undefined, options?: UseAgentRealtimeAudioOutputOptions): UseRealtimeAudioOutputResult;
37
+ export declare function pcm16ChannelToFloat32({ data, frames, channels, channel, }: {
38
+ data: DataView;
39
+ frames: number;
40
+ channels: number;
41
+ channel: number;
42
+ }): Float32Array;
43
+ export declare function pcmAudioBytes(bytes: Uint8Array, mimeType?: string): Uint8Array;
44
+ export declare function wavDataChunk(bytes: Uint8Array): Uint8Array | null;