@nuancelabs/js-sdk 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/index.js +35 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4,7 +4,7 @@ function isRecord(value) {
4
4
  }
5
5
 
6
6
  // src/core/sdk-version.ts
7
- var SDK_HEADER = `js/${"0.1.0"}`;
7
+ var SDK_HEADER = `js/${"0.1.2"}`;
8
8
 
9
9
  // src/utils.ts
10
10
  function normalizeHost(host) {
@@ -35,6 +35,9 @@ class NuanceApiClient {
35
35
  }
36
36
  async createConversation(request) {
37
37
  const token = this.tokenProvider ? await this.tokenProvider() : undefined;
38
+ if (token !== undefined && (typeof token !== "string" || token === "")) {
39
+ throw new TypeError(`The token option must resolve to the session token string, but it resolved to ${token === "" ? "an empty string" : typeof token}. Return the "token" field of your endpoint's response.`);
40
+ }
38
41
  const conversation = await this.request("/conversation", { method: "POST", body: request, token });
39
42
  if (token !== undefined)
40
43
  this.tokens.set(conversation.id, token);
@@ -1075,6 +1078,9 @@ function parseSessionEvent(payload) {
1075
1078
  }
1076
1079
  };
1077
1080
  }
1081
+ if (decoded.type === "floor") {
1082
+ return { type: "floor", speaking: decoded.state === "speaking" };
1083
+ }
1078
1084
  if (decoded.type === "session.status" && decoded.status === "ended") {
1079
1085
  return {
1080
1086
  type: "ended",
@@ -1517,6 +1523,7 @@ class LiveKitConversation {
1517
1523
  eventsRegistered = false;
1518
1524
  sessionEnded = false;
1519
1525
  speaksProtocol = false;
1526
+ avatarSpeaking = false;
1520
1527
  answered = null;
1521
1528
  commands = new Map;
1522
1529
  commandCount = 0;
@@ -1662,6 +1669,12 @@ class LiveKitConversation {
1662
1669
  }
1663
1670
  return this.command({ type: "scene.background", background });
1664
1671
  }
1672
+ async sendText(text) {
1673
+ const line = text.trim();
1674
+ if (!line)
1675
+ throw new Error("Nothing to send: the text is blank");
1676
+ return this.command({ type: "input.text", text: line, respond: true });
1677
+ }
1665
1678
  onChange(handler) {
1666
1679
  return this.onEvent((event) => {
1667
1680
  if (event.type !== "data-event")
@@ -1745,6 +1758,8 @@ class LiveKitConversation {
1745
1758
  const mapped = mapConnectionState(lkState, this.resilient && this.everConnected);
1746
1759
  if (mapped === "connected")
1747
1760
  this.everConnected = true;
1761
+ if (lkState === ConnectionState2.Reconnecting)
1762
+ this.setAvatarSpeaking(false);
1748
1763
  if (mapped !== this._state) {
1749
1764
  this.setState(mapped);
1750
1765
  }
@@ -1784,6 +1799,7 @@ class LiveKitConversation {
1784
1799
  this.room.on(RoomEvent3.Disconnected, () => {
1785
1800
  this.stats?.abandon();
1786
1801
  this.stats = null;
1802
+ this.setAvatarSpeaking(false);
1787
1803
  this.stopPresentation();
1788
1804
  this.stopReadyFallback();
1789
1805
  this.stopLayerFallback();
@@ -1899,6 +1915,8 @@ class LiveKitConversation {
1899
1915
  this.commands.delete(id);
1900
1916
  settle({ status: "rejected", error: `unknown command ${type}` });
1901
1917
  }
1918
+ } else if (event.type === "floor") {
1919
+ this.setAvatarSpeaking(event.speaking);
1902
1920
  } else if (event.type === "ended") {
1903
1921
  this.answered?.();
1904
1922
  if (!event.byClient)
@@ -1931,6 +1949,16 @@ class LiveKitConversation {
1931
1949
  this.readyFallback?.stop();
1932
1950
  this.readyFallback = null;
1933
1951
  }
1952
+ setAvatarSpeaking(speaking) {
1953
+ if (speaking === this.avatarSpeaking)
1954
+ return;
1955
+ this.avatarSpeaking = speaking;
1956
+ this.emit({
1957
+ type: "speaking-changed",
1958
+ participant: "avatar",
1959
+ isSpeaking: speaking
1960
+ });
1961
+ }
1934
1962
  markAvatarReady() {
1935
1963
  this.stopReadyFallback();
1936
1964
  if (this._avatar.isReady)
@@ -2278,6 +2306,12 @@ class NuanceConversation {
2278
2306
  }
2279
2307
  return this.delegate.setBackground(background);
2280
2308
  }
2309
+ async sendText(text) {
2310
+ if (!this.delegate) {
2311
+ throw new Error("Not connected — call connect() first");
2312
+ }
2313
+ return this.delegate.sendText(text);
2314
+ }
2281
2315
  onChange(handler) {
2282
2316
  return this.onEvent((event) => {
2283
2317
  if (event.type !== "data-event")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuancelabs/js-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "JavaScript SDK for Nuance Labs conversation video AI avatar",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {