realtime-avatar 0.5.0 → 0.5.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.
@@ -43,7 +43,7 @@ var RealtimeAvatarHttpError = class extends RealtimeAvatarError {
43
43
 
44
44
  // ../http-client/src/client.ts
45
45
  var DEFAULT_BASE_URL = "https://realtimeavatar.ai/api/v1";
46
- var SDK_VERSION = "0.5.0";
46
+ var SDK_VERSION = "0.5.2";
47
47
  var RealtimeAvatar = class {
48
48
  #apiKey;
49
49
  #baseUrl;
@@ -157,10 +157,15 @@ var RealtimeAvatar = class {
157
157
  /**
158
158
  * Register a character from a looping clip you host.
159
159
  *
160
- * Use a VIDEO source for anything that will be called live. An avatar built from a still
161
- * image reaches `ready`, mints calls, and publishes a BLACK track — the status and the
162
- * track dimensions both look fine, only the pixels are wrong. Image sources are for
163
- * offline lipsync renders.
160
+ * @deprecated CLOSED to new callers — this answers `422` unless your tenant was already
161
+ * creating from video, in which case it keeps working and your existing avatars are
162
+ * untouched. Use {@link createAvatarFromImage}: one still, and the platform renders the
163
+ * resting loop and the motion library from it.
164
+ *
165
+ * The reason it closed is not arbitrary. Every clip has to start and end on ONE rest pose
166
+ * or a state switch reads as a jump, and the platform can only guarantee that when it
167
+ * rendered the loop and the clips from the same portrait. A supplied video cannot honour
168
+ * it, so the lane could never be made to look right.
164
169
  */
165
170
  async createAvatarFromVideo(input) {
166
171
  const asset = await this.createRemoteAsset({ kind: "video", remoteUrl: input.videoUrl });
@@ -173,12 +178,41 @@ var RealtimeAvatar = class {
173
178
  metadata: input.metadata
174
179
  });
175
180
  }
181
+ /**
182
+ * Register a character from ONE still image. The platform generates everything moving:
183
+ * the resting loop she idles in, then a starter motion library rendered against her rest
184
+ * pose. No footage, no clip URLs, nothing to shoot.
185
+ *
186
+ * `motionPrompt` directs the RESTING LOOP — the video she plays when nothing else is
187
+ * happening — and it is the only chance to direct it, because there is no API today that
188
+ * re-generates a loop after creation (see {@link updateAvatar} for the one thing that can
189
+ * be re-pointed). Describe a small closed arc that returns to where it started: "settles
190
+ * into frame, breathes gently, a slow blink". Omit it and the house default is used.
191
+ *
192
+ * Creation returns while the avatar is still `preprocessing`; poll {@link getAvatar} until
193
+ * it leaves that state. The loop is load-bearing, so a failure there settles `failed` with
194
+ * a readable error — the motion library is not, and a library failure degrades to
195
+ * loop-only rather than demoting the character.
196
+ */
197
+ async createAvatarFromImage(input) {
198
+ const asset = await this.createRemoteAsset({ kind: "image", remoteUrl: input.imageUrl });
199
+ return this.createAvatar({
200
+ displayName: input.displayName,
201
+ sourceKind: "image",
202
+ sourceAssetId: asset.id,
203
+ motionPrompt: input.motionPrompt,
204
+ voice: input.voice,
205
+ settings: input.settings,
206
+ metadata: input.metadata
207
+ });
208
+ }
176
209
  async createAvatar(input) {
177
210
  const body = {
178
211
  displayName: input.displayName,
179
212
  sourceKind: input.sourceKind,
180
213
  sourceAssetId: input.sourceAssetId
181
214
  };
215
+ if (input.motionPrompt !== void 0) body.motionPrompt = input.motionPrompt;
182
216
  if (input.voice !== void 0) body.voice = input.voice;
183
217
  if (input.settings !== void 0) body.settings = input.settings;
184
218
  if (input.metadata !== void 0) body.metadata = input.metadata;
@@ -191,7 +225,14 @@ var RealtimeAvatar = class {
191
225
  async getAvatar(avatarId) {
192
226
  return toAvatar(await this.#json(await this.#request("GET", `/avatars/${avatarId}`)));
193
227
  }
194
- /** Re-point what an avatar already is. `defaultVoiceId: null` clears the default voice. */
228
+ /**
229
+ * Re-point what an avatar already is. `defaultVoiceId: null` clears the default voice.
230
+ *
231
+ * Cheap metadata only. The three things that cost a render have their own methods, because
232
+ * putting them in a patch alongside a rename would hide minutes of GPU work behind a field:
233
+ * {@link retimeAnchor} moves the rest frame, {@link swapSource} replaces the footage, and
234
+ * the resting loop is re-directed by description at `PUT /v1/avatars/{id}/loop`.
235
+ */
195
236
  async updateAvatar(avatarId, patch) {
196
237
  return toAvatar(
197
238
  await this.#json(await this.#request("PATCH", `/avatars/${avatarId}`, { json: patch }))
@@ -274,6 +315,94 @@ var RealtimeAvatar = class {
274
315
  )
275
316
  );
276
317
  }
318
+ /**
319
+ * Re-direct the RESTING LOOP — the video she plays when nothing else is happening — from
320
+ * a new one-sentence description.
321
+ *
322
+ * Not a clip, and this is the distinction integrations get wrong: a clip with
323
+ * `role: "idle"` is a variant spliced OVER the loop, and declaring one never changes what
324
+ * she rests in. This is the only thing that does.
325
+ *
326
+ * `202`, because the render takes minutes. Three properties, all measured against a real
327
+ * render rather than asserted:
328
+ *
329
+ * - **She never goes dark.** She stays `ready` and keeps serving her previous loop for the
330
+ * entire render — returned as `servingUrl` — then the swap publishes in one step.
331
+ * - **Your clip library is untouched.** Clips render against the portrait, not against the
332
+ * loop, so a re-direct re-queues nothing and does not move `revision`.
333
+ * - **It bills once**, at the rendering model's rate, per re-direct.
334
+ *
335
+ * Refusals worth telling apart: `409 loop_pending` (one is already in flight — wait) and
336
+ * `422 loop_not_generatable` (a grandfathered video-sourced avatar has no portrait to
337
+ * re-animate — terminal, do not retry).
338
+ */
339
+ async setLoop(avatarId, loop) {
340
+ return await this.#json(
341
+ await this.#request("PUT", `/avatars/${avatarId}/loop`, { json: { motionPrompt: loop.motionPrompt } })
342
+ );
343
+ }
344
+ /**
345
+ * Block until a loop re-direct settles, and throw if it did not take.
346
+ *
347
+ * `setLoop` returns on ACCEPTANCE; the render runs for minutes afterwards. Every caller
348
+ * therefore writes the same polling loop, and the obvious version of it never terminates
349
+ * on failure — a failed re-direct leaves her `ready` (she is still serving the old loop)
350
+ * and writes nothing to `error`. `idleVideoStatus` is the only field that moves, which is
351
+ * why this exists rather than a doc line telling you to poll.
352
+ *
353
+ * Race-free without a baseline: the platform commits `queued` before `setLoop` returns, so
354
+ * by the time you can call this the status has already left `ready`.
355
+ *
356
+ * Resolves with the settled avatar — `sourceAssetId` is now the new loop. Throws on a
357
+ * failed render and on timeout; a timeout is not a failure, so re-poll or call again.
358
+ */
359
+ async waitForLoop(avatarId, options = {}) {
360
+ const timeoutMs = options.timeoutMs ?? 20 * 6e4;
361
+ const pollMs = Math.max(1e3, options.pollMs ?? 1e4);
362
+ const deadline = Date.now() + timeoutMs;
363
+ for (; ; ) {
364
+ const avatar = await this.getAvatar(avatarId);
365
+ if (avatar.idleVideoStatus === "failed") {
366
+ throw new RealtimeAvatarError(
367
+ `Loop re-direct failed for ${avatarId}. She is still serving her previous loop \u2014 nothing was lost, and you can send another description.`
368
+ );
369
+ }
370
+ if (avatar.idleVideoStatus === "ready" || avatar.idleVideoStatus === "none") return avatar;
371
+ if (Date.now() >= deadline) {
372
+ throw new RealtimeAvatarError(
373
+ `Loop re-direct for ${avatarId} was still ${avatar.idleVideoStatus} after ${Math.round(timeoutMs / 1e3)}s. This is a timeout, not a failure \u2014 the render may still land.`
374
+ );
375
+ }
376
+ await sleep(pollMs);
377
+ }
378
+ }
379
+ /**
380
+ * Block until every clip in the library has stopped moving.
381
+ *
382
+ * Settled means no row is `queued` or `generating` — NOT that every row is `ready`.
383
+ * Waiting for all-`ready` is the intuitive version and it hangs forever: a clip rejected
384
+ * by pose validation settles `failed`, which is terminal. So this returns the library
385
+ * with the failures in it and lets you decide; a partial library is a legitimate outcome
386
+ * and the rest of it is already serving.
387
+ *
388
+ * Throws only on timeout.
389
+ */
390
+ async waitForClips(avatarId, options = {}) {
391
+ const timeoutMs = options.timeoutMs ?? 20 * 6e4;
392
+ const pollMs = Math.max(1e3, options.pollMs ?? 1e4);
393
+ const deadline = Date.now() + timeoutMs;
394
+ for (; ; ) {
395
+ const library = await this.listClips(avatarId);
396
+ const moving = library.data.filter((c) => c.status === "queued" || c.status === "generating");
397
+ if (moving.length === 0) return library;
398
+ if (Date.now() >= deadline) {
399
+ throw new RealtimeAvatarError(
400
+ `${moving.length} clip(s) on ${avatarId} were still rendering after ${Math.round(timeoutMs / 1e3)}s: ${moving.map((c) => c.clipId).join(", ")}. This is a timeout, not a failure.`
401
+ );
402
+ }
403
+ await sleep(pollMs);
404
+ }
405
+ }
277
406
  /** The avatar's clip library: every non-retired clip, plus revision, anchor and eligibility. */
278
407
  async listClips(avatarId) {
279
408
  return this.#clipEnvelope(
@@ -475,7 +604,13 @@ function toAvatar(raw) {
475
604
  sourceAssetId: a.sourceAssetId ? String(a.sourceAssetId) : null,
476
605
  // Carried because it is the ONLY channel a failed source swap has: she stays `ready`
477
606
  // and serving, and this says why the re-shoot did not take.
478
- error: a.error ? String(a.error) : null
607
+ error: a.error ? String(a.error) : null,
608
+ // The loop lane's terminal signal, and the reason it is here: a re-direct that fails
609
+ // leaves `status` on `ready` (she is still serving the old loop, which is the whole
610
+ // design) and writes nothing to `error`. Without this field a caller polling after
611
+ // `setLoop` has NO way to distinguish "still rendering" from "gave up", and waits
612
+ // forever. queued → generating → ready | failed.
613
+ idleVideoStatus: a.idleVideoStatus ?? "none"
479
614
  };
480
615
  }
481
616
  function toAsset(raw) {
@@ -525,6 +525,16 @@ interface components {
525
525
  retired: string[];
526
526
  };
527
527
  };
528
+ PutAvatarLoopRequest: {
529
+ motionPrompt: string;
530
+ };
531
+ PutAvatarLoopResponse: {
532
+ avatarId: string;
533
+ /** @enum {string} */
534
+ loopStatus: "generating" | "ready" | "failed";
535
+ motionPrompt: string;
536
+ servingUrl: string | null;
537
+ };
528
538
  SyncAvatarClipsRequest: {
529
539
  clipUrls: string[];
530
540
  };
@@ -843,7 +853,7 @@ type Asset = Pick<Wire["Asset"], "id" | "kind"> & {
843
853
  */
844
854
  status: Wire["Asset"]["status"] | (string & {});
845
855
  };
846
- type Avatar = Pick<Wire["Avatar"], "id" | "displayName" | "sourceKind" | "status" | "defaultVoiceId" | "sourceAssetId" | "error">;
856
+ type Avatar = Pick<Wire["Avatar"], "id" | "displayName" | "sourceKind" | "status" | "defaultVoiceId" | "sourceAssetId" | "error" | "idleVideoStatus">;
847
857
  /**
848
858
  * The patch `updateAvatar` sends — the two fields an integrator re-points after creation.
849
859
  * The contract's `UpdateAvatarRequest` carries more (llm, persona, art direction…); that is
@@ -931,6 +941,13 @@ type ClipLibrary = Wire["ListAvatarClipsResponse"];
931
941
  type ClipLibraryPlan = Wire["PutAvatarClipsResponse"]["plan"];
932
942
  /** The accepted declaration's answer: the post-apply library plus how it reconciled. */
933
943
  type ClipLibraryUpdate = Wire["PutAvatarClipsResponse"];
944
+ /**
945
+ * The accepted re-direct. `servingUrl` is the loop she is playing RIGHT NOW — the previous
946
+ * one, which keeps serving for the whole render. A caller that treated the new description
947
+ * as live on acceptance would be lying to its user for minutes; this is the field that lets
948
+ * it say "being re-directed" while still showing the real thing.
949
+ */
950
+ type LoopRedirect = Wire["PutAvatarLoopResponse"];
934
951
  /**
935
952
  * DERIVATION: hand-written, because the contract does not describe it.
936
953
  *
@@ -978,4 +995,4 @@ interface TranscriptPayload {
978
995
  client_metadata: Record<string, string>;
979
996
  }
980
997
 
981
- export { type Avatar as A, type CallMode as C, type EndCallOptions as E, type ListSessionsOptions as L, type StartCallResult as S, type TranscriptPayload as T, type UsageSessionPage as U, type VideoPolicy as V, type CallPolicy as a, type AvatarUpdate as b, type AvatarSourceSwap as c, type ClipDeclaration as d, type ClipLibraryUpdate as e, type ClipLibrary as f, type ClipSyncResult as g, type AssetKind as h, type Asset as i, type UsageSession as j, type CreditBalance as k, type AvatarClip as l, type CallConnection as m, type CallQueued as n, type ClipLibraryPlan as o, type ClipSource as p, type ContextMessage as q, type EndCallReason as r, type VideoState as s, isQueued as t };
998
+ export { type Avatar as A, type CallMode as C, type EndCallOptions as E, type LoopRedirect as L, type StartCallResult as S, type TranscriptPayload as T, type UsageSessionPage as U, type VideoPolicy as V, type CallPolicy as a, type AvatarUpdate as b, type AvatarSourceSwap as c, type ClipDeclaration as d, type ClipLibraryUpdate as e, type ClipLibrary as f, type ClipSyncResult as g, type AssetKind as h, type Asset as i, type ListSessionsOptions as j, type UsageSession as k, type CreditBalance as l, type AvatarClip as m, type CallConnection as n, type CallQueued as o, type ClipLibraryPlan as p, type ClipSource as q, type ContextMessage as r, type EndCallReason as s, type VideoState as t, isQueued as u };
@@ -1,4 +1,4 @@
1
- import { C as CallMode, a as CallPolicy } from './types-DLxz6uFE.js';
1
+ import { C as CallMode, a as CallPolicy } from './types-BeGuvyra.js';
2
2
 
3
3
  /** The three things a caller can ask the proxy to do. Gate on these, not on URLs. */
4
4
  type ProxyOperation = "connect" | "end" | "avatars" | "credits";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "realtime-avatar",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Realtime Avatar SDK. `realtime-avatar` and the route adapters hold your API key and are server-only; `realtime-avatar/react`, `/browser` and `/tools` never can — importing a server entry into a browser build throws at bundle time.",
5
5
  "license": "MIT",
6
6
  "author": "The Influence Company",