@nuancelabs/js-sdk 0.12.0 → 0.13.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 +119 -0
  2. package/index.js +5 -1
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -217,6 +217,37 @@ export declare interface Conversation {
217
217
  * @returns A function that removes the handler.
218
218
  */
219
219
  on<K extends keyof SessionEventMap>(type: K, handler: (event: SessionEventMap[K]) => void): () => void;
220
+ /**
221
+ * Subscribes to the agent's calls of the conversation's tools, named when
222
+ * your server mints the session token. Run the tool in your page and answer each call with
223
+ * {@link Conversation.sendToolResult}. The agent keeps talking while a call
224
+ * is open, and uses the result when it arrives.
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * conversation.onToolCall(async (call) => {
229
+ * if (call.name === "show_confetti") {
230
+ * launchConfetti();
231
+ * await conversation.sendToolResult(call.callId, "Confetti is falling.");
232
+ * }
233
+ * });
234
+ * ```
235
+ *
236
+ * @returns A function that removes the handler.
237
+ */
238
+ onToolCall(handler: (call: ToolCall) => void): () => void;
239
+ /**
240
+ * Answers a tool call: what it produced, or with `isError` what went wrong.
241
+ * The agent keeps the first 2,000 characters of an output, so return what
242
+ * it needs, not everything you have.
243
+ *
244
+ * @param callId - The call's {@link ToolCall.callId}.
245
+ * @returns Whether the runtime took the result: `status` is `"rejected"`,
246
+ * with the reason in `error`, for an unknown or closed call.
247
+ * @throws If the conversation is not connected, or the runtime does not
248
+ * answer in time.
249
+ */
250
+ sendToolResult(callId: string, output: ToolOutput, options?: ToolResultOptions): Promise<CommandResult>;
220
251
  }
221
252
 
222
253
 
@@ -487,6 +518,33 @@ export declare interface FloorEvent extends SessionEventBase {
487
518
  state: "waiting" | "listening" | "speaking" | (string & {});
488
519
  }
489
520
 
521
+ /**
522
+ * A tool the agent may call, which your page runs: show something on the
523
+ * screen, read what the user has open, look something up in your app. The
524
+ * agent decides when to call it from its `description`, and fills its
525
+ * arguments to match its `parameters`. A conversation has up to 16 tools.
526
+ */
527
+ export declare interface FunctionTool {
528
+ /** Always `"function"`, the default. */
529
+ type?: "function";
530
+ /**
531
+ * The tool's name: letters, digits, `_` and `-`, up to 64 characters,
532
+ * unique in the conversation. `ask_user`, `get_current_time`, `web_search`
533
+ * and the agent's other own tools' names are taken.
534
+ */
535
+ name: string;
536
+ /**
537
+ * What the tool does and when to use it, written for the agent, up to
538
+ * 2,000 characters. Say when to call it, not only what it does.
539
+ */
540
+ description: string;
541
+ /**
542
+ * The arguments, as a JSON Schema whose `type` is `"object"`, up to 16,000
543
+ * characters as compact JSON. `{ type: "object", properties: {} }` takes none.
544
+ */
545
+ parameters: Record<string, unknown>;
546
+ }
547
+
490
548
  /**
491
549
  * Raised by {@link Conversation.connect} when the server refuses a guest's new
492
550
  * session because a guest limit is used up. `reason` says which: `used` (this
@@ -651,6 +709,23 @@ export declare interface SessionPersonality {
651
709
  export declare interface SessionTokenRequest {
652
710
  /** Who the avatar is in the conversation. Leave it out for the default personality. */
653
711
  personality?: SessionPersonality;
712
+ /**
713
+ * Tools the agent may call, which your page runs and answers with
714
+ * `onToolCall` and `sendToolResult`;
715
+ * up to 16. Fixed for the conversation: the page can't change them.
716
+ *
717
+ * @example
718
+ * ```ts
719
+ * tools: [
720
+ * {
721
+ * name: "show_confetti",
722
+ * description: "Plays confetti on the user's screen. Use it to celebrate with them.",
723
+ * parameters: { type: "object", properties: {} },
724
+ * },
725
+ * ]
726
+ * ```
727
+ */
728
+ tools?: FunctionTool[];
654
729
  /**
655
730
  * Your own id for the person this conversation is for, such as a hash of
656
731
  * your user id. After repeated policy violations, new conversations pause
@@ -673,9 +748,53 @@ export declare interface SessionTokenResponse {
673
748
  /** When the avatar starts speaking: see {@link CreateNuanceConversationOptions.startOn}. */
674
749
  export declare type StartOn = "first-frame" | "full-quality";
675
750
 
751
+ /**
752
+ * The agent's call of one of the conversation's tools: run it, then answer
753
+ * with {@link Conversation.sendToolResult} and its `callId`.
754
+ */
755
+ export declare interface ToolCall {
756
+ /** Identifies the call; answer with it. */
757
+ callId: string;
758
+ /** The tool, by its `name`. */
759
+ name: string;
760
+ /** The agent's own short name for this use of the tool, such as `"confetti"`. */
761
+ label: string;
762
+ /** The call's arguments, held to the tool's `parameters` schema. */
763
+ arguments: Record<string, unknown>;
764
+ }
676
765
 
766
+ /**
767
+ * An image a tool produced, for the agent to look at: a screenshot, say, or
768
+ * a page of a document. Up to 8,000,000 base64 characters (about 6 MB); the
769
+ * runtime fits it to 1920 px on its long side.
770
+ */
771
+ export declare interface ToolImage {
772
+ mediaType: "image/jpeg" | "image/png";
773
+ /** The encoded image, base64. */
774
+ data: string;
775
+ }
677
776
 
777
+ /**
778
+ * What a tool call produced: text, or JSON the agent reads as it is. Up to
779
+ * 24,000 characters (its JSON, for an object); the agent keeps the first 2,000.
780
+ */
781
+ export declare type ToolOutput = string | Record<string, unknown> | unknown[];
678
782
 
783
+ /**
784
+ * How {@link Conversation.sendToolResult} reports a result.
785
+ */
786
+ export declare interface ToolResultOptions {
787
+ /** Images the tool produced, up to 4; the agent looks at them, in order,
788
+ * where the result enters the conversation. */
789
+ images?: ToolImage[];
790
+ /** The output says what went wrong rather than what the tool produced. */
791
+ isError?: boolean;
792
+ /** Whether this is the call's last part; a part with `final: false` adds to
793
+ * what the agent knows and keeps the call open.
794
+ *
795
+ * @defaultValue `true` */
796
+ final?: boolean;
797
+ }
679
798
 
680
799
  /**
681
800
  * The local user participant in a conversation.
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.12.0"}`;
7
+ var SDK_HEADER = `js/${"0.13.0"}`;
8
8
 
9
9
  // src/utils.ts
10
10
  function normalizeHost(host) {
@@ -2428,6 +2428,7 @@ class NuanceConversation {
2428
2428
  ticker;
2429
2429
  sessionOverrides;
2430
2430
  personality;
2431
+ tools;
2431
2432
  variant;
2432
2433
  maxSessionSeconds;
2433
2434
  videoCapture;
@@ -2466,6 +2467,7 @@ class NuanceConversation {
2466
2467
  this.ticker = deps.ticker ?? pageTicker;
2467
2468
  this.sessionOverrides = options.sessionOverrides ?? {};
2468
2469
  this.personality = options.personality;
2470
+ this.tools = options.tools;
2469
2471
  this.variant = options.variant;
2470
2472
  this.maxSessionSeconds = options.maxSessionSeconds;
2471
2473
  this.videoCapture = options.videoCapture;
@@ -2502,6 +2504,8 @@ class NuanceConversation {
2502
2504
  request.timezone = timezone;
2503
2505
  if (this.personality)
2504
2506
  request.personality = this.personality;
2507
+ if (this.tools)
2508
+ request.tools = this.tools;
2505
2509
  if (this.variant)
2506
2510
  request.variant = this.variant;
2507
2511
  if (this.maxSessionSeconds !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuancelabs/js-sdk",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "JavaScript SDK for Nuance Labs conversation video AI avatar",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {