@trillet-ai/web-sdk 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40 -45
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,7 +32,6 @@ export class TrilletAgent extends EventEmitter {
|
|
|
32
32
|
this.setupEventForwarding();
|
|
33
33
|
}
|
|
34
34
|
setupEventForwarding() {
|
|
35
|
-
var _a;
|
|
36
35
|
// Forward all SDK events to agent listeners
|
|
37
36
|
this.sdk.on('connected', () => this.emit('connected'));
|
|
38
37
|
this.sdk.on('disconnected', () => this.emit('disconnected'));
|
|
@@ -65,6 +64,32 @@ export class TrilletAgent extends EventEmitter {
|
|
|
65
64
|
this.emit('toolCompleted', toolResult);
|
|
66
65
|
this.emit('transcriptUpdate', this.getTranscripts());
|
|
67
66
|
});
|
|
67
|
+
this.sdk.on('transcript', (transcriptData, participant) => {
|
|
68
|
+
const participantId = participant.identity;
|
|
69
|
+
const isAgent = participantId.startsWith('agent');
|
|
70
|
+
if (transcriptData.isFinal) {
|
|
71
|
+
delete this.currentTranscript[participantId];
|
|
72
|
+
const text = transcriptData.text.trim();
|
|
73
|
+
if (!text)
|
|
74
|
+
return;
|
|
75
|
+
// Check for duplicates
|
|
76
|
+
const lastMessage = this.transcripts[this.transcripts.length - 1];
|
|
77
|
+
if (lastMessage && lastMessage.text === text && lastMessage.participantId === participantId && Date.now() - lastMessage.timestamp.getTime() < 1000) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.transcripts.push({
|
|
81
|
+
role: isAgent ? 'assistant' : 'user',
|
|
82
|
+
text,
|
|
83
|
+
isFinal: true,
|
|
84
|
+
timestamp: new Date(),
|
|
85
|
+
participantId,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.currentTranscript[participantId] = transcriptData.text;
|
|
90
|
+
}
|
|
91
|
+
this.emit('transcriptUpdate', this.getTranscripts());
|
|
92
|
+
});
|
|
68
93
|
// Handle incoming text messages from the agent
|
|
69
94
|
this.sdk.on('message', (message) => {
|
|
70
95
|
var _a, _b;
|
|
@@ -79,49 +104,6 @@ export class TrilletAgent extends EventEmitter {
|
|
|
79
104
|
this.emit('message', message);
|
|
80
105
|
this.emit('transcriptUpdate', this.getTranscripts());
|
|
81
106
|
});
|
|
82
|
-
this.sdk.on('transcript', (transcriptData, participant) => {
|
|
83
|
-
// Use agent-provided transcript as the source of truth
|
|
84
|
-
this.transcripts.push({
|
|
85
|
-
...transcriptData,
|
|
86
|
-
role: 'assistant',
|
|
87
|
-
participantId: participant.identity,
|
|
88
|
-
});
|
|
89
|
-
this.emit('transcriptUpdate', this.getTranscripts());
|
|
90
|
-
});
|
|
91
|
-
// Forward Room events to agent listeners for user transcription
|
|
92
|
-
(_a = this.sdk.getRoom()) === null || _a === void 0 ? void 0 : _a.on(RoomEvent.TranscriptionReceived, (segments, participant) => {
|
|
93
|
-
if (!participant || participant.identity.startsWith('agent')) {
|
|
94
|
-
// We are using agent-provided data for assistant transcripts
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const room = this.sdk.getRoom();
|
|
98
|
-
if (!room)
|
|
99
|
-
return;
|
|
100
|
-
const participantId = participant.identity || room.localParticipant.identity;
|
|
101
|
-
segments.forEach((segment) => {
|
|
102
|
-
if (segment.final) {
|
|
103
|
-
delete this.currentTranscript[participantId];
|
|
104
|
-
const text = segment.text.trim();
|
|
105
|
-
// Check for duplicates
|
|
106
|
-
const lastMessage = this.transcripts[this.transcripts.length - 1];
|
|
107
|
-
if (lastMessage && lastMessage.text === text && lastMessage.participantId === participantId && Date.now() - lastMessage.timestamp.getTime() < 1000) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.transcripts.push({
|
|
111
|
-
role: 'user',
|
|
112
|
-
text,
|
|
113
|
-
isFinal: true,
|
|
114
|
-
timestamp: new Date(),
|
|
115
|
-
participantId,
|
|
116
|
-
});
|
|
117
|
-
this.emit('transcriptUpdate', this.getTranscripts());
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
this.currentTranscript[participantId] = segment.text;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
this.emit(RoomEvent.TranscriptionReceived, segments, participant);
|
|
124
|
-
});
|
|
125
107
|
}
|
|
126
108
|
async startCall() {
|
|
127
109
|
try {
|
|
@@ -367,6 +349,18 @@ class TrilletWebSDK extends EventEmitter {
|
|
|
367
349
|
if (this.isConnected)
|
|
368
350
|
this.endCall();
|
|
369
351
|
});
|
|
352
|
+
this.room.registerTextStreamHandler('lk.transcription', async (reader, info) => {
|
|
353
|
+
var _a, _b;
|
|
354
|
+
const text = await reader.readAll();
|
|
355
|
+
const attributes = ((_a = reader.info) === null || _a === void 0 ? void 0 : _a.attributes) || {};
|
|
356
|
+
const isFinal = attributes['lk.transcription_final'] === 'true' || attributes['lk.transcribed_track_id'];
|
|
357
|
+
if (!info)
|
|
358
|
+
return;
|
|
359
|
+
const participant = (_b = this.room) === null || _b === void 0 ? void 0 : _b.getParticipantByIdentity(info.identity);
|
|
360
|
+
if (!participant)
|
|
361
|
+
return;
|
|
362
|
+
this.emit('transcript', { text, isFinal }, participant);
|
|
363
|
+
});
|
|
370
364
|
// Audio events
|
|
371
365
|
this.room.on(RoomEvent.TrackSubscribed, (track, publication) => {
|
|
372
366
|
var _a;
|
|
@@ -415,7 +409,8 @@ class TrilletWebSDK extends EventEmitter {
|
|
|
415
409
|
this.emit('metadata', event);
|
|
416
410
|
break;
|
|
417
411
|
case 'transcript':
|
|
418
|
-
this
|
|
412
|
+
// this is for agent-generated transcripts, which we are overriding with lk.transcription
|
|
413
|
+
// this.emit('transcript', event.data, participant);
|
|
419
414
|
break;
|
|
420
415
|
case 'llm_call':
|
|
421
416
|
this.emit('toolStarted', { name: event.name, args: event.arguments });
|