@tellyouai/plugin 0.1.9 → 0.1.10

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.
@@ -41017,7 +41017,7 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41017
41017
  let r = await navigator.mediaDevices.enumerateDevices(), i = r.find((e) => e.kind === "audioinput" && e.deviceId === n), a = r.find((e) => e.kind === "audiooutput" && i?.groupId && e.groupId === i.groupId);
41018
41018
  a && await e.setSinkId(a.deviceId);
41019
41019
  }, lce = (e) => {
41020
- let { config: { entityId: t } } = Kl(), { entityId: n } = xu(), { locale: r } = cA(), i = ql(), a = gu(i.config.consent), [o, s] = (0, lA.useState)([]), [c, l] = (0, lA.useState)(!1), [u, d] = (0, lA.useState)(!1), f = (0, lA.useRef)(null), p = (0, lA.useRef)(null), m = (0, lA.useRef)(null), h = (0, lA.useRef)(null), g = (0, lA.useRef)(null), _ = (0, lA.useRef)(0), v = (0, lA.useRef)(/* @__PURE__ */ new Set()), y = (0, lA.useRef)(null), b = (0, lA.useRef)(null), x = (0, lA.useCallback)((e) => {
41020
+ let { config: { entityId: t } } = Kl(), { entityId: n } = xu(), { locale: r } = cA(), i = ql(), a = gu(i.config.consent), [o, s] = (0, lA.useState)([]), [c, l] = (0, lA.useState)(!1), [u, d] = (0, lA.useState)(!1), f = (0, lA.useRef)(null), p = (0, lA.useRef)(null), m = (0, lA.useRef)(null), h = (0, lA.useRef)(null), g = (0, lA.useRef)(null), _ = (0, lA.useRef)(0), v = (0, lA.useRef)(/* @__PURE__ */ new Set()), y = (0, lA.useRef)(null), b = (0, lA.useRef)(null), x = (0, lA.useRef)(null), S = (0, lA.useRef)(null), C = (0, lA.useCallback)((e) => {
41021
41021
  s((t) => {
41022
41022
  let n = e.filter((e) => t.some((t) => t.id === e.id)), r = e.filter((e) => !t.some((t) => t.id === e.id));
41023
41023
  return [...t.map((e) => {
@@ -41032,13 +41032,13 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41032
41032
  createdAt: e.createdAt || /* @__PURE__ */ new Date()
41033
41033
  }))];
41034
41034
  });
41035
- }, []), S = (0, lA.useCallback)((r, i, a) => {
41035
+ }, []), w = (0, lA.useCallback)((r, i, a) => {
41036
41036
  let o = r === "agent" ? b : y, s = o.current || {
41037
41037
  id: Tt(),
41038
41038
  content: "",
41039
41039
  createdAt: /* @__PURE__ */ new Date()
41040
41040
  }, c = a ? i : s.content + i;
41041
- c.trim() && x([{
41041
+ c.trim() && C([{
41042
41042
  id: s.id,
41043
41043
  content: c.trim(),
41044
41044
  createdAt: s.createdAt,
@@ -41051,16 +41051,16 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41051
41051
  }, [
41052
41052
  n,
41053
41053
  e,
41054
- x,
41054
+ C,
41055
41055
  t
41056
- ]), C = (0, lA.useCallback)(() => {
41056
+ ]), T = (0, lA.useCallback)(() => {
41057
41057
  let e = f.current;
41058
41058
  f.current = null, e && e.readyState < WebSocket.CLOSING && e.close(), g.current?.disconnect(), g.current = null, m.current?.getTracks().forEach((e) => e.stop()), m.current = null, h.current &&= (navigator.mediaDevices.removeEventListener("devicechange", h.current), null), v.current.forEach((e) => {
41059
41059
  try {
41060
41060
  e.stop();
41061
41061
  } catch {}
41062
- }), v.current.clear(), y.current = null, b.current = null, _.current = 0, p.current?.close(), p.current = null, l(!1), d(!1);
41063
- }, []), w = (0, lA.useCallback)((e) => {
41062
+ }), v.current.clear(), y.current = null, b.current = null, x.current = null, S.current = null, _.current = 0, p.current?.close(), p.current = null, l(!1), d(!1);
41063
+ }, []), E = (0, lA.useCallback)((e) => {
41064
41064
  let t = p.current;
41065
41065
  if (!t) return;
41066
41066
  let n = cce(e), r = Math.floor(n.byteLength / 2), i = t.createBuffer(1, r, 24e3), a = i.getChannelData(0), o = new DataView(n.buffer, n.byteOffset, n.byteLength);
@@ -41069,13 +41069,13 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41069
41069
  s.buffer = i, s.connect(t.destination);
41070
41070
  let c = Math.max(t.currentTime, _.current);
41071
41071
  s.start(c), _.current = c + i.duration, v.current.add(s), s.onended = () => v.current.delete(s);
41072
- }, []), T = (0, lA.useCallback)(() => {
41072
+ }, []), D = (0, lA.useCallback)(() => {
41073
41073
  v.current.forEach((e) => {
41074
41074
  try {
41075
41075
  e.stop();
41076
41076
  } catch {}
41077
41077
  }), v.current.clear(), _.current = p.current?.currentTime || 0;
41078
- }, []), E = (0, lA.useCallback)(async () => {
41078
+ }, []), O = (0, lA.useCallback)(async () => {
41079
41079
  if (t && n) {
41080
41080
  l(!0);
41081
41081
  try {
@@ -41089,9 +41089,9 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41089
41089
  uA(_, u).catch((e) => console.warn("Unable to route voice playback to headset:", e));
41090
41090
  };
41091
41091
  navigator.mediaDevices.addEventListener("devicechange", v);
41092
- let x = new WebSocket(c.mediaUrl);
41093
- m.current = u, p.current = _, h.current = v, f.current = x, x.onopen = () => {
41094
- x.send(JSON.stringify({
41092
+ let C = new WebSocket(c.mediaUrl);
41093
+ m.current = u, p.current = _, h.current = v, f.current = C, C.onopen = () => {
41094
+ C.send(JSON.stringify({
41095
41095
  type: "proxy.configure",
41096
41096
  token: c.token,
41097
41097
  context: {
@@ -41113,7 +41113,7 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41113
41113
  parameters: t.inputSchema
41114
41114
  }))
41115
41115
  }));
41116
- }, x.onmessage = async (e) => {
41116
+ }, C.onmessage = async (e) => {
41117
41117
  let t = JSON.parse(e.data);
41118
41118
  if (t.type === "proxy.tool_call") {
41119
41119
  let e = t.name ? s[t.name] : void 0, n;
@@ -41122,7 +41122,7 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41122
41122
  } catch (e) {
41123
41123
  n = `Client tool "${t.name}" failed: ${e instanceof Error ? e.message : String(e)}`;
41124
41124
  }
41125
- x.readyState === WebSocket.OPEN && x.send(JSON.stringify({
41125
+ C.readyState === WebSocket.OPEN && C.send(JSON.stringify({
41126
41126
  type: "proxy.tool_result",
41127
41127
  callId: t.callId,
41128
41128
  output: n
@@ -41130,49 +41130,53 @@ var bp, xp, Sp, Cp, wp, Tp, Ep, Dp, Op, kp, Ap, jp, Mp, Np, Pp, Fp, Ip, Lp, Rp,
41130
41130
  } else if (t.type === "proxy.ready") {
41131
41131
  let e = _.createMediaStreamSource(u), t = _.createScriptProcessor(4096, 1, 1), n = _.createGain();
41132
41132
  n.gain.value = 0, t.onaudioprocess = (e) => {
41133
- if (x.readyState !== WebSocket.OPEN) return;
41133
+ if (C.readyState !== WebSocket.OPEN) return;
41134
41134
  let t = e.inputBuffer.getChannelData(0), n = new Int16Array(t.length);
41135
41135
  for (let e = 0; e < t.length; e += 1) {
41136
41136
  let r = Math.max(-1, Math.min(1, t[e]));
41137
41137
  n[e] = r < 0 ? r * 32768 : r * 32767;
41138
41138
  }
41139
- x.send(n.buffer);
41139
+ C.send(n.buffer);
41140
41140
  }, e.connect(t), t.connect(n), n.connect(_.destination), g.current = t, _.resume(), l(!1), d(!0);
41141
41141
  } else if (t.type === "proxy.takeover_announcement" && t.announcement) {
41142
- T(), speechSynthesis.cancel();
41142
+ D(), speechSynthesis.cancel();
41143
41143
  let e = new SpeechSynthesisUtterance(t.announcement);
41144
41144
  e.lang = r;
41145
41145
  let n = () => {
41146
- x.readyState === WebSocket.OPEN && x.send(JSON.stringify({ type: "proxy.takeover_announcement_done" }));
41146
+ C.readyState === WebSocket.OPEN && C.send(JSON.stringify({ type: "proxy.takeover_announcement_done" }));
41147
41147
  };
41148
41148
  e.onend = n, e.onerror = n, speechSynthesis.speak(e);
41149
- } else t.type === "response.output_audio.delta" ? t.delta && w(t.delta) : t.type === "input_audio_buffer.speech_started" ? (T(), y.current = null, b.current = null) : t.type === "conversation.item.input_audio_transcription.delta" ? S("user", t.delta || "", !1) : t.type === "conversation.item.input_audio_transcription.completed" ? S("user", t.transcript || "", !0) : t.type === "response.output_audio_transcript.delta" ? S("agent", t.delta || "", !1) : t.type === "response.output_audio_transcript.done" ? S("agent", t.transcript || "", !0) : t.type === "error" && console.error("OpenAI Realtime error:", t.message || t);
41150
- }, x.onerror = (e) => {
41151
- console.error("OpenAI Realtime connection failed:", e), C();
41152
- }, x.onclose = () => C();
41149
+ } else if (t.type === "session.output_audio.delta") t.delta && E(t.delta);
41150
+ else if (t.type === "session.input_transcript.delta" || t.type === "session.output_transcript.delta") {
41151
+ let e = t.type === "session.input_transcript.delta", n = e ? x : S, r = e ? y : b;
41152
+ n.current !== null && t.start_ms !== void 0 && t.start_ms > n.current + 1200 && (r.current = null, e && D()), e && n.current === null && D(), n.current = t.end_ms ?? n.current, w(e ? "user" : "agent", t.delta || "", !1);
41153
+ } else t.type === "error" && console.error("OpenAI Live error:", t.message || t);
41154
+ }, C.onerror = (e) => {
41155
+ console.error("OpenAI Realtime connection failed:", e), T();
41156
+ }, C.onclose = () => T();
41153
41157
  } catch (e) {
41154
- C(), console.error("Failed to start OpenAI Realtime conversation:", e);
41158
+ T(), console.error("Failed to start OpenAI Realtime conversation:", e);
41155
41159
  }
41156
41160
  }
41157
41161
  }, [
41158
- T,
41162
+ D,
41159
41163
  n,
41160
41164
  e,
41161
41165
  i,
41162
41166
  r,
41163
- w,
41167
+ E,
41164
41168
  a.analytics,
41165
- C,
41169
+ T,
41166
41170
  t,
41167
- S
41171
+ w
41168
41172
  ]);
41169
41173
  return (0, lA.useEffect)(() => () => {
41170
- f.current && C();
41171
- }, [C]), {
41172
- startCall: E,
41173
- endCall: C,
41174
+ f.current && T();
41175
+ }, [T]), {
41176
+ startCall: O,
41177
+ endCall: T,
41174
41178
  messages: o,
41175
- onMessages: x,
41179
+ onMessages: C,
41176
41180
  isConnected: u,
41177
41181
  isConnecting: c
41178
41182
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tellyouai/plugin",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Framework-agnostic browser SDK for the Tellyou AI plugin",
5
5
  "repository": {
6
6
  "type": "git",