@trillet-ai/web-sdk 1.0.1 → 1.0.3

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,27 +1,85 @@
1
1
  # Trillet AI Web SDK
2
2
 
3
- Official Web SDK for integrating Trillet AI voice agents into your web applications. This SDK enables real-time voice communication with Trillet AI agents in your web applications.
3
+ Official Web SDK for integrating Trillet AI voice agents into your web applications. This SDK enables real-time voice communication with Trillet AI agents directly in your frontend application.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @trillet-ai/webcalls-sdk
8
+ npm install @trillet-ai/web-sdk
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Quick Start
12
12
 
13
- ```typescript
14
- import { TrilletAgent } from '@trillet-ai/webcalls-sdk';
13
+ ### React Integration
14
+
15
+ ```tsx
16
+ import { TrilletAgent } from '@trillet-ai/web-sdk';
17
+ import { useState } from 'react';
18
+
19
+ function VoiceAgent() {
20
+ const [agent] = useState(() => new TrilletAgent({
21
+ apiKey: 'your-api-key',
22
+ workspaceId: 'your-workspace-id',
23
+ agentId: 'your-agent-id'
24
+ }));
25
+
26
+ return (
27
+ <div>
28
+ <button onClick={() => agent.startCall()}>Start Call</button>
29
+ <button onClick={() => agent.endCall()}>End Call</button>
30
+ <button onClick={() => agent.toggleMicrophone(false)}>Mute</button>
31
+ </div>
32
+ );
33
+ }
34
+ ```
35
+
36
+ ### Vanilla JavaScript
37
+
38
+ ```javascript
39
+ import { TrilletAgent } from '@trillet-ai/web-sdk';
15
40
 
16
41
  const agent = new TrilletAgent({
17
- apiKey: 'your-api-key'
42
+ apiKey: 'your-api-key',
43
+ workspaceId: 'your-workspace-id',
44
+ agentId: 'your-agent-id'
18
45
  });
19
46
 
20
- // Start a call
21
- await agent.startCall();
47
+ // Add event listeners
48
+ agent.on('connected', () => console.log('Connected to agent'));
49
+ agent.on('disconnected', () => console.log('Disconnected from agent'));
50
+ agent.on('error', (error) => console.error('Error:', error));
22
51
 
23
- // End the call
52
+ // Control the call
53
+ await agent.startCall();
24
54
  await agent.endCall();
55
+ agent.toggleMicrophone(false); // mute
56
+ ```
57
+
58
+ ## Required Parameters
59
+
60
+ - `apiKey`: Your Trillet API key for authentication
61
+ - `agentId`: The unique identifier of the Trillet AI agent you want to connect to
62
+ - `workspaceId`: Your Trillet workspace identifier
63
+
64
+ ## Features
65
+
66
+ - 🎯 Frontend-only integration - no backend required
67
+ - 🔒 Secure WebRTC communication
68
+ - 🎤 High-quality audio streaming
69
+ - ⚛️ React support out of the box
70
+ - 📱 Mobile browser support
71
+ - 🔊 Audio device control (mute/unmute)
72
+
73
+ ## Events
74
+
75
+ The SDK emits several events you can listen to:
76
+
77
+ ```typescript
78
+ agent.on('connected', () => {}); // Call connected
79
+ agent.on('disconnected', () => {}); // Call ended
80
+ agent.on('error', (error) => {}); // Error occurred
81
+ agent.on('assistantStartedSpeaking', () => {}); // AI started speaking
82
+ agent.on('assistantStoppedSpeaking', () => {}); // AI stopped speaking
25
83
  ```
26
84
 
27
85
  ## Documentation
package/dist/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  import { EventEmitter } from "eventemitter3";
2
+ export interface TrilletAgentConfig {
3
+ apiKey: string;
4
+ workspaceId: string;
5
+ agentId: string;
6
+ variables?: Record<string, any>;
7
+ }
2
8
  export interface TrilletCallConfig {
3
9
  token: string;
4
10
  audioSettings?: {
@@ -10,22 +16,13 @@ export interface TrilletCallConfig {
10
16
  enableRawAudio?: boolean;
11
17
  };
12
18
  }
13
- export declare class TrilletWebSDK extends EventEmitter {
14
- private room;
15
- private isConnected;
16
- isAssistantSpeaking: boolean;
17
- audioAnalyzer?: {
18
- calculateVolume: () => number;
19
- analyser: AnalyserNode;
20
- cleanup: () => Promise<void>;
21
- };
22
- private audioFrameCapture;
23
- constructor();
24
- initializeCall(config: TrilletCallConfig): Promise<void>;
25
- enableAudioPlayback(): Promise<void>;
19
+ export declare class TrilletAgent extends EventEmitter {
20
+ private sdk;
21
+ private config;
22
+ constructor(config: TrilletAgentConfig);
23
+ private setupEventForwarding;
24
+ startCall(): Promise<void>;
26
25
  endCall(): void;
27
26
  toggleMicrophone(enabled: boolean): void;
28
- private captureAudio;
29
- private setupEventHandlers;
30
- private handleDataEvent;
27
+ get isAssistantSpeaking(): boolean;
31
28
  }
package/dist/index.js CHANGED
@@ -1,8 +1,77 @@
1
1
  import { EventEmitter } from "eventemitter3";
2
2
  import { RemoteAudioTrack, Room, RoomEvent, Track, createAudioAnalyser, } from "livekit-client";
3
- const TRILLET_WS_URL = "wss://trillet-ai-xdx0dw5r.livekit.cloud";
3
+ const TRILLET_API_URL = "https://api.trillet.ai/v1/api/web-call";
4
+ const TRILLET_WS_URL = "wss://trilletai-ek0j3un1.livekit.cloud";
4
5
  const decoder = new TextDecoder();
5
- export class TrilletWebSDK extends EventEmitter {
6
+ export class TrilletAgent extends EventEmitter {
7
+ constructor(config) {
8
+ super();
9
+ this.config = config;
10
+ this.sdk = new TrilletWebSDK();
11
+ this.setupEventForwarding();
12
+ }
13
+ setupEventForwarding() {
14
+ // Forward all SDK events to agent listeners
15
+ this.sdk.on('connected', () => this.emit('connected'));
16
+ this.sdk.on('disconnected', () => this.emit('disconnected'));
17
+ this.sdk.on('error', (error) => this.emit('error', error));
18
+ this.sdk.on('status', (status) => this.emit('status', status));
19
+ this.sdk.on('metadata', (metadata) => this.emit('metadata', metadata));
20
+ this.sdk.on('assistantStartedSpeaking', () => this.emit('assistantStartedSpeaking'));
21
+ this.sdk.on('assistantStoppedSpeaking', () => this.emit('assistantStoppedSpeaking'));
22
+ this.sdk.on('audioData', (data) => this.emit('audioData', data));
23
+ }
24
+ async startCall() {
25
+ try {
26
+ // 1. Get LiveKit token from Trillet API
27
+ const response = await fetch(TRILLET_API_URL, {
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ 'Accept': 'application/json',
32
+ 'x-workspace-id': this.config.workspaceId,
33
+ 'x-api-key': this.config.apiKey
34
+ },
35
+ body: JSON.stringify({
36
+ call_agent_id: this.config.agentId,
37
+ dynamic_variables: this.config.variables || {}
38
+ })
39
+ });
40
+ if (!response.ok) {
41
+ const error = await response.text();
42
+ throw new Error(`API Error: ${error}`);
43
+ }
44
+ const data = await response.json();
45
+ // 2. Initialize call with LiveKit token
46
+ await this.sdk.initializeCall({
47
+ token: data.token,
48
+ audioSettings: {
49
+ sampleRate: 48000
50
+ },
51
+ features: {
52
+ enableRawAudio: true
53
+ }
54
+ });
55
+ // 3. Enable audio playback
56
+ await this.sdk.enableAudioPlayback();
57
+ }
58
+ catch (error) {
59
+ this.emit('error', error);
60
+ throw error;
61
+ }
62
+ }
63
+ endCall() {
64
+ this.sdk.endCall();
65
+ }
66
+ toggleMicrophone(enabled) {
67
+ this.sdk.toggleMicrophone(enabled);
68
+ }
69
+ get isAssistantSpeaking() {
70
+ return this.sdk.isAssistantSpeaking;
71
+ }
72
+ }
73
+ // Internal SDK class
74
+ class TrilletWebSDK extends EventEmitter {
6
75
  constructor() {
7
76
  super();
8
77
  this.isConnected = false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trillet-ai/web-sdk",
3
- "version": "1.0.1",
4
- "description": "Trillet Web SDK for real-time audio communication",
3
+ "version": "1.0.3",
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",
7
7
  "type": "module",
@@ -13,8 +13,7 @@
13
13
  "dev": "tsc --watch",
14
14
  "lint": "eslint src/**/*.{ts,tsx}",
15
15
  "prepare": "npm run build",
16
- "test": "node test/browser/server.js",
17
- "test:api": "node test/test-api.js"
16
+ "test": "node test/browser/server.js"
18
17
  },
19
18
  "peerDependencies": {
20
19
  "react": ">=16.8.0",
@@ -22,17 +21,18 @@
22
21
  },
23
22
  "keywords": [
24
23
  "trillet",
24
+ "ai",
25
+ "voice",
25
26
  "audio",
26
27
  "sdk",
27
- "webrtc"
28
+ "webrtc",
29
+ "react"
28
30
  ],
29
31
  "author": "Trillet AI",
30
32
  "license": "MIT",
31
33
  "dependencies": {
32
- "dotenv": "^16.4.7",
33
34
  "eventemitter3": "^5.0.1",
34
- "livekit-client": "^1.15.5",
35
- "node-fetch": "^3.3.2"
35
+ "livekit-client": "^1.15.5"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^20.11.0",
@@ -48,6 +48,7 @@
48
48
  },
49
49
  "files": [
50
50
  "dist",
51
- "README.md"
51
+ "README.md",
52
+ "LICENSE"
52
53
  ]
53
54
  }