@escapeaihq/client-core 0.5.0 → 0.6.1
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/dist/api.d.ts +129 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +69 -0
- package/dist/api.js.map +1 -1
- package/dist/visemeGeometry.d.ts +15 -0
- package/dist/visemeGeometry.d.ts.map +1 -1
- package/dist/visemeGeometry.js +26 -0
- package/dist/visemeGeometry.js.map +1 -1
- package/dist/visemeScheduler.d.ts +12 -0
- package/dist/visemeScheduler.d.ts.map +1 -1
- package/dist/visemeScheduler.js +24 -0
- package/dist/visemeScheduler.js.map +1 -1
- package/dist/websocket.d.ts +156 -4
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +52 -7
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/chat-auth.test.ts +261 -0
- package/src/__tests__/tools-wrappers.test.ts +219 -0
- package/src/__tests__/websocket.test.ts +278 -0
- package/src/api.ts +179 -0
- package/src/visemeGeometry.ts +30 -0
- package/src/visemeScheduler.ts +25 -0
- package/src/websocket.ts +193 -8
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the §2 additions to ChatWebSocket — `fetchToken` supplier
|
|
3
|
+
* (per-attempt) and `onReconnect` hello-payload hook — plus
|
|
4
|
+
* back-compat coverage for static `authToken` callers.
|
|
5
|
+
*
|
|
6
|
+
* Strategy: replace the global `WebSocket` constructor with a stub
|
|
7
|
+
* that captures the constructed URL, exposes `instances[]`, and lets
|
|
8
|
+
* each test drive open/close events synchronously via
|
|
9
|
+
* `instance.simulateOpen()` / `simulateClose()`. jsdom provides a
|
|
10
|
+
* `WebSocket` but it tries to actually dial — that's why we stub it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { ChatWebSocket } from '../websocket';
|
|
14
|
+
|
|
15
|
+
interface FakeWebSocket {
|
|
16
|
+
url: string;
|
|
17
|
+
readyState: number;
|
|
18
|
+
binaryType: string;
|
|
19
|
+
sent: string[];
|
|
20
|
+
onopen?: () => void;
|
|
21
|
+
onerror?: (err: Event) => void;
|
|
22
|
+
onmessage?: (event: MessageEvent) => void;
|
|
23
|
+
onclose?: () => void;
|
|
24
|
+
close: () => void;
|
|
25
|
+
send: (data: string | ArrayBuffer | Uint8Array) => void;
|
|
26
|
+
simulateOpen: () => void;
|
|
27
|
+
simulateClose: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const instances: FakeWebSocket[] = [];
|
|
31
|
+
|
|
32
|
+
class StubWebSocket {
|
|
33
|
+
static CONNECTING = 0;
|
|
34
|
+
static OPEN = 1;
|
|
35
|
+
static CLOSING = 2;
|
|
36
|
+
static CLOSED = 3;
|
|
37
|
+
|
|
38
|
+
url: string;
|
|
39
|
+
readyState = StubWebSocket.CONNECTING;
|
|
40
|
+
binaryType = 'blob';
|
|
41
|
+
sent: string[] = [];
|
|
42
|
+
onopen?: () => void;
|
|
43
|
+
onerror?: (err: Event) => void;
|
|
44
|
+
onmessage?: (event: MessageEvent) => void;
|
|
45
|
+
onclose?: () => void;
|
|
46
|
+
|
|
47
|
+
constructor(url: string) {
|
|
48
|
+
this.url = url;
|
|
49
|
+
const ref = this as unknown as FakeWebSocket;
|
|
50
|
+
ref.close = () => {
|
|
51
|
+
this.readyState = StubWebSocket.CLOSED;
|
|
52
|
+
};
|
|
53
|
+
ref.send = (data: string | ArrayBuffer | Uint8Array) => {
|
|
54
|
+
if (typeof data === 'string') {
|
|
55
|
+
this.sent.push(data);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
ref.simulateOpen = () => {
|
|
59
|
+
this.readyState = StubWebSocket.OPEN;
|
|
60
|
+
this.onopen?.();
|
|
61
|
+
};
|
|
62
|
+
ref.simulateClose = () => {
|
|
63
|
+
this.readyState = StubWebSocket.CLOSED;
|
|
64
|
+
this.onclose?.();
|
|
65
|
+
};
|
|
66
|
+
instances.push(ref);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const originalWebSocket = globalThis.WebSocket;
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
instances.length = 0;
|
|
74
|
+
(globalThis as unknown as { WebSocket: typeof StubWebSocket }).WebSocket =
|
|
75
|
+
StubWebSocket;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
// Reconnect tests opt into fake timers per-test; restore here so a
|
|
80
|
+
// failure mid-test doesn't bleed timer state into the next case.
|
|
81
|
+
jest.useRealTimers();
|
|
82
|
+
(globalThis as { WebSocket?: typeof WebSocket }).WebSocket = originalWebSocket;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Flush enough microtask ticks for an awaited mocked promise + the
|
|
87
|
+
* resolved-then-chained constructor call to settle. Two ticks is the
|
|
88
|
+
* empirical minimum for `await this._resolveToken()` + the awaited
|
|
89
|
+
* `mockResolvedValue` to land before our test inspects `instances`.
|
|
90
|
+
*/
|
|
91
|
+
const flushMicrotasks = async (): Promise<void> => {
|
|
92
|
+
await Promise.resolve();
|
|
93
|
+
await Promise.resolve();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const lastSocket = (): FakeWebSocket => {
|
|
97
|
+
const last = instances[instances.length - 1];
|
|
98
|
+
if (!last) throw new Error('No WebSocket has been constructed yet');
|
|
99
|
+
return last;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
describe('ChatWebSocket — fetchToken supplier', () => {
|
|
103
|
+
it('invokes fetchToken on initial connect and uses its result in the URL', async () => {
|
|
104
|
+
const fetchToken = jest.fn().mockResolvedValue('ephemeral-aaa');
|
|
105
|
+
const ws = new ChatWebSocket({
|
|
106
|
+
url: 'ws://test/chat',
|
|
107
|
+
fetchToken,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const connectPromise = ws.connect();
|
|
111
|
+
// Drain the awaited fetchToken microtasks before we poke the stub.
|
|
112
|
+
await flushMicrotasks();
|
|
113
|
+
lastSocket().simulateOpen();
|
|
114
|
+
await connectPromise;
|
|
115
|
+
|
|
116
|
+
expect(fetchToken).toHaveBeenCalledTimes(1);
|
|
117
|
+
expect(lastSocket().url).toBe('ws://test/chat?token=ephemeral-aaa');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('re-invokes fetchToken on every reconnect (proves no stale token)', async () => {
|
|
121
|
+
const fetchToken = jest
|
|
122
|
+
.fn()
|
|
123
|
+
.mockResolvedValueOnce('token-1')
|
|
124
|
+
.mockResolvedValueOnce('token-2');
|
|
125
|
+
|
|
126
|
+
const ws = new ChatWebSocket({
|
|
127
|
+
url: 'ws://test/chat',
|
|
128
|
+
fetchToken,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const firstConnect = ws.connect();
|
|
132
|
+
await flushMicrotasks();
|
|
133
|
+
lastSocket().simulateOpen();
|
|
134
|
+
await firstConnect;
|
|
135
|
+
expect(lastSocket().url).toBe('ws://test/chat?token=token-1');
|
|
136
|
+
|
|
137
|
+
// Switch to fake timers only AFTER the initial connect resolves —
|
|
138
|
+
// modern fake timers replace `queueMicrotask`, which would starve
|
|
139
|
+
// the awaited `fetchToken` during the initial connect.
|
|
140
|
+
jest.useFakeTimers();
|
|
141
|
+
lastSocket().simulateClose();
|
|
142
|
+
// 1000ms = reconnectDelay * 2^0. `advanceTimersByTimeAsync` drains
|
|
143
|
+
// microtasks between ticks so the awaited `_resolveToken()` inside
|
|
144
|
+
// the rescheduled `_connect(true)` settles before we look.
|
|
145
|
+
await jest.advanceTimersByTimeAsync(1000);
|
|
146
|
+
lastSocket().simulateOpen();
|
|
147
|
+
|
|
148
|
+
expect(fetchToken).toHaveBeenCalledTimes(2);
|
|
149
|
+
expect(lastSocket().url).toBe('ws://test/chat?token=token-2');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('takes precedence over authToken when both are provided', async () => {
|
|
153
|
+
const fetchToken = jest.fn().mockResolvedValue('from-supplier');
|
|
154
|
+
const ws = new ChatWebSocket({
|
|
155
|
+
url: 'ws://test/chat',
|
|
156
|
+
authToken: 'from-static',
|
|
157
|
+
fetchToken,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const connectPromise = ws.connect();
|
|
161
|
+
await flushMicrotasks();
|
|
162
|
+
lastSocket().simulateOpen();
|
|
163
|
+
await connectPromise;
|
|
164
|
+
|
|
165
|
+
expect(lastSocket().url).toBe('ws://test/chat?token=from-supplier');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('propagates fetchToken rejection on the initial connect', async () => {
|
|
169
|
+
const fetchToken = jest.fn().mockRejectedValue(new Error('token boom'));
|
|
170
|
+
const ws = new ChatWebSocket({
|
|
171
|
+
url: 'ws://test/chat',
|
|
172
|
+
fetchToken,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await expect(ws.connect()).rejects.toThrow('token boom');
|
|
176
|
+
expect(instances).toHaveLength(0);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('ChatWebSocket — onReconnect hello payload', () => {
|
|
181
|
+
const helloPayload = {
|
|
182
|
+
action: 'hello' as const,
|
|
183
|
+
sessionId: 'sess-1',
|
|
184
|
+
mode: 'hybrid' as const,
|
|
185
|
+
personaId: 'p-1',
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
it('sends the onReconnect payload after a successful reconnect', async () => {
|
|
189
|
+
const onReconnect = jest.fn().mockReturnValue(helloPayload);
|
|
190
|
+
const onReconnected = jest.fn();
|
|
191
|
+
|
|
192
|
+
const ws = new ChatWebSocket({
|
|
193
|
+
url: 'ws://test/chat',
|
|
194
|
+
fetchToken: jest.fn().mockResolvedValue('tok'),
|
|
195
|
+
onReconnect,
|
|
196
|
+
onReconnected,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const first = ws.connect();
|
|
200
|
+
await flushMicrotasks();
|
|
201
|
+
lastSocket().simulateOpen();
|
|
202
|
+
await first;
|
|
203
|
+
|
|
204
|
+
jest.useFakeTimers();
|
|
205
|
+
lastSocket().simulateClose();
|
|
206
|
+
await jest.advanceTimersByTimeAsync(1000);
|
|
207
|
+
lastSocket().simulateOpen();
|
|
208
|
+
|
|
209
|
+
expect(onReconnect).toHaveBeenCalledTimes(1);
|
|
210
|
+
expect(lastSocket().sent).toEqual([JSON.stringify(helloPayload)]);
|
|
211
|
+
expect(onReconnected).toHaveBeenCalledTimes(1);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('skips the send when onReconnect returns null', async () => {
|
|
215
|
+
const onReconnect = jest.fn().mockReturnValue(null);
|
|
216
|
+
const ws = new ChatWebSocket({
|
|
217
|
+
url: 'ws://test/chat',
|
|
218
|
+
fetchToken: jest.fn().mockResolvedValue('tok'),
|
|
219
|
+
onReconnect,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const first = ws.connect();
|
|
223
|
+
await flushMicrotasks();
|
|
224
|
+
lastSocket().simulateOpen();
|
|
225
|
+
await first;
|
|
226
|
+
|
|
227
|
+
jest.useFakeTimers();
|
|
228
|
+
lastSocket().simulateClose();
|
|
229
|
+
await jest.advanceTimersByTimeAsync(1000);
|
|
230
|
+
lastSocket().simulateOpen();
|
|
231
|
+
|
|
232
|
+
expect(onReconnect).toHaveBeenCalledTimes(1);
|
|
233
|
+
expect(lastSocket().sent).toEqual([]);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('does NOT fire on the initial connect (only on reconnects)', async () => {
|
|
237
|
+
const onReconnect = jest.fn();
|
|
238
|
+
const ws = new ChatWebSocket({
|
|
239
|
+
url: 'ws://test/chat',
|
|
240
|
+
authToken: 'tok',
|
|
241
|
+
onReconnect,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const connectPromise = ws.connect();
|
|
245
|
+
await flushMicrotasks();
|
|
246
|
+
lastSocket().simulateOpen();
|
|
247
|
+
await connectPromise;
|
|
248
|
+
|
|
249
|
+
expect(onReconnect).not.toHaveBeenCalled();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe('ChatWebSocket — back-compat with static authToken', () => {
|
|
254
|
+
it('builds the URL from authToken when fetchToken is absent', async () => {
|
|
255
|
+
const ws = new ChatWebSocket({
|
|
256
|
+
url: 'ws://test/chat',
|
|
257
|
+
authToken: 'legacy-jwt',
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const connectPromise = ws.connect();
|
|
261
|
+
await flushMicrotasks();
|
|
262
|
+
lastSocket().simulateOpen();
|
|
263
|
+
await connectPromise;
|
|
264
|
+
|
|
265
|
+
expect(lastSocket().url).toBe('ws://test/chat?token=legacy-jwt');
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('omits the ?token= query when neither authToken nor fetchToken is set', async () => {
|
|
269
|
+
const ws = new ChatWebSocket({ url: 'ws://test/chat' });
|
|
270
|
+
|
|
271
|
+
const connectPromise = ws.connect();
|
|
272
|
+
await flushMicrotasks();
|
|
273
|
+
lastSocket().simulateOpen();
|
|
274
|
+
await connectPromise;
|
|
275
|
+
|
|
276
|
+
expect(lastSocket().url).toBe('ws://test/chat');
|
|
277
|
+
});
|
|
278
|
+
});
|
package/src/api.ts
CHANGED
|
@@ -364,6 +364,34 @@ export interface GenerateCharacterResponse {
|
|
|
364
364
|
statusUrl: string;
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
+
/** Request body for `POST /api/v1/personas/{personaId}/character` —
|
|
368
|
+
* generate AND link a rest-pose character in one shot. The server-side
|
|
369
|
+
* `model_validator` requires **exactly one** of `source_image_id` or
|
|
370
|
+
* `video_id`; `entity` / `timestamp` are only valid alongside
|
|
371
|
+
* `video_id`. Mirrors `api/personas/character.py::CreateCharacterRequest`. */
|
|
372
|
+
export interface CreatePersonaCharacterRequest {
|
|
373
|
+
source_image_id?: string;
|
|
374
|
+
video_id?: string;
|
|
375
|
+
entity?: string;
|
|
376
|
+
timestamp?: number;
|
|
377
|
+
style?: string;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** 202 Accepted envelope for `POST /api/v1/personas/{personaId}/character`.
|
|
381
|
+
*
|
|
382
|
+
* Snake-case to mirror the server's `CreateCharacterResponse` model —
|
|
383
|
+
* the `traceId` field stays camel-case because cross-endpoint trace
|
|
384
|
+
* correlation already uses that key everywhere else. The persona's
|
|
385
|
+
* `character_image_id` is set upfront on the persona row, so the
|
|
386
|
+
* persona detail page can render the link immediately and the caller
|
|
387
|
+
* just polls `status_url` for completion. */
|
|
388
|
+
export interface CreatePersonaCharacterResponse {
|
|
389
|
+
character_image_id: string;
|
|
390
|
+
status: 'pending';
|
|
391
|
+
status_url: string;
|
|
392
|
+
traceId: string;
|
|
393
|
+
}
|
|
394
|
+
|
|
367
395
|
export interface CreatePersonaRequest {
|
|
368
396
|
name: string;
|
|
369
397
|
description?: string | null;
|
|
@@ -442,11 +470,46 @@ export interface VoiceInfo {
|
|
|
442
470
|
voiceId: string;
|
|
443
471
|
displayName: string;
|
|
444
472
|
description: string;
|
|
473
|
+
/** Inworld language code (e.g. `'EN_US'`, `'ZH_CN'`). Always present
|
|
474
|
+
* on current API responses — the backend pydantic model defaults to
|
|
475
|
+
* `""` rather than omitting the field — but typed optional so older
|
|
476
|
+
* cached payloads (pre-field) don't break consumers. Treat `""` and
|
|
477
|
+
* `undefined` equivalently as "no language code". */
|
|
478
|
+
langCode?: string;
|
|
445
479
|
languages: string[];
|
|
446
480
|
tags: string[];
|
|
481
|
+
/** Voice origin per `schemas.VoiceInfo.source`:
|
|
482
|
+
* - `'SYSTEM'` — built-in Inworld voice
|
|
483
|
+
* - `'IVC'` — Instant Voice Clone
|
|
484
|
+
* - `'PVC'` — Professional Voice Clone
|
|
485
|
+
* Backend default is `'SYSTEM'`. */
|
|
486
|
+
source?: string;
|
|
447
487
|
isCustom: boolean;
|
|
448
488
|
}
|
|
449
489
|
|
|
490
|
+
export interface VoicesResponse {
|
|
491
|
+
voices: VoiceInfo[];
|
|
492
|
+
/** Server reports whether this response came from the 5-min in-memory
|
|
493
|
+
* cache or a fresh Inworld fetch. */
|
|
494
|
+
cached: boolean;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** Response shape for `POST /api/v1/chat/ws-token` — see
|
|
498
|
+
* `api/chat/app.py:create_websocket_token` + `schemas.WebSocketTokenResponse`.
|
|
499
|
+
* Ephemeral token (10-min TTL via `WS_TOKEN_TTL_SECONDS`) consumed by the
|
|
500
|
+
* WebSocket handler's auth cache. Prefer over passing the raw JWT in the
|
|
501
|
+
* `?token=` query param — JWTs leak into CloudFront / ALB / CloudWatch
|
|
502
|
+
* Logs which the ephemeral exchange avoids. */
|
|
503
|
+
export interface ChatWsTokenResponse {
|
|
504
|
+
wsToken: string;
|
|
505
|
+
/** Unix epoch seconds. Backend declares `float`, so the value may
|
|
506
|
+
* carry fractional seconds — don't `parseInt`/floor unless you need
|
|
507
|
+
* whole-second precision. */
|
|
508
|
+
expiresAt: number;
|
|
509
|
+
/** Seconds until expiry. Mirrors `WS_TOKEN_TTL_SECONDS` server-side. */
|
|
510
|
+
expiresIn: number;
|
|
511
|
+
}
|
|
512
|
+
|
|
450
513
|
// Session types matching backend shared/persona_models.py
|
|
451
514
|
export interface SessionMessage {
|
|
452
515
|
role: string;
|
|
@@ -514,6 +577,30 @@ export interface DialogSearchResponse {
|
|
|
514
577
|
results: DialogSearchResult[];
|
|
515
578
|
}
|
|
516
579
|
|
|
580
|
+
/** One shot in the entity-timeline result list. `entityStart`/`entityEnd`
|
|
581
|
+
* are the entity-tracking span within the shot when known. Mirrors
|
|
582
|
+
* `api/tools/schemas.py::TimelineEntry`. */
|
|
583
|
+
export interface EntityTimelineEntry {
|
|
584
|
+
shotId: string;
|
|
585
|
+
videoId: string;
|
|
586
|
+
t0: number;
|
|
587
|
+
t1: number;
|
|
588
|
+
entityStart?: number | null;
|
|
589
|
+
entityEnd?: number | null;
|
|
590
|
+
caption?: string | null;
|
|
591
|
+
/** Dialog lines spoken by (or near) the entity in this shot.
|
|
592
|
+
* Backend returns an opaque dict per line — leave loose here rather
|
|
593
|
+
* than tying client-core to a transcript schema that may evolve. */
|
|
594
|
+
dialog?: Array<Record<string, unknown>> | null;
|
|
595
|
+
citation: Citation;
|
|
596
|
+
source: SourceMetadata;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export interface EntityTimelineResponse {
|
|
600
|
+
traceId: string;
|
|
601
|
+
results: EntityTimelineEntry[];
|
|
602
|
+
}
|
|
603
|
+
|
|
517
604
|
// ---------------------------------------------------------------------------
|
|
518
605
|
// Narrative / Enrichment types
|
|
519
606
|
// ---------------------------------------------------------------------------
|
|
@@ -1106,6 +1193,35 @@ export class ApiClient {
|
|
|
1106
1193
|
);
|
|
1107
1194
|
}
|
|
1108
1195
|
|
|
1196
|
+
/**
|
|
1197
|
+
* Generate AND link a rest-pose character image for a persona in one
|
|
1198
|
+
* shot — the alternative to `generateCharacter` (which only generates;
|
|
1199
|
+
* the caller assigns later via PATCH).
|
|
1200
|
+
*
|
|
1201
|
+
* Returns 202 with `character_image_id` (stable for the lifetime of
|
|
1202
|
+
* the row) and `status_url` (== `/api/v1/images/{character_image_id}`).
|
|
1203
|
+
* Poll the status URL via `getImage()` / `pollImageUntilDone()` until
|
|
1204
|
+
* `status` flips off `'pending'`. The persona's `character_image_id`
|
|
1205
|
+
* is set upfront so the persona detail page can show the linkage
|
|
1206
|
+
* immediately and just renders the image once the poll resolves.
|
|
1207
|
+
*
|
|
1208
|
+
* The server's `model_validator` enforces "exactly one source" —
|
|
1209
|
+
* provide either `source_image_id` OR `video_id` (with optional
|
|
1210
|
+
* `entity`/`timestamp`), never both, never neither.
|
|
1211
|
+
*/
|
|
1212
|
+
async createPersonaCharacter(
|
|
1213
|
+
personaId: string,
|
|
1214
|
+
body: CreatePersonaCharacterRequest,
|
|
1215
|
+
): Promise<CreatePersonaCharacterResponse> {
|
|
1216
|
+
return this.request<CreatePersonaCharacterResponse>(
|
|
1217
|
+
`/api/v1/personas/${encodeURIComponent(personaId)}/character`,
|
|
1218
|
+
{
|
|
1219
|
+
method: 'POST',
|
|
1220
|
+
body: JSON.stringify(body),
|
|
1221
|
+
},
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1109
1225
|
/**
|
|
1110
1226
|
* Extract a raw video frame at an entity's location or a specific
|
|
1111
1227
|
* timestamp. Synchronous (no polling) — the path is ffmpeg-only with
|
|
@@ -1203,6 +1319,41 @@ export class ApiClient {
|
|
|
1203
1319
|
}
|
|
1204
1320
|
}
|
|
1205
1321
|
|
|
1322
|
+
// ==================== Chat Auth + Voices ====================
|
|
1323
|
+
// Note: Both endpoints live on the Chat API (chatBaseUrl).
|
|
1324
|
+
|
|
1325
|
+
/**
|
|
1326
|
+
* Exchange a valid JWT for a short-lived (10-min TTL) ephemeral
|
|
1327
|
+
* WebSocket token. Use the returned `wsToken` as the `?token=` query
|
|
1328
|
+
* param when opening the chat WS. This avoids leaking the long-lived
|
|
1329
|
+
* JWT into query-string logs (CloudFront / ALB / CloudWatch). Backed
|
|
1330
|
+
* by `POST /api/v1/chat/ws-token` in `api/chat/app.py`.
|
|
1331
|
+
*/
|
|
1332
|
+
async getChatWsToken(): Promise<ChatWsTokenResponse> {
|
|
1333
|
+
return this.chatRequest<ChatWsTokenResponse>('/api/v1/chat/ws-token', {
|
|
1334
|
+
method: 'POST',
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* List available TTS voices. Backed by `GET /api/voices` — server
|
|
1340
|
+
* caches Inworld results for 5 min; pass `refresh: true` to bypass.
|
|
1341
|
+
*/
|
|
1342
|
+
async listVoices(params?: {
|
|
1343
|
+
/** ISO 639-1 (e.g. 'en'). */
|
|
1344
|
+
language?: string;
|
|
1345
|
+
/** Force a fresh fetch from Inworld, bypassing the 5-min cache. */
|
|
1346
|
+
refresh?: boolean;
|
|
1347
|
+
}): Promise<VoicesResponse> {
|
|
1348
|
+
const search = new URLSearchParams();
|
|
1349
|
+
if (params?.language) search.append('language', params.language);
|
|
1350
|
+
if (params?.refresh) search.append('refresh', 'true');
|
|
1351
|
+
const qs = search.toString();
|
|
1352
|
+
return this.chatRequest<VoicesResponse>(
|
|
1353
|
+
`/api/voices${qs ? `?${qs}` : ''}`
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1206
1357
|
// ==================== Session API Methods ====================
|
|
1207
1358
|
// Note: Sessions are served by the Chat API, not the Tools API
|
|
1208
1359
|
|
|
@@ -1290,6 +1441,34 @@ export class ApiClient {
|
|
|
1290
1441
|
});
|
|
1291
1442
|
}
|
|
1292
1443
|
|
|
1444
|
+
/**
|
|
1445
|
+
* Return a time-ordered list of shots where an entity appears.
|
|
1446
|
+
* Optional `t0`/`t1` bounds (seconds) narrow the query window —
|
|
1447
|
+
* the server validates `t1 > t0` when both are provided.
|
|
1448
|
+
*
|
|
1449
|
+
* Backed by `POST /api/v1/tools/entity-timeline`. Returns an empty
|
|
1450
|
+
* `results` array (not a 404) when the entity isn't found after
|
|
1451
|
+
* graph resolution — callers can treat "no results" uniformly.
|
|
1452
|
+
*/
|
|
1453
|
+
async getEntityTimeline(
|
|
1454
|
+
videoId: string,
|
|
1455
|
+
entity: string,
|
|
1456
|
+
bounds?: { t0?: number; t1?: number },
|
|
1457
|
+
): Promise<EntityTimelineResponse> {
|
|
1458
|
+
return this.request<EntityTimelineResponse>(
|
|
1459
|
+
'/api/v1/tools/entity-timeline',
|
|
1460
|
+
{
|
|
1461
|
+
method: 'POST',
|
|
1462
|
+
body: JSON.stringify({
|
|
1463
|
+
videoId,
|
|
1464
|
+
entity,
|
|
1465
|
+
t0: bounds?.t0,
|
|
1466
|
+
t1: bounds?.t1,
|
|
1467
|
+
}),
|
|
1468
|
+
},
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1293
1472
|
// ==================== Graph Editor API Methods ====================
|
|
1294
1473
|
|
|
1295
1474
|
async getVideoGraph(videoId: string): Promise<VideoGraphResponse> {
|
package/src/visemeGeometry.ts
CHANGED
|
@@ -7,6 +7,36 @@
|
|
|
7
7
|
* without rendering a React tree.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import type { VisemeSymbol } from './visemeScheduler';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fallback SVG path table used by mouth renderers BEFORE a persona's
|
|
14
|
+
* viseme bundle has finished loading (and as a backstop for personas
|
|
15
|
+
* that don't ship a custom bundle). Each value is the `d` attribute
|
|
16
|
+
* for the `<path>` driven by the viseme switch.
|
|
17
|
+
*
|
|
18
|
+
* Coordinates assume a 200×100 viewBox centered horizontally — the
|
|
19
|
+
* same canvas the Web-App `seer-character-face.vue` and seer-agent
|
|
20
|
+
* `CharacterFace.tsx` renderers use. Promoted from
|
|
21
|
+
* `seer-character-face.vue` so both renderers can share the source
|
|
22
|
+
* of truth; this is the §7 cleanup from
|
|
23
|
+
* `specs/2026-05-14-client-core-cleanup-plan.md`.
|
|
24
|
+
*/
|
|
25
|
+
export const DEFAULT_MOUTH_PATHS: Record<VisemeSymbol, string> = {
|
|
26
|
+
rest: 'M 40,50 C 60,50 140,50 160,50 C 160,52 140,54 100,54 C 60,54 40,52 40,50 C 40,50 40,50 40,50',
|
|
27
|
+
aei: 'M 40,38 C 60,32 140,32 160,38 C 160,56 140,72 100,74 C 60,72 40,56 40,38 C 40,38 40,38 40,38',
|
|
28
|
+
o: 'M 62,34 C 78,28 122,28 138,34 C 142,50 138,70 100,72 C 62,70 58,50 62,34 C 62,34 62,34 62,34',
|
|
29
|
+
ee: 'M 28,44 C 52,40 148,40 172,44 C 172,52 148,58 100,58 C 52,58 28,52 28,44 C 28,44 28,44 28,44',
|
|
30
|
+
bmp: 'M 48,48 C 68,46 132,46 152,48 C 152,52 132,54 100,54 C 68,54 48,52 48,48 C 48,48 48,48 48,48',
|
|
31
|
+
fv: 'M 42,44 C 62,42 138,42 158,44 C 158,52 138,58 100,58 C 62,58 42,52 42,44 C 42,44 42,44 42,44',
|
|
32
|
+
l: 'M 42,40 C 62,36 138,36 158,40 C 158,54 138,64 100,66 C 62,64 42,54 42,40 C 42,40 42,40 42,40',
|
|
33
|
+
r: 'M 52,38 C 72,34 128,34 148,38 C 148,52 128,64 100,66 C 72,64 52,52 52,38 C 52,38 52,38 52,38',
|
|
34
|
+
th: 'M 42,42 C 62,38 138,38 158,42 C 158,52 138,60 100,62 C 62,60 42,52 42,42 C 42,42 42,42 42,42',
|
|
35
|
+
qw: 'M 58,36 C 76,30 124,30 142,36 C 146,52 138,68 100,70 C 62,68 54,52 58,36 C 58,36 58,36 58,36',
|
|
36
|
+
cdgknstxyz:
|
|
37
|
+
'M 44,46 C 64,43 136,43 156,46 C 156,53 136,57 100,57 C 64,57 44,53 44,46 C 44,46 44,46 44,46',
|
|
38
|
+
};
|
|
39
|
+
|
|
10
40
|
export interface Point {
|
|
11
41
|
x: number;
|
|
12
42
|
y: number;
|
package/src/visemeScheduler.ts
CHANGED
|
@@ -34,6 +34,31 @@ const VALID_VISEMES: ReadonlySet<string> = new Set<string>([
|
|
|
34
34
|
'cdgknstxyz',
|
|
35
35
|
]);
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Map VisemeSymbol → 0-14 integer index expected by the PlayCanvas
|
|
39
|
+
* iframe TTS bridge (Web-App: `utils/seer/iframeMessaging.ts`).
|
|
40
|
+
*
|
|
41
|
+
* The indices are intentionally sparse (gaps at 4, 6, 7, 11): they
|
|
42
|
+
* match the PlayCanvas mouth animation channel constants and **must
|
|
43
|
+
* not be re-densified** without updating the engine side. Promoted to
|
|
44
|
+
* client-core so the next renderer (or a future seer-agent PlayCanvas
|
|
45
|
+
* iframe consumer) inherits the same mapping — §8 in
|
|
46
|
+
* `specs/2026-05-14-client-core-cleanup-plan.md`.
|
|
47
|
+
*/
|
|
48
|
+
export const iframeVisemeIndexMap: Readonly<Record<VisemeSymbol, number>> = {
|
|
49
|
+
rest: 0,
|
|
50
|
+
bmp: 1,
|
|
51
|
+
fv: 2,
|
|
52
|
+
th: 3,
|
|
53
|
+
cdgknstxyz: 5,
|
|
54
|
+
l: 8,
|
|
55
|
+
r: 9,
|
|
56
|
+
aei: 10,
|
|
57
|
+
ee: 12,
|
|
58
|
+
o: 13,
|
|
59
|
+
qw: 14,
|
|
60
|
+
};
|
|
61
|
+
|
|
37
62
|
interface ScheduledViseme {
|
|
38
63
|
startTime: number; // Absolute AudioContext.currentTime
|
|
39
64
|
endTime: number;
|