ttp-agent-sdk 2.34.13 → 2.35.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.
@@ -315,10 +315,6 @@
315
315
  <span class="section-toggle" id="common-toggle">▼</span>
316
316
  </div>
317
317
  <div class="section-content" id="common-content">
318
- <label id="labelSignedUrl" style="grid-column: 1/-1;">🔐 Signed URL (Optional - overrides Agent ID/App ID)
319
- <input id="signedUrlInput" type="text" value="" placeholder="wss://speech.talktopc.com/ws/conv?signed_token=..." style="width: 100%; font-size: 12px;" />
320
- <small style="color: #6B7280; font-size: 12px; margin-top: 4px; display: block;">If provided, this will be used for authentication instead of Agent ID/App ID</small>
321
- </label>
322
318
  <label id="labelAgentId">Agent ID
323
319
  <input id="agentIdInput" type="text" value="agent_87c4a55a1" placeholder="agent_xxxxx" />
324
320
  </label>
@@ -914,23 +910,8 @@
914
910
  }
915
911
 
916
912
  function getConfigFromForm() {
917
- const signedUrl = document.getElementById('signedUrlInput').value.trim();
918
-
919
- // Extract agentId and appId from signed URL if present
920
- let agentId = document.getElementById('agentIdInput').value || 'agent_87c4a55a1';
921
- let appId = document.getElementById('appIdInput').value || 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC';
922
-
923
- if (signedUrl) {
924
- try {
925
- const url = new URL(signedUrl);
926
- const urlAgentId = url.searchParams.get('agentId');
927
- const urlAppId = url.searchParams.get('appId');
928
- if (urlAgentId) agentId = urlAgentId;
929
- if (urlAppId) appId = urlAppId;
930
- } catch (e) {
931
- console.warn('Could not parse signed URL:', e);
932
- }
933
- }
913
+ const agentId = document.getElementById('agentIdInput').value || 'agent_87c4a55a1';
914
+ const appId = document.getElementById('appIdInput').value || 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC';
934
915
 
935
916
  const config = {
936
917
  agentId: agentId,
@@ -1078,11 +1059,6 @@
1078
1059
  config.button.hoverColor = hoverColorInput.value;
1079
1060
  }
1080
1061
 
1081
- // If signed URL is provided, use it directly
1082
- if (signedUrl) {
1083
- config.signedUrl = signedUrl;
1084
- }
1085
-
1086
1062
  return config;
1087
1063
  }
1088
1064
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttp-agent-sdk",
3
- "version": "2.34.13",
3
+ "version": "2.35.0",
4
4
  "description": "Comprehensive Voice Agent SDK with Customizable Widget - Real-time audio, WebSocket communication, React components, and extensive customization options",
5
5
  "main": "dist/agent-widget.js",
6
6
  "module": "dist/agent-widget.esm.js",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "scripts": {
26
26
  "build": "npm run build:umd && npm run build:esm && npm run build:dev",
27
- "deploy": "npm run build && npx wrangler pages deploy dist --project-name=ttp-sdk-front",
27
+ "deploy": "npm run build && npx wrangler pages deploy dist --project-name=ttp-sdk-front --branch=main --commit-dirty=true",
28
28
  "deploy:prod": "./deploy-production.sh",
29
29
  "build:prod": "webpack --config webpack.config.js",
30
30
  "build:dev": "webpack --config webpack.dev.config.js",
@@ -1,249 +0,0 @@
1
- # TTP Agent SDK - Signed Link Authentication Guide
2
-
3
- ## 🔐 Understanding Signed Links
4
-
5
- Signed links provide **secure, production-ready authentication** for your voice agents. Your **UI backend** generates secure, time-limited URLs that the widget uses to connect to the **conversation backend**.
6
-
7
- ## 🏗️ Architecture Overview
8
-
9
- ```
10
- User's Frontend → User's Backend → TTP UI Backend → TTP Conversation Backend
11
- ↓ ↓ ↓ ↓
12
- Requests Requests Generates Handles
13
- signed URL signed URL signed URL conversation
14
- ↑ ↑ ↑ ↑
15
- Receives Receives Returns Validates
16
- signed URL signed URL signed URL signed token
17
- ```
18
-
19
- **The complete flow:**
20
- 1. **User's Frontend** → requests signed URL from **User's Backend**
21
- 2. **User's Backend** → requests signed URL from **TTP UI Backend** (`/api/public/agents`)
22
- 3. **TTP UI Backend** → generates signed URL and returns to **User's Backend**
23
- 4. **User's Backend** → returns signed URL to **User's Frontend**
24
- 5. **User's Frontend** → connects directly to **TTP Conversation Backend** using signed URL
25
-
26
- ## 🎯 Why Use Signed Links?
27
-
28
- ### ❌ **Direct Agent ID (Insecure)**
29
- ```javascript
30
- // DON'T DO THIS IN PRODUCTION
31
- new TTPChatWidget({
32
- agentId: 'agent_12345', // ❌ Visible in network traffic
33
- websocketUrl: 'wss://speech.talktopc.com/ws/conv'
34
- });
35
- ```
36
-
37
- **Problems:**
38
- - Agent ID exposed in browser network tab
39
- - No cost control
40
- - No user-specific permissions
41
- - Security risk
42
-
43
- ### ✅ **Signed Link (Secure)**
44
- ```javascript
45
- // PRODUCTION-READY APPROACH - Option 1: Direct signed URL
46
- new TTPChatWidget({
47
- agentId: 'agent_12345', // Still needed for widget initialization
48
- signedUrl: 'wss://speech.talktopc.com/ws/conv?signed_token=eyJ...' // ✅ Direct signed URL
49
- });
50
- ```
51
-
52
- ```javascript
53
- // PRODUCTION-READY APPROACH - Option 2: Get signed URL from backend
54
- new TTPChatWidget({
55
- agentId: 'your_agent_id',
56
- signedUrl: async () => {
57
- // User's Frontend calls User's Backend
58
- const response = await fetch('/api/get-voice-session', {
59
- method: 'POST',
60
- headers: { 'Content-Type': 'application/json' },
61
- body: JSON.stringify({ agentId: 'your_agent_id' })
62
- });
63
- const data = await response.json();
64
- return data.signedUrl; // ✅ Secure, time-limited URL from TTP
65
- }
66
- });
67
- ```
68
-
69
- **Benefits:**
70
- - ✅ Secure authentication
71
- - ✅ Cost control per user
72
- - ✅ User-specific permissions
73
- - ✅ Time-limited access
74
- - ✅ Production-ready
75
-
76
- ## 🏗️ Implementation Guide
77
-
78
- ### Step 1: User's Backend Implementation
79
-
80
- Your user's backend should have an endpoint that requests signed URLs from TTP:
81
-
82
- ```javascript
83
- // User's Backend (Node.js example)
84
- app.post('/api/get-voice-session', async (req, res) => {
85
- try {
86
- const { agentId, variables } = req.body;
87
-
88
- // Validate user authentication
89
- const user = await validateUser(req.headers.authorization);
90
- if (!user) {
91
- return res.status(401).json({ error: 'Unauthorized' });
92
- }
93
-
94
- // Request signed URL from TTP UI Backend
95
- const ttpResponse = await fetch('https://backend.talktopc.com/api/public/agents', {
96
- method: 'POST',
97
- headers: {
98
- 'Content-Type': 'application/json',
99
- 'Authorization': `Bearer ${process.env.TTP_API_KEY}` // Your TTP API key
100
- },
101
- body: JSON.stringify({
102
- agentId,
103
- variables: {
104
- ...variables,
105
- userId: user.id,
106
- userEmail: user.email
107
- }
108
- })
109
- });
110
-
111
- if (!ttpResponse.ok) {
112
- throw new Error(`TTP API error: ${ttpResponse.status}`);
113
- }
114
-
115
- const ttpData = await ttpResponse.json();
116
-
117
- // Return signed URL to user's frontend
118
- res.json({
119
- signedUrl: ttpData.signedUrl
120
- });
121
-
122
- } catch (error) {
123
- console.error('Failed to get signed URL from TTP:', error);
124
- res.status(500).json({ error: 'Failed to get voice session' });
125
- }
126
- });
127
- ```
128
-
129
- ### Step 2: User's Frontend Integration
130
-
131
- **Option 1: Direct Signed URL (Simplest)**
132
-
133
- ```javascript
134
- import { TTPChatWidget } from 'ttp-agent-sdk';
135
-
136
- // Get signed URL from your backend first
137
- const response = await fetch('/api/get-voice-session', {
138
- method: 'POST',
139
- headers: {
140
- 'Content-Type': 'application/json',
141
- 'Authorization': `Bearer ${getAuthToken()}`
142
- },
143
- body: JSON.stringify({
144
- agentId: 'your_agent_id',
145
- variables: {
146
- page: 'homepage',
147
- userType: 'customer'
148
- }
149
- })
150
- });
151
-
152
- const data = await response.json();
153
-
154
- // Use the signed URL directly
155
- new TTPChatWidget({
156
- agentId: 'your_agent_id', // Still needed for widget initialization
157
- signedUrl: data.signedUrl // ✅ Direct signed URL
158
- });
159
- ```
160
-
161
- **Option 2: Function that Returns Signed URL**
162
-
163
- ```javascript
164
- import { TTPChatWidget } from 'ttp-agent-sdk';
165
-
166
- new TTPChatWidget({
167
- agentId: 'your_agent_id',
168
-
169
- // Function that fetches and returns signed URL
170
- signedUrl: async () => {
171
- const response = await fetch('/api/get-voice-session', {
172
- method: 'POST',
173
- headers: {
174
- 'Content-Type': 'application/json',
175
- 'Authorization': `Bearer ${getAuthToken()}`
176
- },
177
- body: JSON.stringify({
178
- agentId: 'your_agent_id',
179
- variables: {
180
- page: 'homepage',
181
- userType: 'customer'
182
- }
183
- })
184
- });
185
-
186
- if (!response.ok) {
187
- throw new Error(`Your backend responded with ${response.status}`);
188
- }
189
-
190
- const data = await response.json();
191
- return data.signedUrl; // This connects directly to TTP Conversation Backend
192
- }
193
- });
194
- ```
195
-
196
- ## 🔧 Your Current Implementation
197
-
198
- Based on your setup, you can use signed URLs like this:
199
-
200
- ```javascript
201
- // Get signed URL from your backend
202
- const response = await fetch(buildApiUrl('/api/landing/signed-url'), {
203
- method: 'POST',
204
- headers: { 'Content-Type': 'application/json' },
205
- body: JSON.stringify({
206
- agentId: 'your_agent_id',
207
- variables: {
208
- page: 'landing',
209
- userType: 'visitor'
210
- }
211
- })
212
- });
213
-
214
- const data = await response.json();
215
-
216
- // Use the signed URL directly
217
- new TTPChatWidget({
218
- agentId: 'your_agent_id',
219
- signedUrl: data.signedUrl // ✅ Direct signed URL
220
- });
221
- ```
222
-
223
- ## 🎯 Key Points
224
-
225
- 1. **UI Backend** (`/api/landing/signed-url`):
226
- - Handles authentication
227
- - Generates signed URLs
228
- - Manages user permissions
229
- - Controls costs
230
-
231
- 2. **Conversation Backend** (`wss://speech.talktopc.com/ws/conv`):
232
- - Validates signed tokens
233
- - Handles voice conversations
234
- - Processes audio streams
235
-
236
- 3. **Frontend Widget**:
237
- - Requests signed URL from UI backend
238
- - Connects to conversation backend using signed URL
239
- - Never exposes agent IDs directly
240
-
241
- ## 🚀 Production Benefits
242
-
243
- - **Security**: Agent IDs never exposed in frontend
244
- - **Separation**: UI logic separate from conversation logic
245
- - **Scalability**: Each backend can scale independently
246
- - **Control**: UI backend controls access and permissions
247
- - **Monitoring**: Track usage and costs at UI backend level
248
-
249
- This architecture ensures your voice agents are secure, scalable, and production-ready! 🎤✨