@nuancelabs/js-sdk 0.13.0 → 0.13.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.
Files changed (3) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +40 -4
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -557,6 +557,7 @@ export declare class GuestLimitError extends Error {
557
557
  constructor(reason: string, message: string);
558
558
  }
559
559
 
560
+
560
561
  /**
561
562
  * Raised by {@link Conversation.connect} when the server refuses a new session
562
563
  * because the account has not completed onboarding or accepted the current
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.13.0"}`;
7
+ var SDK_HEADER = `js/${"0.13.1"}`;
8
8
 
9
9
  // src/utils.ts
10
10
  function normalizeHost(host) {
@@ -1676,6 +1676,10 @@ var COMMAND_TIMEOUT_MS = 5000;
1676
1676
  var STREAM_TIMEOUT_MS = 30000;
1677
1677
  var BACKGROUND_ID = /^[a-z0-9][a-z0-9_-]{0,63}$/;
1678
1678
  var AVATAR_RETURN_TIMEOUT_MS = 8000;
1679
+ function contextItem(item) {
1680
+ const name = item.name === undefined ? {} : { name: item.name };
1681
+ return item.type === "text" ? { type: "text", text: item.text, ...name } : { type: "image", media_type: item.mediaType, data: item.data, ...name };
1682
+ }
1679
1683
  function isReconnecting(lkState) {
1680
1684
  return lkState === ConnectionState2.Reconnecting || lkState === ConnectionState2.SignalReconnecting;
1681
1685
  }
@@ -1736,6 +1740,7 @@ class LiveKitConversation {
1736
1740
  awayTimer = null;
1737
1741
  presentationPaused = false;
1738
1742
  readySending = false;
1743
+ contextSent = null;
1739
1744
  leaving = null;
1740
1745
  connectGeneration = 0;
1741
1746
  _id;
@@ -1744,6 +1749,8 @@ class LiveKitConversation {
1744
1749
  cameraFacing;
1745
1750
  tokenProvider;
1746
1751
  opensOnReady;
1752
+ presentsAtFullSize;
1753
+ initialContext;
1747
1754
  resilient;
1748
1755
  constructor(config) {
1749
1756
  this.room = new Room({
@@ -1765,6 +1772,8 @@ class LiveKitConversation {
1765
1772
  this.cameraFacing = config.mediaDevices?.cameraFacing;
1766
1773
  this.tokenProvider = config.tokenProvider;
1767
1774
  this.opensOnReady = config.opensOnReady ?? false;
1775
+ this.presentsAtFullSize = config.presentsAtFullSize ?? this.opensOnReady;
1776
+ this.initialContext = config.initialContext ?? [];
1768
1777
  this.resilient = config.resilientReconnect ?? false;
1769
1778
  }
1770
1779
  get id() {
@@ -1780,6 +1789,7 @@ class LiveKitConversation {
1780
1789
  this.sequence.stop();
1781
1790
  this.sequence = this.newSequence();
1782
1791
  this.readyOwed = false;
1792
+ this.contextSent = null;
1783
1793
  this.everConnected = false;
1784
1794
  if (!this.eventsRegistered) {
1785
1795
  this.registerRoomEvents();
@@ -2150,6 +2160,7 @@ class LiveKitConversation {
2150
2160
  if (packet === null)
2151
2161
  return;
2152
2162
  this.speaksProtocol = true;
2163
+ this.sendContext();
2153
2164
  const { seq, event } = packet;
2154
2165
  if (this.sequence.repeats(seq))
2155
2166
  return;
@@ -2243,6 +2254,10 @@ class LiveKitConversation {
2243
2254
  this.emit({ type: "avatar-presented" });
2244
2255
  return;
2245
2256
  }
2257
+ if (!this.presentsAtFullSize) {
2258
+ this.markAvatarPresented();
2259
+ return;
2260
+ }
2246
2261
  this.startPresentation();
2247
2262
  }
2248
2263
  startPresentation() {
@@ -2253,7 +2268,7 @@ class LiveKitConversation {
2253
2268
  markAvatarPresented() {
2254
2269
  this.presentation = null;
2255
2270
  if (this.speaksProtocol && this.room.state === ConnectionState2.Connected) {
2256
- this.command({ type: "session.ready" }).catch(() => {
2271
+ this.ready().catch(() => {
2257
2272
  return;
2258
2273
  });
2259
2274
  } else if (this.resilient && this.speaksProtocol && isReconnecting(this.room.state)) {
@@ -2261,11 +2276,28 @@ class LiveKitConversation {
2261
2276
  }
2262
2277
  this.emit({ type: "avatar-presented" });
2263
2278
  }
2279
+ sendContext() {
2280
+ if (this.contextSent !== null || this.initialContext.length === 0)
2281
+ return;
2282
+ this.contextSent = this.command({
2283
+ type: "session.context",
2284
+ items: this.initialContext.map(contextItem)
2285
+ }).then(() => {
2286
+ return;
2287
+ }, () => {
2288
+ return;
2289
+ });
2290
+ }
2291
+ ready() {
2292
+ this.sendContext();
2293
+ const ready = () => this.command({ type: "session.ready" });
2294
+ return this.contextSent === null ? ready() : this.contextSent.then(ready);
2295
+ }
2264
2296
  sendOwedReady() {
2265
2297
  if (!this.readyOwed || !this.speaksProtocol || this.readySending)
2266
2298
  return;
2267
2299
  this.readySending = true;
2268
- this.command({ type: "session.ready" }).then(() => {
2300
+ this.ready().then(() => {
2269
2301
  this.readyOwed = false;
2270
2302
  }).catch(() => {
2271
2303
  return;
@@ -2429,6 +2461,7 @@ class NuanceConversation {
2429
2461
  sessionOverrides;
2430
2462
  personality;
2431
2463
  tools;
2464
+ initialContext;
2432
2465
  variant;
2433
2466
  maxSessionSeconds;
2434
2467
  videoCapture;
@@ -2468,6 +2501,7 @@ class NuanceConversation {
2468
2501
  this.sessionOverrides = options.sessionOverrides ?? {};
2469
2502
  this.personality = options.personality;
2470
2503
  this.tools = options.tools;
2504
+ this.initialContext = options.initialContext ?? [];
2471
2505
  this.variant = options.variant;
2472
2506
  this.maxSessionSeconds = options.maxSessionSeconds;
2473
2507
  this.videoCapture = options.videoCapture;
@@ -2497,7 +2531,7 @@ class NuanceConversation {
2497
2531
  try {
2498
2532
  const request = {
2499
2533
  session_overrides: this.sessionOverrides,
2500
- client_ready: this.startOn === "full-quality"
2534
+ client_ready: this.startOn === "full-quality" || this.initialContext.length > 0
2501
2535
  };
2502
2536
  const timezone = this.timezone();
2503
2537
  if (timezone)
@@ -2809,6 +2843,8 @@ class NuanceConversation {
2809
2843
  cameraEnabled: !this.sessionOverrides.disable_camera && mediaDevices.cameraEnabled !== false,
2810
2844
  videoCapture: this.videoCapture,
2811
2845
  opensOnReady: conversation.provider_metadata?.client_ready === true,
2846
+ presentsAtFullSize: this.startOn === "full-quality",
2847
+ initialContext: this.initialContext,
2812
2848
  resilientReconnect: this.resilient
2813
2849
  });
2814
2850
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuancelabs/js-sdk",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "JavaScript SDK for Nuance Labs conversation video AI avatar",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {