@trillet-ai/web-sdk 1.3.0 → 1.3.2

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/README.md CHANGED
@@ -1,174 +1,184 @@
1
- # Trillet Web SDK
1
+ # Trillet AI Web Calls SDK
2
2
 
3
- The Trillet Web SDK enables you to integrate voice AI agents into your web applications. This SDK provides a simple interface for initiating and managing voice calls with Trillet AI agents.
3
+ The Trillet AI Web Calls SDK enables seamless integration of AI-powered voice and text interactions into web applications. This SDK provides a simple interface to connect with Trillet AI agents for real-time communication.
4
4
 
5
- ## Installation
5
+ ## Features
6
6
 
7
- ```bash
8
- npm install @trillet/web-sdk
9
- ```
7
+ - 🎙️ Real-time voice interactions with AI agents
8
+ - 💬 Text-based conversations
9
+ - 🔒 Secure authentication options
10
+ - 📊 Audio visualization capabilities
11
+ - 🎯 Event-driven architecture
12
+ - 🔄 Real-time transcription
13
+ - 🌐 Browser compatibility checks
10
14
 
11
- ## Authentication
15
+ ## Installation
12
16
 
13
- There are two methods to authenticate with the Trillet API:
14
-
15
- ### 1. Server-Side Authentication (Recommended)
16
-
17
- For production environments, we strongly recommend using server-side authentication to keep your API keys secure. Here's how to implement it:
18
-
19
- 1. First, generate a token on your backend server:
20
-
21
- ```javascript
22
- // Backend (Node.js example)
23
- app.post('/get-trillet-token', async (req, res) => {
24
- try {
25
- const response = await fetch('https://api.trillet.ai/v1/api/calls/sdk/auth', {
26
- method: 'POST',
27
- headers: {
28
- 'Content-Type': 'application/json',
29
- },
30
- body: JSON.stringify({
31
- api_key: process.env.TRILLET_API_KEY,
32
- workspace_id: process.env.TRILLET_WORKSPACE_ID
33
- })
34
- });
35
-
36
- const { sdk_token } = await response.json();
37
- res.json({ token: sdk_token });
38
- } catch (error) {
39
- res.status(500).json({ error: 'Failed to generate token' });
40
- }
41
- });
17
+ ```bash
18
+ npm install @trillet/webcalls-sdk
19
+ # or
20
+ yarn add @trillet/webcalls-sdk
42
21
  ```
43
22
 
44
- 2. Then use the token in your frontend code:
23
+ ## Quick Start
45
24
 
46
- ```javascript
47
- // Frontend
48
- const response = await fetch('/get-trillet-token');
49
- const { token } = await response.json();
25
+ ```typescript
26
+ import { TrilletAgent } from '@trillet/webcalls-sdk';
50
27
 
28
+ // Initialize the agent with API Key (Standard Method)
51
29
  const agent = new TrilletAgent({
52
- connectionToken: token, // Use the token from your backend
53
- agentId: 'your-agent-id'
30
+ apiKey: 'your-api-key',
31
+ workspaceId: 'your-workspace-id',
32
+ agentId: 'your-agent-id',
33
+
34
+ // Optional parameters
35
+ variables: {
36
+ customVar1: 'value1',
37
+ customVar2: 'value2'
38
+ },
39
+ callbackUrl: 'https://your-callback-url.com'
54
40
  });
55
41
 
42
+ // Start a regular call
56
43
  await agent.startCall();
57
- ```
58
44
 
59
- ### 2. Direct Authentication (Development Only)
45
+ // Or start a public call
46
+ await agent.startPublicCall();
60
47
 
61
- For development and testing purposes only, you can authenticate directly:
48
+ // Listen for events
49
+ agent.on('connected', (details) => {
50
+ console.log('Connected to call:', details);
51
+ });
62
52
 
63
- ```javascript
64
- const agent = new TrilletAgent({
65
- apiKey: 'your-api-key', // Not recommended in production
66
- workspaceId: 'your-workspace-id', // Not recommended in production
67
- agentId: 'your-agent-id'
53
+ agent.on('transcriptionReceived', (transcript) => {
54
+ console.log('New transcript:', transcript);
68
55
  });
69
56
 
70
- await agent.startCall();
57
+ // Control the call
58
+ agent.toggleMicrophone(true); // Enable/disable microphone
59
+ agent.endCall(); // End the call
71
60
  ```
72
61
 
73
- ⚠️ **Security Warning**: Never expose your API keys in frontend code in production. Always use server-side token generation for production environments.
74
-
75
- ## Basic Usage
62
+ ## Authentication
76
63
 
77
- ```javascript
78
- import { TrilletAgent } from '@trillet/web-sdk';
64
+ The SDK supports two authentication methods:
65
+
66
+ 1. **API Key Authentication (Standard Method)**
67
+ ```typescript
68
+ const agent = new TrilletAgent({
69
+ apiKey: 'your-api-key',
70
+ workspaceId: 'your-workspace-id',
71
+ agentId: 'your-agent-id'
72
+ });
73
+ ```
74
+
75
+ 2. **Public Access**
76
+ - For public-facing applications
77
+ - Uses `startPublicCall()` method
78
+ ```typescript
79
+ const agent = new TrilletAgent({
80
+ workspaceId: 'your-workspace-id',
81
+ agentId: 'your-agent-id'
82
+ });
83
+ await agent.startPublicCall();
84
+ ```
85
+
86
+ ## Call Types
87
+
88
+ The SDK supports two types of calls:
89
+
90
+ 1. **Regular Call** - Using `startCall()`
91
+ - Requires full authentication with API Key
92
+ - Suitable for authenticated users
93
+
94
+ 2. **Public Call** - Using `startPublicCall()`
95
+ - Requires workspace ID and agent ID
96
+ - Suitable for public-facing applications
97
+ - No API key needed in client-side code
98
+ - Example:
99
+ ```typescript
100
+ const agent = new TrilletAgent({
101
+ workspaceId: 'your-workspace-id',
102
+ agentId: 'your-agent-id' // Required for both public and regular calls
103
+ });
104
+ await agent.startPublicCall();
105
+ ```
79
106
 
80
- // Initialize the agent
81
- const agent = new TrilletAgent({
82
- connectionToken: 'token-from-your-backend',
83
- agentId: 'your-agent-id',
84
- variables: {
85
- // Optional variables to customize agent behavior
86
- customerName: 'John Doe',
87
- context: 'support'
88
- },
89
- callbackUrl: 'https://your-server.com/webhooks/calls' // Optional webhook URL for call events
90
- });
107
+ ## Events
91
108
 
92
- // Start a call
93
- await agent.startCall();
109
+ The SDK emits various events that you can listen to:
94
110
 
95
- // Listen for events
96
- agent.on('connected', () => {
97
- console.log('Connected to agent');
111
+ ```typescript
112
+ agent.on('connected', (details) => {
113
+ // Called when successfully connected to a call
98
114
  });
99
115
 
100
116
  agent.on('disconnected', () => {
101
- console.log('Disconnected from agent');
117
+ // Called when the call ends
102
118
  });
103
119
 
104
120
  agent.on('error', (error) => {
105
- console.error('Error:', error);
121
+ // Called when an error occurs
122
+ });
123
+
124
+ agent.on('transcriptionReceived', (segments, participant) => {
125
+ // Called when new transcription is available
106
126
  });
107
127
 
108
- // End the call
109
- agent.endCall();
128
+ agent.on('assistantStartedSpeaking', () => {
129
+ // Called when the AI agent starts speaking
130
+ });
110
131
 
111
- // Get Finalized Transcripts:
112
- agent.getTranscripts();
132
+ agent.on('assistantStoppedSpeaking', () => {
133
+ // Called when the AI agent stops speaking
134
+ });
113
135
 
114
- // Get Ongoing Transcripts:
115
- agent.getCurrentTranscripts();
136
+ agent.on('audioData', (data) => {
137
+ // Raw audio data for visualization
138
+ });
116
139
  ```
117
140
 
118
- ## API Endpoints
141
+ ## Voice Mode Features
119
142
 
120
- The SDK uses the following endpoints:
143
+ When using voice mode, the SDK provides additional audio-related features:
121
144
 
122
- - Authentication: `https://api.trillet.ai/v1/api/calls/sdk/auth`
123
- - Connection: `https://api.trillet.ai/v1/api/calls/web/connect`
124
-
125
- ## Events
145
+ ```typescript
146
+ // Check if the assistant is currently speaking
147
+ const isSpeaking = agent.isAssistantSpeaking;
126
148
 
127
- The SDK emits various events you can listen to:
149
+ // Access transcripts
150
+ const allTranscripts = agent.getTranscripts();
151
+ const currentTranscript = agent.getCurrentTranscript();
152
+ ```
128
153
 
129
- - `connected`: Fired when successfully connected to the agent
130
- - `disconnected`: Fired when disconnected from the agent
131
- - `error`: Fired when an error occurs
132
- - `status`: Provides status updates about the call
133
- - `metadata`: Provides additional data about the call
134
- - `assistantStartedSpeaking`: Fired when the AI agent starts speaking
135
- - `assistantStoppedSpeaking`: Fired when the AI agent stops speaking
136
- - `audioData`: Provides raw audio data (if enabled)
137
- - `transcriptionReceived`: Provides transcript and participant
154
+ ## Requirements
138
155
 
139
- ## Advanced Configuration
156
+ - Modern web browser with secure context (HTTPS or localhost)
157
+ - WebRTC support
158
+ - Microphone access (for voice mode)
140
159
 
141
- You can customize various aspects of the call:
160
+ ## Browser Support
142
161
 
143
- ```javascript
144
- const agent = new TrilletAgent({
145
- connectionToken: 'your-token',
146
- agentId: 'your-agent-id',
147
- variables: {
148
- // Custom variables for your agent
149
- },
150
- callbackUrl: 'https://your-webhook-url.com',
151
- });
162
+ The SDK is compatible with modern browsers that support WebRTC:
163
+ - Chrome (recommended)
164
+ - Firefox
165
+ - Safari
166
+ - Edge
152
167
 
153
- await agent.startCall();
168
+ ## Error Handling
154
169
 
155
- // Toggle microphone
156
- agent.toggleMicrophone(false); // Mute
157
- agent.toggleMicrophone(true); // Unmute
170
+ The SDK includes comprehensive error handling:
158
171
 
159
- // Check if assistant is speaking
160
- const isSpeaking = agent.isAssistantSpeaking;
172
+ ```typescript
173
+ agent.on('error', (error) => {
174
+ console.error('Trillet SDK Error:', error);
175
+ });
161
176
  ```
162
177
 
163
- ## Browser Support
178
+ ## License
164
179
 
165
- The SDK requires a secure context (HTTPS or localhost) and modern browser features. Supported browsers:
166
- - Chrome (recommended)
167
- - Firefox
168
- - Safari
169
- - Edge
180
+ [License details here]
170
181
 
171
- ## Need Help?
182
+ ## Support
172
183
 
173
- - Documentation: [https://docs.trillet.ai](https://docs.trillet.ai)
174
- - Support: [support@trillet.ai](mailto:support@trillet.ai)
184
+ For support, please contact [support contact information].
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { EventEmitter } from "eventemitter3";
2
2
  export interface TrilletAgentConfig {
3
- connectionToken?: string;
4
3
  apiKey?: string;
5
4
  workspaceId?: string;
6
5
  agentId: string;
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { EventEmitter } from "eventemitter3";
2
2
  import { RemoteAudioTrack, Room, RoomEvent, Track, createAudioAnalyser, } from "livekit-client";
3
3
  const TRILLET_API_URL = {
4
- AUTH: "https://api.trillet.ai/v1/api/calls/sdk/auth",
5
4
  CONNECT: "https://api.trillet.ai/v1/api/calls/web/connect",
6
5
  PUBLIC_CONNECT: "https://api.trillet.ai/v1/api/web-call/public",
7
6
  };
@@ -22,10 +21,6 @@ export class TrilletAgent extends EventEmitter {
22
21
  if (!isSecureContext) {
23
22
  throw new Error("Trillet SDK requires a secure context (HTTPS or localhost)");
24
23
  }
25
- // Validate config
26
- if (!config.connectionToken && (!config.apiKey || !config.workspaceId)) {
27
- throw new Error("Either connectionToken OR (apiKey AND workspaceId) must be provided");
28
- }
29
24
  if (!config.agentId) {
30
25
  throw new Error("agentId is required");
31
26
  }
@@ -128,7 +123,7 @@ export class TrilletAgent extends EventEmitter {
128
123
  await this.sdk.initializeCall({
129
124
  token: data.token,
130
125
  wsUrl: process.env.LIVEKIT_WS_URL ||
131
- "wss://trillet-ai-xdx0dw5r.livekit.cloud",
126
+ "wss://trilletai-ek0j3un1.livekit.cloud",
132
127
  audioSettings: {
133
128
  sampleRate: 48000,
134
129
  },
@@ -187,7 +182,7 @@ export class TrilletAgent extends EventEmitter {
187
182
  // Initialize call with LiveKit token
188
183
  await this.sdk.initializeCall({
189
184
  token: data.token,
190
- wsUrl: process.env.LIVEKIT_WS_URL || "wss://trillet-ai-xdx0dw5r.livekit.cloud",
185
+ wsUrl: process.env.LIVEKIT_WS_URL || "wss://trilletai-ek0j3un1.livekit.cloud",
191
186
  audioSettings: {
192
187
  sampleRate: 48000,
193
188
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trillet-ai/web-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Trillet Web SDK for real-time audio communication with AI agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,7 +13,8 @@
13
13
  "build": "npm run clean && tsc",
14
14
  "dev": "tsc --watch",
15
15
  "lint": "eslint src/**/*.{ts,tsx}",
16
- "prepare": "npm run build"
16
+ "prepare": "npm run build",
17
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
17
18
  },
18
19
  "peerDependencies": {
19
20
  "react": ">=16.8.0",
@@ -35,13 +36,16 @@
35
36
  "livekit-client": "^2.8.1"
36
37
  },
37
38
  "devDependencies": {
39
+ "@types/jest": "^29.5.12",
38
40
  "@types/node": "^20.11.0",
39
41
  "@types/react": "^18.2.0",
40
42
  "@types/react-dom": "^18.2.0",
41
43
  "@typescript-eslint/eslint-plugin": "^6.18.1",
42
44
  "@typescript-eslint/parser": "^6.18.1",
43
45
  "eslint": "^8.56.0",
46
+ "jest": "^29.7.0",
44
47
  "rimraf": "^5.0.10",
48
+ "ts-jest": "^29.1.2",
45
49
  "typescript": "^5.3.3"
46
50
  },
47
51
  "files": [