ttp-agent-sdk 2.44.0 → 2.45.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/dist/agent-widget.dev.js +2131 -646
- package/dist/agent-widget.dev.js.map +1 -1
- package/dist/agent-widget.esm.js +1 -1
- package/dist/agent-widget.esm.js.map +1 -1
- package/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/dist/demos/demo-sdk-loader.js +1 -0
- package/dist/demos/test-ecommerce.html +23 -42
- package/dist/demos/test-tour.html +15 -33
- package/dist/demos/test-widget.html +38 -18
- package/dist/demos/widget-customization-dev.html +15 -6
- package/dist/demos/widget-customization.html +14 -6
- package/dist/examples/demo-sdk-loader.js +1 -0
- package/dist/examples/ocado-cart-network-probe.js +1 -0
- package/dist/examples/sobeys-cart-dispatch-probe.js +1 -0
- package/dist/examples/sobeys-cart-read-test.html +112 -0
- package/dist/examples/sobeys-cart-read-test.js +1 -0
- package/dist/examples/sobeys-cart-subscribe-probe.js +1 -0
- package/dist/examples/sobeys-cart-subscribe-test.html +168 -0
- package/dist/examples/sobeys-cart-subscribe-test.js +1 -0
- package/dist/examples/sobeys-inject-probe-min.js +1 -0
- package/dist/examples/sobeys-inject-probe.js +1 -0
- package/dist/examples/test-ecommerce.html +23 -42
- package/dist/examples/test-tour.html +15 -33
- package/dist/examples/test-widget.html +38 -18
- package/dist/examples/widget-customization-dev.html +15 -6
- package/dist/examples/widget-customization.html +14 -6
- package/examples/demo-sdk-loader.js +249 -0
- package/examples/test-ecommerce.html +23 -42
- package/examples/test-tour.html +15 -33
- package/examples/test-widget.html +38 -18
- package/examples/widget-customization-dev.html +15 -6
- package/examples/widget-customization.html +14 -6
- package/package.json +2 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo pages: toggle Production vs Development SDK bundle.
|
|
3
|
+
* Persists choice in localStorage; dispatches `ttp-demo-sdk-ready` after each load.
|
|
4
|
+
*/
|
|
5
|
+
(function (global) {
|
|
6
|
+
const STORAGE_KEY = 'ttp-demo-sdk-mode';
|
|
7
|
+
const PROD_SRC = '/agent-widget.js';
|
|
8
|
+
const DEV_SRC = '/agent-widget.dev.js';
|
|
9
|
+
const PROD_WS_URL = 'wss://speech.talktopc.com/ws/conv';
|
|
10
|
+
const DEV_WS_URL = 'wss://speech.bidme.co.il/ws/conv';
|
|
11
|
+
|
|
12
|
+
let loadPromise = null;
|
|
13
|
+
let currentMode = null;
|
|
14
|
+
|
|
15
|
+
function getMode() {
|
|
16
|
+
return global.localStorage.getItem(STORAGE_KEY) === 'dev' ? 'dev' : 'prod';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getSrc(mode) {
|
|
20
|
+
return mode === 'dev' ? DEV_SRC : PROD_SRC;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getLabel(mode) {
|
|
24
|
+
return mode === 'dev' ? 'Development' : 'Production';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** WebSocket URL for widget config — tied to SDK mode, not user-editable. */
|
|
28
|
+
function getWebSocketUrl(mode) {
|
|
29
|
+
return (mode === 'dev' ? DEV_WS_URL : PROD_WS_URL);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function applyWebSocketUrl(config, mode) {
|
|
33
|
+
const next = config && typeof config === 'object' ? config : {};
|
|
34
|
+
const resolvedMode = mode === 'dev' || mode === 'prod' ? mode : getMode();
|
|
35
|
+
next.websocketUrl = getWebSocketUrl(resolvedMode);
|
|
36
|
+
return next;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function destroyWidgetInstances() {
|
|
40
|
+
const destroy = (w) => {
|
|
41
|
+
try {
|
|
42
|
+
w?.destroy?.();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.warn('[TTPDemoSdk] destroy failed', e);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
destroy(global.widgetInstance);
|
|
48
|
+
destroy(global.chatWidget);
|
|
49
|
+
destroy(global.testWidget);
|
|
50
|
+
if (typeof global.actualWidgetInstance !== 'undefined') {
|
|
51
|
+
destroy(global.actualWidgetInstance);
|
|
52
|
+
global.actualWidgetInstance = null;
|
|
53
|
+
}
|
|
54
|
+
global.widgetInstance = null;
|
|
55
|
+
global.chatWidget = null;
|
|
56
|
+
global.testWidget = null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function removeSdkScripts() {
|
|
60
|
+
document.querySelectorAll('script[src*="agent-widget"]').forEach((s) => s.remove());
|
|
61
|
+
delete global.TTPAgentSDK;
|
|
62
|
+
delete global.TTPChatWidget;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function loadSdkViaScriptTag(mode) {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
removeSdkScripts();
|
|
68
|
+
const script = document.createElement('script');
|
|
69
|
+
script.src = getSrc(mode) + '?t=' + Date.now();
|
|
70
|
+
script.onload = () => {
|
|
71
|
+
currentMode = mode;
|
|
72
|
+
const detail = { mode, src: script.src, label: getLabel(mode) };
|
|
73
|
+
global.dispatchEvent(new CustomEvent('ttp-demo-sdk-ready', { detail }));
|
|
74
|
+
resolve(global.TTPAgentSDK);
|
|
75
|
+
};
|
|
76
|
+
script.onerror = () => reject(new Error('Failed to load SDK: ' + script.src));
|
|
77
|
+
document.head.appendChild(script);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function loadSdkViaNgrokFetch(mode) {
|
|
82
|
+
return fetch(getSrc(mode), { headers: { 'ngrok-skip-browser-warning': '1' } })
|
|
83
|
+
.then((r) => {
|
|
84
|
+
if (!r.ok) throw new Error('SDK fetch HTTP ' + r.status);
|
|
85
|
+
return r.text();
|
|
86
|
+
})
|
|
87
|
+
.then((code) => {
|
|
88
|
+
removeSdkScripts();
|
|
89
|
+
const script = document.createElement('script');
|
|
90
|
+
script.type = 'text/javascript';
|
|
91
|
+
script.textContent = code;
|
|
92
|
+
document.head.appendChild(script);
|
|
93
|
+
currentMode = mode;
|
|
94
|
+
const detail = { mode, src: getSrc(mode), label: getLabel(mode), ngrok: true };
|
|
95
|
+
global.dispatchEvent(new CustomEvent('ttp-demo-sdk-ready', { detail }));
|
|
96
|
+
return global.TTPAgentSDK;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function loadSdk(mode) {
|
|
101
|
+
mode = mode === 'dev' || mode === 'prod' ? mode : getMode();
|
|
102
|
+
global.localStorage.setItem(STORAGE_KEY, mode);
|
|
103
|
+
updateToggleUI(mode);
|
|
104
|
+
|
|
105
|
+
loadPromise = global.location.hostname.includes('ngrok')
|
|
106
|
+
? loadSdkViaNgrokFetch(mode)
|
|
107
|
+
: loadSdkViaScriptTag(mode);
|
|
108
|
+
|
|
109
|
+
return loadPromise.catch((err) => {
|
|
110
|
+
console.error('[TTPDemoSdk]', err);
|
|
111
|
+
throw err;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function setMode(mode) {
|
|
116
|
+
if (mode !== 'dev' && mode !== 'prod') return loadSdk(getMode());
|
|
117
|
+
destroyWidgetInstances();
|
|
118
|
+
return loadSdk(mode);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function waitForReady() {
|
|
122
|
+
if (global.TTPAgentSDK?.TTPChatWidget && loadPromise) {
|
|
123
|
+
return Promise.resolve(global.TTPAgentSDK);
|
|
124
|
+
}
|
|
125
|
+
return loadPromise || loadSdk(getMode());
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function injectStyles() {
|
|
129
|
+
if (document.getElementById('ttp-demo-sdk-toggle-styles')) return;
|
|
130
|
+
const style = document.createElement('style');
|
|
131
|
+
style.id = 'ttp-demo-sdk-toggle-styles';
|
|
132
|
+
style.textContent = `
|
|
133
|
+
#ttp-demo-sdk-toggle {
|
|
134
|
+
position: fixed;
|
|
135
|
+
top: 12px;
|
|
136
|
+
right: 12px;
|
|
137
|
+
z-index: 2147483646;
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
gap: 8px;
|
|
141
|
+
padding: 8px 12px;
|
|
142
|
+
background: #111827;
|
|
143
|
+
color: #f9fafb;
|
|
144
|
+
font: 13px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
145
|
+
border-radius: 10px;
|
|
146
|
+
box-shadow: 0 4px 14px rgba(0,0,0,.25);
|
|
147
|
+
}
|
|
148
|
+
#ttp-demo-sdk-toggle .ttp-demo-sdk-label { opacity: .85; margin-right: 4px; }
|
|
149
|
+
#ttp-demo-sdk-toggle button {
|
|
150
|
+
border: none;
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
padding: 6px 12px;
|
|
153
|
+
border-radius: 6px;
|
|
154
|
+
font-size: 12px;
|
|
155
|
+
font-weight: 600;
|
|
156
|
+
background: #374151;
|
|
157
|
+
color: #e5e7eb;
|
|
158
|
+
}
|
|
159
|
+
#ttp-demo-sdk-toggle button:hover { background: #4b5563; }
|
|
160
|
+
#ttp-demo-sdk-toggle button.active {
|
|
161
|
+
background: #4f46e5;
|
|
162
|
+
color: #fff;
|
|
163
|
+
}
|
|
164
|
+
#ttp-demo-sdk-toggle button.active-dev {
|
|
165
|
+
background: #d97706;
|
|
166
|
+
color: #fff;
|
|
167
|
+
}
|
|
168
|
+
#ttp-demo-sdk-toggle .ttp-demo-sdk-file {
|
|
169
|
+
font-size: 11px;
|
|
170
|
+
opacity: .7;
|
|
171
|
+
max-width: 140px;
|
|
172
|
+
overflow: hidden;
|
|
173
|
+
text-overflow: ellipsis;
|
|
174
|
+
white-space: nowrap;
|
|
175
|
+
}
|
|
176
|
+
`;
|
|
177
|
+
document.head.appendChild(style);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function updateToggleUI(mode) {
|
|
181
|
+
const root = document.getElementById('ttp-demo-sdk-toggle');
|
|
182
|
+
if (!root) return;
|
|
183
|
+
const prodBtn = root.querySelector('[data-mode="prod"]');
|
|
184
|
+
const devBtn = root.querySelector('[data-mode="dev"]');
|
|
185
|
+
const fileEl = root.querySelector('.ttp-demo-sdk-file');
|
|
186
|
+
if (prodBtn) {
|
|
187
|
+
prodBtn.classList.toggle('active', mode === 'prod');
|
|
188
|
+
prodBtn.classList.toggle('active-dev', false);
|
|
189
|
+
}
|
|
190
|
+
if (devBtn) {
|
|
191
|
+
devBtn.classList.toggle('active', mode === 'dev');
|
|
192
|
+
devBtn.classList.toggle('active-dev', mode === 'dev');
|
|
193
|
+
}
|
|
194
|
+
if (fileEl) {
|
|
195
|
+
fileEl.title = getWebSocketUrl(mode);
|
|
196
|
+
fileEl.textContent = mode === 'dev' ? 'dev.js · speech.bidme' : 'prod.js · talktopc';
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function injectToggle() {
|
|
201
|
+
if (document.getElementById('ttp-demo-sdk-toggle')) return;
|
|
202
|
+
injectStyles();
|
|
203
|
+
const root = document.createElement('div');
|
|
204
|
+
root.id = 'ttp-demo-sdk-toggle';
|
|
205
|
+
root.setAttribute('role', 'group');
|
|
206
|
+
root.setAttribute('aria-label', 'SDK bundle');
|
|
207
|
+
root.innerHTML =
|
|
208
|
+
'<span class="ttp-demo-sdk-label">SDK</span>' +
|
|
209
|
+
'<button type="button" data-mode="prod" title="Production minified bundle">Production</button>' +
|
|
210
|
+
'<button type="button" data-mode="dev" title="Development bundle with source maps">Development</button>' +
|
|
211
|
+
'<span class="ttp-demo-sdk-file"></span>';
|
|
212
|
+
root.querySelector('[data-mode="prod"]').addEventListener('click', () => {
|
|
213
|
+
if (getMode() !== 'prod') setMode('prod');
|
|
214
|
+
});
|
|
215
|
+
root.querySelector('[data-mode="dev"]').addEventListener('click', () => {
|
|
216
|
+
if (getMode() !== 'dev') setMode('dev');
|
|
217
|
+
});
|
|
218
|
+
document.body.appendChild(root);
|
|
219
|
+
updateToggleUI(getMode());
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function init() {
|
|
223
|
+
injectToggle();
|
|
224
|
+
return loadSdk(getMode());
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
global.TTPDemoSdkLoader = {
|
|
228
|
+
STORAGE_KEY,
|
|
229
|
+
PROD_SRC,
|
|
230
|
+
DEV_SRC,
|
|
231
|
+
PROD_WS_URL,
|
|
232
|
+
DEV_WS_URL,
|
|
233
|
+
getMode,
|
|
234
|
+
getSrc,
|
|
235
|
+
getLabel,
|
|
236
|
+
getWebSocketUrl,
|
|
237
|
+
applyWebSocketUrl,
|
|
238
|
+
loadSdk,
|
|
239
|
+
setMode,
|
|
240
|
+
waitForReady,
|
|
241
|
+
destroyWidgetInstances,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
if (document.readyState === 'loading') {
|
|
245
|
+
document.addEventListener('DOMContentLoaded', init);
|
|
246
|
+
} else {
|
|
247
|
+
init();
|
|
248
|
+
}
|
|
249
|
+
})(window);
|
|
@@ -119,16 +119,14 @@
|
|
|
119
119
|
</head>
|
|
120
120
|
<body>
|
|
121
121
|
<div class="container">
|
|
122
|
-
<h1>TTP Hotels
|
|
122
|
+
<h1>TTP Flavor Test (Ecommerce / Hotels / …)</h1>
|
|
123
123
|
|
|
124
124
|
<div class="info">
|
|
125
125
|
<strong>How it works:</strong>
|
|
126
126
|
<ul>
|
|
127
|
-
<li>
|
|
128
|
-
<li>
|
|
129
|
-
<li>
|
|
130
|
-
<li>Booking summary updates on <code>booking_updated</code> messages</li>
|
|
131
|
-
<li>Gallery (<code>show_media</code>) opens fullscreen with widget minimized</li>
|
|
127
|
+
<li>Pick an <strong>Agent</strong> below — the demo passes <code>flavor: { type, partnerId, callView: 'minimized' }</code> for every vertical.</li>
|
|
128
|
+
<li>On <strong>desktop</strong> (>768px), <strong><code>callView: 'minimized'</code></strong> uses the bottom voice strip when a call is active (in-panel active call UI is hidden). Mobile keeps the existing minimized bar behavior.</li>
|
|
129
|
+
<li>Each vertical wires WebSocket handlers (e.g. hotels: <code>show_items</code> rooms, <code>booking_updated</code>, <code>show_media</code>).</li>
|
|
132
130
|
</ul>
|
|
133
131
|
</div>
|
|
134
132
|
|
|
@@ -138,8 +136,8 @@
|
|
|
138
136
|
<div class="settings-grid">
|
|
139
137
|
<label>Agent
|
|
140
138
|
<select id="agentSelect" onchange="handleAgentChange()">
|
|
141
|
-
<option value="agent_ed18369b3|app_wNGQKiMUfUT5JdVIaxzXOJfdcgBegxGY5hZo|ecommerce|mock-store">Ecommerce Demo (agent_ed18369b3)</option>
|
|
142
|
-
<option value="agent_d0774f1af|app_wNGQKiMUfUT5JdVIaxzXOJfdcgBegxGY5hZo|hotels|mock-hotel"
|
|
139
|
+
<option value="agent_ed18369b3|app_wNGQKiMUfUT5JdVIaxzXOJfdcgBegxGY5hZo|ecommerce|mock-store" selected>Ecommerce Demo (agent_ed18369b3)</option>
|
|
140
|
+
<option value="agent_d0774f1af|app_wNGQKiMUfUT5JdVIaxzXOJfdcgBegxGY5hZo|hotels|mock-hotel">Hotels Demo (agent_d0774f1af)</option>
|
|
143
141
|
<option value="agent_PHARMA_ID|app_wNGQKiMUfUT5JdVIaxzXOJfdcgBegxGY5hZo|pharma|mock-pharm">Pharma Demo (update agent ID)</option>
|
|
144
142
|
<option value="agent_RESTAURANT_ID|app_wNGQKiMUfUT5JdVIaxzXOJfdcgBegxGY5hZo|restaurants|mock-restaurant">Restaurant Demo (update agent ID)</option>
|
|
145
143
|
<option value="agent_TOUR_ID|app_wNGQKiMUfUT5JdVIaxzXOJfdcgBegxGY5hZo|tours|mock-tour">Tour Demo (update agent ID)</option>
|
|
@@ -233,24 +231,7 @@ window.testWidget._flavor.messageHandlers['show_media']({
|
|
|
233
231
|
});</div>
|
|
234
232
|
</div>
|
|
235
233
|
|
|
236
|
-
<script>
|
|
237
|
-
(function() {
|
|
238
|
-
var isNgrok = window.location.hostname.includes('ngrok');
|
|
239
|
-
if (isNgrok) {
|
|
240
|
-
var s = document.createElement('script');
|
|
241
|
-
s.type = 'text/javascript';
|
|
242
|
-
document.head.appendChild(s);
|
|
243
|
-
fetch('/agent-widget.js', { headers: { 'ngrok-skip-browser-warning': '1' } })
|
|
244
|
-
.then(function(r) { return r.text(); })
|
|
245
|
-
.then(function(code) { s.textContent = code; })
|
|
246
|
-
.catch(function(e) { console.error('SDK fetch failed:', e); });
|
|
247
|
-
} else {
|
|
248
|
-
var s = document.createElement('script');
|
|
249
|
-
s.src = '/agent-widget.js';
|
|
250
|
-
document.head.appendChild(s);
|
|
251
|
-
}
|
|
252
|
-
})();
|
|
253
|
-
</script>
|
|
234
|
+
<script src="demo-sdk-loader.js"></script>
|
|
254
235
|
|
|
255
236
|
<script>
|
|
256
237
|
let chatWidget = null;
|
|
@@ -296,7 +277,7 @@ window.testWidget._flavor.messageHandlers['show_media']({
|
|
|
296
277
|
|
|
297
278
|
const agent = getAgentConfig();
|
|
298
279
|
|
|
299
|
-
|
|
280
|
+
const widgetConfig = window.TTPDemoSdkLoader.applyWebSocketUrl({
|
|
300
281
|
agentId: agent.agentId,
|
|
301
282
|
appId: agent.appId,
|
|
302
283
|
language: document.getElementById('languageSelect').value,
|
|
@@ -313,7 +294,8 @@ window.testWidget._flavor.messageHandlers['show_media']({
|
|
|
313
294
|
},
|
|
314
295
|
flavor: {
|
|
315
296
|
type: agent.flavorType,
|
|
316
|
-
partnerId: agent.partnerId
|
|
297
|
+
partnerId: agent.partnerId,
|
|
298
|
+
callView: 'minimized',
|
|
317
299
|
},
|
|
318
300
|
icon: {
|
|
319
301
|
type: 'custom',
|
|
@@ -326,6 +308,7 @@ window.testWidget._flavor.messageHandlers['show_media']({
|
|
|
326
308
|
text: 'היי, אשמח אם תוכלי לעזור לי '
|
|
327
309
|
}
|
|
328
310
|
});
|
|
311
|
+
chatWidget = new TTPAgentSDK.TTPChatWidget(widgetConfig);
|
|
329
312
|
|
|
330
313
|
window.testWidget = chatWidget;
|
|
331
314
|
const sttLabel = document.getElementById('sttSelect').selectedOptions[0].text;
|
|
@@ -416,22 +399,20 @@ window.testWidget._flavor.messageHandlers['show_media']({
|
|
|
416
399
|
};
|
|
417
400
|
|
|
418
401
|
// Wait for SDK and auto-create
|
|
419
|
-
function
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const iv = setInterval(() => {
|
|
424
|
-
attempts++;
|
|
425
|
-
if (window.TTPAgentSDK?.TTPChatWidget) { clearInterval(iv); resolve(); }
|
|
426
|
-
else if (attempts >= 150) { clearInterval(iv); reject(new Error('SDK failed to load')); }
|
|
427
|
-
}, 100);
|
|
428
|
-
});
|
|
402
|
+
function boot() {
|
|
403
|
+
const mode = window.TTPDemoSdkLoader?.getMode?.() || 'prod';
|
|
404
|
+
updateStatus('SDK loaded (' + mode + ') — click Create Widget or wait...', '');
|
|
405
|
+
createWidget();
|
|
429
406
|
}
|
|
430
407
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
408
|
+
window.addEventListener('ttp-demo-sdk-ready', () => {
|
|
409
|
+
if (chatWidget) {
|
|
410
|
+
chatWidget.destroy();
|
|
411
|
+
chatWidget = null;
|
|
412
|
+
}
|
|
413
|
+
boot();
|
|
414
|
+
});
|
|
415
|
+
window.TTPDemoSdkLoader.waitForReady().then(boot).catch((e) => {
|
|
435
416
|
updateStatus('SDK load failed: ' + e.message, 'error');
|
|
436
417
|
});
|
|
437
418
|
</script>
|
package/examples/test-tour.html
CHANGED
|
@@ -202,24 +202,7 @@ window.testWidget._flavor.messageHandlers['show_items']({
|
|
|
202
202
|
});</div>
|
|
203
203
|
</div>
|
|
204
204
|
|
|
205
|
-
<script>
|
|
206
|
-
(function() {
|
|
207
|
-
var isNgrok = window.location.hostname.includes('ngrok');
|
|
208
|
-
if (isNgrok) {
|
|
209
|
-
var s = document.createElement('script');
|
|
210
|
-
s.type = 'text/javascript';
|
|
211
|
-
document.head.appendChild(s);
|
|
212
|
-
fetch('/agent-widget.js', { headers: { 'ngrok-skip-browser-warning': '1' } })
|
|
213
|
-
.then(function(r) { return r.text(); })
|
|
214
|
-
.then(function(code) { s.textContent = code; })
|
|
215
|
-
.catch(function(e) { console.error('SDK fetch failed:', e); });
|
|
216
|
-
} else {
|
|
217
|
-
var s = document.createElement('script');
|
|
218
|
-
s.src = '/agent-widget.js';
|
|
219
|
-
document.head.appendChild(s);
|
|
220
|
-
}
|
|
221
|
-
})();
|
|
222
|
-
</script>
|
|
205
|
+
<script src="demo-sdk-loader.js"></script>
|
|
223
206
|
|
|
224
207
|
<script>
|
|
225
208
|
let chatWidget = null;
|
|
@@ -245,7 +228,7 @@ window.testWidget._flavor.messageHandlers['show_items']({
|
|
|
245
228
|
const agentId = document.getElementById('agentId').value;
|
|
246
229
|
const appId = document.getElementById('appId').value;
|
|
247
230
|
|
|
248
|
-
|
|
231
|
+
const widgetConfig = window.TTPDemoSdkLoader.applyWebSocketUrl({
|
|
249
232
|
agentId,
|
|
250
233
|
appId,
|
|
251
234
|
language: document.getElementById('languageSelect').value,
|
|
@@ -274,6 +257,7 @@ window.testWidget._flavor.messageHandlers['show_items']({
|
|
|
274
257
|
text: 'היי, אשמח אם תוכלי לעזור לי במשהו....'
|
|
275
258
|
}
|
|
276
259
|
});
|
|
260
|
+
chatWidget = new TTPAgentSDK.TTPChatWidget(widgetConfig);
|
|
277
261
|
|
|
278
262
|
window.testWidget = chatWidget;
|
|
279
263
|
updateStatus('TTPChatWidget created — tours flavor (mock-tour)', 'success');
|
|
@@ -354,22 +338,20 @@ window.testWidget._flavor.messageHandlers['show_items']({
|
|
|
354
338
|
updateStatus('Booking cleared', '');
|
|
355
339
|
};
|
|
356
340
|
|
|
357
|
-
function
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const iv = setInterval(() => {
|
|
362
|
-
attempts++;
|
|
363
|
-
if (window.TTPAgentSDK?.TTPChatWidget) { clearInterval(iv); resolve(); }
|
|
364
|
-
else if (attempts >= 150) { clearInterval(iv); reject(new Error('SDK failed to load')); }
|
|
365
|
-
}, 100);
|
|
366
|
-
});
|
|
341
|
+
function boot() {
|
|
342
|
+
const mode = window.TTPDemoSdkLoader?.getMode?.() || 'prod';
|
|
343
|
+
updateStatus('SDK loaded (' + mode + ') — creating widget...', '');
|
|
344
|
+
createWidget();
|
|
367
345
|
}
|
|
368
346
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
347
|
+
window.addEventListener('ttp-demo-sdk-ready', () => {
|
|
348
|
+
if (chatWidget) {
|
|
349
|
+
chatWidget.destroy();
|
|
350
|
+
chatWidget = null;
|
|
351
|
+
}
|
|
352
|
+
boot();
|
|
353
|
+
});
|
|
354
|
+
window.TTPDemoSdkLoader.waitForReady().then(boot).catch((e) => {
|
|
373
355
|
updateStatus('SDK load failed: ' + e.message, 'error');
|
|
374
356
|
});
|
|
375
357
|
</script>
|
|
@@ -285,9 +285,11 @@
|
|
|
285
285
|
<input type="text" id="getSessionUrl" value="" placeholder="https://your-api.com/get-session">
|
|
286
286
|
</div>
|
|
287
287
|
|
|
288
|
-
<div class="config-group">
|
|
289
|
-
<label
|
|
290
|
-
<
|
|
288
|
+
<div class="config-group" style="grid-column: 1 / -1;">
|
|
289
|
+
<label>WebSocket URL</label>
|
|
290
|
+
<p id="demoWsUrlDisplay" style="font-size: 13px; color: #4b5563; margin-top: 4px; font-family: monospace;">
|
|
291
|
+
Set by SDK toggle (top-right): Production → speech.talktopc.com · Development → speech.bidme.co.il
|
|
292
|
+
</p>
|
|
291
293
|
</div>
|
|
292
294
|
|
|
293
295
|
<div class="config-group">
|
|
@@ -398,16 +400,12 @@
|
|
|
398
400
|
</div>
|
|
399
401
|
</div>
|
|
400
402
|
|
|
401
|
-
|
|
402
|
-
<script src="/agent-widget.js" onload="console.log('✅ SDK script loaded, TTPAgentSDK:', typeof window.TTPAgentSDK)" onerror="console.error('❌ Failed to load SDK script')"></script>
|
|
403
|
+
<script src="demo-sdk-loader.js"></script>
|
|
403
404
|
<script>
|
|
404
|
-
console.log('🔵 Waiting for SDK to load...');
|
|
405
|
-
|
|
406
|
-
// Wait for TTPAgentSDK to be available (UMD library loads as global)
|
|
405
|
+
console.log('🔵 Waiting for SDK to load (use top-right toggle for prod/dev)...');
|
|
406
|
+
|
|
407
407
|
function initSDK() {
|
|
408
408
|
if (typeof window.TTPAgentSDK === 'undefined') {
|
|
409
|
-
console.log('⏳ TTPAgentSDK not ready yet, waiting...');
|
|
410
|
-
setTimeout(initSDK, 100);
|
|
411
409
|
return;
|
|
412
410
|
}
|
|
413
411
|
|
|
@@ -427,6 +425,8 @@
|
|
|
427
425
|
|
|
428
426
|
window.TTPChatWidget = TTPChatWidget;
|
|
429
427
|
window.widgetInstance = null;
|
|
428
|
+
const mode = window.TTPDemoSdkLoader?.getMode?.() || '?';
|
|
429
|
+
console.log('✅ SDK ready:', window.TTPDemoSdkLoader?.getSrc?.(mode), '(' + mode + ')');
|
|
430
430
|
|
|
431
431
|
// Define functions after module loads
|
|
432
432
|
window.initializeWidget = function() {
|
|
@@ -442,7 +442,6 @@
|
|
|
442
442
|
const agentId = document.getElementById('agentId').value;
|
|
443
443
|
const appId = document.getElementById('appId').value;
|
|
444
444
|
const getSessionUrl = document.getElementById('getSessionUrl').value;
|
|
445
|
-
const websocketUrl = document.getElementById('websocketUrl').value;
|
|
446
445
|
const position = document.getElementById('position').value;
|
|
447
446
|
const language = document.getElementById('language').value;
|
|
448
447
|
const mode = document.getElementById('mode').value;
|
|
@@ -477,9 +476,8 @@
|
|
|
477
476
|
config.getSessionUrl = getSessionUrl;
|
|
478
477
|
}
|
|
479
478
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
479
|
+
window.TTPDemoSdkLoader.applyWebSocketUrl(config);
|
|
480
|
+
console.log('🔌 websocketUrl:', config.websocketUrl, '(SDK mode:', window.TTPDemoSdkLoader.getMode() + ')');
|
|
483
481
|
|
|
484
482
|
// Handle position
|
|
485
483
|
if (position) {
|
|
@@ -549,7 +547,6 @@
|
|
|
549
547
|
document.getElementById('agentId').value = 'agent_e5cf06457';
|
|
550
548
|
document.getElementById('appId').value = 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC';
|
|
551
549
|
document.getElementById('getSessionUrl').value = '';
|
|
552
|
-
document.getElementById('websocketUrl').value = 'wss://speech.talktopc.com/ws/conv';
|
|
553
550
|
document.getElementById('position').value = 'bottom-right';
|
|
554
551
|
document.getElementById('language').value = 'en';
|
|
555
552
|
document.getElementById('mode').value = 'unified';
|
|
@@ -638,9 +635,32 @@
|
|
|
638
635
|
resetConfig: typeof window.resetConfig
|
|
639
636
|
});
|
|
640
637
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
638
|
+
|
|
639
|
+
function updateWsUrlDisplay() {
|
|
640
|
+
const el = document.getElementById('demoWsUrlDisplay');
|
|
641
|
+
if (!el || !window.TTPDemoSdkLoader) return;
|
|
642
|
+
const mode = window.TTPDemoSdkLoader.getMode();
|
|
643
|
+
el.textContent = window.TTPDemoSdkLoader.getWebSocketUrl(mode) + ' (' + mode + ')';
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
window.addEventListener('ttp-demo-sdk-ready', () => {
|
|
647
|
+
updateWsUrlDisplay();
|
|
648
|
+
if (window.widgetInstance && typeof window.destroyWidget === 'function') {
|
|
649
|
+
window.destroyWidget();
|
|
650
|
+
}
|
|
651
|
+
initSDK();
|
|
652
|
+
// Re-create widget if user already initialized (so WS URL matches new SDK mode)
|
|
653
|
+
if (typeof window.initializeWidget === 'function' && document.getElementById('widgetStatus')?.textContent === 'Yes') {
|
|
654
|
+
window.initializeWidget();
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
window.TTPDemoSdkLoader.waitForReady().then(() => {
|
|
658
|
+
updateWsUrlDisplay();
|
|
659
|
+
initSDK();
|
|
660
|
+
}).catch((e) => {
|
|
661
|
+
console.error('❌ SDK load failed:', e);
|
|
662
|
+
alert('SDK load failed. Check Network for agent-widget*.js');
|
|
663
|
+
});
|
|
644
664
|
</script>
|
|
645
665
|
</body>
|
|
646
666
|
</html>
|
|
@@ -1280,10 +1280,11 @@
|
|
|
1280
1280
|
}
|
|
1281
1281
|
}
|
|
1282
1282
|
</style>
|
|
1283
|
+
<script src="demo-sdk-loader.js"></script>
|
|
1283
1284
|
</head>
|
|
1284
1285
|
<body>
|
|
1285
1286
|
<div class="header">
|
|
1286
|
-
<div class="dev-banner"
|
|
1287
|
+
<div class="dev-banner">🔧 Use the SDK toggle (top-right) to switch Production ↔ Development bundles</div>
|
|
1287
1288
|
<a href="test-index.html" class="back-link">← Back to Demos</a>
|
|
1288
1289
|
<h1>🎨 Widget Live Customization (Dev Page)</h1>
|
|
1289
1290
|
<div style="margin-top: 16px; display: flex; align-items: center; justify-content: center; gap: 24px; flex-wrap: wrap;">
|
|
@@ -4126,6 +4127,10 @@
|
|
|
4126
4127
|
}
|
|
4127
4128
|
};
|
|
4128
4129
|
|
|
4130
|
+
if (window.TTPDemoSdkLoader) {
|
|
4131
|
+
window.TTPDemoSdkLoader.applyWebSocketUrl(actualConfig);
|
|
4132
|
+
}
|
|
4133
|
+
|
|
4129
4134
|
try {
|
|
4130
4135
|
// Reset manual close tracking when widget is recreated (unless user manually closed it)
|
|
4131
4136
|
// Don't reset if widget was manually closed and mock panel is also closed
|
|
@@ -4348,8 +4353,15 @@
|
|
|
4348
4353
|
};
|
|
4349
4354
|
|
|
4350
4355
|
// Start checking for SDK (will also be called when script loads)
|
|
4351
|
-
window.
|
|
4352
|
-
|
|
4356
|
+
window.addEventListener('ttp-demo-sdk-ready', () => {
|
|
4357
|
+
if (actualWidgetInstance) {
|
|
4358
|
+
try { actualWidgetInstance.destroy(); } catch (e) { /* ignore */ }
|
|
4359
|
+
actualWidgetInstance = null;
|
|
4360
|
+
}
|
|
4361
|
+
window.checkAndInitWidget();
|
|
4362
|
+
});
|
|
4363
|
+
window.TTPDemoSdkLoader.waitForReady().then(() => window.checkAndInitWidget());
|
|
4364
|
+
|
|
4353
4365
|
// Debug helper - expose widget instance globally for inspection
|
|
4354
4366
|
window.debugWidget = function() {
|
|
4355
4367
|
console.log('=== Widget Debug Info ===');
|
|
@@ -4376,8 +4388,5 @@
|
|
|
4376
4388
|
};
|
|
4377
4389
|
};
|
|
4378
4390
|
</script>
|
|
4379
|
-
|
|
4380
|
-
<!-- Load the widget SDK (production version) -->
|
|
4381
|
-
<script src="/agent-widget.js?v=2.34.2" onload="if (typeof window.checkAndInitWidget === 'function') setTimeout(window.checkAndInitWidget, 100);" onerror="console.error('❌ Failed to load SDK script from /agent-widget.js'); alert('Failed to load SDK. Check console for details.');"></script>
|
|
4382
4391
|
</body>
|
|
4383
4392
|
</html>
|
|
@@ -1793,6 +1793,7 @@
|
|
|
1793
1793
|
}
|
|
1794
1794
|
}
|
|
1795
1795
|
</style>
|
|
1796
|
+
<script src="demo-sdk-loader.js"></script>
|
|
1796
1797
|
</head>
|
|
1797
1798
|
<body>
|
|
1798
1799
|
<div class="header">
|
|
@@ -5017,6 +5018,10 @@
|
|
|
5017
5018
|
}
|
|
5018
5019
|
};
|
|
5019
5020
|
|
|
5021
|
+
if (window.TTPDemoSdkLoader) {
|
|
5022
|
+
window.TTPDemoSdkLoader.applyWebSocketUrl(actualConfig);
|
|
5023
|
+
}
|
|
5024
|
+
|
|
5020
5025
|
try {
|
|
5021
5026
|
// Reset manual close tracking when widget is recreated (unless user manually closed it)
|
|
5022
5027
|
// Don't reset if widget was manually closed and mock panel is also closed
|
|
@@ -5450,9 +5455,15 @@
|
|
|
5450
5455
|
}
|
|
5451
5456
|
};
|
|
5452
5457
|
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5458
|
+
window.addEventListener('ttp-demo-sdk-ready', () => {
|
|
5459
|
+
if (actualWidgetInstance) {
|
|
5460
|
+
try { actualWidgetInstance.destroy(); } catch (e) { /* ignore */ }
|
|
5461
|
+
actualWidgetInstance = null;
|
|
5462
|
+
}
|
|
5463
|
+
window.checkAndInitWidget();
|
|
5464
|
+
});
|
|
5465
|
+
window.TTPDemoSdkLoader.waitForReady().then(() => window.checkAndInitWidget());
|
|
5466
|
+
|
|
5456
5467
|
// Debug helper - expose widget instance globally for inspection
|
|
5457
5468
|
window.debugWidget = function() {
|
|
5458
5469
|
console.log('=== Widget Debug Info ===');
|
|
@@ -5479,8 +5490,5 @@
|
|
|
5479
5490
|
};
|
|
5480
5491
|
};
|
|
5481
5492
|
</script>
|
|
5482
|
-
|
|
5483
|
-
<!-- Load the widget SDK -->
|
|
5484
|
-
<script src="/agent-widget.js" onload="if (typeof window.checkAndInitWidget === 'function') setTimeout(window.checkAndInitWidget, 100);" onerror="console.error('❌ Failed to load SDK script from /agent-widget.js'); alert('Failed to load SDK. Check console for details.');"></script>
|
|
5485
5493
|
</body>
|
|
5486
5494
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttp-agent-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.45.1",
|
|
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,6 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "npm run build:umd && npm run build:esm && npm run build:dev",
|
|
26
26
|
"deploy": "npm run build && npx wrangler pages deploy dist --project-name=ttp-sdk-front --branch=master --commit-dirty=true",
|
|
27
|
+
"deploy:sandbox": "./deploy-sandbox-sdk.sh",
|
|
27
28
|
"deploy:prod": "./deploy-production.sh",
|
|
28
29
|
"build:prod": "webpack --config webpack.config.js",
|
|
29
30
|
"build:dev": "webpack --config webpack.dev.config.js",
|