@convai/web-sdk 2.1.0-beta.3 → 2.2.0-beta.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.
- package/README.md +2 -0
- package/dist/core/BlendshapeQueue.d.ts +8 -0
- package/dist/core/BlendshapeQueue.js +11 -0
- package/dist/core/ConvaiClient.d.ts +36 -0
- package/dist/core/ConvaiClient.js +106 -1
- package/dist/core/MessageHandler.d.ts +6 -0
- package/dist/core/MessageHandler.js +13 -2
- package/dist/core/SSESession.d.ts +2 -0
- package/dist/core/SSESession.js +3 -0
- package/dist/core/VideoManager.d.ts +97 -2
- package/dist/core/VideoManager.js +434 -64
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/types.d.ts +105 -0
- package/dist/core/videoSourceState.d.ts +25 -1
- package/dist/core/videoSourceState.js +55 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +1 -0
- package/dist/utils/inlineMarkdown.js +24 -13
- package/dist/utils/markdownBlocks.d.ts +57 -0
- package/dist/utils/markdownBlocks.js +254 -0
- package/dist/vanilla/index.d.ts +2 -0
- package/dist/vanilla/index.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -573,6 +573,8 @@ await client.videoControls.unpublishVisionSource(handle);
|
|
|
573
573
|
|
|
574
574
|
`visionStatus()` and `visionTrigger()` return an update id. Match it against `serverResponse` events for outcomes such as `frames_available`, `buffer_empty`, `attached`, `no_active_video` or `vision_not_enabled`. Vision needs more than `enableVideo: true`: the account's unified vision context feature and a vision-capable, non-realtime model. Without them frames publish fine but are never seen, and the SDK warns once per session.
|
|
575
575
|
|
|
576
|
+
One source is live at a time: starting a source through `videoControls` replaces the one that was live. To keep a webcam, a screen and a canvas live together, connect with `visionSourceMode: "multi"`. Sources then coexist once the server reports multi-source vision for the session (`videoControls.multiSourceVision === "active"`); on a server without it they stay one at a time, because that server would label all of a participant's tracks as one source.
|
|
577
|
+
|
|
576
578
|
---
|
|
577
579
|
|
|
578
580
|
## Actions
|
|
@@ -260,6 +260,14 @@ export declare class BlendshapeQueue {
|
|
|
260
260
|
*/
|
|
261
261
|
isAllFramesConsumed(): boolean;
|
|
262
262
|
private hasUnconsumedExpectedFrames;
|
|
263
|
+
/**
|
|
264
|
+
* Forget every finished owner. Retired aliases are only meaningful on the
|
|
265
|
+
* connection that produced them: a new connection (fresh connect, resume
|
|
266
|
+
* or reconnect after resetSession) numbers its answers from turn 1 again,
|
|
267
|
+
* often with the same epoch and response id, so keeping the old aliases
|
|
268
|
+
* would drop the new answers' frames as late chunks of finished ones.
|
|
269
|
+
*/
|
|
270
|
+
forgetRetiredOwners(): void;
|
|
263
271
|
/**
|
|
264
272
|
* Reset queue for new conversation
|
|
265
273
|
* Should be called after all frames have been consumed
|
|
@@ -766,6 +766,17 @@ export class BlendshapeQueue {
|
|
|
766
766
|
const receivedOrConsumedFrames = this.framesConsumed + this.queue.length + this.pendingTimelineFrames.size;
|
|
767
767
|
return receivedOrConsumedFrames < this.turnStats.total_blendshapes;
|
|
768
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* Forget every finished owner. Retired aliases are only meaningful on the
|
|
771
|
+
* connection that produced them: a new connection (fresh connect, resume
|
|
772
|
+
* or reconnect after resetSession) numbers its answers from turn 1 again,
|
|
773
|
+
* often with the same epoch and response id, so keeping the old aliases
|
|
774
|
+
* would drop the new answers' frames as late chunks of finished ones.
|
|
775
|
+
*/
|
|
776
|
+
forgetRetiredOwners() {
|
|
777
|
+
this.retiredTimelineAliases.clear();
|
|
778
|
+
this.retiredOwnerlessTimelineAliases.clear();
|
|
779
|
+
}
|
|
769
780
|
/**
|
|
770
781
|
* Reset queue for new conversation
|
|
771
782
|
* Should be called after all frames have been consumed
|
|
@@ -101,6 +101,8 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
101
101
|
private static readonly TURN_END_SETTLE_MS;
|
|
102
102
|
/** Warn once per connect when Core reports vision off for the session. */
|
|
103
103
|
private _warnedVisionNotEnabled;
|
|
104
|
+
/** Ends the wait for the server's multi-source vision answer. */
|
|
105
|
+
private _visionMultiSourceProbeTimer;
|
|
104
106
|
private _participantSid;
|
|
105
107
|
private _audioSettings;
|
|
106
108
|
private _storedConfig;
|
|
@@ -154,6 +156,8 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
154
156
|
private _pendingActionResultAcks;
|
|
155
157
|
private static readonly CLIENT_READY_RETRY_MS;
|
|
156
158
|
private static readonly CLIENT_READY_TIMEOUT_MS;
|
|
159
|
+
/** How long the multi-source vision probe waits for its vision-status ack. */
|
|
160
|
+
private static readonly VISION_MULTI_SOURCE_PROBE_TIMEOUT_MS;
|
|
157
161
|
private static readonly ACTION_RESULT_ACK_TIMEOUT_MS;
|
|
158
162
|
/**
|
|
159
163
|
* Register the WebSocket transport factory. Called automatically as a side-effect
|
|
@@ -454,6 +458,38 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
454
458
|
* (or, on SSE, applied to the session it creates).
|
|
455
459
|
*/
|
|
456
460
|
private _beginAttempt;
|
|
461
|
+
/**
|
|
462
|
+
* `visionSourceMode: "multi"` asks for several vision sources live at once.
|
|
463
|
+
* That is safe only on a server that keeps a buffer per source: one without
|
|
464
|
+
* it files all of a participant's video tracks under one label. So the
|
|
465
|
+
* session starts as `"pending"` and sources stay one at a time until the
|
|
466
|
+
* server reports `vision_buffer.multi_source` (see `_probeVisionMultiSource`).
|
|
467
|
+
* Only LiveKit publishes a track per source.
|
|
468
|
+
*/
|
|
469
|
+
private _beginVisionMultiSource;
|
|
470
|
+
/**
|
|
471
|
+
* Ask the server once, when this room's character can receive it, whether
|
|
472
|
+
* it keeps a vision buffer per source. The `vision-status` ack answers; no
|
|
473
|
+
* ack within the timeout counts as no. A multi-character room is not asked:
|
|
474
|
+
* each member has its own vision pipeline, and one answer does not speak
|
|
475
|
+
* for the others.
|
|
476
|
+
*/
|
|
477
|
+
private _probeVisionMultiSource;
|
|
478
|
+
/**
|
|
479
|
+
* A `vision-status` ack that carries the vision buffer answers the
|
|
480
|
+
* multi-source question: the probe's, or the app's own visionStatus().
|
|
481
|
+
* Core reports `multi_source` on that reply; the buffer that rides on other
|
|
482
|
+
* acks (vision-trigger, for one) is not taken as an answer, so an unrelated
|
|
483
|
+
* early ack cannot settle the session. Core's acks do not echo update_id, so
|
|
484
|
+
* the probe's own reply cannot be told apart from the app's.
|
|
485
|
+
*/
|
|
486
|
+
private _settleVisionMultiSource;
|
|
487
|
+
private _clearVisionMultiSourceProbe;
|
|
488
|
+
/**
|
|
489
|
+
* The session is gone, or the attempt failed before there was one: nothing
|
|
490
|
+
* is pending and no sources coexist.
|
|
491
|
+
*/
|
|
492
|
+
private _endVisionMultiSource;
|
|
457
493
|
/**
|
|
458
494
|
* ttsEnabled for a boot built now: toggleTts() may have run since the
|
|
459
495
|
* attempt captured its config (a stateChange listener, for example).
|
|
@@ -199,6 +199,8 @@ export class ConvaiClient extends EventEmitter {
|
|
|
199
199
|
this._pendingTurnEnd = null;
|
|
200
200
|
/** Warn once per connect when Core reports vision off for the session. */
|
|
201
201
|
this._warnedVisionNotEnabled = false;
|
|
202
|
+
/** Ends the wait for the server's multi-source vision answer. */
|
|
203
|
+
this._visionMultiSourceProbeTimer = null;
|
|
202
204
|
this._participantSid = "";
|
|
203
205
|
this._storedConfig = null;
|
|
204
206
|
/**
|
|
@@ -615,6 +617,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
615
617
|
});
|
|
616
618
|
this._room.on(RoomEvent.Disconnected, (reason) => {
|
|
617
619
|
this._resetToggleGate();
|
|
620
|
+
this._endVisionMultiSource();
|
|
618
621
|
this._connectionStateHandler.handleDisconnected(reason);
|
|
619
622
|
});
|
|
620
623
|
this._room.on(RoomEvent.ConnectionStateChanged, this._connectionStateHandler.handleConnectionStateChanged.bind(this._connectionStateHandler));
|
|
@@ -643,6 +646,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
643
646
|
this._membersSeenRunning.add(membershipId);
|
|
644
647
|
this._flushHeldToggles();
|
|
645
648
|
}
|
|
649
|
+
this._probeVisionMultiSource();
|
|
646
650
|
// Server may send multiple bot-ready frames (one per client-ready
|
|
647
651
|
// we retried). Only surface the first to consumers per connect.
|
|
648
652
|
if (this._isBotReady) {
|
|
@@ -860,6 +864,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
860
864
|
"It needs enableVideo: true, the unified vision context feature on the account, and a " +
|
|
861
865
|
"vision-capable non-realtime model on the character.");
|
|
862
866
|
}
|
|
867
|
+
this._settleVisionMultiSource(response);
|
|
863
868
|
if (request)
|
|
864
869
|
this.emit("serverResponse", response, request);
|
|
865
870
|
else
|
|
@@ -999,6 +1004,9 @@ export class ConvaiClient extends EventEmitter {
|
|
|
999
1004
|
// A fresh connect starts on the v1 model-output contract; the /connect
|
|
1000
1005
|
// response upgrades it once the server confirms the negotiated version.
|
|
1001
1006
|
this._messageHandler.setModelOutputVersion(1);
|
|
1007
|
+
// Answer ids restart on every connection, so finished answers from the
|
|
1008
|
+
// previous one must not make this connection's lip-sync frames look stale.
|
|
1009
|
+
this._messageHandler.beginConnection();
|
|
1002
1010
|
this.updateState({ isConnecting: true });
|
|
1003
1011
|
this._requestTraceId = null;
|
|
1004
1012
|
try {
|
|
@@ -1050,6 +1058,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1050
1058
|
},
|
|
1051
1059
|
endUserId: configWithDefaults.endUserId,
|
|
1052
1060
|
endUserMetadata: configWithDefaults.endUserMetadata,
|
|
1061
|
+
preserveMarkdownInOutput: configWithDefaults.preserveMarkdownInOutput,
|
|
1053
1062
|
...(configWithDefaults.endUserToken !== undefined && {
|
|
1054
1063
|
getEndUserToken: () => resolveEndUserToken(configWithDefaults.endUserToken),
|
|
1055
1064
|
}),
|
|
@@ -1163,6 +1172,9 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1163
1172
|
...(configWithDefaults.preserveLinksInOutput !== undefined && {
|
|
1164
1173
|
preserve_links_in_output: configWithDefaults.preserveLinksInOutput,
|
|
1165
1174
|
}),
|
|
1175
|
+
...(configWithDefaults.preserveMarkdownInOutput !== undefined && {
|
|
1176
|
+
preserve_markdown_in_output: configWithDefaults.preserveMarkdownInOutput,
|
|
1177
|
+
}),
|
|
1166
1178
|
...(configWithDefaults.useResponseLifecycleContract !== undefined && {
|
|
1167
1179
|
use_response_lifecycle_contract: configWithDefaults.useResponseLifecycleContract,
|
|
1168
1180
|
}),
|
|
@@ -1246,6 +1258,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1246
1258
|
}
|
|
1247
1259
|
catch (error) {
|
|
1248
1260
|
await this.cleanupWebSocketSessionAfterConnectFailure();
|
|
1261
|
+
this._endVisionMultiSource();
|
|
1249
1262
|
this.updateState({
|
|
1250
1263
|
isConnected: false,
|
|
1251
1264
|
isConnecting: false,
|
|
@@ -1304,6 +1317,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1304
1317
|
}
|
|
1305
1318
|
catch (error) {
|
|
1306
1319
|
await this.cleanupWebSocketSessionAfterConnectFailure();
|
|
1320
|
+
this._endVisionMultiSource();
|
|
1307
1321
|
this.updateState({
|
|
1308
1322
|
isConnected: false,
|
|
1309
1323
|
isConnecting: false,
|
|
@@ -1582,6 +1596,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1582
1596
|
}
|
|
1583
1597
|
catch (error) {
|
|
1584
1598
|
await this.cleanupWebSocketSessionAfterConnectFailure();
|
|
1599
|
+
this._endVisionMultiSource();
|
|
1585
1600
|
this.updateState({ isConnected: false, isConnecting: false });
|
|
1586
1601
|
this.emit("error", error);
|
|
1587
1602
|
throw error;
|
|
@@ -1729,7 +1744,8 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1729
1744
|
if (transportType === "websocket") {
|
|
1730
1745
|
// ── WebSocket (Pipecat) transport path ────────────────────────────
|
|
1731
1746
|
// Server returns the WebSocket URL in room_url (same field as LiveKit).
|
|
1732
|
-
// Hosted Convai returns
|
|
1747
|
+
// Hosted Convai returns a plain (non-TLS) WebSocket URL for a TLS-only
|
|
1748
|
+
// endpoint; secureWebSocketUrl upgrades it (see websocketUrl.ts).
|
|
1733
1749
|
const roomUrl = connectionData.room_url;
|
|
1734
1750
|
const wsUrl = roomUrl && secureWebSocketUrl(roomUrl, configWithDefaults.url);
|
|
1735
1751
|
if (!wsUrl) {
|
|
@@ -1953,6 +1969,9 @@ export class ConvaiClient extends EventEmitter {
|
|
|
1953
1969
|
// have previously connected to a v2 character, so restore the default v1
|
|
1954
1970
|
// handling before accepting this text-only session's legacy envelopes.
|
|
1955
1971
|
this._messageHandler.setModelOutputVersion(1);
|
|
1972
|
+
// Answer ids restart on every connection, so finished answers from the
|
|
1973
|
+
// previous one must not make this connection's lip-sync frames look stale.
|
|
1974
|
+
this._messageHandler.beginConnection();
|
|
1956
1975
|
this.updateState({ isConnecting: true });
|
|
1957
1976
|
try {
|
|
1958
1977
|
options.signal?.addEventListener("abort", disconnectOnAbort, {
|
|
@@ -2188,6 +2207,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
2188
2207
|
_onBotPipelineFrame(participant) {
|
|
2189
2208
|
if (!this._roster.isMultiCharacter) {
|
|
2190
2209
|
this._openToggleGate();
|
|
2210
|
+
this._probeVisionMultiSource();
|
|
2191
2211
|
return;
|
|
2192
2212
|
}
|
|
2193
2213
|
const identity = participant?.identity;
|
|
@@ -2226,6 +2246,88 @@ export class ConvaiClient extends EventEmitter {
|
|
|
2226
2246
|
_beginAttempt(transport) {
|
|
2227
2247
|
this._resetToggleGate();
|
|
2228
2248
|
this._activeTransport = transport;
|
|
2249
|
+
this._beginVisionMultiSource(transport);
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* `visionSourceMode: "multi"` asks for several vision sources live at once.
|
|
2253
|
+
* That is safe only on a server that keeps a buffer per source: one without
|
|
2254
|
+
* it files all of a participant's video tracks under one label. So the
|
|
2255
|
+
* session starts as `"pending"` and sources stay one at a time until the
|
|
2256
|
+
* server reports `vision_buffer.multi_source` (see `_probeVisionMultiSource`).
|
|
2257
|
+
* Only LiveKit publishes a track per source.
|
|
2258
|
+
*/
|
|
2259
|
+
_beginVisionMultiSource(transport) {
|
|
2260
|
+
this._clearVisionMultiSourceProbe();
|
|
2261
|
+
const requested = this._storedConfig?.visionSourceMode === "multi";
|
|
2262
|
+
this._videoManager.setMultiSourceVision(!requested ? "off" : transport === "livekit" ? "pending" : "unsupported");
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Ask the server once, when this room's character can receive it, whether
|
|
2266
|
+
* it keeps a vision buffer per source. The `vision-status` ack answers; no
|
|
2267
|
+
* ack within the timeout counts as no. A multi-character room is not asked:
|
|
2268
|
+
* each member has its own vision pipeline, and one answer does not speak
|
|
2269
|
+
* for the others.
|
|
2270
|
+
*/
|
|
2271
|
+
_probeVisionMultiSource() {
|
|
2272
|
+
if (this._videoManager.multiSourceVision !== "pending")
|
|
2273
|
+
return;
|
|
2274
|
+
if (this._roster.isMultiCharacter) {
|
|
2275
|
+
this._videoManager.setMultiSourceVision("unsupported");
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2278
|
+
if (this._visionMultiSourceProbeTimer !== null)
|
|
2279
|
+
return;
|
|
2280
|
+
if (this._toggleGate !== "open" || !this.isTransportReady())
|
|
2281
|
+
return;
|
|
2282
|
+
this.publishMessage("vision-status", {
|
|
2283
|
+
update_id: this.createUpdateId("vision-multi-source"),
|
|
2284
|
+
participant_sid: this._participantSid || this._room.localParticipant?.sid,
|
|
2285
|
+
});
|
|
2286
|
+
// A source waiting for the answer now waits a bounded time from here,
|
|
2287
|
+
// not from when it started: the question went out only now.
|
|
2288
|
+
this._videoManager.noteMultiSourceProbeSent();
|
|
2289
|
+
this._visionMultiSourceProbeTimer = setTimeout(() => {
|
|
2290
|
+
this._visionMultiSourceProbeTimer = null;
|
|
2291
|
+
if (this._videoManager.multiSourceVision !== "pending")
|
|
2292
|
+
return;
|
|
2293
|
+
console.warn("[ConvaiClient] visionSourceMode is \"multi\", but no vision-status reply reporting the " +
|
|
2294
|
+
"vision buffer arrived in time (no reply, or vision is off for this character), " +
|
|
2295
|
+
"so vision sources stay one at a time for this session.");
|
|
2296
|
+
this._videoManager.setMultiSourceVision("unsupported");
|
|
2297
|
+
}, ConvaiClient.VISION_MULTI_SOURCE_PROBE_TIMEOUT_MS);
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* A `vision-status` ack that carries the vision buffer answers the
|
|
2301
|
+
* multi-source question: the probe's, or the app's own visionStatus().
|
|
2302
|
+
* Core reports `multi_source` on that reply; the buffer that rides on other
|
|
2303
|
+
* acks (vision-trigger, for one) is not taken as an answer, so an unrelated
|
|
2304
|
+
* early ack cannot settle the session. Core's acks do not echo update_id, so
|
|
2305
|
+
* the probe's own reply cannot be told apart from the app's.
|
|
2306
|
+
*/
|
|
2307
|
+
_settleVisionMultiSource(response) {
|
|
2308
|
+
if (this._videoManager.multiSourceVision !== "pending")
|
|
2309
|
+
return;
|
|
2310
|
+
if (response.event_type !== "vision-status")
|
|
2311
|
+
return;
|
|
2312
|
+
const buffer = response.extras?.vision_buffer;
|
|
2313
|
+
if (!buffer || this._roster.isMultiCharacter)
|
|
2314
|
+
return;
|
|
2315
|
+
this._clearVisionMultiSourceProbe();
|
|
2316
|
+
this._videoManager.setMultiSourceVision(buffer.multi_source === true ? "active" : "unsupported");
|
|
2317
|
+
}
|
|
2318
|
+
_clearVisionMultiSourceProbe() {
|
|
2319
|
+
if (this._visionMultiSourceProbeTimer === null)
|
|
2320
|
+
return;
|
|
2321
|
+
clearTimeout(this._visionMultiSourceProbeTimer);
|
|
2322
|
+
this._visionMultiSourceProbeTimer = null;
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* The session is gone, or the attempt failed before there was one: nothing
|
|
2326
|
+
* is pending and no sources coexist.
|
|
2327
|
+
*/
|
|
2328
|
+
_endVisionMultiSource() {
|
|
2329
|
+
this._clearVisionMultiSourceProbe();
|
|
2330
|
+
this._videoManager.setMultiSourceVision("off");
|
|
2229
2331
|
}
|
|
2230
2332
|
/**
|
|
2231
2333
|
* ttsEnabled for a boot built now: toggleTts() may have run since the
|
|
@@ -2252,6 +2354,7 @@ export class ConvaiClient extends EventEmitter {
|
|
|
2252
2354
|
async disconnect() {
|
|
2253
2355
|
this._stopClientReadyHandshake();
|
|
2254
2356
|
this._resetToggleGate();
|
|
2357
|
+
this._clearVisionMultiSourceProbe();
|
|
2255
2358
|
// Unconditional: the branches below each depend on a transport being
|
|
2256
2359
|
// matched, and none of them runs when there is nothing to tear down. A
|
|
2257
2360
|
// command in flight must still be settled either way.
|
|
@@ -2992,6 +3095,8 @@ export class ConvaiClient extends EventEmitter {
|
|
|
2992
3095
|
ConvaiClient.TURN_END_SETTLE_MS = 150;
|
|
2993
3096
|
ConvaiClient.CLIENT_READY_RETRY_MS = 500;
|
|
2994
3097
|
ConvaiClient.CLIENT_READY_TIMEOUT_MS = 45000;
|
|
3098
|
+
/** How long the multi-source vision probe waits for its vision-status ack. */
|
|
3099
|
+
ConvaiClient.VISION_MULTI_SOURCE_PROBE_TIMEOUT_MS = 5000;
|
|
2995
3100
|
ConvaiClient.ACTION_RESULT_ACK_TIMEOUT_MS = 10000;
|
|
2996
3101
|
/**
|
|
2997
3102
|
* How long to wait for a roster command's ack.
|
|
@@ -110,6 +110,7 @@ export declare class MessageHandler extends EventEmitter {
|
|
|
110
110
|
private _handleModelOutput;
|
|
111
111
|
private _clearModelOutputReplayLedger;
|
|
112
112
|
private _handleBotLlmTextRaw;
|
|
113
|
+
private speakingEventOwner;
|
|
113
114
|
private lifecycleOwner;
|
|
114
115
|
private numberOrUndefined;
|
|
115
116
|
private transcriptionLogicalTurnId;
|
|
@@ -136,5 +137,10 @@ export declare class MessageHandler extends EventEmitter {
|
|
|
136
137
|
/**
|
|
137
138
|
* Reset message state
|
|
138
139
|
*/
|
|
140
|
+
/**
|
|
141
|
+
* Called when a new connection starts. Finished answers belong to the
|
|
142
|
+
* connection that produced them; see BlendshapeQueue.forgetRetiredOwners().
|
|
143
|
+
*/
|
|
144
|
+
beginConnection(): void;
|
|
139
145
|
reset(): void;
|
|
140
146
|
}
|
|
@@ -672,7 +672,7 @@ export class MessageHandler extends EventEmitter {
|
|
|
672
672
|
this.emit("serverSpeakingChange", true);
|
|
673
673
|
break;
|
|
674
674
|
}
|
|
675
|
-
const owner = this.
|
|
675
|
+
const owner = this.speakingEventOwner(messageData);
|
|
676
676
|
if (this.blendshapeQueue.isStaleOwner(owner)) {
|
|
677
677
|
break;
|
|
678
678
|
}
|
|
@@ -690,7 +690,7 @@ export class MessageHandler extends EventEmitter {
|
|
|
690
690
|
this.emit("serverSpeakingChange", false);
|
|
691
691
|
break;
|
|
692
692
|
}
|
|
693
|
-
if (this.blendshapeQueue.isStaleOwner(this.
|
|
693
|
+
if (this.blendshapeQueue.isStaleOwner(this.speakingEventOwner(messageData))) {
|
|
694
694
|
break;
|
|
695
695
|
}
|
|
696
696
|
if (this.isSpeaking) {
|
|
@@ -1078,6 +1078,10 @@ export class MessageHandler extends EventEmitter {
|
|
|
1078
1078
|
: {}),
|
|
1079
1079
|
});
|
|
1080
1080
|
}
|
|
1081
|
+
speakingEventOwner(message) {
|
|
1082
|
+
// Core sends speaking events with the owner on the envelope. Older senders nest it in data.
|
|
1083
|
+
return this.lifecycleOwner({ ...message.data, ...message });
|
|
1084
|
+
}
|
|
1081
1085
|
lifecycleOwner(data) {
|
|
1082
1086
|
if (!data) {
|
|
1083
1087
|
return {};
|
|
@@ -1143,6 +1147,13 @@ export class MessageHandler extends EventEmitter {
|
|
|
1143
1147
|
/**
|
|
1144
1148
|
* Reset message state
|
|
1145
1149
|
*/
|
|
1150
|
+
/**
|
|
1151
|
+
* Called when a new connection starts. Finished answers belong to the
|
|
1152
|
+
* connection that produced them; see BlendshapeQueue.forgetRetiredOwners().
|
|
1153
|
+
*/
|
|
1154
|
+
beginConnection() {
|
|
1155
|
+
this.blendshapeQueue.forgetRetiredOwners();
|
|
1156
|
+
}
|
|
1146
1157
|
reset() {
|
|
1147
1158
|
// A disconnect resets three times (the Disconnected state change,
|
|
1148
1159
|
// handleDisconnected, resetConnectionState). Emitting unconditionally made
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ConvaiConfig, SSERequestContext, RawMessageEvent } from "./types.js";
|
|
2
2
|
export interface SSESessionOptions {
|
|
3
3
|
interactionApiUrl: string;
|
|
4
|
+
/** CORE-2008: forwarded as preserve_markdown_in_output when set. */
|
|
5
|
+
preserveMarkdownInOutput?: boolean;
|
|
4
6
|
/** API key, sent as `Authorization: Bearer`. */
|
|
5
7
|
authorization: string;
|
|
6
8
|
/**
|
package/dist/core/SSESession.js
CHANGED
|
@@ -144,6 +144,9 @@ export class SSESession {
|
|
|
144
144
|
...(this.options.endUserId
|
|
145
145
|
? { end_user_id: this.options.endUserId }
|
|
146
146
|
: {}),
|
|
147
|
+
...(this.options.preserveMarkdownInOutput !== undefined && {
|
|
148
|
+
preserve_markdown_in_output: this.options.preserveMarkdownInOutput,
|
|
149
|
+
}),
|
|
147
150
|
...(this.options.endUserMetadata
|
|
148
151
|
? { end_user_metadata: this.options.endUserMetadata }
|
|
149
152
|
: {}),
|
|
@@ -1,19 +1,49 @@
|
|
|
1
1
|
import { Room } from "livekit-client";
|
|
2
|
-
import { PublishCanvasOptions, PublishVideoTrackOptions, VideoControls, VisionSourceHandle, VisionSourceState } from "./types.js";
|
|
2
|
+
import { PublishCanvasOptions, PublishVideoTrackOptions, VideoControls, VisionMultiSourceState, VisionSourceHandle, VisionSourceState } from "./types.js";
|
|
3
3
|
import { EventEmitter } from "./EventEmitter.js";
|
|
4
4
|
type WebSocketVisionMessageType = "vision-frame" | "vision-source-state";
|
|
5
5
|
type WebSocketVisionMessageSender = (type: WebSocketVisionMessageType, data: Record<string, unknown>) => void;
|
|
6
6
|
/**
|
|
7
7
|
* Manages visual source controls. LiveKit publishes real video tracks;
|
|
8
8
|
* WebSocket samples active sources into vision-frame messages.
|
|
9
|
+
*
|
|
10
|
+
* One source is live at a time: starting another replaces it. Sources with
|
|
11
|
+
* different labels stay live together only while `multiSourceVision` is
|
|
12
|
+
* `"active"`, which takes the `visionSourceMode: "multi"` option and a server
|
|
13
|
+
* that keeps a buffer per source. A server without that files every track of
|
|
14
|
+
* a participant under one label, so coexistence there mislabels the frames.
|
|
9
15
|
*/
|
|
10
16
|
export declare class VideoManager extends EventEmitter implements VideoControls {
|
|
17
|
+
/**
|
|
18
|
+
* How long a second source waits for the server's multi-source answer,
|
|
19
|
+
* counted from when the question is sent (`noteMultiSourceProbeSent`).
|
|
20
|
+
*/
|
|
21
|
+
static readonly MULTI_SOURCE_DECISION_TIMEOUT_MS = 10000;
|
|
22
|
+
/**
|
|
23
|
+
* The wait before the question is sent. The client asks only once the
|
|
24
|
+
* character can receive it, which a cold start can delay well past the
|
|
25
|
+
* decision timeout; a source must not replace another on a guess in the
|
|
26
|
+
* meantime. Matches the client's bot-ready timeout.
|
|
27
|
+
*/
|
|
28
|
+
static readonly MULTI_SOURCE_READY_BACKSTOP_MS = 45000;
|
|
11
29
|
private room;
|
|
12
30
|
/** Listeners on the current room's local participant, so setRoom can detach them. */
|
|
13
31
|
private listeners;
|
|
14
32
|
private _isVideoEnabled;
|
|
15
33
|
private _isVideoHidden;
|
|
16
|
-
|
|
34
|
+
/** Vision sources, oldest first. At most one unless sources coexist. */
|
|
35
|
+
private _visionSources;
|
|
36
|
+
private _multiSourceVision;
|
|
37
|
+
/** Publishes held until the server says whether sources may coexist. */
|
|
38
|
+
private multiSourceDecisionWaiters;
|
|
39
|
+
/** Whether this session's multi-source question has been sent. */
|
|
40
|
+
private multiSourceProbeSent;
|
|
41
|
+
/** Tracks being moved to their coexistence publication; their unpublish is not a stop. */
|
|
42
|
+
private republishingTracks;
|
|
43
|
+
/** Settles when sources published while pending have been moved for coexistence. */
|
|
44
|
+
private coexistenceAdoption;
|
|
45
|
+
/** Settles when the source start ahead of the next one has finished. */
|
|
46
|
+
private sourceStartQueue;
|
|
17
47
|
private pendingVisionSourceTracks;
|
|
18
48
|
private webSocketVisionMessageSender;
|
|
19
49
|
private webSocketVisionMode;
|
|
@@ -23,6 +53,30 @@ export declare class VideoManager extends EventEmitter implements VideoControls
|
|
|
23
53
|
get activeVisionSource(): VisionSourceHandle | null;
|
|
24
54
|
get hasActiveVisionSource(): boolean;
|
|
25
55
|
get visionSourceState(): VisionSourceState;
|
|
56
|
+
get visionSources(): VisionSourceHandle[];
|
|
57
|
+
get multiSourceVision(): VisionMultiSourceState;
|
|
58
|
+
/**
|
|
59
|
+
* Set by ConvaiClient: `"pending"` when a session that asked for several
|
|
60
|
+
* sources starts, then the server's answer, and `"off"` when it ends.
|
|
61
|
+
*
|
|
62
|
+
* A session can end with its room already gone (LiveKit dropped it). The
|
|
63
|
+
* room took the publications with it, so its sources are released here as
|
|
64
|
+
* `reset()` releases them on `disconnect()`; none may outlive the session
|
|
65
|
+
* that let them coexist.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
setMultiSourceVision(state: VisionMultiSourceState): void;
|
|
69
|
+
/**
|
|
70
|
+
* Set by ConvaiClient when it sends the multi-source question: a source
|
|
71
|
+
* waiting for the answer now waits `MULTI_SOURCE_DECISION_TIMEOUT_MS` at
|
|
72
|
+
* most, counted from here.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
noteMultiSourceProbeSent(): void;
|
|
76
|
+
/** The source that started last. */
|
|
77
|
+
private get _activeVisionSource();
|
|
78
|
+
/** Sources with different labels stay live together. */
|
|
79
|
+
private get sourcesCoexist();
|
|
26
80
|
/**
|
|
27
81
|
* Set the LiveKit room instance
|
|
28
82
|
*/
|
|
@@ -75,6 +129,7 @@ export declare class VideoManager extends EventEmitter implements VideoControls
|
|
|
75
129
|
setVideoQuality(quality: "low" | "medium" | "high"): Promise<void>;
|
|
76
130
|
publishCanvas(canvas: HTMLCanvasElement, options?: PublishCanvasOptions): Promise<VisionSourceHandle>;
|
|
77
131
|
publishVideoTrack(track: MediaStreamTrack, options?: PublishVideoTrackOptions): Promise<VisionSourceHandle>;
|
|
132
|
+
private publishLiveKitVideoTrack;
|
|
78
133
|
unpublishVisionSource(source?: VisionSourceHandle | MediaStreamTrack): Promise<void>;
|
|
79
134
|
private publishWebSocketVideoTrack;
|
|
80
135
|
private resolveVisionSource;
|
|
@@ -88,11 +143,51 @@ export declare class VideoManager extends EventEmitter implements VideoControls
|
|
|
88
143
|
private makeVisionSourceState;
|
|
89
144
|
private emitVideoStateChange;
|
|
90
145
|
private setActiveVisionSource;
|
|
146
|
+
/** Remove the source that owns `track`, without cleaning it up. */
|
|
147
|
+
private forgetVisionSource;
|
|
148
|
+
/** Drop every source without unpublishing: the session that carried them is gone. */
|
|
149
|
+
private releaseVisionSources;
|
|
150
|
+
/**
|
|
151
|
+
* Make room for the next source. One source at a time: whatever is live is
|
|
152
|
+
* unpublished. Coexisting sources: only one with the same label is, since
|
|
153
|
+
* Core keeps one buffer per label.
|
|
154
|
+
*/
|
|
91
155
|
private replaceActiveVisionSource;
|
|
156
|
+
/**
|
|
157
|
+
* Take a turn at starting a source; the caller runs when the start ahead of
|
|
158
|
+
* it has finished, and calls the returned function when its own has.
|
|
159
|
+
*
|
|
160
|
+
* Making room for a source and publishing it is one step. Two starts that
|
|
161
|
+
* interleave both find nothing to replace or to wait for, and both tracks
|
|
162
|
+
* go out: the two-tracks-to-an-unconfirmed-server case the multi-source
|
|
163
|
+
* state exists to rule out. So starts take turns in a session that asked for
|
|
164
|
+
* several sources. Elsewhere this returns null and they run as they always
|
|
165
|
+
* have. Stopping a source never waits.
|
|
166
|
+
*/
|
|
167
|
+
private queueSourceStart;
|
|
168
|
+
private waitForMultiSourceDecision;
|
|
169
|
+
private settleMultiSourceDecision;
|
|
170
|
+
/**
|
|
171
|
+
* Coexistence confirmed: move each source published while the answer was
|
|
172
|
+
* pending to the publication Core files under its own label.
|
|
173
|
+
*/
|
|
174
|
+
private adoptCoexistencePublications;
|
|
175
|
+
/**
|
|
176
|
+
* Republish a live LiveKit source under its coexistence LiveKit source and
|
|
177
|
+
* name, when it is not already. The same MediaStreamTrack and handle carry
|
|
178
|
+
* on; only the publication changes. A source that cannot be republished is
|
|
179
|
+
* dropped, as a source unpublished outside videoControls is.
|
|
180
|
+
*/
|
|
181
|
+
private moveToCoexistencePublication;
|
|
182
|
+
/** A source whose move was abandoned: it is no longer published, so forget it. */
|
|
183
|
+
private dropMovedSource;
|
|
184
|
+
/** Sources stopped coexisting with the room still live: keep only the newest. */
|
|
185
|
+
private collapseToLastSource;
|
|
92
186
|
private createPublicationHandle;
|
|
93
187
|
private addTrackEndedListener;
|
|
94
188
|
private clearEndedVisionSource;
|
|
95
189
|
private clearActiveVisionSourceForPublication;
|
|
190
|
+
private visionSourceForPublication;
|
|
96
191
|
private mediaTrackFromPublication;
|
|
97
192
|
private semanticSourceForPublication;
|
|
98
193
|
private isWebcamPublication;
|