@trillet-ai/web-sdk 1.3.0 → 1.3.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/README.md +133 -123
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -5
- package/package.json +7 -2
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
|
|
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
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
##
|
|
15
|
+
## Installation
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
23
|
+
## Quick Start
|
|
45
24
|
|
|
46
|
-
```
|
|
47
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
45
|
+
// Or start a public call
|
|
46
|
+
await agent.startPublicCall();
|
|
60
47
|
|
|
61
|
-
|
|
48
|
+
// Listen for events
|
|
49
|
+
agent.on('connected', (details) => {
|
|
50
|
+
console.log('Connected to call:', details);
|
|
51
|
+
});
|
|
62
52
|
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
57
|
+
// Control the call
|
|
58
|
+
agent.toggleMicrophone(true); // Enable/disable microphone
|
|
59
|
+
agent.endCall(); // End the call
|
|
71
60
|
```
|
|
72
61
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
## Basic Usage
|
|
62
|
+
## Authentication
|
|
76
63
|
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
-
await agent.startCall();
|
|
109
|
+
The SDK emits various events that you can listen to:
|
|
94
110
|
|
|
95
|
-
|
|
96
|
-
agent.on('connected', () => {
|
|
97
|
-
|
|
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
|
-
|
|
117
|
+
// Called when the call ends
|
|
102
118
|
});
|
|
103
119
|
|
|
104
120
|
agent.on('error', (error) => {
|
|
105
|
-
|
|
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
|
-
|
|
109
|
-
agent
|
|
128
|
+
agent.on('assistantStartedSpeaking', () => {
|
|
129
|
+
// Called when the AI agent starts speaking
|
|
130
|
+
});
|
|
110
131
|
|
|
111
|
-
|
|
112
|
-
agent
|
|
132
|
+
agent.on('assistantStoppedSpeaking', () => {
|
|
133
|
+
// Called when the AI agent stops speaking
|
|
134
|
+
});
|
|
113
135
|
|
|
114
|
-
|
|
115
|
-
|
|
136
|
+
agent.on('audioData', (data) => {
|
|
137
|
+
// Raw audio data for visualization
|
|
138
|
+
});
|
|
116
139
|
```
|
|
117
140
|
|
|
118
|
-
##
|
|
141
|
+
## Voice Mode Features
|
|
119
142
|
|
|
120
|
-
|
|
143
|
+
When using voice mode, the SDK provides additional audio-related features:
|
|
121
144
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
## Events
|
|
145
|
+
```typescript
|
|
146
|
+
// Check if the assistant is currently speaking
|
|
147
|
+
const isSpeaking = agent.isAssistantSpeaking;
|
|
126
148
|
|
|
127
|
-
|
|
149
|
+
// Access transcripts
|
|
150
|
+
const allTranscripts = agent.getTranscripts();
|
|
151
|
+
const currentTranscript = agent.getCurrentTranscript();
|
|
152
|
+
```
|
|
128
153
|
|
|
129
|
-
|
|
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
|
-
|
|
156
|
+
- Modern web browser with secure context (HTTPS or localhost)
|
|
157
|
+
- WebRTC support
|
|
158
|
+
- Microphone access (for voice mode)
|
|
140
159
|
|
|
141
|
-
|
|
160
|
+
## Browser Support
|
|
142
161
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
168
|
+
## Error Handling
|
|
154
169
|
|
|
155
|
-
|
|
156
|
-
agent.toggleMicrophone(false); // Mute
|
|
157
|
-
agent.toggleMicrophone(true); // Unmute
|
|
170
|
+
The SDK includes comprehensive error handling:
|
|
158
171
|
|
|
159
|
-
|
|
160
|
-
|
|
172
|
+
```typescript
|
|
173
|
+
agent.on('error', (error) => {
|
|
174
|
+
console.error('Trillet SDK Error:', error);
|
|
175
|
+
});
|
|
161
176
|
```
|
|
162
177
|
|
|
163
|
-
##
|
|
178
|
+
## License
|
|
164
179
|
|
|
165
|
-
|
|
166
|
-
- Chrome (recommended)
|
|
167
|
-
- Firefox
|
|
168
|
-
- Safari
|
|
169
|
-
- Edge
|
|
180
|
+
[License details here]
|
|
170
181
|
|
|
171
|
-
##
|
|
182
|
+
## Support
|
|
172
183
|
|
|
173
|
-
|
|
174
|
-
- Support: [support@trillet.ai](mailto:support@trillet.ai)
|
|
184
|
+
For support, please contact [support contact information].
|
package/dist/index.d.ts
CHANGED
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trillet-ai/web-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
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",
|
|
@@ -31,17 +32,21 @@
|
|
|
31
32
|
"author": "Trillet AI",
|
|
32
33
|
"license": "MIT",
|
|
33
34
|
"dependencies": {
|
|
35
|
+
"@trillet-ai/web-sdk": "file:",
|
|
34
36
|
"eventemitter3": "^5.0.1",
|
|
35
37
|
"livekit-client": "^2.8.1"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
40
|
+
"@types/jest": "^29.5.12",
|
|
38
41
|
"@types/node": "^20.11.0",
|
|
39
42
|
"@types/react": "^18.2.0",
|
|
40
43
|
"@types/react-dom": "^18.2.0",
|
|
41
44
|
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
42
45
|
"@typescript-eslint/parser": "^6.18.1",
|
|
43
46
|
"eslint": "^8.56.0",
|
|
47
|
+
"jest": "^29.7.0",
|
|
44
48
|
"rimraf": "^5.0.10",
|
|
49
|
+
"ts-jest": "^29.1.2",
|
|
45
50
|
"typescript": "^5.3.3"
|
|
46
51
|
},
|
|
47
52
|
"files": [
|