@convai/web-sdk 1.9.3 → 1.9.4

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 CHANGED
@@ -10,6 +10,15 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
10
10
 
11
11
  ---
12
12
 
13
+ ## Fixes in 1.9.1 – 1.9.4
14
+
15
+ - **1.9.4** — The SSE transport sends `authToken` as `API-AUTH-TOKEN`. It sent the token as `Authorization: Bearer`, which the interaction API reads as an API key, so every SSE message made with an `authToken` failed with `401`. [Usage below.](#sse-interaction-transport-beta)
16
+ - **1.9.3** — `audioControls`, `videoControls` and `screenShareControls` follow tracks changed outside them, including a share ended from the browser's "Stop sharing" bar; a disconnected mic reads as muted; the character-info lookup (the widget's name and avatar) sends `CONVAI-API-KEY`; the `mha` lip sync helpers no longer hold a frozen sneer.
17
+ - **1.9.2** — `transport: "websocket"` connects on hosted Convai (`wss://`), and `setCharacterMuted()` silences the character on WebSocket.
18
+ - **1.9.1** — README links point at docs.convai.com.
19
+
20
+ Details in the [CHANGELOG](./CHANGELOG.md).
21
+
13
22
  ## What's new in 1.9.0
14
23
 
15
24
  > **Breaking for 1.8.0 users:** the `<convai-chat>` custom element and the `./embed/browser` entry point (`dist/embed/chat-embed-v1.js`) are removed. The copy/paste published-chat embed is now `<convai-widget>` from [`@convai/web-widget`](https://www.npmjs.com/package/@convai/web-widget); the [CHANGELOG](./CHANGELOG.md) has the before/after snippet.
@@ -331,14 +340,29 @@ Use the interaction API for chat — typed input, with the reply streamed as tex
331
340
  const client = new ConvaiClient({
332
341
  apiKey: "...",
333
342
  characterId: "...",
334
- interactionApiUrl: "https://interaction-api-stg.convai.com/v1/interactions",
343
+ interactionApiUrl: "https://interaction-api.convai.com/v1/interactions",
335
344
  });
336
345
 
337
346
  await client.connect();
338
347
  client.sendUserTextMessage("Hello!");
339
348
  ```
340
349
 
341
- This sends each message as an SSE `POST` with `Authorization: Bearer ...`. Set `transport: "sse"`
350
+ This sends each message as an SSE `POST`. An `apiKey` travels as `Authorization: Bearer ...`.
351
+ To keep the key off the page, mint a short-lived token on your server
352
+ (`POST https://api.convai.com/user/connect` with the `CONVAI-API-KEY` header) and pass it as
353
+ `authToken` instead; the SDK sends it as `API-AUTH-TOKEN` (1.9.4 and later — earlier versions
354
+ sent it as Bearer, which the interaction API rejects with `401`):
355
+
356
+ ```ts
357
+ const { apiAuthToken } = await fetch("/api/convai-token", { method: "POST" }).then((r) => r.json());
358
+ const client = new ConvaiClient({
359
+ authToken: apiAuthToken,
360
+ characterId: "...",
361
+ interactionApiUrl: "https://interaction-api.convai.com/v1/interactions",
362
+ });
363
+ ```
364
+
365
+ Set `transport: "sse"`
342
366
  explicitly if preferred. With `ttsEnabled: true` the reply's speech streams as `audioData`
343
367
  events on the same response; there is no microphone, video, or lipsync. It never calls
344
368
  `/connect`, so `connect()` makes no network request and the session id arrives on the first
@@ -352,7 +376,10 @@ Because it needs neither WebRTC nor a DOM, this is the only transport that runs
352
376
  Import `@convai/web-sdk/core` from Node, SSR, or a serverless function — not the root or `/react`
353
377
  entry points, which pull in browser-only dependencies.
354
378
 
355
- The interaction API is currently reachable at staging only; a production host is planned.
379
+ The interaction API is in beta. It is reachable in production at
380
+ `https://interaction-api.convai.com/v1/interactions`, at staging
381
+ (`https://interaction-api-stg.convai.com/v1/interactions`), and on self-hosted deployments. A token
382
+ works only on the environment that minted it, and a character with Long Term Memory needs `endUserId`.
356
383
  Full guide: [SSE Interaction Transport](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/sse-transport).
357
384
 
358
385
  ---
@@ -890,7 +890,8 @@ export class ConvaiClient extends EventEmitter {
890
890
  if (transportType === "sse") {
891
891
  this._sseSession = new SSESession({
892
892
  interactionApiUrl: configWithDefaults.interactionApiUrl,
893
- authorization: configWithDefaults.authToken ?? configWithDefaults.apiKey,
893
+ authorization: configWithDefaults.apiKey ?? "",
894
+ ...(configWithDefaults.authToken && { authToken: configWithDefaults.authToken }),
894
895
  credentialProvider: configWithDefaults.interactionCredentialProvider,
895
896
  characterId: configWithDefaults.characterReference,
896
897
  getCharacterSessionId: () => this._characterSessionId,
@@ -1,7 +1,14 @@
1
1
  import type { ConvaiConfig, SSERequestContext, RawMessageEvent } from "./types.js";
2
2
  export interface SSESessionOptions {
3
3
  interactionApiUrl: string;
4
+ /** API key, sent as `Authorization: Bearer`. */
4
5
  authorization: string;
6
+ /**
7
+ * Auth token, sent as `API-AUTH-TOKEN` and preferred over `authorization`.
8
+ * The interaction API reads a Bearer value as an API key, so a token sent
9
+ * that way is rejected with 401.
10
+ */
11
+ authToken?: string;
5
12
  credentialProvider?: ConvaiConfig["interactionCredentialProvider"];
6
13
  characterId: string;
7
14
  getCharacterSessionId: () => string | null;
@@ -103,9 +103,9 @@ export class SSESession {
103
103
  const controller = new AbortController();
104
104
  this.abortController = controller;
105
105
  try {
106
- let credentialHeaders = {
107
- Authorization: `Bearer ${this.options.authorization}`,
108
- };
106
+ let credentialHeaders = this.options.authToken
107
+ ? { "API-AUTH-TOKEN": this.options.authToken }
108
+ : { Authorization: `Bearer ${this.options.authorization}` };
109
109
  let connectAttemptId;
110
110
  if (this.options.credentialProvider) {
111
111
  const provider = this.options.credentialProvider;
@@ -271,6 +271,10 @@ export class SSESession {
271
271
  let sawTerminal = false;
272
272
  let sawTurnResponse = false;
273
273
  let sawError = false;
274
+ // `done` is the server's last event for this request. Some deployments
275
+ // hold the connection open long after it (prod: ~85 s), and the request
276
+ // queue is serial, so waiting for EOF would stall every following turn.
277
+ let sawDone = false;
274
278
  const dispatch = () => {
275
279
  if (signal.aborted) {
276
280
  eventType = "message";
@@ -385,6 +389,8 @@ export class SSESession {
385
389
  }
386
390
  }
387
391
  if (eventType === "session" || eventType === "done") {
392
+ if (eventType === "done")
393
+ sawDone = true;
388
394
  const sessionId = data
389
395
  ?.character_session_id;
390
396
  if (typeof sessionId === "string")
@@ -410,6 +416,8 @@ export class SSESession {
410
416
  for (const line of lines) {
411
417
  if (signal.aborted)
412
418
  return;
419
+ if (sawDone)
420
+ break;
413
421
  if (!line)
414
422
  dispatch();
415
423
  else if (line.startsWith("event:"))
@@ -418,8 +426,8 @@ export class SSESession {
418
426
  eventData.push(line.slice(5).trimStart());
419
427
  }
420
428
  }
421
- if (done) {
422
- if (buffer) {
429
+ if (done || sawDone) {
430
+ if (done && buffer) {
423
431
  if (buffer.startsWith("event:"))
424
432
  eventType = buffer.slice(6).trim();
425
433
  else if (buffer.startsWith("data:"))
@@ -427,7 +435,7 @@ export class SSESession {
427
435
  }
428
436
  dispatch();
429
437
  this.flushBotLlmText();
430
- // EOF is a request boundary, not proof the model finished the turn.
438
+ // EOF (or `done`) is a request boundary, not proof the model finished the turn.
431
439
  // Preserve partial output and fail only when the response has closed;
432
440
  // no watchdog may cancel an otherwise active long-running stream.
433
441
  if (!signal.aborted &&
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.9.3";
1
+ export declare const SDK_VERSION = "1.9.4";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // GENERATED by scripts/sync-version.mjs — do not edit by hand.
2
2
  // Regenerated from package.json on every build.
3
- export const SDK_VERSION = "1.9.3";
3
+ export const SDK_VERSION = "1.9.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convai/web-sdk",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "description": "Build web apps with lifelike AI characters. The Convai Web SDK gives you real-time voice, lipsync, emotions, and dynamic context — with first-class support for React and vanilla TypeScript.",
5
5
  "private": false,
6
6
  "type": "module",