@nuancelabs/js-sdk 0.14.1 → 0.33.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.
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/index.d.ts +262 -350
- package/index.js +859 -577
- package/package.json +14 -2
- package/react/index.d.ts +52 -0
- package/react/index.js +171 -0
package/index.d.ts
CHANGED
|
@@ -7,89 +7,10 @@ export declare class ActiveSessionError extends Error {
|
|
|
7
7
|
constructor();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* The turn's first audio. `atMs` is when it plays, which can be after the
|
|
12
|
-
* event arrives.
|
|
13
|
-
*/
|
|
14
|
-
export declare interface AgentSpeechStartedEvent extends SessionEventBase {
|
|
15
|
-
type: "agent.speech.started";
|
|
16
|
-
/** The turn, as {@link AgentTurnStartedEvent.turnId} names it. */
|
|
17
|
-
turnId: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The agent's words, in whole words, as they are committed to the
|
|
22
|
-
* conversation. They arrive ahead of their audio: `atMs` is when the first
|
|
23
|
-
* of them plays. When the agent's turn is interrupted, words whose `atMs` is
|
|
24
|
-
* later than the {@link AgentTurnEndedEvent}'s were never heard.
|
|
25
|
-
*/
|
|
26
|
-
export declare interface AgentTextEvent extends SessionEventBase {
|
|
27
|
-
type: "agent.text";
|
|
28
|
-
/**
|
|
29
|
-
* The turn the words belong to, as {@link AgentTurnStartedEvent.turnId}
|
|
30
|
-
* names it; null for words outside any turn.
|
|
31
|
-
*/
|
|
32
|
-
turnId: string | null;
|
|
33
|
-
/** The words, with the spacing to join them to the turn's other words. */
|
|
34
|
-
text: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The agent's turn is over. `atMs` is when the turn's audio ends: for an
|
|
39
|
-
* interrupted turn, where the agent was cut off.
|
|
40
|
-
*/
|
|
41
|
-
export declare interface AgentTurnEndedEvent extends SessionEventBase {
|
|
42
|
-
type: "agent.turn.ended";
|
|
43
|
-
/** The turn, as {@link AgentTurnStartedEvent.turnId} names it. */
|
|
44
|
-
turnId: string;
|
|
45
|
-
/**
|
|
46
|
-
* `"completed"`: the agent said all of it. `"interrupted"`: the user cut
|
|
47
|
-
* in. `"stopped"`: a command stopped the agent. `"abandoned"`: the turn
|
|
48
|
-
* gave up, as when nothing of it was heard for a while or it had nothing
|
|
49
|
-
* to say; `spoken` is then the runtime's estimate of what played. A newer
|
|
50
|
-
* runtime may send other values.
|
|
51
|
-
*/
|
|
52
|
-
reason: "completed" | "interrupted" | "stopped" | "abandoned" | (string & {});
|
|
53
|
-
/**
|
|
54
|
-
* Every word the turn committed, as its {@link AgentTextEvent}s carried
|
|
55
|
-
* them. After an interruption it includes words that were cut before they
|
|
56
|
-
* played; their `agent.text` events have an `atMs` later than this
|
|
57
|
-
* event's.
|
|
58
|
-
*/
|
|
59
|
-
spoken: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The agent took the floor, before its first audio. Its words follow as
|
|
64
|
-
* {@link AgentTextEvent}s and the turn closes with an
|
|
65
|
-
* {@link AgentTurnEndedEvent}, both with the same `turnId`. `atMs` is where
|
|
66
|
-
* on the timeline the agent took it.
|
|
67
|
-
*/
|
|
68
|
-
export declare interface AgentTurnStartedEvent extends SessionEventBase {
|
|
69
|
-
type: "agent.turn.started";
|
|
70
|
-
/** The turn's id, unique within the session. */
|
|
71
|
-
turnId: string;
|
|
72
|
-
/**
|
|
73
|
-
* What opened the turn. `"user_done"`: the agent judged the user had
|
|
74
|
-
* finished. `"silence"`: the user went quiet long enough. `"check_in"`:
|
|
75
|
-
* both were quiet and the agent spoke first, as in its opening greeting.
|
|
76
|
-
* `"command"`: a command asked for the turn. `"tool"`: a tool's result
|
|
77
|
-
* reached the agent while both were quiet. A newer runtime may send other
|
|
78
|
-
* values.
|
|
79
|
-
*/
|
|
80
|
-
openedBy: "user_done" | "silence" | "check_in" | "command" | "tool" | (string & {});
|
|
81
|
-
/**
|
|
82
|
-
* `"reply"`: the agent wrote the turn's words itself. `"say"`: the agent
|
|
83
|
-
* says a line it was given, word for word. A newer runtime may send other
|
|
84
|
-
* values.
|
|
85
|
-
*/
|
|
86
|
-
source: "reply" | "say" | (string & {});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
10
|
/**
|
|
90
11
|
* An error answer from the Nuance API that the SDK has no more specific error
|
|
91
|
-
* for, such as a `401` for an expired or used session token, a `429` when
|
|
92
|
-
*
|
|
12
|
+
* for, such as a `401` for an expired or used session token, a `429` when today's
|
|
13
|
+
* credits are spent, or a `503` once the SDK has stopped
|
|
93
14
|
* retrying a busy service. See the Errors guide for each status and `code`.
|
|
94
15
|
*
|
|
95
16
|
* Act on `status` and `code`, never on `message`: the message is the server's
|
|
@@ -113,6 +34,11 @@ export declare class ApiError extends Error {
|
|
|
113
34
|
readonly code: string | null;
|
|
114
35
|
/** How long to wait before trying again, when the server said. */
|
|
115
36
|
readonly retryAfterSeconds: number | null;
|
|
37
|
+
/**
|
|
38
|
+
* When the allowance the refusal is about renews (UTC, ISO 8601), when the
|
|
39
|
+
* server said, such as today's credits for a `429`.
|
|
40
|
+
*/
|
|
41
|
+
readonly renewsAt: string | null;
|
|
116
42
|
/** The parsed JSON body of the answer, or `null` when it had none. */
|
|
117
43
|
readonly body: unknown;
|
|
118
44
|
constructor(status: number, detail: string, body?: unknown);
|
|
@@ -161,15 +87,6 @@ export declare interface AvatarParticipant {
|
|
|
161
87
|
/** The direction a camera faces relative to the user. */
|
|
162
88
|
export declare type CameraFacing = "user" | "environment";
|
|
163
89
|
|
|
164
|
-
/**
|
|
165
|
-
* The runtime's answer to a command: `"applied"`, or `"rejected"` with the
|
|
166
|
-
* runtime's reason in `error`.
|
|
167
|
-
*/
|
|
168
|
-
export declare interface CommandResult {
|
|
169
|
-
status: "applied" | "rejected";
|
|
170
|
-
error: string | null;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
90
|
|
|
174
91
|
/**
|
|
175
92
|
* A live avatar conversation controlled by the SDK.
|
|
@@ -182,7 +99,9 @@ export declare interface Conversation {
|
|
|
182
99
|
* Starts the conversation.
|
|
183
100
|
*
|
|
184
101
|
* This creates or joins the underlying session and requests local camera and
|
|
185
|
-
* microphone access when required.
|
|
102
|
+
* microphone access when required. A session the server ends while it
|
|
103
|
+
* joins is left at once: `connect()` then resolves after `session-ended`,
|
|
104
|
+
* with the state `"disconnected"`.
|
|
186
105
|
*/
|
|
187
106
|
connect(): Promise<void>;
|
|
188
107
|
/**
|
|
@@ -212,18 +131,11 @@ export declare interface Conversation {
|
|
|
212
131
|
*/
|
|
213
132
|
readonly avatar: AvatarParticipant;
|
|
214
133
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* Resolves with the runtime's answer: a runtime without a background
|
|
220
|
-
* library, or one that does not serve the id, rejects it.
|
|
221
|
-
*
|
|
222
|
-
* @throws If the id is not a background id, the conversation is not
|
|
223
|
-
* connected, the runtime takes no session commands, or it does not answer
|
|
224
|
-
* in time.
|
|
134
|
+
* The interface the session runs on, whose events
|
|
135
|
+
* {@link Conversation.onInterfaceEvent} and
|
|
136
|
+
* {@link Conversation.sendInterfaceEvent} carry: `"nuance_live"`.
|
|
225
137
|
*/
|
|
226
|
-
|
|
138
|
+
readonly interface: string;
|
|
227
139
|
/**
|
|
228
140
|
* Subscribes to conversation lifecycle and media events.
|
|
229
141
|
*
|
|
@@ -231,55 +143,36 @@ export declare interface Conversation {
|
|
|
231
143
|
*/
|
|
232
144
|
onChange(handler: (event: ConversationEvent) => void): () => void;
|
|
233
145
|
/**
|
|
234
|
-
* Subscribes to
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* ```ts
|
|
244
|
-
* const stop = conversation.on("agent.text", (event) => {
|
|
245
|
-
* transcript.textContent += event.text;
|
|
246
|
-
* });
|
|
247
|
-
* ```
|
|
248
|
-
*
|
|
249
|
-
* @returns A function that removes the handler.
|
|
250
|
-
*/
|
|
251
|
-
on<K extends keyof SessionEventMap>(type: K, handler: (event: SessionEventMap[K]) => void): () => void;
|
|
252
|
-
/**
|
|
253
|
-
* Subscribes to the agent's calls of the conversation's tools, named when
|
|
254
|
-
* your server mints the session token. Run the tool in your page and answer each call with
|
|
255
|
-
* {@link Conversation.sendToolResult}. The agent keeps talking while a call
|
|
256
|
-
* is open, and uses the result when it arrives.
|
|
146
|
+
* Subscribes to the session's Nuance Live events: each JSON object the
|
|
147
|
+
* runtime sends on the interface's topic, parsed, in the order it was sent.
|
|
148
|
+
* What the user and the agent say, her turns, her tool calls through a
|
|
149
|
+
* delegation and the session's end all arrive here. An event too large for one packet arrives as `message.part`
|
|
150
|
+
* packets; the handler gets the event they carry, in its place, and never
|
|
151
|
+
* the parts. Subscribe before `connect()` to see the session's first
|
|
152
|
+
* events; a handler stays subscribed when the conversation connects again.
|
|
153
|
+
* Events sent while the connection was down are not delivered again.
|
|
257
154
|
*
|
|
258
155
|
* @example
|
|
259
156
|
* ```ts
|
|
260
|
-
* conversation.
|
|
261
|
-
* if (
|
|
262
|
-
*
|
|
263
|
-
* await conversation.sendToolResult(call.callId, "Confetti is falling.");
|
|
157
|
+
* conversation.onInterfaceEvent((event) => {
|
|
158
|
+
* if (event.type === "session.output_transcript.delta") {
|
|
159
|
+
* transcript.textContent += String(event.delta);
|
|
264
160
|
* }
|
|
265
161
|
* });
|
|
266
162
|
* ```
|
|
267
163
|
*
|
|
268
164
|
* @returns A function that removes the handler.
|
|
269
165
|
*/
|
|
270
|
-
|
|
166
|
+
onInterfaceEvent(handler: (event: Record<string, unknown>) => void): () => void;
|
|
271
167
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
168
|
+
* Sends one Nuance Live event, such as `response.create` or
|
|
169
|
+
* `conversation.item.create`, as JSON on the interface's topic: one reliable packet, or, for an event over 64,000 bytes as JSON
|
|
170
|
+
* (UTF-8), one text stream. A `response.create` sent after a streamed event
|
|
171
|
+
* waits for the runtime to read it.
|
|
275
172
|
*
|
|
276
|
-
* @
|
|
277
|
-
* @returns Whether the runtime took the result: `status` is `"rejected"`,
|
|
278
|
-
* with the reason in `error`, for an unknown or closed call.
|
|
279
|
-
* @throws If the conversation is not connected, or the runtime does not
|
|
280
|
-
* answer in time.
|
|
173
|
+
* @throws If the conversation is not connected.
|
|
281
174
|
*/
|
|
282
|
-
|
|
175
|
+
sendInterfaceEvent(event: Record<string, unknown>): Promise<void>;
|
|
283
176
|
}
|
|
284
177
|
|
|
285
178
|
|
|
@@ -301,6 +194,15 @@ export declare type ConversationEvent =
|
|
|
301
194
|
type: "session-created";
|
|
302
195
|
id: string;
|
|
303
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* A runtime is held for an API conversation and is getting ready for it,
|
|
199
|
+
* which can take up to about half a minute; the conversation then connects.
|
|
200
|
+
* Fires once, while `connecting`. An API conversation never queues, so this
|
|
201
|
+
* is all it is told before it connects.
|
|
202
|
+
*/
|
|
203
|
+
| {
|
|
204
|
+
type: "avatar-preparing";
|
|
205
|
+
}
|
|
304
206
|
/** The avatar participant joined the conversation. */
|
|
305
207
|
| {
|
|
306
208
|
type: "avatar-connected";
|
|
@@ -392,15 +294,40 @@ export declare type ConversationEvent =
|
|
|
392
294
|
* A runtime that stops at its limit does not necessarily leave the transport,
|
|
393
295
|
* so a caller cannot infer this from the connection alone. `reason` is
|
|
394
296
|
* `"time-limit"` when the session was capped and ran out its clock,
|
|
395
|
-
* `"policy-violation"` when
|
|
297
|
+
* `"policy-violation"` when a safety check ended it for a policy
|
|
298
|
+
* violation, `"age-check"` when it ended because the camera showed only
|
|
299
|
+
* people who look under 18 (each with `message`, the same words for every
|
|
300
|
+
* end of its kind, for you to show the person), `"refused"`
|
|
396
301
|
* when the runtime would not start it, with its reason in `message` when it
|
|
397
|
-
* gave one
|
|
398
|
-
*
|
|
302
|
+
* gave one, or when the server refused to create it.
|
|
303
|
+
*
|
|
304
|
+
* On any end the server makes (its goodbye, the time limit, a policy end,
|
|
305
|
+
* an age check), the SDK then leaves the call and stops the camera and
|
|
306
|
+
* microphone: the state becomes `"disconnected"`, and `user` and `avatar`
|
|
307
|
+
* throw from then on. An end that arrives while the conversation joins
|
|
308
|
+
* stops the join and releases any camera or microphone it opened, so
|
|
309
|
+
* `connect()` can resolve with the state already `"disconnected"`. With
|
|
310
|
+
* {@link CreateNuanceConversationOptions.stayConnectedOnEnd} it stays in
|
|
311
|
+
* the call until you call {@link Conversation.disconnect}.
|
|
312
|
+
*
|
|
313
|
+
* `endReason` is the runtime's own word for the end ({@link EndReason}),
|
|
314
|
+
* and says who ended the session where `reason` cannot: an agent that hung
|
|
315
|
+
* up reads `"end_call"`, a runtime that failed the session `"error"`. It is
|
|
316
|
+
* absent only when the end reached the SDK without one. `reason` keeps the
|
|
317
|
+
* values it has always had, so code reading it needs no change.
|
|
399
318
|
*/
|
|
400
319
|
| {
|
|
401
320
|
type: "session-ended";
|
|
402
321
|
reason: SessionEndReason;
|
|
322
|
+
endReason?: EndReason;
|
|
403
323
|
message?: string;
|
|
324
|
+
/**
|
|
325
|
+
* Why the server refused to create the conversation, when it did: the
|
|
326
|
+
* error `connect()` rejects with, such as an `ApiError` with the
|
|
327
|
+
* answer's `status`, `code` and `renewsAt`. It comes before the state
|
|
328
|
+
* becomes `"disconnected"`.
|
|
329
|
+
*/
|
|
330
|
+
error?: Error;
|
|
404
331
|
} | {
|
|
405
332
|
type: "queue-changed";
|
|
406
333
|
position: number;
|
|
@@ -440,6 +367,8 @@ export declare type ConversationStateValue = `${ConversationState}`;
|
|
|
440
367
|
* The returned conversation is idle until {@link Conversation.connect} is
|
|
441
368
|
* called. The SDK creates the backend conversation session, waits until it is
|
|
442
369
|
* ready, and connects using the connection details returned by the Nuance API.
|
|
370
|
+
* An option it does not know is ignored, with a warning in the console that
|
|
371
|
+
* names it.
|
|
443
372
|
*
|
|
444
373
|
* @example
|
|
445
374
|
* ```ts
|
|
@@ -524,61 +453,39 @@ export declare interface CreateNuanceConversationOptions {
|
|
|
524
453
|
/** Local capture preferences, resolved once for each connection attempt. */
|
|
525
454
|
mediaDevices?: MediaDevicePreferences | (() => MediaDevicePreferences);
|
|
526
455
|
/**
|
|
527
|
-
* When
|
|
456
|
+
* When `avatar-presented` fires. She speaks first once your page sends
|
|
457
|
+
* `response.create`, so send it on `avatar-presented`.
|
|
528
458
|
*
|
|
529
459
|
* - `"first-frame"`: as soon as her first frame reaches the page.
|
|
530
460
|
* `avatar-presented` follows `avatar-ready` at once. Her video may be
|
|
531
461
|
* soft for its first few seconds while the connection ramps up.
|
|
532
462
|
* - `"full-quality"`: once her video has reached its full size and held
|
|
533
|
-
* it, or after at most about 12 seconds. She is in view
|
|
534
|
-
*
|
|
535
|
-
* `avatar-presented`.
|
|
463
|
+
* it, or after at most about 12 seconds. She is in view in between, so a
|
|
464
|
+
* page using this should cover her until `avatar-presented`.
|
|
536
465
|
*
|
|
537
466
|
* @defaultValue `"first-frame"`
|
|
538
467
|
*/
|
|
539
468
|
startOn?: StartOn;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Who has the floor changed. `atMs` is when the change plays.
|
|
545
|
-
*/
|
|
546
|
-
export declare interface FloorEvent extends SessionEventBase {
|
|
547
|
-
type: "floor";
|
|
548
469
|
/**
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
470
|
+
* Stays in the call after the conversation ends on the server's side (its
|
|
471
|
+
* goodbye, the time limit, a policy end, an age check), with the camera
|
|
472
|
+
* and microphone on, until you call `disconnect()`. Left out, the SDK
|
|
473
|
+
* leaves the call and stops the camera and microphone right after it
|
|
474
|
+
* reports `session-ended`. `useNuanceConversation` leaves on every end
|
|
475
|
+
* whatever this says.
|
|
476
|
+
*
|
|
477
|
+
* @defaultValue `false`
|
|
552
478
|
*/
|
|
553
|
-
|
|
479
|
+
stayConnectedOnEnd?: boolean;
|
|
554
480
|
}
|
|
555
481
|
|
|
482
|
+
|
|
556
483
|
/**
|
|
557
|
-
* A
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
* arguments to match its `parameters`. A conversation has up to 16 tools.
|
|
484
|
+
* A {@link KnownEndReason}, or any other string the runtime sends. A reason
|
|
485
|
+
* the SDK does not know is passed through as it arrived rather than dropped
|
|
486
|
+
* or flattened, so a value a newer runtime adds still reaches the app.
|
|
561
487
|
*/
|
|
562
|
-
export declare
|
|
563
|
-
/** Always `"function"`, the default. */
|
|
564
|
-
type?: "function";
|
|
565
|
-
/**
|
|
566
|
-
* The tool's name: letters, digits, `_` and `-`, up to 64 characters,
|
|
567
|
-
* unique in the conversation. `ask_user`, `get_current_time`, `web_search`
|
|
568
|
-
* and the agent's other own tools' names are taken.
|
|
569
|
-
*/
|
|
570
|
-
name: string;
|
|
571
|
-
/**
|
|
572
|
-
* What the tool does and when to use it, written for the agent, up to
|
|
573
|
-
* 2,000 characters. Say when to call it, not only what it does.
|
|
574
|
-
*/
|
|
575
|
-
description: string;
|
|
576
|
-
/**
|
|
577
|
-
* The arguments, as a JSON Schema whose `type` is `"object"`, up to 16,000
|
|
578
|
-
* characters as compact JSON. `{ type: "object", properties: {} }` takes none.
|
|
579
|
-
*/
|
|
580
|
-
parameters: Record<string, unknown>;
|
|
581
|
-
}
|
|
488
|
+
export declare type EndReason = KnownEndReason | (string & {});
|
|
582
489
|
|
|
583
490
|
/**
|
|
584
491
|
* Raised by {@link Conversation.connect} when the server refuses a guest's new
|
|
@@ -592,6 +499,29 @@ export declare class GuestLimitError extends Error {
|
|
|
592
499
|
constructor(reason: string, message: string);
|
|
593
500
|
}
|
|
594
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Why a session ended, in the runtime's own words.
|
|
504
|
+
*
|
|
505
|
+
* The end reason is decided in one place: the `reason` the runtime puts on
|
|
506
|
+
* `session.closed`, which {@link endReasonOf} reads. A v1 session has an older
|
|
507
|
+
* vocabulary of its own, which {@link v1EndReason} maps onto the same words,
|
|
508
|
+
* so a room session and a socket session answer alike for the same end.
|
|
509
|
+
*/
|
|
510
|
+
/**
|
|
511
|
+
* The reasons the runtime names. A session ends for exactly one of these.
|
|
512
|
+
*
|
|
513
|
+
* - `close_requested`: a client closed the session — `session.close` (this
|
|
514
|
+
* page's, or another client's, such as your server's attach connection),
|
|
515
|
+
* v1's session end, or its input stream ending.
|
|
516
|
+
* - `content`: a safety check ended it for a policy violation.
|
|
517
|
+
* - `age_check`: the age check ended it: the camera showed only people who
|
|
518
|
+
* look under 18.
|
|
519
|
+
* - `expired`: it ran out its time cap or its idle limit.
|
|
520
|
+
* - `end_call`: the agent hung up.
|
|
521
|
+
* - `error`: the runtime failed the session, a worker drain included.
|
|
522
|
+
* - `connection_lost`: the client's transport went away without closing.
|
|
523
|
+
*/
|
|
524
|
+
export declare type KnownEndReason = "close_requested" | "content" | "age_check" | "expired" | "end_call" | "error" | "connection_lost";
|
|
595
525
|
|
|
596
526
|
/**
|
|
597
527
|
* Raised by {@link Conversation.connect} when the server refuses a new session
|
|
@@ -651,6 +581,110 @@ export declare type MediaErrorReason = "permission-denied" | "device-not-found"
|
|
|
651
581
|
*/
|
|
652
582
|
export declare type NetworkQuality = "good" | "poor" | "lost";
|
|
653
583
|
|
|
584
|
+
/**
|
|
585
|
+
* Who does the work the avatar hands off: `client`, your page, which reports
|
|
586
|
+
* back with appends naming the delegation; `responses`, a backend that calls
|
|
587
|
+
* your tools, which your page runs; or `none`, when nothing on your side would
|
|
588
|
+
* answer a hand-off: she hands nothing off and answers with her own tools.
|
|
589
|
+
*/
|
|
590
|
+
export declare type NuanceLiveDelegation = {
|
|
591
|
+
type: "client";
|
|
592
|
+
acknowledgement_delay_ms?: number;
|
|
593
|
+
} | {
|
|
594
|
+
type: "none";
|
|
595
|
+
} | {
|
|
596
|
+
type: "responses";
|
|
597
|
+
/** Accepted and recorded, 0 to 800; changes nothing. */
|
|
598
|
+
acknowledgement_delay_ms?: number;
|
|
599
|
+
responses: NuanceLiveResponses;
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
/** The backend's settings in a `responses` delegation. */
|
|
603
|
+
export declare type NuanceLiveResponses = {
|
|
604
|
+
/** Required: any non-empty name up to 256 characters. It is recorded; the backend runs Nuance's own model. */
|
|
605
|
+
model: string;
|
|
606
|
+
/** The backend's instructions, up to 65,536 characters, which only the backend sees. */
|
|
607
|
+
instructions?: string;
|
|
608
|
+
/** Your function tools; a session runs at most 16. */
|
|
609
|
+
tools?: NuanceLiveTool[];
|
|
610
|
+
/** `auto` (the default), `none`, `required`, or one tool by name. */
|
|
611
|
+
tool_choice?: "auto" | "none" | "required" | {
|
|
612
|
+
type: "function";
|
|
613
|
+
name: string;
|
|
614
|
+
};
|
|
615
|
+
/** `true` (the default) lets a step make several calls; `false`, one per step. */
|
|
616
|
+
parallel_tool_calls?: boolean;
|
|
617
|
+
/** The most a step writes, from 16. Reasoning tokens count toward it. */
|
|
618
|
+
max_output_tokens?: number;
|
|
619
|
+
/** How much the backend thinks before each step; `low` is the default. */
|
|
620
|
+
reasoning?: {
|
|
621
|
+
effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
622
|
+
/** Accepted and echoed; changes nothing. */
|
|
623
|
+
summary?: "concise" | "detailed" | "auto";
|
|
624
|
+
};
|
|
625
|
+
/** Accepted and echoed; changes nothing. */
|
|
626
|
+
service_tier?: "auto" | "default" | "flex" | "priority" | "fast_tier_temp_pilot" | "ultrafast";
|
|
627
|
+
/** Accepted and echoed; changes nothing. */
|
|
628
|
+
text?: {
|
|
629
|
+
verbosity?: "low" | "medium" | "high";
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
/** Nuance Live's settings in a session token (`interface_setup`). */
|
|
634
|
+
export declare type NuanceLiveSetup = {
|
|
635
|
+
/** Who does the work she hands off: your page (the default), a backend, or nobody. */
|
|
636
|
+
delegation?: NuanceLiveDelegation;
|
|
637
|
+
/**
|
|
638
|
+
* The avatar's own tools, each on (`true`) or off (`false`). Left out, a tool
|
|
639
|
+
* keeps its default: `stay_quiet` and `switch_identity` on, `end_call`,
|
|
640
|
+
* `call_time` and `do_gaze` off. A tool runs only where the deployment
|
|
641
|
+
* offers it.
|
|
642
|
+
*/
|
|
643
|
+
runtime_tools?: {
|
|
644
|
+
stay_quiet?: boolean;
|
|
645
|
+
end_call?: boolean;
|
|
646
|
+
call_time?: boolean;
|
|
647
|
+
switch_identity?: boolean;
|
|
648
|
+
/** Where the deployment offers it, `true` runs her with glances away to think and back. */
|
|
649
|
+
do_gaze?: boolean;
|
|
650
|
+
};
|
|
651
|
+
/** `{ input: { camera: false } }` keeps her from using the user's camera. */
|
|
652
|
+
video?: {
|
|
653
|
+
input?: {
|
|
654
|
+
camera?: boolean;
|
|
655
|
+
};
|
|
656
|
+
};
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* One of your tools in a `responses` delegation: the backend calls it, and
|
|
661
|
+
* your page runs it and sends back the result.
|
|
662
|
+
*/
|
|
663
|
+
export declare type NuanceLiveTool = {
|
|
664
|
+
type: "function";
|
|
665
|
+
/** Letters, digits, `_` and `-`, up to 64 characters, unique in the list. */
|
|
666
|
+
name: string;
|
|
667
|
+
/** When to use it, up to 2,000 characters. */
|
|
668
|
+
description?: string;
|
|
669
|
+
/**
|
|
670
|
+
* A JSON Schema whose `type` is `"object"`, up to 16,000 characters as
|
|
671
|
+
* compact JSON. Left out, the tool takes no arguments.
|
|
672
|
+
*/
|
|
673
|
+
parameters?: Record<string, unknown>;
|
|
674
|
+
strict?: boolean;
|
|
675
|
+
/**
|
|
676
|
+
* `confirm`: she reads the call back and sends it only after the user's
|
|
677
|
+
* clear yes. `safety_resource`: a tool that gives a crisis or safety
|
|
678
|
+
* resource, whose numbers she must say in full.
|
|
679
|
+
*/
|
|
680
|
+
policy?: {
|
|
681
|
+
confirm?: boolean;
|
|
682
|
+
safety_resource?: boolean;
|
|
683
|
+
};
|
|
684
|
+
/** MCP's tool hints; see {@link ToolAnnotations}. */
|
|
685
|
+
annotations?: ToolAnnotations;
|
|
686
|
+
};
|
|
687
|
+
|
|
654
688
|
/**
|
|
655
689
|
* Who the avatar is in a conversation created with
|
|
656
690
|
* {@link CreateNuanceConversationOptions.personality}.
|
|
@@ -662,62 +696,23 @@ export declare interface PersonalityChoice extends SessionPersonality {
|
|
|
662
696
|
* Raised by {@link Conversation.connect} when the server refuses a new session
|
|
663
697
|
* because the runtime recently ended too many of this account's sessions for
|
|
664
698
|
* content-policy violations. `retryAfterSeconds` is the server's estimate of
|
|
665
|
-
* when a new session may be started, when it sent one.
|
|
699
|
+
* when a new session may be started, when it sent one. `message` says so in
|
|
700
|
+
* words to show the person, with the wait when it is known.
|
|
666
701
|
*/
|
|
667
702
|
export declare class PolicyCurfewError extends Error {
|
|
668
703
|
readonly retryAfterSeconds: number | null;
|
|
669
704
|
constructor(retryAfterSeconds: number | null);
|
|
670
705
|
}
|
|
671
706
|
|
|
672
|
-
|
|
673
707
|
/**
|
|
674
708
|
* Why a session is over. `"time-limit"`: the capped session ran out its clock.
|
|
675
709
|
* `"policy-violation"`: the runtime ended it for content that breaks the usage
|
|
676
|
-
* policy. `"
|
|
677
|
-
*
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
/** Any one of the session's events. */
|
|
682
|
-
export declare type SessionEvent = SessionEventMap[keyof SessionEventMap];
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* What every session event carries: its place in the session's order and on
|
|
686
|
-
* the session's timeline.
|
|
710
|
+
* policy. `"age-check"`: the runtime ended it because the camera showed only
|
|
711
|
+
* people who look under 18. `"refused"`: it never started: the runtime would not start it, for
|
|
712
|
+
* the reason in the event's `message`, or the server refused to create it,
|
|
713
|
+
* for the reason in its `error`. `"ended"`: any other server-side end.
|
|
687
714
|
*/
|
|
688
|
-
export declare
|
|
689
|
-
/**
|
|
690
|
-
* The event's number in the session's sequence: from 1, one more for each
|
|
691
|
-
* event the runtime sends, of every kind, so the events one handler sees
|
|
692
|
-
* skip numbers. The SDK delivers events in this order, each once. 0 for an
|
|
693
|
-
* event the runtime did not number.
|
|
694
|
-
*/
|
|
695
|
-
seq: number;
|
|
696
|
-
/**
|
|
697
|
-
* Where the event falls on the session's timeline, in milliseconds. The
|
|
698
|
-
* timeline counts the user's audio from the start of the session. A user
|
|
699
|
-
* event is stamped on the user's audio, as where the user said it; an
|
|
700
|
-
* agent event where the agent's audio for it plays, which can be ahead of
|
|
701
|
-
* when the event arrives. Every event of a session is on this one timeline, so
|
|
702
|
-
* their `atMs` compare. Null when the runtime gives no time.
|
|
703
|
-
*/
|
|
704
|
-
atMs: number | null;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
* The session's events by their `type`, for {@link Conversation.on}.
|
|
709
|
-
*/
|
|
710
|
-
export declare interface SessionEventMap {
|
|
711
|
-
"user.transcript": UserTranscriptEvent;
|
|
712
|
-
"user.speech.started": UserSpeechStartedEvent;
|
|
713
|
-
"user.speech.ended": UserSpeechEndedEvent;
|
|
714
|
-
"user.turn.ended": UserTurnEndedEvent;
|
|
715
|
-
"agent.turn.started": AgentTurnStartedEvent;
|
|
716
|
-
"agent.speech.started": AgentSpeechStartedEvent;
|
|
717
|
-
"agent.text": AgentTextEvent;
|
|
718
|
-
"agent.turn.ended": AgentTurnEndedEvent;
|
|
719
|
-
floor: FloorEvent;
|
|
720
|
-
}
|
|
715
|
+
export declare type SessionEndReason = "time-limit" | "ended" | "policy-violation" | "age-check" | "refused" | "connection-lost";
|
|
721
716
|
|
|
722
717
|
|
|
723
718
|
|
|
@@ -730,38 +725,22 @@ export declare interface SessionPersonality {
|
|
|
730
725
|
*/
|
|
731
726
|
system_prompt?: string;
|
|
732
727
|
/**
|
|
733
|
-
* The
|
|
734
|
-
* Leave it out for the default
|
|
735
|
-
*
|
|
728
|
+
* The persona the avatar is drawn as, by the id Nuance gave your
|
|
729
|
+
* organization: who it looks like. Leave it out for the default. An id you
|
|
730
|
+
* can't use, including `"emma"`, the Nuance app's own character, is refused
|
|
731
|
+
* when the token is minted.
|
|
736
732
|
*/
|
|
737
|
-
|
|
733
|
+
persona_id?: string;
|
|
738
734
|
}
|
|
739
735
|
|
|
740
736
|
/**
|
|
741
737
|
* What your server sends to `POST /session-tokens` with its API key. Every
|
|
742
|
-
* field is fixed for the conversation the token starts
|
|
743
|
-
* defaults.
|
|
738
|
+
* field is fixed for the conversation the token starts. Send `end_user_id`
|
|
739
|
+
* with every token; leave the other fields out for the defaults.
|
|
744
740
|
*/
|
|
745
741
|
export declare interface SessionTokenRequest {
|
|
746
742
|
/** Who the avatar is in the conversation. Leave it out for the default personality. */
|
|
747
743
|
personality?: SessionPersonality;
|
|
748
|
-
/**
|
|
749
|
-
* Tools the agent may call, which your page runs and answers with
|
|
750
|
-
* `onToolCall` and `sendToolResult`;
|
|
751
|
-
* up to 16. Fixed for the conversation: the page can't change them.
|
|
752
|
-
*
|
|
753
|
-
* @example
|
|
754
|
-
* ```ts
|
|
755
|
-
* tools: [
|
|
756
|
-
* {
|
|
757
|
-
* name: "show_confetti",
|
|
758
|
-
* description: "Plays confetti on the user's screen. Use it to celebrate with them.",
|
|
759
|
-
* parameters: { type: "object", properties: {} },
|
|
760
|
-
* },
|
|
761
|
-
* ]
|
|
762
|
-
* ```
|
|
763
|
-
*/
|
|
764
|
-
tools?: FunctionTool[];
|
|
765
744
|
/**
|
|
766
745
|
* Your own id for the person this conversation is for, such as a hash of
|
|
767
746
|
* your user id. After repeated policy violations, new conversations pause
|
|
@@ -769,6 +748,19 @@ export declare interface SessionTokenRequest {
|
|
|
769
748
|
* `_ . : -`, up to 128 characters: never an email address or a name.
|
|
770
749
|
*/
|
|
771
750
|
end_user_id?: string;
|
|
751
|
+
/**
|
|
752
|
+
* The interface the conversation runs: Nuance Live, the default, whose
|
|
753
|
+
* events your page sends and receives with `conversation.sendInterfaceEvent`
|
|
754
|
+
* and `conversation.onInterfaceEvent`. Leave it out.
|
|
755
|
+
*/
|
|
756
|
+
interface?: "nuance_live";
|
|
757
|
+
/**
|
|
758
|
+
* Nuance Live's settings for the session, fixed by the token: who does the
|
|
759
|
+
* work she hands off, the avatar's own tools, and whether she sees the
|
|
760
|
+
* user's camera. Any key it doesn't list is refused with `422`
|
|
761
|
+
* `interface_setup`.
|
|
762
|
+
*/
|
|
763
|
+
interface_setup?: NuanceLiveSetup;
|
|
772
764
|
}
|
|
773
765
|
|
|
774
766
|
/** What `POST /session-tokens` returns. */
|
|
@@ -785,52 +777,25 @@ export declare interface SessionTokenResponse {
|
|
|
785
777
|
export declare type StartOn = "first-frame" | "full-quality";
|
|
786
778
|
|
|
787
779
|
/**
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
/** The
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
/**
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
export declare interface ToolImage {
|
|
808
|
-
mediaType: "image/jpeg" | "image/png";
|
|
809
|
-
/** The encoded image, base64. */
|
|
810
|
-
data: string;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
/**
|
|
814
|
-
* What a tool call produced: text, or JSON the agent reads as it is. Up to
|
|
815
|
-
* 24,000 characters (its JSON, for an object); the agent keeps the first 2,000.
|
|
816
|
-
*/
|
|
817
|
-
export declare type ToolOutput = string | Record<string, unknown> | unknown[];
|
|
818
|
-
|
|
819
|
-
/**
|
|
820
|
-
* How {@link Conversation.sendToolResult} reports a result.
|
|
821
|
-
*/
|
|
822
|
-
export declare interface ToolResultOptions {
|
|
823
|
-
/** Images the tool produced, up to 4; the agent looks at them, in order,
|
|
824
|
-
* where the result enters the conversation. */
|
|
825
|
-
images?: ToolImage[];
|
|
826
|
-
/** The output says what went wrong rather than what the tool produced. */
|
|
827
|
-
isError?: boolean;
|
|
828
|
-
/** Whether this is the call's last part; a part with `final: false` adds to
|
|
829
|
-
* what the agent knows and keeps the call open.
|
|
830
|
-
*
|
|
831
|
-
* @defaultValue `true` */
|
|
832
|
-
final?: boolean;
|
|
833
|
-
}
|
|
780
|
+
* MCP's tool hints, up to 2,000 characters as compact JSON. A tool whose
|
|
781
|
+
* `readOnlyHint` and `idempotentHint` are both `false` or left out is called
|
|
782
|
+
* at most once per user request with the same arguments, across all the
|
|
783
|
+
* session's tasks: annotate tools that send, book, pay or post this way. A
|
|
784
|
+
* tool with no `annotations` runs every call. MCP's other hints are accepted
|
|
785
|
+
* and not read.
|
|
786
|
+
*/
|
|
787
|
+
export declare type ToolAnnotations = {
|
|
788
|
+
/** The tool only reads: calling it again changes nothing. */
|
|
789
|
+
readOnlyHint?: boolean;
|
|
790
|
+
/** Calling it again with the same arguments has no further effect. */
|
|
791
|
+
idempotentHint?: boolean;
|
|
792
|
+
/** MCP's hint; accepted and not read. */
|
|
793
|
+
destructiveHint?: boolean;
|
|
794
|
+
/** MCP's hint; accepted and not read. */
|
|
795
|
+
openWorldHint?: boolean;
|
|
796
|
+
/** MCP's display title; accepted and not read. */
|
|
797
|
+
title?: string;
|
|
798
|
+
};
|
|
834
799
|
|
|
835
800
|
/**
|
|
836
801
|
* The local user participant in a conversation.
|
|
@@ -868,59 +833,6 @@ export declare interface UserParticipant {
|
|
|
868
833
|
readonly isSpeaking: boolean;
|
|
869
834
|
}
|
|
870
835
|
|
|
871
|
-
/**
|
|
872
|
-
* The user's voice went off, as the same detection reads it. `atMs` is where
|
|
873
|
-
* on the timeline it went off.
|
|
874
|
-
*/
|
|
875
|
-
export declare interface UserSpeechEndedEvent extends SessionEventBase {
|
|
876
|
-
type: "user.speech.ended";
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
/**
|
|
880
|
-
* The user's voice came on, as the runtime's voice-activity detection reads
|
|
881
|
-
* the microphone. `atMs` is where on the timeline it came on.
|
|
882
|
-
*/
|
|
883
|
-
export declare interface UserSpeechStartedEvent extends SessionEventBase {
|
|
884
|
-
type: "user.speech.started";
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
/**
|
|
888
|
-
* The user's words, live: one recognized segment at a time, as the runtime
|
|
889
|
-
* hears them. A later {@link UserTurnEndedEvent} may read the same speech
|
|
890
|
-
* differently; its `text` is the record of what the agent answered.
|
|
891
|
-
*/
|
|
892
|
-
export declare interface UserTranscriptEvent extends SessionEventBase {
|
|
893
|
-
type: "user.transcript";
|
|
894
|
-
/** The segment's words. */
|
|
895
|
-
text: string;
|
|
896
|
-
/**
|
|
897
|
-
* `"asr"`: recognized from the user's microphone. `"text"`: a line given
|
|
898
|
-
* as the user's turn in text rather than spoken. `"forced"`: a transcript
|
|
899
|
-
* supplied for the user's audio in place of recognition. A newer runtime
|
|
900
|
-
* may send other values.
|
|
901
|
-
*/
|
|
902
|
-
source: "asr" | "forced" | "text" | (string & {});
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* The agent is taking the turn to answer the user; sent each time it does.
|
|
907
|
-
* `atMs` is the point in the user's audio where the agent took the turn: the
|
|
908
|
-
* same moment as the turn's {@link AgentTurnStartedEvent}, stamped on the
|
|
909
|
-
* user's side of the timeline, so it is earlier than that event's `atMs` by
|
|
910
|
-
* the delay before the agent's audio plays.
|
|
911
|
-
*/
|
|
912
|
-
export declare interface UserTurnEndedEvent extends SessionEventBase {
|
|
913
|
-
type: "user.turn.ended";
|
|
914
|
-
/**
|
|
915
|
-
* The user's words since the agent last spoke, as the agent read them: a
|
|
916
|
-
* second, more careful hearing's words in place of the live
|
|
917
|
-
* {@link UserTranscriptEvent}s' where the runtime has one. When an agent
|
|
918
|
-
* turn ends before it said a word, the next `user.turn.ended` covers the
|
|
919
|
-
* same words again.
|
|
920
|
-
*/
|
|
921
|
-
text: string;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
836
|
/**
|
|
925
837
|
* Capture constraints for the user's published camera track.
|
|
926
838
|
*
|