@nuancelabs/js-sdk 0.8.0 → 0.10.0

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 +18 -0
  2. package/index.js +23 -1
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -344,6 +344,12 @@ export declare interface CreateNuanceConversationOptions {
344
344
  * ```
345
345
  */
346
346
  personality?: PersonalityChoice;
347
+ /**
348
+ * The longest the conversation may run, in seconds. The server holds it to
349
+ * the account's maximum, so a longer value runs for that maximum; left out,
350
+ * the conversation runs for the maximum.
351
+ */
352
+ maxSessionSeconds?: number;
347
353
  /**
348
354
  * Capture constraints for the user's camera.
349
355
  *
@@ -370,6 +376,18 @@ export declare interface CreateNuanceConversationOptions {
370
376
  }
371
377
 
372
378
 
379
+ /**
380
+ * Raised by {@link Conversation.connect} when the server refuses a guest's new
381
+ * session because a guest limit is used up. `reason` says which: `used` (this
382
+ * guest has had its conversations), `device` (so has this browser) or `network`
383
+ * (so has this network today). The message is the server's, written for the
384
+ * person.
385
+ */
386
+ export declare class GuestLimitError extends Error {
387
+ readonly reason: string;
388
+ constructor(reason: string, message: string);
389
+ }
390
+
373
391
  /**
374
392
  * Raised by {@link Conversation.connect} when the server refuses a new session
375
393
  * 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.8.0"}`;
7
+ var SDK_HEADER = `js/${"0.10.0"}`;
8
8
 
9
9
  // src/utils.ts
10
10
  function normalizeHost(host) {
@@ -108,6 +108,16 @@ class ActiveSessionError extends Error {
108
108
  }
109
109
  }
110
110
 
111
+ // src/core/guest-limit-error.ts
112
+ class GuestLimitError extends Error {
113
+ reason;
114
+ constructor(reason, message) {
115
+ super(message);
116
+ this.name = "GuestLimitError";
117
+ this.reason = reason;
118
+ }
119
+ }
120
+
111
121
  // src/core/legal-required-error.ts
112
122
  class LegalRequiredError extends Error {
113
123
  constructor() {
@@ -2211,6 +2221,9 @@ function isMaintenanceBody(body) {
2211
2221
  function isBusyBody(body) {
2212
2222
  return isRecord(body) && body.code === "busy";
2213
2223
  }
2224
+ function isGuestLimitBody(body) {
2225
+ return isRecord(body) && body.code === "guest_limit";
2226
+ }
2214
2227
  function isCurfewBody(body) {
2215
2228
  return isRecord(body) && body.code === "policy_curfew";
2216
2229
  }
@@ -2236,6 +2249,7 @@ class NuanceConversation {
2236
2249
  sessionOverrides;
2237
2250
  personality;
2238
2251
  variant;
2252
+ maxSessionSeconds;
2239
2253
  videoCapture;
2240
2254
  startOn;
2241
2255
  mediaDevices;
@@ -2273,6 +2287,7 @@ class NuanceConversation {
2273
2287
  this.sessionOverrides = options.sessionOverrides ?? {};
2274
2288
  this.personality = options.personality;
2275
2289
  this.variant = options.variant;
2290
+ this.maxSessionSeconds = options.maxSessionSeconds;
2276
2291
  this.videoCapture = options.videoCapture;
2277
2292
  this.startOn = options.startOn ?? "first-frame";
2278
2293
  this.mediaDevices = options.mediaDevices;
@@ -2309,6 +2324,9 @@ class NuanceConversation {
2309
2324
  request.personality = this.personality;
2310
2325
  if (this.variant)
2311
2326
  request.variant = this.variant;
2327
+ if (this.maxSessionSeconds !== undefined) {
2328
+ request.max_session_seconds = this.maxSessionSeconds;
2329
+ }
2312
2330
  conversation = await this.createWhenNotBusy(request, attempt);
2313
2331
  } catch (error) {
2314
2332
  if (error instanceof ApiError && error.status === 409) {
@@ -2320,6 +2338,9 @@ class NuanceConversation {
2320
2338
  if (error instanceof ApiError && error.status === 503 && isMaintenanceBody(error.body)) {
2321
2339
  throw new MaintenanceError(typeof error.body.detail === "string" ? error.body.detail : "The service is under maintenance");
2322
2340
  }
2341
+ if (error instanceof ApiError && error.status === 429 && isGuestLimitBody(error.body)) {
2342
+ throw new GuestLimitError(typeof error.body.reason === "string" ? error.body.reason : "used", typeof error.body.detail === "string" ? error.body.detail : "You've had your free conversation");
2343
+ }
2323
2344
  if (error instanceof ApiError && error.status === 403 && isCurfewBody(error.body)) {
2324
2345
  throw new PolicyCurfewError(typeof error.body.retry_after_seconds === "number" ? error.body.retry_after_seconds : null);
2325
2346
  }
@@ -2790,6 +2811,7 @@ export {
2790
2811
  MediaAccessError,
2791
2812
  MaintenanceError,
2792
2813
  LegalRequiredError,
2814
+ GuestLimitError,
2793
2815
  ConversationState,
2794
2816
  ActiveSessionError
2795
2817
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuancelabs/js-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "JavaScript SDK for Nuance Labs conversation video AI avatar",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {