@trillet-ai/web-sdk 1.3.7 → 1.4.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/LICENSE +1 -1
- package/README.md +46 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +44 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ const agent = new TrilletAgent({
|
|
|
30
30
|
apiKey: 'your-api-key',
|
|
31
31
|
workspaceId: 'your-workspace-id',
|
|
32
32
|
agentId: 'your-agent-id',
|
|
33
|
+
mode: 'voice', // 'voice' or 'text'
|
|
33
34
|
|
|
34
35
|
// Optional parameters
|
|
35
36
|
variables: {
|
|
@@ -51,11 +52,20 @@ agent.on('connected', (details) => {
|
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
agent.on('transcriptionReceived', (transcript) => {
|
|
54
|
-
console.log('New transcript:', transcript);
|
|
55
|
+
console.log('New voice transcript:', transcript);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
agent.on('message', (message) => {
|
|
59
|
+
console.log('New text message from agent:', message);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
agent.on('transcriptUpdate', (transcripts) => {
|
|
63
|
+
console.log('Transcript updated:', transcripts);
|
|
55
64
|
});
|
|
56
65
|
|
|
57
66
|
// Control the call
|
|
58
|
-
agent.toggleMicrophone(true); // Enable/disable microphone
|
|
67
|
+
agent.toggleMicrophone(true); // Enable/disable microphone in voice mode
|
|
68
|
+
agent.sendTextMessage("Hello, agent!"); // Send a text message in text mode
|
|
59
69
|
agent.endCall(); // End the call
|
|
60
70
|
```
|
|
61
71
|
|
|
@@ -78,7 +88,8 @@ The SDK supports two authentication methods:
|
|
|
78
88
|
```typescript
|
|
79
89
|
const agent = new TrilletAgent({
|
|
80
90
|
workspaceId: 'your-workspace-id',
|
|
81
|
-
agentId: 'your-agent-id'
|
|
91
|
+
agentId: 'your-agent-id',
|
|
92
|
+
mode: 'text' // Or 'voice'
|
|
82
93
|
});
|
|
83
94
|
await agent.startPublicCall();
|
|
84
95
|
```
|
|
@@ -99,7 +110,8 @@ The SDK supports two types of calls:
|
|
|
99
110
|
```typescript
|
|
100
111
|
const agent = new TrilletAgent({
|
|
101
112
|
workspaceId: 'your-workspace-id',
|
|
102
|
-
agentId: 'your-agent-id' // Required for both public and regular calls
|
|
113
|
+
agentId: 'your-agent-id', // Required for both public and regular calls
|
|
114
|
+
mode: 'text' // Or 'voice'
|
|
103
115
|
});
|
|
104
116
|
await agent.startPublicCall();
|
|
105
117
|
```
|
|
@@ -122,19 +134,27 @@ agent.on('error', (error) => {
|
|
|
122
134
|
});
|
|
123
135
|
|
|
124
136
|
agent.on('transcriptionReceived', (segments, participant) => {
|
|
125
|
-
// Called when new transcription is available
|
|
137
|
+
// Called when new transcription is available (voice mode)
|
|
126
138
|
});
|
|
127
139
|
|
|
128
140
|
agent.on('assistantStartedSpeaking', () => {
|
|
129
|
-
// Called when the AI agent starts speaking
|
|
141
|
+
// Called when the AI agent starts speaking (voice mode)
|
|
130
142
|
});
|
|
131
143
|
|
|
132
144
|
agent.on('assistantStoppedSpeaking', () => {
|
|
133
|
-
// Called when the AI agent stops speaking
|
|
145
|
+
// Called when the AI agent stops speaking (voice mode)
|
|
134
146
|
});
|
|
135
147
|
|
|
136
148
|
agent.on('audioData', (data) => {
|
|
137
|
-
// Raw audio data for visualization
|
|
149
|
+
// Raw audio data for visualization (voice mode)
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
agent.on('message', (message) => {
|
|
153
|
+
// Called when a text message is received from the agent (text mode)
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
agent.on('transcriptUpdate', (transcripts) => {
|
|
157
|
+
// Called whenever the transcript is updated (voice or text)
|
|
138
158
|
});
|
|
139
159
|
```
|
|
140
160
|
|
|
@@ -151,6 +171,24 @@ const allTranscripts = agent.getTranscripts();
|
|
|
151
171
|
const currentTranscript = agent.getCurrentTranscript();
|
|
152
172
|
```
|
|
153
173
|
|
|
174
|
+
## Text Mode Features
|
|
175
|
+
|
|
176
|
+
When using text mode, you can send and receive text messages.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
// Send a message to the agent
|
|
180
|
+
agent.sendTextMessage("Hello, how are you?");
|
|
181
|
+
|
|
182
|
+
// Listen for messages from the agent
|
|
183
|
+
agent.on('message', (message) => {
|
|
184
|
+
console.log('Agent says:', message.text);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// The full conversation transcript is available for both modes
|
|
188
|
+
const fullConversation = agent.getTranscripts();
|
|
189
|
+
console.log(fullConversation);
|
|
190
|
+
```
|
|
191
|
+
|
|
154
192
|
## Requirements
|
|
155
193
|
|
|
156
194
|
- Modern web browser with secure context (HTTPS or localhost)
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface TrilletCallConfig {
|
|
|
15
15
|
inputDeviceId?: string;
|
|
16
16
|
outputDeviceId?: string;
|
|
17
17
|
};
|
|
18
|
+
mode?: 'voice' | 'text';
|
|
18
19
|
features?: {
|
|
19
20
|
enableRawAudio?: boolean;
|
|
20
21
|
};
|
|
@@ -49,5 +50,6 @@ export declare class TrilletAgent extends EventEmitter {
|
|
|
49
50
|
getCurrentTranscript(): {
|
|
50
51
|
[key: string]: string;
|
|
51
52
|
};
|
|
53
|
+
sendTextMessage(text: string): void;
|
|
52
54
|
}
|
|
53
55
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,20 @@ export class TrilletAgent extends EventEmitter {
|
|
|
42
42
|
this.sdk.on('assistantStartedSpeaking', () => this.emit('assistantStartedSpeaking'));
|
|
43
43
|
this.sdk.on('assistantStoppedSpeaking', () => this.emit('assistantStoppedSpeaking'));
|
|
44
44
|
this.sdk.on('audioData', (data) => this.emit('audioData', data));
|
|
45
|
+
// Handle incoming text messages from the agent
|
|
46
|
+
this.sdk.on('message', (message) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const agentParticipant = Array.from((_b = (_a = this.sdk.getRoom()) === null || _a === void 0 ? void 0 : _a.remoteParticipants.values()) !== null && _b !== void 0 ? _b : []).find((p) => p.identity.startsWith('agent-'));
|
|
49
|
+
this.transcripts.push({
|
|
50
|
+
role: 'assistant',
|
|
51
|
+
text: message.text,
|
|
52
|
+
isFinal: true,
|
|
53
|
+
timestamp: new Date(),
|
|
54
|
+
participantId: agentParticipant === null || agentParticipant === void 0 ? void 0 : agentParticipant.identity,
|
|
55
|
+
});
|
|
56
|
+
this.emit('message', message);
|
|
57
|
+
this.emit('transcriptUpdate', this.getTranscripts());
|
|
58
|
+
});
|
|
45
59
|
// Forward Room events to agent listeners
|
|
46
60
|
(_a = this.sdk.getRoom()) === null || _a === void 0 ? void 0 : _a.on(RoomEvent.TranscriptionReceived, (segments, participant) => {
|
|
47
61
|
const room = this.sdk.getRoom();
|
|
@@ -117,6 +131,7 @@ export class TrilletAgent extends EventEmitter {
|
|
|
117
131
|
await this.sdk.initializeCall({
|
|
118
132
|
token: data.token,
|
|
119
133
|
wsUrl: process.env.LIVEKIT_WS_URL || 'wss://trillet-ai-xdx0dw5r.livekit.cloud',
|
|
134
|
+
mode: this.config.mode,
|
|
120
135
|
audioSettings: {
|
|
121
136
|
sampleRate: 48000,
|
|
122
137
|
},
|
|
@@ -176,6 +191,7 @@ export class TrilletAgent extends EventEmitter {
|
|
|
176
191
|
await this.sdk.initializeCall({
|
|
177
192
|
token: data.token,
|
|
178
193
|
wsUrl: process.env.LIVEKIT_WS_URL || 'wss://trillet-ai-xdx0dw5r.livekit.cloud',
|
|
194
|
+
mode: this.config.mode,
|
|
179
195
|
audioSettings: {
|
|
180
196
|
sampleRate: 48000,
|
|
181
197
|
},
|
|
@@ -209,6 +225,28 @@ export class TrilletAgent extends EventEmitter {
|
|
|
209
225
|
getCurrentTranscript() {
|
|
210
226
|
return this.currentTranscript;
|
|
211
227
|
}
|
|
228
|
+
sendTextMessage(text) {
|
|
229
|
+
var _a, _b;
|
|
230
|
+
if (this.config.mode !== 'text') {
|
|
231
|
+
console.warn('Cannot send text message in voice mode.');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (!this.sdk.getRoom() || !this.sdk.isConnected) {
|
|
235
|
+
this.emit('error', new Error('Not connected. Cannot send message.'));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const payload = { type: 'user_message', message: text };
|
|
239
|
+
const encoder = new TextEncoder();
|
|
240
|
+
(_a = this.sdk.getRoom()) === null || _a === void 0 ? void 0 : _a.localParticipant.publishData(encoder.encode(JSON.stringify(payload)), { reliable: true });
|
|
241
|
+
this.transcripts.push({
|
|
242
|
+
role: 'user',
|
|
243
|
+
text,
|
|
244
|
+
isFinal: true,
|
|
245
|
+
timestamp: new Date(),
|
|
246
|
+
participantId: (_b = this.sdk.getRoom()) === null || _b === void 0 ? void 0 : _b.localParticipant.identity,
|
|
247
|
+
});
|
|
248
|
+
this.emit('transcriptUpdate', this.transcripts);
|
|
249
|
+
}
|
|
212
250
|
}
|
|
213
251
|
// Internal SDK class
|
|
214
252
|
class TrilletWebSDK extends EventEmitter {
|
|
@@ -237,7 +275,9 @@ class TrilletWebSDK extends EventEmitter {
|
|
|
237
275
|
this.setupEventHandlers(config);
|
|
238
276
|
await this.room.connect(config.wsUrl, config.token);
|
|
239
277
|
console.log('Connected to Trillet room:', this.room.name);
|
|
240
|
-
|
|
278
|
+
if (config.mode !== 'text') {
|
|
279
|
+
this.room.localParticipant.setMicrophoneEnabled(true);
|
|
280
|
+
}
|
|
241
281
|
this.isConnected = true;
|
|
242
282
|
this.emit('connected');
|
|
243
283
|
}
|
|
@@ -354,6 +394,9 @@ class TrilletWebSDK extends EventEmitter {
|
|
|
354
394
|
this.isAssistantSpeaking = false;
|
|
355
395
|
this.emit('assistantStoppedSpeaking');
|
|
356
396
|
break;
|
|
397
|
+
case 'agent_message':
|
|
398
|
+
this.emit('message', event);
|
|
399
|
+
break;
|
|
357
400
|
}
|
|
358
401
|
}
|
|
359
402
|
getRoom() {
|