@bevyra/avatar 1.0.7 → 1.0.9

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
@@ -36,4 +36,22 @@ for await (const event of session.events()) {
36
36
  session.close(); client.close();
37
37
  ```
38
38
 
39
- Speech and idle JPEGs are composited over off-white `#F5F3EE` by default. Pass `{ background: '#FFFFFF' }` to `client.connect` to use a different solid color. Other local processes can use `url` and `token` to connect to the loopback WebSocket. Keep the token private. `npx bevyra-avatar serve` prints them as JSON. Send complete speech units with natural pauses; `session.interrupt` cancels the current generation. See the [Python package protocol](../avatar-python/README.md).
39
+ Speech and idle JPEGs are composited over off-white `#F5F3EE` by default. Pass `{ background: '#FFFFFF' }` for a solid color, or `{ background: readFileSync('background.gif'), width: 720, height: 1280 }` for an image. JPEG, PNG, GIF and WebP buffers or data URLs are accepted; animated GIF and WebP loop through speech and idle. Images fill the requested dimensions by center cropping while the avatar keeps its aspect ratio. Images must be 64–4096 pixels per side and at most 8 MiB; animation is limited to 300 frames and 30 seconds. Output dimensions must be 160–1920 pixels per side and at most 2.07 megapixels. Other local processes can use `url` and `token` to connect to the loopback WebSocket. Keep the token private. `npx bevyra-avatar serve` prints them as JSON. Send complete speech units with natural pauses; `session.interrupt` cancels the current generation. See the [Python package protocol](../avatar-python/README.md).
40
+
41
+ ```js
42
+ import { readFileSync } from 'node:fs';
43
+
44
+ // Choose one background; omit the option for off-white.
45
+ const backgrounds = {
46
+ color: '#FFFFFF',
47
+ jpeg: readFileSync('background.jpg'),
48
+ png: readFileSync('background.png'),
49
+ gif: readFileSync('background.gif'),
50
+ webp: readFileSync('background.webp'),
51
+ };
52
+ const session = await client.connect('noora', {
53
+ background: backgrounds.gif, width: 720, height: 1280,
54
+ }); // GIF and animated WebP loop during speech and idle.
55
+ ```
56
+
57
+ When an inference update requires a newer SDK, the service returns HTTP 426 `sdk_update_required`. Run `npm install @bevyra/avatar@latest` and restart the local renderer. The Node package pins a matching Python renderer; cached avatars remain in place.
package/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare class AvatarClient {
7
7
  assign(slot: number, avatar: string, replace?: boolean): Record<string, unknown>;
8
8
  download(avatar: string): { avatar: string; path: string };
9
9
  start(options?: { port?: number }): Promise<{ url: string; token: string }>;
10
- connect(avatar: string, options?: { background?: string }): Promise<AvatarSession>;
10
+ connect(avatar: string, options?: { background?: string | Uint8Array; width?: number; height?: number }): Promise<AvatarSession>;
11
11
  close(): void;
12
12
  }
13
13
  export declare class AvatarSession {
package/index.js CHANGED
@@ -6,7 +6,18 @@ import path from "node:path";
6
6
  import readline from "node:readline";
7
7
  import WebSocket from "ws";
8
8
 
9
- const VERSION = "1.0.7";
9
+ const VERSION = "1.0.9";
10
+
11
+ function backgroundValue(value) {
12
+ if (value == null || typeof value === "string") return value;
13
+ const bytes = Buffer.from(value);
14
+ const mime = bytes.subarray(0, 3).equals(Buffer.from("GIF")) ? "image/gif"
15
+ : bytes.subarray(0, 4).equals(Buffer.from([0x52, 0x49, 0x46, 0x46])) && bytes.subarray(8, 12).toString() === "WEBP" ? "image/webp"
16
+ : bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) ? "image/png"
17
+ : bytes.subarray(0, 3).equals(Buffer.from([255, 216, 255])) ? "image/jpeg" : null;
18
+ if (!mime) throw new TypeError("Background must be JPEG, PNG, GIF, WebP, a data URL, or #RRGGBB");
19
+ return `data:${mime};base64,${bytes.toString("base64")}`;
20
+ }
10
21
 
11
22
  function python() {
12
23
  if (process.env.BEVYRA_PYTHON) return { executable: process.env.BEVYRA_PYTHON, prefix: [] };
@@ -63,12 +74,14 @@ export class AvatarClient {
63
74
  this.server = { ...ready, child };
64
75
  return { url: ready.url, token: ready.token };
65
76
  }
66
- connect(avatar, { background } = {}) {
77
+ connect(avatar, { background, width, height } = {}) {
67
78
  if (!this.server) throw new Error("Start the local renderer first");
68
79
  return new Promise((resolve, reject) => {
69
80
  const url = new URL("/v1/stream", this.server.url); url.protocol = "ws:";
70
81
  const socket = new WebSocket(url, { headers: { Authorization: `Bearer ${this.server.token}` } });
71
- socket.once("open", () => { socket.send(JSON.stringify({ type: "session.setup", avatar, ...(background ? { background } : {}) })); resolve(new AvatarSession(socket)); });
82
+ socket.once("open", () => { socket.send(JSON.stringify({ type: "session.setup", avatar,
83
+ ...(background != null ? { background: backgroundValue(background) } : {}),
84
+ ...(width != null ? { width } : {}), ...(height != null ? { height } : {}) })); resolve(new AvatarSession(socket)); });
72
85
  socket.once("error", reject);
73
86
  });
74
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevyra/avatar",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "API-authorized local BeVyra avatar service for Node.js",
5
5
  "homepage": "https://bevyra.ai/docs",
6
6
  "bugs": {"url": "https://bevyra.ai/docs"},