@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.
- package/CHANGELOG.md +9 -0
- package/README.md +47 -0
- package/dist/cjs/chat/chat-bot-view.d.ts +4 -1
- package/dist/cjs/chat/chat-bot-view.js +20 -52
- package/dist/cjs/chat/dataset-agent-thread.d.ts +35 -0
- package/dist/cjs/chat/dataset-agent-thread.js +429 -0
- package/dist/cjs/chat/realtime-audio-output.d.ts +44 -0
- package/dist/cjs/chat/realtime-audio-output.js +326 -0
- package/dist/cjs/chat/thread-list-view.js +18 -1
- package/dist/cjs/chat/thread-view.d.ts +32 -0
- package/dist/cjs/chat/thread-view.js +157 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/meetings/controls.js +8 -15
- package/dist/cjs/meetings/lobby.d.ts +1 -1
- package/dist/cjs/meetings/lobby.js +10 -6
- package/dist/cjs/meetings/meeting-scope.d.ts +3 -0
- package/dist/cjs/meetings/meeting-scope.js +25 -4
- package/dist/cjs/meetings/meeting-view.d.ts +4 -0
- package/dist/cjs/meetings/meeting-view.js +4 -10
- package/dist/cjs/meetings/meetings.d.ts +1 -0
- package/dist/cjs/meetings/meetings.js +1 -0
- package/dist/cjs/meetings/voice-agent-caller.d.ts +11 -0
- package/dist/cjs/meetings/voice-agent-caller.js +133 -0
- package/dist/esm/chat/chat-bot-view.d.ts +4 -1
- package/dist/esm/chat/chat-bot-view.js +23 -55
- package/dist/esm/chat/dataset-agent-thread.d.ts +35 -0
- package/dist/esm/chat/dataset-agent-thread.js +426 -0
- package/dist/esm/chat/realtime-audio-output.d.ts +44 -0
- package/dist/esm/chat/realtime-audio-output.js +310 -0
- package/dist/esm/chat/thread-list-view.js +18 -1
- package/dist/esm/chat/thread-view.d.ts +32 -0
- package/dist/esm/chat/thread-view.js +137 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/meetings/controls.js +8 -15
- package/dist/esm/meetings/lobby.d.ts +1 -1
- package/dist/esm/meetings/lobby.js +10 -8
- package/dist/esm/meetings/meeting-scope.d.ts +3 -0
- package/dist/esm/meetings/meeting-scope.js +25 -4
- package/dist/esm/meetings/meeting-view.d.ts +4 -0
- package/dist/esm/meetings/meeting-view.js +4 -10
- package/dist/esm/meetings/meetings.d.ts +1 -0
- package/dist/esm/meetings/meetings.js +1 -0
- package/dist/esm/meetings/voice-agent-caller.d.ts +11 -0
- package/dist/esm/meetings/voice-agent-caller.js +113 -0
- package/dist/index.css +2 -2
- package/package.json +5 -4
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
agentAudioGenerationCompletedType,
|
|
4
|
+
agentAudioGenerationDeltaType,
|
|
5
|
+
agentRealtimeAudioChunkType
|
|
6
|
+
} from "@meshagent/meshagent-agents";
|
|
7
|
+
const defaultSampleRate = 24e3;
|
|
8
|
+
const defaultChannels = 1;
|
|
9
|
+
const bytesPerSample = 2;
|
|
10
|
+
const scheduleLeadSeconds = 0.03;
|
|
11
|
+
function createRealtimeAudioOutput() {
|
|
12
|
+
return new BrowserRealtimeAudioOutput();
|
|
13
|
+
}
|
|
14
|
+
class BrowserRealtimeAudioOutput {
|
|
15
|
+
context = null;
|
|
16
|
+
nodes = [];
|
|
17
|
+
generation = 0;
|
|
18
|
+
sampleRate = defaultSampleRate;
|
|
19
|
+
channels = defaultChannels;
|
|
20
|
+
nextStartTime = 0;
|
|
21
|
+
started = false;
|
|
22
|
+
async start({ sampleRate, channels }) {
|
|
23
|
+
validateAudioFormat({ sampleRate, channels });
|
|
24
|
+
if (this.started && this.sampleRate === sampleRate && this.channels === channels) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (this.started || this.nodes.length > 0) {
|
|
28
|
+
await this.stop();
|
|
29
|
+
}
|
|
30
|
+
this.sampleRate = sampleRate;
|
|
31
|
+
this.channels = channels;
|
|
32
|
+
const context = this.context ?? new AudioContext();
|
|
33
|
+
this.context = context;
|
|
34
|
+
void context.resume().catch(() => void 0);
|
|
35
|
+
this.nextStartTime = context.currentTime + scheduleLeadSeconds;
|
|
36
|
+
this.started = true;
|
|
37
|
+
}
|
|
38
|
+
async append(bytes, options = {}) {
|
|
39
|
+
if (!this.started || bytes.length === 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const context = this.context;
|
|
43
|
+
if (context == null) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const pcm = pcmAudioBytes(bytes, options.mimeType);
|
|
47
|
+
const bytesPerFrame = this.channels * bytesPerSample;
|
|
48
|
+
if (pcm.length === 0 || pcm.length % bytesPerFrame !== 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const frames = pcm.length / bytesPerFrame;
|
|
52
|
+
const buffer = context.createBuffer(this.channels, frames, this.sampleRate);
|
|
53
|
+
const data = new DataView(pcm.buffer, pcm.byteOffset, pcm.byteLength);
|
|
54
|
+
for (let channel = 0; channel < this.channels; channel++) {
|
|
55
|
+
buffer.copyToChannel(pcm16ChannelToFloat32({ data, frames, channels: this.channels, channel }), channel);
|
|
56
|
+
}
|
|
57
|
+
const source = context.createBufferSource();
|
|
58
|
+
source.buffer = buffer;
|
|
59
|
+
source.connect(context.destination);
|
|
60
|
+
const startAt = this.nextStartTime < context.currentTime ? context.currentTime : this.nextStartTime;
|
|
61
|
+
this.nextStartTime = startAt + frames / this.sampleRate;
|
|
62
|
+
const generation = this.generation;
|
|
63
|
+
this.nodes.push(source);
|
|
64
|
+
source.onended = () => {
|
|
65
|
+
this.nodes = this.nodes.filter((node) => node !== source);
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
source.start(startAt);
|
|
69
|
+
} catch {
|
|
70
|
+
if (generation === this.generation) {
|
|
71
|
+
this.nodes = this.nodes.filter((node) => node !== source);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async complete() {
|
|
76
|
+
this.started = false;
|
|
77
|
+
}
|
|
78
|
+
async stop() {
|
|
79
|
+
this.generation += 1;
|
|
80
|
+
this.started = false;
|
|
81
|
+
this.nextStartTime = this.context?.currentTime ?? 0;
|
|
82
|
+
const nodes = this.nodes;
|
|
83
|
+
this.nodes = [];
|
|
84
|
+
for (const node of nodes) {
|
|
85
|
+
try {
|
|
86
|
+
node.stop();
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
node.disconnect();
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async dispose() {
|
|
96
|
+
await this.stop();
|
|
97
|
+
const context = this.context;
|
|
98
|
+
this.context = null;
|
|
99
|
+
if (context != null) {
|
|
100
|
+
try {
|
|
101
|
+
await context.close();
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function useRealtimeAudioOutput({
|
|
108
|
+
sampleRate = defaultSampleRate,
|
|
109
|
+
channels = defaultChannels,
|
|
110
|
+
createOutput = createRealtimeAudioOutput
|
|
111
|
+
} = {}) {
|
|
112
|
+
const outputRef = useRef(null);
|
|
113
|
+
const disposedRef = useRef(false);
|
|
114
|
+
const [state, setState] = useState("idle");
|
|
115
|
+
const [error, setError] = useState(null);
|
|
116
|
+
const output = useMemo(() => {
|
|
117
|
+
const created = createOutput();
|
|
118
|
+
outputRef.current = created;
|
|
119
|
+
return created;
|
|
120
|
+
}, [createOutput]);
|
|
121
|
+
const run = useCallback(async (nextState, action) => {
|
|
122
|
+
if (disposedRef.current) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
setError(null);
|
|
127
|
+
await action();
|
|
128
|
+
if (!disposedRef.current) {
|
|
129
|
+
setState(nextState);
|
|
130
|
+
}
|
|
131
|
+
} catch (caught) {
|
|
132
|
+
if (!disposedRef.current) {
|
|
133
|
+
setError(caught);
|
|
134
|
+
setState("error");
|
|
135
|
+
}
|
|
136
|
+
throw caught;
|
|
137
|
+
}
|
|
138
|
+
}, []);
|
|
139
|
+
const start = useCallback(
|
|
140
|
+
(options = {}) => run("playing", async () => {
|
|
141
|
+
setState("starting");
|
|
142
|
+
await output.start({
|
|
143
|
+
sampleRate: options.sampleRate ?? sampleRate,
|
|
144
|
+
channels: options.channels ?? channels
|
|
145
|
+
});
|
|
146
|
+
}),
|
|
147
|
+
[channels, output, run, sampleRate]
|
|
148
|
+
);
|
|
149
|
+
const append = useCallback(
|
|
150
|
+
(pcm, options) => run("playing", () => output.append(pcm, options)),
|
|
151
|
+
[output, run]
|
|
152
|
+
);
|
|
153
|
+
const complete = useCallback(() => run("completed", () => output.complete()), [output, run]);
|
|
154
|
+
const stop = useCallback(() => run("stopped", () => output.stop()), [output, run]);
|
|
155
|
+
const dispose = useCallback(async () => {
|
|
156
|
+
disposedRef.current = true;
|
|
157
|
+
await outputRef.current?.dispose();
|
|
158
|
+
outputRef.current = null;
|
|
159
|
+
}, []);
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
disposedRef.current = false;
|
|
162
|
+
return () => {
|
|
163
|
+
disposedRef.current = true;
|
|
164
|
+
void output.dispose();
|
|
165
|
+
if (outputRef.current === output) {
|
|
166
|
+
outputRef.current = null;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}, [output]);
|
|
170
|
+
return { state, error, start, append, complete, stop, dispose };
|
|
171
|
+
}
|
|
172
|
+
function useAgentRealtimeAudioOutput(session, options = {}) {
|
|
173
|
+
const { enabled = true, ...audioOptions } = options;
|
|
174
|
+
const audio = useRealtimeAudioOutput(audioOptions);
|
|
175
|
+
const processedMessageIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
176
|
+
const activeItemIdRef = useRef(null);
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (!enabled || session == null) {
|
|
179
|
+
return void 0;
|
|
180
|
+
}
|
|
181
|
+
const processEvent = (event) => {
|
|
182
|
+
if (processedMessageIdsRef.current.has(event.message.messageId)) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
processedMessageIdsRef.current.add(event.message.messageId);
|
|
186
|
+
void handleRealtimeAudioEvent({
|
|
187
|
+
event,
|
|
188
|
+
audio,
|
|
189
|
+
activeItemIdRef,
|
|
190
|
+
fallbackSampleRate: audioOptions.sampleRate ?? defaultSampleRate,
|
|
191
|
+
fallbackChannels: audioOptions.channels ?? defaultChannels
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
for (const event of session.messages) {
|
|
195
|
+
processEvent(event);
|
|
196
|
+
}
|
|
197
|
+
const listener = () => {
|
|
198
|
+
for (const event of session.messages) {
|
|
199
|
+
processEvent(event);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
session.addListener(listener);
|
|
203
|
+
return () => {
|
|
204
|
+
session.removeListener(listener);
|
|
205
|
+
};
|
|
206
|
+
}, [audio, audioOptions.channels, audioOptions.sampleRate, enabled, session]);
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
if (enabled) {
|
|
209
|
+
return void 0;
|
|
210
|
+
}
|
|
211
|
+
void audio.stop();
|
|
212
|
+
return void 0;
|
|
213
|
+
}, [audio, enabled]);
|
|
214
|
+
return audio;
|
|
215
|
+
}
|
|
216
|
+
async function handleRealtimeAudioEvent({
|
|
217
|
+
event,
|
|
218
|
+
audio,
|
|
219
|
+
activeItemIdRef,
|
|
220
|
+
fallbackSampleRate,
|
|
221
|
+
fallbackChannels
|
|
222
|
+
}) {
|
|
223
|
+
const message = event.message;
|
|
224
|
+
if (message.type === agentAudioGenerationDeltaType) {
|
|
225
|
+
const audioMessage = message;
|
|
226
|
+
const itemId = audioMessage.itemId ?? message.messageId;
|
|
227
|
+
if (activeItemIdRef.current !== itemId) {
|
|
228
|
+
await audio.stop();
|
|
229
|
+
await audio.start({
|
|
230
|
+
sampleRate: audioMessage.outputFormat?.sampleRate ?? fallbackSampleRate,
|
|
231
|
+
channels: fallbackChannels
|
|
232
|
+
});
|
|
233
|
+
activeItemIdRef.current = itemId;
|
|
234
|
+
}
|
|
235
|
+
await audio.append(audioMessage.data, { mimeType: audioMessage.mimeType ?? audioMessage.outputFormat?.type });
|
|
236
|
+
} else if (message.type === agentAudioGenerationCompletedType) {
|
|
237
|
+
await audio.complete();
|
|
238
|
+
activeItemIdRef.current = null;
|
|
239
|
+
} else if (message.type === agentRealtimeAudioChunkType) {
|
|
240
|
+
const audioMessage = message;
|
|
241
|
+
if (activeItemIdRef.current == null) {
|
|
242
|
+
await audio.start({
|
|
243
|
+
sampleRate: audioMessage.format?.sampleRate ?? fallbackSampleRate,
|
|
244
|
+
channels: fallbackChannels
|
|
245
|
+
});
|
|
246
|
+
activeItemIdRef.current = message.messageId;
|
|
247
|
+
}
|
|
248
|
+
await audio.append(audioMessage.data, { mimeType: audioMessage.format?.type });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function pcm16ChannelToFloat32({
|
|
252
|
+
data,
|
|
253
|
+
frames,
|
|
254
|
+
channels,
|
|
255
|
+
channel
|
|
256
|
+
}) {
|
|
257
|
+
const samples = new Float32Array(frames);
|
|
258
|
+
const bytesPerFrame = channels * bytesPerSample;
|
|
259
|
+
for (let frame = 0; frame < frames; frame++) {
|
|
260
|
+
samples[frame] = data.getInt16(frame * bytesPerFrame + channel * bytesPerSample, true) / 32768;
|
|
261
|
+
}
|
|
262
|
+
return samples;
|
|
263
|
+
}
|
|
264
|
+
function pcmAudioBytes(bytes, mimeType) {
|
|
265
|
+
const normalizedMimeType = mimeType?.split(";")[0]?.trim().toLowerCase();
|
|
266
|
+
if (normalizedMimeType === "audio/wav" || normalizedMimeType === "audio/wave" || normalizedMimeType === "audio/x-wav") {
|
|
267
|
+
return wavDataChunk(bytes) ?? bytes;
|
|
268
|
+
}
|
|
269
|
+
return bytes;
|
|
270
|
+
}
|
|
271
|
+
function wavDataChunk(bytes) {
|
|
272
|
+
if (bytes.length < 44 || ascii(bytes, 0, 4) !== "RIFF" || ascii(bytes, 8, 12) !== "WAVE") {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
const data = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
276
|
+
let offset = 12;
|
|
277
|
+
while (offset + 8 <= bytes.length) {
|
|
278
|
+
const chunkId = ascii(bytes, offset, offset + 4);
|
|
279
|
+
const chunkSize = data.getUint32(offset + 4, true);
|
|
280
|
+
const chunkStart = offset + 8;
|
|
281
|
+
const chunkEnd = chunkStart + chunkSize;
|
|
282
|
+
if (chunkEnd > bytes.length) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
if (chunkId === "data") {
|
|
286
|
+
return bytes.subarray(chunkStart, chunkEnd);
|
|
287
|
+
}
|
|
288
|
+
offset = chunkEnd + (chunkSize % 2 === 1 ? 1 : 0);
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
function ascii(bytes, start, end) {
|
|
293
|
+
return String.fromCharCode(...bytes.subarray(start, end));
|
|
294
|
+
}
|
|
295
|
+
function validateAudioFormat({ sampleRate, channels }) {
|
|
296
|
+
if (!Number.isInteger(sampleRate) || sampleRate <= 0) {
|
|
297
|
+
throw new TypeError("sampleRate must be a positive integer");
|
|
298
|
+
}
|
|
299
|
+
if (!Number.isInteger(channels) || channels <= 0) {
|
|
300
|
+
throw new TypeError("channels must be a positive integer");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
export {
|
|
304
|
+
createRealtimeAudioOutput,
|
|
305
|
+
pcm16ChannelToFloat32,
|
|
306
|
+
pcmAudioBytes,
|
|
307
|
+
useAgentRealtimeAudioOutput,
|
|
308
|
+
useRealtimeAudioOutput,
|
|
309
|
+
wavDataChunk
|
|
310
|
+
};
|
|
@@ -71,6 +71,17 @@ function describeError(error) {
|
|
|
71
71
|
}
|
|
72
72
|
return `${error}`;
|
|
73
73
|
}
|
|
74
|
+
function hasAgentParticipantWaiter(chatClient) {
|
|
75
|
+
return "waitForAgentParticipant" in chatClient && typeof chatClient.waitForAgentParticipant === "function";
|
|
76
|
+
}
|
|
77
|
+
async function waitForThreadListPrerequisites(chatClient) {
|
|
78
|
+
if (chatClient.agentParticipant() !== null) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (hasAgentParticipantWaiter(chatClient)) {
|
|
82
|
+
await chatClient.waitForAgentParticipant({ waitKey: "thread-list" });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
74
85
|
class ChatThreadListStore {
|
|
75
86
|
constructor(repository, onChanged) {
|
|
76
87
|
this.repository = repository;
|
|
@@ -123,9 +134,15 @@ function useThreadList({ room, chatClient }) {
|
|
|
123
134
|
setEntries([]);
|
|
124
135
|
setLoading(true);
|
|
125
136
|
setError(null);
|
|
137
|
+
if (chatClient === null) {
|
|
138
|
+
setEntries([]);
|
|
139
|
+
setLoading(false);
|
|
140
|
+
setError(new Error("Agent thread lists require a chat client."));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
126
143
|
const store = createStore();
|
|
127
144
|
storeRef.current = store;
|
|
128
|
-
void store.open().then(() => {
|
|
145
|
+
void waitForThreadListPrerequisites(chatClient).then(() => store.open()).then(() => {
|
|
129
146
|
if (cancelled) {
|
|
130
147
|
void store.close();
|
|
131
148
|
return;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { RoomClient } from "@meshagent/meshagent";
|
|
3
|
+
import type { BaseChatClient, ClientToolkitDescription } from "@meshagent/meshagent-agents";
|
|
4
|
+
import type { AgentToolChoice } from "./agent-thread";
|
|
5
|
+
import { ChatThreadDisplayMode } from "./conversation-descriptor";
|
|
6
|
+
import type { DatasetThreadRowsLoader } from "./dataset-agent-thread";
|
|
7
|
+
export interface ThreadViewProps {
|
|
8
|
+
room: RoomClient;
|
|
9
|
+
chatClient?: BaseChatClient | null;
|
|
10
|
+
path?: string;
|
|
11
|
+
documentPath?: string;
|
|
12
|
+
agentName?: string;
|
|
13
|
+
threadDisplayMode?: ChatThreadDisplayMode;
|
|
14
|
+
threadDir?: string;
|
|
15
|
+
toolkit?: string;
|
|
16
|
+
tool?: string;
|
|
17
|
+
centerComposer?: boolean;
|
|
18
|
+
emptyStateTitle?: string;
|
|
19
|
+
emptyStateDescription?: string;
|
|
20
|
+
startNewThreadTitle?: string;
|
|
21
|
+
startNewThreadDescription?: string;
|
|
22
|
+
selectedThreadPath?: string | null;
|
|
23
|
+
onSelectedThreadPathChanged?: (path: string | null) => void;
|
|
24
|
+
onSelectedThreadResolved?: (path: string | null, displayName: string | null) => void;
|
|
25
|
+
newThreadResetVersion?: number;
|
|
26
|
+
clientToolkits?: ClientToolkitDescription[];
|
|
27
|
+
toolChoice?: AgentToolChoice;
|
|
28
|
+
collapseMessages?: boolean;
|
|
29
|
+
threadSource?: "session" | "dataset";
|
|
30
|
+
rowsLoader?: DatasetThreadRowsLoader;
|
|
31
|
+
}
|
|
32
|
+
export declare function ThreadView({ room, chatClient, path, documentPath, agentName, threadDisplayMode, threadDir, toolkit, tool, centerComposer, emptyStateTitle, emptyStateDescription, startNewThreadTitle, startNewThreadDescription, selectedThreadPath, onSelectedThreadPathChanged, onSelectedThreadResolved, newThreadResetVersion, clientToolkits, toolChoice, collapseMessages, threadSource, rowsLoader, }: ThreadViewProps): ReactElement;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AlertTriangle } from "lucide-react";
|
|
3
|
+
import { AgentThread } from "./agent-thread";
|
|
4
|
+
import { ChatThreadDisplayMode, chatDocumentPath } from "./conversation-descriptor";
|
|
5
|
+
import { DatasetAgentThread } from "./dataset-agent-thread";
|
|
6
|
+
import { MultiThreadView } from "./multi-thread-view";
|
|
7
|
+
function normalizePath(path) {
|
|
8
|
+
const normalized = path?.trim();
|
|
9
|
+
return normalized ? normalized : null;
|
|
10
|
+
}
|
|
11
|
+
function MultiThreadUnavailable() {
|
|
12
|
+
return /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 items-center justify-center px-4 py-8", children: /* @__PURE__ */ jsx("div", { className: "w-full max-w-[912px] rounded-3xl border border-destructive/30 bg-destructive/5 p-6 text-destructive", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
13
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "mt-0.5 h-5 w-5 shrink-0" }),
|
|
14
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
15
|
+
/* @__PURE__ */ jsx("h2", { className: "text-lg font-semibold", children: "Unable to start a new thread" }),
|
|
16
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-destructive/80", children: "No chat agent is selected." })
|
|
17
|
+
] })
|
|
18
|
+
] }) }) });
|
|
19
|
+
}
|
|
20
|
+
function ThreadView({
|
|
21
|
+
room,
|
|
22
|
+
chatClient = null,
|
|
23
|
+
path,
|
|
24
|
+
documentPath,
|
|
25
|
+
agentName,
|
|
26
|
+
threadDisplayMode = ChatThreadDisplayMode.SingleThread,
|
|
27
|
+
threadDir,
|
|
28
|
+
toolkit,
|
|
29
|
+
tool,
|
|
30
|
+
centerComposer = false,
|
|
31
|
+
emptyStateTitle = "No threads yet",
|
|
32
|
+
emptyStateDescription = "Start a new conversation to see it here.",
|
|
33
|
+
startNewThreadTitle = "Start a new thread",
|
|
34
|
+
startNewThreadDescription = "Connect with this agent and your team.",
|
|
35
|
+
selectedThreadPath,
|
|
36
|
+
onSelectedThreadPathChanged,
|
|
37
|
+
onSelectedThreadResolved,
|
|
38
|
+
newThreadResetVersion = 0,
|
|
39
|
+
clientToolkits,
|
|
40
|
+
toolChoice,
|
|
41
|
+
collapseMessages = true,
|
|
42
|
+
threadSource = "session",
|
|
43
|
+
rowsLoader
|
|
44
|
+
}) {
|
|
45
|
+
const resolvedDocumentPath = normalizePath(documentPath ?? path);
|
|
46
|
+
const resolvedSingleThreadPath = resolvedDocumentPath ?? chatDocumentPath(agentName, { threadDir });
|
|
47
|
+
const activeChatClient = chatClient ?? void 0;
|
|
48
|
+
if (threadDisplayMode !== ChatThreadDisplayMode.MultiThreadComposer) {
|
|
49
|
+
if (threadSource === "dataset") {
|
|
50
|
+
return /* @__PURE__ */ jsx(
|
|
51
|
+
DatasetAgentThread,
|
|
52
|
+
{
|
|
53
|
+
room,
|
|
54
|
+
path: resolvedSingleThreadPath,
|
|
55
|
+
chatClient: activeChatClient,
|
|
56
|
+
disposeChatClient: false,
|
|
57
|
+
agentName,
|
|
58
|
+
rowsLoader,
|
|
59
|
+
emptyStateTitle,
|
|
60
|
+
emptyStateDescription,
|
|
61
|
+
clientToolkits,
|
|
62
|
+
toolChoice,
|
|
63
|
+
collapseMessages
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return /* @__PURE__ */ jsx(
|
|
68
|
+
AgentThread,
|
|
69
|
+
{
|
|
70
|
+
room,
|
|
71
|
+
path: resolvedSingleThreadPath,
|
|
72
|
+
chatClient: activeChatClient,
|
|
73
|
+
disposeChatClient: false,
|
|
74
|
+
agentName,
|
|
75
|
+
emptyStateTitle,
|
|
76
|
+
emptyStateDescription,
|
|
77
|
+
clientToolkits,
|
|
78
|
+
toolChoice,
|
|
79
|
+
collapseMessages
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (!agentName?.trim()) {
|
|
84
|
+
return /* @__PURE__ */ jsx(MultiThreadUnavailable, {});
|
|
85
|
+
}
|
|
86
|
+
return /* @__PURE__ */ jsx(
|
|
87
|
+
MultiThreadView,
|
|
88
|
+
{
|
|
89
|
+
room,
|
|
90
|
+
chatClient: activeChatClient,
|
|
91
|
+
disposeChatClient: false,
|
|
92
|
+
agentName,
|
|
93
|
+
toolkit,
|
|
94
|
+
tool,
|
|
95
|
+
selectedThreadPath,
|
|
96
|
+
onSelectedThreadPathChanged,
|
|
97
|
+
onSelectedThreadResolved,
|
|
98
|
+
newThreadResetVersion,
|
|
99
|
+
centerComposer,
|
|
100
|
+
clientToolkits,
|
|
101
|
+
toolChoice,
|
|
102
|
+
builder: (threadPath) => threadSource === "dataset" ? /* @__PURE__ */ jsx(
|
|
103
|
+
DatasetAgentThread,
|
|
104
|
+
{
|
|
105
|
+
room,
|
|
106
|
+
path: threadPath,
|
|
107
|
+
chatClient: activeChatClient,
|
|
108
|
+
disposeChatClient: false,
|
|
109
|
+
agentName,
|
|
110
|
+
rowsLoader,
|
|
111
|
+
emptyStateTitle: startNewThreadTitle,
|
|
112
|
+
emptyStateDescription: startNewThreadDescription,
|
|
113
|
+
clientToolkits,
|
|
114
|
+
toolChoice,
|
|
115
|
+
collapseMessages
|
|
116
|
+
}
|
|
117
|
+
) : /* @__PURE__ */ jsx(
|
|
118
|
+
AgentThread,
|
|
119
|
+
{
|
|
120
|
+
room,
|
|
121
|
+
path: threadPath,
|
|
122
|
+
chatClient: activeChatClient,
|
|
123
|
+
disposeChatClient: false,
|
|
124
|
+
agentName,
|
|
125
|
+
emptyStateTitle: startNewThreadTitle,
|
|
126
|
+
emptyStateDescription: startNewThreadDescription,
|
|
127
|
+
clientToolkits,
|
|
128
|
+
toolChoice,
|
|
129
|
+
collapseMessages
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
ThreadView
|
|
137
|
+
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,12 +4,15 @@ export * from './chat/chat-input.js';
|
|
|
4
4
|
export * from './chat/chat-message.js';
|
|
5
5
|
export * from './chat/chat-typing-indicator.js';
|
|
6
6
|
export * from './chat/conversation-descriptor.js';
|
|
7
|
+
export * from './chat/dataset-agent-thread.js';
|
|
7
8
|
export * from './chat/file-attachment.js';
|
|
8
9
|
export * from './chat/file-uploader.js';
|
|
9
10
|
export * from './chat/multi-thread-view.js';
|
|
10
11
|
export * from './chat/thread-list-view.js';
|
|
12
|
+
export * from './chat/thread-view.js';
|
|
11
13
|
export * from './chat/agent-thread.js';
|
|
12
14
|
export * from './chat/new-chat-thread.js';
|
|
15
|
+
export * from './chat/realtime-audio-output.js';
|
|
13
16
|
export * from './chat/tool-call-status-accumulator.js';
|
|
14
17
|
export { AgentThreadMessageStatusStore, resolveChatThreadStatusFromStore, shouldShowChatThreadStatus, trackAgentThreadStatusMessageInStore } from './chat/agent-thread-message-status-store.js';
|
|
15
18
|
export * from './file-preview/file-preview.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -4,12 +4,15 @@ export * from "./chat/chat-input.js";
|
|
|
4
4
|
export * from "./chat/chat-message.js";
|
|
5
5
|
export * from "./chat/chat-typing-indicator.js";
|
|
6
6
|
export * from "./chat/conversation-descriptor.js";
|
|
7
|
+
export * from "./chat/dataset-agent-thread.js";
|
|
7
8
|
export * from "./chat/file-attachment.js";
|
|
8
9
|
export * from "./chat/file-uploader.js";
|
|
9
10
|
export * from "./chat/multi-thread-view.js";
|
|
10
11
|
export * from "./chat/thread-list-view.js";
|
|
12
|
+
export * from "./chat/thread-view.js";
|
|
11
13
|
export * from "./chat/agent-thread.js";
|
|
12
14
|
export * from "./chat/new-chat-thread.js";
|
|
15
|
+
export * from "./chat/realtime-audio-output.js";
|
|
13
16
|
export * from "./chat/tool-call-status-accumulator.js";
|
|
14
17
|
import { AgentThreadMessageStatusStore, resolveChatThreadStatusFromStore, shouldShowChatThreadStatus, trackAgentThreadStatusMessageInStore } from "./chat/agent-thread-message-status-store.js";
|
|
15
18
|
export * from "./file-preview/file-preview.js";
|
|
@@ -42,21 +42,14 @@ function MeetingControls({
|
|
|
42
42
|
const controller = useMeetingController(providedController);
|
|
43
43
|
useControllerVersion(controller);
|
|
44
44
|
const hasLocalParticipant = controller.livekitRoom.localParticipant != null;
|
|
45
|
-
return /* @__PURE__ */ jsxs(
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/* @__PURE__ */ jsx(MicToggle, { controller }),
|
|
54
|
-
/* @__PURE__ */ jsx(CameraToggle, { controller }),
|
|
55
|
-
/* @__PURE__ */ jsx(ChangeSettings, { room: controller.livekitRoom })
|
|
56
|
-
] }) : null
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
);
|
|
45
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-center", style: { gap: spacing }, children: [
|
|
46
|
+
/* @__PURE__ */ jsx(ConnectionButton, { controller, onDisconnect }),
|
|
47
|
+
hasLocalParticipant ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
48
|
+
/* @__PURE__ */ jsx(MicToggle, { controller }),
|
|
49
|
+
/* @__PURE__ */ jsx(CameraToggle, { controller }),
|
|
50
|
+
/* @__PURE__ */ jsx(ChangeSettings, { room: controller.livekitRoom })
|
|
51
|
+
] }) : null
|
|
52
|
+
] });
|
|
60
53
|
}
|
|
61
54
|
function describeCameraToggleError(error) {
|
|
62
55
|
const message = String(error);
|
|
@@ -10,7 +10,7 @@ export interface MeetingLobbyJoinOptions {
|
|
|
10
10
|
audioOutputDeviceId?: string;
|
|
11
11
|
}
|
|
12
12
|
export declare function meetingFastConnectOptions(options: MeetingLobbyJoinOptions): MeetingFastConnectOptions;
|
|
13
|
-
export declare function MeetingLobby({
|
|
13
|
+
export declare function MeetingLobby({ onCancel, onJoin, }: {
|
|
14
14
|
controller?: MeetingController;
|
|
15
15
|
onCancel?: () => void;
|
|
16
16
|
onJoin?: (options: MeetingLobbyJoinOptions) => void | Promise<void>;
|
|
@@ -25,9 +25,6 @@ import {
|
|
|
25
25
|
} from "../components/ui/select.js";
|
|
26
26
|
import { Spinner } from "../components/ui/spinner.js";
|
|
27
27
|
import { cn } from "../lib/utils.js";
|
|
28
|
-
import {
|
|
29
|
-
useMeetingController
|
|
30
|
-
} from "./meeting-scope.js";
|
|
31
28
|
const audioInputStorageKey = "audioInput";
|
|
32
29
|
const audioOutputStorageKey = "audioOutput";
|
|
33
30
|
const videoInputStorageKey = "videoInput";
|
|
@@ -507,17 +504,16 @@ function meetingFastConnectOptions(options) {
|
|
|
507
504
|
};
|
|
508
505
|
}
|
|
509
506
|
function MeetingLobby({
|
|
510
|
-
controller: providedController,
|
|
511
507
|
onCancel,
|
|
512
508
|
onJoin
|
|
513
509
|
}) {
|
|
514
|
-
const controller = useMeetingController(providedController);
|
|
515
510
|
const state = useMeetingLobbyState();
|
|
511
|
+
const [joining, setJoining] = useState(false);
|
|
516
512
|
const previewRef = useAttachedPreviewVideo(state.videoTrack);
|
|
517
513
|
const videoPending = state.videoOn && state.videoTrack == null && !state.videoUnavailable;
|
|
518
514
|
const audioPending = state.audioOn && state.audioTrack == null && !state.audioUnavailable;
|
|
519
515
|
const starting = videoPending || audioPending || state.videoProcessing || state.audioProcessing;
|
|
520
|
-
const canJoin =
|
|
516
|
+
const canJoin = !starting && !joining;
|
|
521
517
|
const statusText = state.loaded ? "Get ready to meet" : "Preparing devices";
|
|
522
518
|
return /* @__PURE__ */ jsx("div", { className: "flex h-full min-h-0 flex-col px-6 py-5", children: /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "grid w-full max-w-[800px] gap-5", children: [
|
|
523
519
|
/* @__PURE__ */ jsx("div", { className: "text-center text-base font-semibold", children: statusText }),
|
|
@@ -577,9 +573,15 @@ function MeetingLobby({
|
|
|
577
573
|
className: "h-10 bg-emerald-600 text-white hover:bg-emerald-700 sm:w-[120px]",
|
|
578
574
|
disabled: !canJoin,
|
|
579
575
|
onClick: () => {
|
|
580
|
-
|
|
576
|
+
if (joining) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
setJoining(true);
|
|
580
|
+
Promise.resolve().then(() => onJoin?.(joinOptions(state))).catch((error) => {
|
|
581
|
+
console.warn("Unable to join meeting", error);
|
|
582
|
+
}).finally(() => setJoining(false));
|
|
581
583
|
},
|
|
582
|
-
children: starting ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
584
|
+
children: starting || joining ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
583
585
|
/* @__PURE__ */ jsx(Spinner, { className: "h-4 w-4" }),
|
|
584
586
|
"Starting"
|
|
585
587
|
] }) : "Meet now"
|
|
@@ -54,12 +54,15 @@ export declare class MeetingController {
|
|
|
54
54
|
private readonly listeners;
|
|
55
55
|
private _config;
|
|
56
56
|
private _configurationError;
|
|
57
|
+
private _configurationRequestId;
|
|
58
|
+
private _snapshotVersion;
|
|
57
59
|
constructor({ room, roomOptions }: {
|
|
58
60
|
room: RoomClient;
|
|
59
61
|
roomOptions?: RoomOptions;
|
|
60
62
|
});
|
|
61
63
|
get config(): LivekitConnectionInfo | null;
|
|
62
64
|
get configurationError(): unknown;
|
|
65
|
+
get snapshotVersion(): number;
|
|
63
66
|
get isConnected(): boolean;
|
|
64
67
|
get hasParticipantsWithVideo(): boolean;
|
|
65
68
|
subscribe(listener: Listener): () => void;
|