@exotel-npm-dev/exotel-ai-assist 1.2.7 → 1.2.9

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.
@@ -343,7 +343,7 @@ class BroadcastChannelTransport {
343
343
  this.pendingUrl = null;
344
344
  this.pendingAuthToken = null;
345
345
  this.lockReleaser = null;
346
- this.ackReceived = false;
346
+ this.ackPayload = null;
347
347
  this._destroyed = false;
348
348
  const channelName = `exotel-ai-assist:${sessionHash}`;
349
349
  const lockName = `exotel-ai-assist-leader:${sessionHash}`;
@@ -352,15 +352,14 @@ class BroadcastChannelTransport {
352
352
  var _a;
353
353
  const data = ev.data;
354
354
  if (this.isLeader) {
355
- if (data.type === "JOIN" && this.socketConnected) {
355
+ if (data.type === "JOIN" && this.socketConnected && this.ackPayload) {
356
356
  this.channel.postMessage({
357
357
  type: "CONNECTED"
358
358
  });
359
- if (this.ackReceived) {
360
- this.channel.postMessage({
361
- type: "ACKNOWLEDGED"
362
- });
363
- }
359
+ this.channel.postMessage({
360
+ type: "MESSAGE",
361
+ payload: this.ackPayload
362
+ });
364
363
  }
365
364
  return;
366
365
  }
@@ -415,7 +414,7 @@ class BroadcastChannelTransport {
415
414
  var _a;
416
415
  if (this._destroyed) return;
417
416
  this.socketConnected = true;
418
- this.ackReceived = false;
417
+ this.ackPayload = null;
419
418
  this.socket.send(JSON.stringify({
420
419
  type: "auth",
421
420
  access_token: authToken
@@ -450,7 +449,7 @@ class BroadcastChannelTransport {
450
449
  var _a;
451
450
  if (this._destroyed) return;
452
451
  this.socketConnected = false;
453
- this.ackReceived = false;
452
+ this.ackPayload = null;
454
453
  const msg = {
455
454
  type: "DISCONNECTED",
456
455
  code: ev.code
@@ -483,8 +482,8 @@ class BroadcastChannelTransport {
483
482
  onMessage(handler) {
484
483
  this.handler = handler;
485
484
  }
486
- markAcknowledged() {
487
- this.ackReceived = true;
485
+ markAcknowledged(rawAckPayload) {
486
+ this.ackPayload = rawAckPayload;
488
487
  }
489
488
  destroy() {
490
489
  var _a;
@@ -1775,7 +1774,7 @@ class ExotelAIAssistController extends EventEmitter {
1775
1774
  return;
1776
1775
  }
1777
1776
  if (msgType === "ack") {
1778
- (_b = this.transport) === null || _b === void 0 ? void 0 : _b.markAcknowledged();
1777
+ (_b = this.transport) === null || _b === void 0 ? void 0 : _b.markAcknowledged(raw);
1779
1778
  const state = parsed.stream_state;
1780
1779
  if (state) this._handleStreamStatus(state);
1781
1780
  }
@@ -1833,7 +1832,7 @@ class ExotelAIAssistController extends EventEmitter {
1833
1832
  this.emit("streamState", state);
1834
1833
  if (state === "connected" || state === "throttled") {
1835
1834
  this._fireReady();
1836
- } else if ((state === "connection_timeout" || state === "disconnected") && this.readyFired) {
1835
+ } else if (this.readyFired) {
1837
1836
  this.readyFired = false;
1838
1837
  this.emit("onReady", false);
1839
1838
  }
package/dist/index.js CHANGED
@@ -19785,7 +19785,7 @@ class BroadcastChannelTransport {
19785
19785
  this.pendingUrl = null;
19786
19786
  this.pendingAuthToken = null;
19787
19787
  this.lockReleaser = null;
19788
- this.ackReceived = false;
19788
+ this.ackPayload = null;
19789
19789
  this._destroyed = false;
19790
19790
  const channelName = `exotel-ai-assist:${sessionHash}`;
19791
19791
  const lockName = `exotel-ai-assist-leader:${sessionHash}`;
@@ -19794,15 +19794,14 @@ class BroadcastChannelTransport {
19794
19794
  var _a;
19795
19795
  const data = ev.data;
19796
19796
  if (this.isLeader) {
19797
- if (data.type === "JOIN" && this.socketConnected) {
19797
+ if (data.type === "JOIN" && this.socketConnected && this.ackPayload) {
19798
19798
  this.channel.postMessage({
19799
19799
  type: "CONNECTED"
19800
19800
  });
19801
- if (this.ackReceived) {
19802
- this.channel.postMessage({
19803
- type: "ACKNOWLEDGED"
19804
- });
19805
- }
19801
+ this.channel.postMessage({
19802
+ type: "MESSAGE",
19803
+ payload: this.ackPayload
19804
+ });
19806
19805
  }
19807
19806
  return;
19808
19807
  }
@@ -19857,7 +19856,7 @@ class BroadcastChannelTransport {
19857
19856
  var _a;
19858
19857
  if (this._destroyed) return;
19859
19858
  this.socketConnected = true;
19860
- this.ackReceived = false;
19859
+ this.ackPayload = null;
19861
19860
  this.socket.send(JSON.stringify({
19862
19861
  type: "auth",
19863
19862
  access_token: authToken
@@ -19892,7 +19891,7 @@ class BroadcastChannelTransport {
19892
19891
  var _a;
19893
19892
  if (this._destroyed) return;
19894
19893
  this.socketConnected = false;
19895
- this.ackReceived = false;
19894
+ this.ackPayload = null;
19896
19895
  const msg = {
19897
19896
  type: "DISCONNECTED",
19898
19897
  code: ev.code
@@ -19925,8 +19924,8 @@ class BroadcastChannelTransport {
19925
19924
  onMessage(handler) {
19926
19925
  this.handler = handler;
19927
19926
  }
19928
- markAcknowledged() {
19929
- this.ackReceived = true;
19927
+ markAcknowledged(rawAckPayload) {
19928
+ this.ackPayload = rawAckPayload;
19930
19929
  }
19931
19930
  destroy() {
19932
19931
  var _a;
@@ -21217,7 +21216,7 @@ class ExotelAIAssistController extends EventEmitter {
21217
21216
  return;
21218
21217
  }
21219
21218
  if (msgType === "ack") {
21220
- (_b = this.transport) === null || _b === void 0 ? void 0 : _b.markAcknowledged();
21219
+ (_b = this.transport) === null || _b === void 0 ? void 0 : _b.markAcknowledged(raw);
21221
21220
  const state = parsed.stream_state;
21222
21221
  if (state) this._handleStreamStatus(state);
21223
21222
  }
@@ -21275,7 +21274,7 @@ class ExotelAIAssistController extends EventEmitter {
21275
21274
  this.emit("streamState", state);
21276
21275
  if (state === "connected" || state === "throttled") {
21277
21276
  this._fireReady();
21278
- } else if ((state === "connection_timeout" || state === "disconnected") && this.readyFired) {
21277
+ } else if (this.readyFired) {
21279
21278
  this.readyFired = false;
21280
21279
  this.emit("onReady", false);
21281
21280
  }
@@ -5071,7 +5071,7 @@ class BroadcastChannelTransport {
5071
5071
  this.pendingUrl = null;
5072
5072
  this.pendingAuthToken = null;
5073
5073
  this.lockReleaser = null;
5074
- this.ackReceived = false;
5074
+ this.ackPayload = null;
5075
5075
  this._destroyed = false;
5076
5076
  const channelName = `exotel-ai-assist:${sessionHash}`;
5077
5077
  const lockName = `exotel-ai-assist-leader:${sessionHash}`;
@@ -5080,15 +5080,14 @@ class BroadcastChannelTransport {
5080
5080
  var _a;
5081
5081
  const data = ev.data;
5082
5082
  if (this.isLeader) {
5083
- if (data.type === "JOIN" && this.socketConnected) {
5083
+ if (data.type === "JOIN" && this.socketConnected && this.ackPayload) {
5084
5084
  this.channel.postMessage({
5085
5085
  type: "CONNECTED"
5086
5086
  });
5087
- if (this.ackReceived) {
5088
- this.channel.postMessage({
5089
- type: "ACKNOWLEDGED"
5090
- });
5091
- }
5087
+ this.channel.postMessage({
5088
+ type: "MESSAGE",
5089
+ payload: this.ackPayload
5090
+ });
5092
5091
  }
5093
5092
  return;
5094
5093
  }
@@ -5143,7 +5142,7 @@ class BroadcastChannelTransport {
5143
5142
  var _a;
5144
5143
  if (this._destroyed) return;
5145
5144
  this.socketConnected = true;
5146
- this.ackReceived = false;
5145
+ this.ackPayload = null;
5147
5146
  this.socket.send(JSON.stringify({
5148
5147
  type: "auth",
5149
5148
  access_token: authToken
@@ -5178,7 +5177,7 @@ class BroadcastChannelTransport {
5178
5177
  var _a;
5179
5178
  if (this._destroyed) return;
5180
5179
  this.socketConnected = false;
5181
- this.ackReceived = false;
5180
+ this.ackPayload = null;
5182
5181
  const msg = {
5183
5182
  type: "DISCONNECTED",
5184
5183
  code: ev.code
@@ -5211,8 +5210,8 @@ class BroadcastChannelTransport {
5211
5210
  onMessage(handler) {
5212
5211
  this.handler = handler;
5213
5212
  }
5214
- markAcknowledged() {
5215
- this.ackReceived = true;
5213
+ markAcknowledged(rawAckPayload) {
5214
+ this.ackPayload = rawAckPayload;
5216
5215
  }
5217
5216
  destroy() {
5218
5217
  var _a;
@@ -6503,7 +6502,7 @@ class ExotelAIAssistController extends EventEmitter {
6503
6502
  return;
6504
6503
  }
6505
6504
  if (msgType === "ack") {
6506
- (_b = this.transport) === null || _b === void 0 ? void 0 : _b.markAcknowledged();
6505
+ (_b = this.transport) === null || _b === void 0 ? void 0 : _b.markAcknowledged(raw);
6507
6506
  const state = parsed.stream_state;
6508
6507
  if (state) this._handleStreamStatus(state);
6509
6508
  }
@@ -6561,7 +6560,7 @@ class ExotelAIAssistController extends EventEmitter {
6561
6560
  this.emit("streamState", state);
6562
6561
  if (state === "connected" || state === "throttled") {
6563
6562
  this._fireReady();
6564
- } else if ((state === "connection_timeout" || state === "disconnected") && this.readyFired) {
6563
+ } else if (this.readyFired) {
6565
6564
  this.readyFired = false;
6566
6565
  this.emit("onReady", false);
6567
6566
  }
@@ -5,9 +5,9 @@ export interface ITransport {
5
5
  disconnect(): void;
6
6
  send(payload: string): void;
7
7
  onMessage(handler: TransportMessageHandler): void;
8
- /** Signal that the server ack has been received. The leader stores this so
9
- * follower tabs joining later get an immediate ACKNOWLEDGED broadcast. */
10
- markAcknowledged(): void;
8
+ /** Store the raw ack payload so follower tabs joining later receive it as a
9
+ * MESSAGE replay instead of a bare ACKNOWLEDGED signal. */
10
+ markAcknowledged(rawAckPayload: string): void;
11
11
  destroy(): void;
12
12
  }
13
13
  export declare class BroadcastChannelTransport implements ITransport {
@@ -19,7 +19,7 @@ export declare class BroadcastChannelTransport implements ITransport {
19
19
  private pendingUrl;
20
20
  private pendingAuthToken;
21
21
  private lockReleaser;
22
- private ackReceived;
22
+ private ackPayload;
23
23
  private _destroyed;
24
24
  /**
25
25
  * @param sessionHash - A hash of all connection-relevant params (see
@@ -34,7 +34,7 @@ export declare class BroadcastChannelTransport implements ITransport {
34
34
  disconnect(): void;
35
35
  send(payload: string): void;
36
36
  onMessage(handler: TransportMessageHandler): void;
37
- markAcknowledged(): void;
37
+ markAcknowledged(rawAckPayload: string): void;
38
38
  destroy(): void;
39
39
  }
40
40
  export declare function createTransport(sessionHash: string): ITransport;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exotel-npm-dev/exotel-ai-assist",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "AI-powered real-time suggestions, transcript, and sentiment for agent calls",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -224,7 +224,7 @@ export class ExotelAIAssistController extends EventEmitter<ControllerEvents> {
224
224
  }
225
225
 
226
226
  if (msgType === "ack") {
227
- this.transport?.markAcknowledged();
227
+ this.transport?.markAcknowledged(raw);
228
228
  const state = (parsed as WssResponse).stream_state;
229
229
  if (state) this._handleStreamStatus(state);
230
230
  }
@@ -290,7 +290,7 @@ export class ExotelAIAssistController extends EventEmitter<ControllerEvents> {
290
290
  this.emit("streamState", state);
291
291
  if (state === "connected" || state === "throttled") {
292
292
  this._fireReady();
293
- } else if ((state === "connection_timeout" || state === "disconnected") && this.readyFired) {
293
+ } else if (this.readyFired) {
294
294
  this.readyFired = false;
295
295
  this.emit("onReady", false);
296
296
  }
@@ -11,9 +11,9 @@ export interface ITransport {
11
11
  disconnect(): void;
12
12
  send(payload: string): void;
13
13
  onMessage(handler: TransportMessageHandler): void;
14
- /** Signal that the server ack has been received. The leader stores this so
15
- * follower tabs joining later get an immediate ACKNOWLEDGED broadcast. */
16
- markAcknowledged(): void;
14
+ /** Store the raw ack payload so follower tabs joining later receive it as a
15
+ * MESSAGE replay instead of a bare ACKNOWLEDGED signal. */
16
+ markAcknowledged(rawAckPayload: string): void;
17
17
  destroy(): void;
18
18
  }
19
19
 
@@ -26,7 +26,7 @@ export class BroadcastChannelTransport implements ITransport {
26
26
  private pendingUrl: string | null = null;
27
27
  private pendingAuthToken: string | null = null;
28
28
  private lockReleaser: (() => void) | null = null;
29
- private ackReceived = false;
29
+ private ackPayload: string | null = null;
30
30
  private _destroyed = false;
31
31
 
32
32
  /**
@@ -44,11 +44,9 @@ export class BroadcastChannelTransport implements ITransport {
44
44
  const data = ev.data;
45
45
 
46
46
  if (this.isLeader) {
47
- if (data.type === "JOIN" && this.socketConnected) {
47
+ if (data.type === "JOIN" && this.socketConnected && this.ackPayload) {
48
48
  this.channel.postMessage({ type: "CONNECTED" } satisfies WorkerInboundMessage);
49
- if (this.ackReceived) {
50
- this.channel.postMessage({ type: "ACKNOWLEDGED" } satisfies WorkerInboundMessage);
51
- }
49
+ this.channel.postMessage({ type: "MESSAGE", payload: this.ackPayload } satisfies WorkerInboundMessage);
52
50
  }
53
51
  return;
54
52
  }
@@ -107,7 +105,7 @@ export class BroadcastChannelTransport implements ITransport {
107
105
  this.socket.onopen = () => {
108
106
  if (this._destroyed) return;
109
107
  this.socketConnected = true;
110
- this.ackReceived = false;
108
+ this.ackPayload = null;
111
109
  this.socket!.send(JSON.stringify({ type: "auth", access_token: authToken }));
112
110
  const msg: WorkerInboundMessage = { type: "CONNECTED" };
113
111
  this.channel.postMessage(msg);
@@ -131,7 +129,7 @@ export class BroadcastChannelTransport implements ITransport {
131
129
  this.socket.onclose = (ev) => {
132
130
  if (this._destroyed) return;
133
131
  this.socketConnected = false;
134
- this.ackReceived = false;
132
+ this.ackPayload = null;
135
133
  const msg: WorkerInboundMessage = { type: "DISCONNECTED", code: ev.code };
136
134
  this.channel.postMessage(msg);
137
135
  this.handler?.(msg);
@@ -165,8 +163,8 @@ export class BroadcastChannelTransport implements ITransport {
165
163
  this.handler = handler;
166
164
  }
167
165
 
168
- markAcknowledged(): void {
169
- this.ackReceived = true;
166
+ markAcknowledged(rawAckPayload: string): void {
167
+ this.ackPayload = rawAckPayload;
170
168
  }
171
169
 
172
170
  destroy(): void {