@runwayml/avatars 0.16.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 +103 -0
- package/dist/api.cjs +189 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +247 -0
- package/dist/api.d.ts +247 -0
- package/dist/api.js +182 -0
- package/dist/api.js.map +1 -0
- package/dist/index.cjs +928 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +534 -0
- package/dist/index.d.ts +534 -0
- package/dist/index.js +911 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny typed event emitter. No Node.js polyfills, no dependencies.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* type Events = { count: [number]; ready: [] };
|
|
7
|
+
* const ee = new Emitter<Events>();
|
|
8
|
+
* ee.on('count', (n) => console.log(n));
|
|
9
|
+
* ee.emit('count', 42);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
type EventMap = Record<string, Array<unknown>>;
|
|
13
|
+
type Handler<Args extends Array<unknown>> = (...args: Args) => void;
|
|
14
|
+
declare class Emitter<E extends EventMap> {
|
|
15
|
+
private listeners;
|
|
16
|
+
on<K extends keyof E>(event: K, handler: Handler<E[K]>): this;
|
|
17
|
+
once<K extends keyof E>(event: K, handler: Handler<E[K]>): this;
|
|
18
|
+
off<K extends keyof E>(event: K, handler: Handler<E[K]>): this;
|
|
19
|
+
protected emit<K extends keyof E>(event: K, ...args: E[K]): void;
|
|
20
|
+
removeAllListeners(event?: keyof E): this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @runwayml/avatars Types
|
|
25
|
+
*
|
|
26
|
+
* Core types for the avatar SDK. No React or framework dependencies.
|
|
27
|
+
*/
|
|
28
|
+
type SessionState = 'idle' | 'connecting' | 'reconnecting' | 'active' | 'ending' | 'ended' | 'error';
|
|
29
|
+
interface ConsumeSessionResponse {
|
|
30
|
+
url: string;
|
|
31
|
+
token: string;
|
|
32
|
+
roomName: string;
|
|
33
|
+
}
|
|
34
|
+
interface SessionCredentials {
|
|
35
|
+
sessionId: string;
|
|
36
|
+
serverUrl: string;
|
|
37
|
+
token: string;
|
|
38
|
+
roomName: string;
|
|
39
|
+
}
|
|
40
|
+
interface SessionKeyResponse {
|
|
41
|
+
sessionId: string;
|
|
42
|
+
sessionKey: string;
|
|
43
|
+
}
|
|
44
|
+
type ConnectResponse = SessionCredentials | SessionKeyResponse;
|
|
45
|
+
interface ConsumeSessionOptions {
|
|
46
|
+
sessionId: string;
|
|
47
|
+
sessionKey: string;
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
}
|
|
50
|
+
interface ClientEvent<T extends string = string, A = Record<string, unknown>> {
|
|
51
|
+
type: 'client_event';
|
|
52
|
+
tool: T;
|
|
53
|
+
args: A;
|
|
54
|
+
}
|
|
55
|
+
type ClientEventHandler<E extends ClientEvent = ClientEvent> = (event: E) => void;
|
|
56
|
+
interface TranscriptionEntry {
|
|
57
|
+
id: string;
|
|
58
|
+
text: string;
|
|
59
|
+
final: boolean;
|
|
60
|
+
participantIdentity: string;
|
|
61
|
+
channel?: 'native' | 'custom';
|
|
62
|
+
}
|
|
63
|
+
type TranscriptionHandler = (entry: TranscriptionEntry) => void;
|
|
64
|
+
type MicPermissionState = 'pending' | 'granted' | 'denied';
|
|
65
|
+
type ConnectionQuality = 'excellent' | 'good' | 'poor' | 'lost' | 'unknown';
|
|
66
|
+
type ActiveSpeaker = 'user' | 'avatar';
|
|
67
|
+
declare const AvatarEvent: {
|
|
68
|
+
readonly StateChanged: "stateChanged";
|
|
69
|
+
readonly Transcript: "transcript";
|
|
70
|
+
readonly ClientEvent: "clientEvent";
|
|
71
|
+
readonly Error: "error";
|
|
72
|
+
readonly AvatarVideoReady: "avatarVideoReady";
|
|
73
|
+
readonly AvatarAudioReady: "avatarAudioReady";
|
|
74
|
+
readonly ScreenShareReady: "screenShareReady";
|
|
75
|
+
readonly LocalVideoReady: "localVideoReady";
|
|
76
|
+
readonly MediaChanged: "mediaChanged";
|
|
77
|
+
readonly UserSpeechStarted: "userSpeechStarted";
|
|
78
|
+
readonly UserSpeechEnded: "userSpeechEnded";
|
|
79
|
+
readonly AvatarSpeechStarted: "avatarSpeechStarted";
|
|
80
|
+
readonly AvatarSpeechEnded: "avatarSpeechEnded";
|
|
81
|
+
readonly ConnectionQualityChanged: "connectionQualityChanged";
|
|
82
|
+
readonly MicPermissionChanged: "micPermissionChanged";
|
|
83
|
+
readonly ActiveSpeakersChanged: "activeSpeakersChanged";
|
|
84
|
+
};
|
|
85
|
+
type AvatarEventMap = {
|
|
86
|
+
[AvatarEvent.StateChanged]: [state: SessionState];
|
|
87
|
+
[AvatarEvent.Transcript]: [entry: TranscriptionEntry];
|
|
88
|
+
[AvatarEvent.ClientEvent]: [event: ClientEvent];
|
|
89
|
+
[AvatarEvent.Error]: [error: Error];
|
|
90
|
+
[AvatarEvent.AvatarVideoReady]: [track: MediaStreamTrack];
|
|
91
|
+
[AvatarEvent.AvatarAudioReady]: [track: MediaStreamTrack];
|
|
92
|
+
[AvatarEvent.ScreenShareReady]: [track: MediaStreamTrack];
|
|
93
|
+
[AvatarEvent.LocalVideoReady]: [track: MediaStreamTrack];
|
|
94
|
+
[AvatarEvent.MediaChanged]: [];
|
|
95
|
+
[AvatarEvent.UserSpeechStarted]: [];
|
|
96
|
+
[AvatarEvent.UserSpeechEnded]: [];
|
|
97
|
+
[AvatarEvent.AvatarSpeechStarted]: [];
|
|
98
|
+
[AvatarEvent.AvatarSpeechEnded]: [];
|
|
99
|
+
[AvatarEvent.ConnectionQualityChanged]: [quality: ConnectionQuality];
|
|
100
|
+
[AvatarEvent.MicPermissionChanged]: [state: MicPermissionState];
|
|
101
|
+
[AvatarEvent.ActiveSpeakersChanged]: [speakers: ReadonlyArray<ActiveSpeaker>];
|
|
102
|
+
};
|
|
103
|
+
interface MediaController {
|
|
104
|
+
readonly isEnabled: boolean;
|
|
105
|
+
enable(): Promise<void>;
|
|
106
|
+
disable(): Promise<void>;
|
|
107
|
+
toggle(): Promise<void>;
|
|
108
|
+
setDevice(deviceId: string): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
interface ScreenShareController {
|
|
111
|
+
readonly isActive: boolean;
|
|
112
|
+
start(): Promise<void>;
|
|
113
|
+
stop(): Promise<void>;
|
|
114
|
+
toggle(): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
interface TranscriptOptions {
|
|
117
|
+
interim?: boolean;
|
|
118
|
+
bufferSize?: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type TranscriptEvents = {
|
|
122
|
+
update: [entries: ReadonlyArray<TranscriptionEntry>];
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Stateful transcript accumulator. Deduplicates by segment `id`, caps at
|
|
126
|
+
* `bufferSize`, and emits `update` on every change.
|
|
127
|
+
*
|
|
128
|
+
* Handles both LiveKit-style `{ segments: [...] }` and Runway flat-delta
|
|
129
|
+
* `{ type: "transcription", role, turn, text }` data-channel payloads,
|
|
130
|
+
* as well as native `TranscriptionReceived` segment arrays.
|
|
131
|
+
*/
|
|
132
|
+
declare class TranscriptAccumulator extends Emitter<TranscriptEvents> {
|
|
133
|
+
private readonly map;
|
|
134
|
+
private readonly flatAcc;
|
|
135
|
+
private readonly interim;
|
|
136
|
+
private readonly bufferSize;
|
|
137
|
+
private snapshot;
|
|
138
|
+
constructor(options?: TranscriptOptions);
|
|
139
|
+
get entries(): ReadonlyArray<TranscriptionEntry>;
|
|
140
|
+
/**
|
|
141
|
+
* Ingest a native transcription segment (from `RoomEvent.TranscriptionReceived`).
|
|
142
|
+
*/
|
|
143
|
+
ingestNative(segments: ReadonlyArray<{
|
|
144
|
+
id: string;
|
|
145
|
+
text: string;
|
|
146
|
+
final: boolean;
|
|
147
|
+
}>, participantIdentity: string): void;
|
|
148
|
+
/**
|
|
149
|
+
* Ingest a raw data-channel payload (from `RoomEvent.DataReceived`).
|
|
150
|
+
* Handles both segment arrays and flat deltas.
|
|
151
|
+
*/
|
|
152
|
+
ingestDataChannel(payload: Uint8Array, participantIdentity: string): void;
|
|
153
|
+
dispose(): void;
|
|
154
|
+
private flush;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A live avatar session. Returned by `streamTo` or `connect`.
|
|
159
|
+
*
|
|
160
|
+
* Wraps a LiveKit Room behind a clean event-driven API. No LiveKit
|
|
161
|
+
* types are exposed — tracks are standard `MediaStreamTrack` objects.
|
|
162
|
+
*/
|
|
163
|
+
declare class AvatarSession extends Emitter<AvatarEventMap> {
|
|
164
|
+
private room;
|
|
165
|
+
private _sessionId;
|
|
166
|
+
private _state;
|
|
167
|
+
private _error;
|
|
168
|
+
private _micEnabled;
|
|
169
|
+
private _cameraEnabled;
|
|
170
|
+
private _screenShareActive;
|
|
171
|
+
private attachedVideoElement;
|
|
172
|
+
private attachedAudioElement;
|
|
173
|
+
private avatarVideoTrack;
|
|
174
|
+
private avatarAudioTrack;
|
|
175
|
+
private _localVideoTrack;
|
|
176
|
+
private autoAudioElement;
|
|
177
|
+
private flatDeltaAcc;
|
|
178
|
+
private _userSpeaking;
|
|
179
|
+
private _avatarSpeaking;
|
|
180
|
+
private _connectedAt;
|
|
181
|
+
readonly mic: MediaController;
|
|
182
|
+
readonly camera: MediaController;
|
|
183
|
+
readonly screenShare: ScreenShareController;
|
|
184
|
+
constructor(sessionId: string);
|
|
185
|
+
get state(): SessionState;
|
|
186
|
+
get sessionId(): string;
|
|
187
|
+
get error(): Error | null;
|
|
188
|
+
get localVideoTrack(): MediaStreamTrack | null;
|
|
189
|
+
get duration(): number;
|
|
190
|
+
waitFor<K extends keyof AvatarEventMap>(event: K): Promise<AvatarEventMap[K][0]>;
|
|
191
|
+
streamTo(element: HTMLVideoElement): void;
|
|
192
|
+
stopStreaming(): void;
|
|
193
|
+
attachAudio(element: HTMLAudioElement): void;
|
|
194
|
+
detachAudio(): void;
|
|
195
|
+
end(): Promise<void>;
|
|
196
|
+
transcript(options?: TranscriptOptions): TranscriptAccumulator;
|
|
197
|
+
onClientEvent<T extends string, A>(toolOrName: {
|
|
198
|
+
name: T;
|
|
199
|
+
} | T, handler: (args: A) => void): () => void;
|
|
200
|
+
/** @internal Called by `streamTo` and `connect` entry points. */
|
|
201
|
+
_connect(serverUrl: string, token: string, options: {
|
|
202
|
+
audio?: boolean;
|
|
203
|
+
video?: boolean;
|
|
204
|
+
}): Promise<void>;
|
|
205
|
+
publishScreenShare(stream: MediaStream): Promise<void>;
|
|
206
|
+
private bindRoomEvents;
|
|
207
|
+
private reattachTracks;
|
|
208
|
+
private syncVideoElement;
|
|
209
|
+
private enableInitialMedia;
|
|
210
|
+
private setMic;
|
|
211
|
+
private setCamera;
|
|
212
|
+
private emitLocalVideoTrack;
|
|
213
|
+
private setScreenShare;
|
|
214
|
+
private switchDevice;
|
|
215
|
+
private autoPlayAudio;
|
|
216
|
+
private setError;
|
|
217
|
+
private setState;
|
|
218
|
+
private cleanup;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Start an avatar session and stream video to an element.
|
|
222
|
+
*
|
|
223
|
+
* Handles the consume call, LiveKit connection, and media setup
|
|
224
|
+
* in one call. Returns an `AvatarSession` for media controls,
|
|
225
|
+
* events, and ending the call.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* const credentials = await fetch('/api/connect').then(r => r.json());
|
|
230
|
+
* const session = await streamTo({ credentials, target: document.getElementById('avatar') });
|
|
231
|
+
*
|
|
232
|
+
* session.mic.toggle();
|
|
233
|
+
* session.end();
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function streamTo(options: {
|
|
237
|
+
credentials: {
|
|
238
|
+
sessionId: string;
|
|
239
|
+
sessionKey: string;
|
|
240
|
+
baseUrl?: string;
|
|
241
|
+
};
|
|
242
|
+
target: HTMLVideoElement;
|
|
243
|
+
audio?: boolean;
|
|
244
|
+
video?: boolean;
|
|
245
|
+
}): Promise<AvatarSession>;
|
|
246
|
+
/**
|
|
247
|
+
* Start an avatar session without a video element (headless).
|
|
248
|
+
*
|
|
249
|
+
* Use `session.streamTo(element)` later to attach video, or use
|
|
250
|
+
* this for audio-only sessions.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const credentials = await fetch('/api/connect').then(r => r.json());
|
|
255
|
+
* const session = await connect({ credentials });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare function connect(options: {
|
|
259
|
+
credentials: {
|
|
260
|
+
sessionId: string;
|
|
261
|
+
sessionKey: string;
|
|
262
|
+
baseUrl?: string;
|
|
263
|
+
};
|
|
264
|
+
audio?: boolean;
|
|
265
|
+
video?: boolean;
|
|
266
|
+
}): Promise<AvatarSession>;
|
|
267
|
+
|
|
268
|
+
type AvatarErrorCode = 'CONSUME_FAILED' | 'CONNECTION_FAILED' | 'MEDIA_PERMISSION_DENIED' | 'MEDIA_DEVICE_ERROR' | 'SCREEN_SHARE_FAILED' | 'PUBLISH_FAILED' | 'UNKNOWN';
|
|
269
|
+
declare class AvatarError extends Error {
|
|
270
|
+
readonly code: AvatarErrorCode;
|
|
271
|
+
readonly cause?: Error;
|
|
272
|
+
constructor(code: AvatarErrorCode, message: string, cause?: Error);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
declare function consumeSession(options: ConsumeSessionOptions): Promise<ConsumeSessionResponse>;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Standard Schema v1 — a tiny cross-library validation interface implemented
|
|
279
|
+
* by Zod, Valibot, ArkType, and others. Anything matching this shape plugs
|
|
280
|
+
* into `clientTool({ schema })`.
|
|
281
|
+
*
|
|
282
|
+
* @see https://standardschema.dev/
|
|
283
|
+
*
|
|
284
|
+
* We re-declare the spec here (instead of depending on `@standard-schema/spec`)
|
|
285
|
+
* so the SDK stays dependency-free and server-safe.
|
|
286
|
+
*/
|
|
287
|
+
/** The schema itself — what a `z.object(...)` etc. resolves to. */
|
|
288
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
289
|
+
readonly '~standard': {
|
|
290
|
+
readonly version: 1;
|
|
291
|
+
readonly vendor: string;
|
|
292
|
+
readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
|
|
293
|
+
readonly types?: {
|
|
294
|
+
readonly input: Input;
|
|
295
|
+
readonly output: Output;
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/** Result of calling `schema['~standard'].validate(value)`. */
|
|
300
|
+
type StandardSchemaResult<Output> = {
|
|
301
|
+
readonly value: Output;
|
|
302
|
+
readonly issues?: undefined;
|
|
303
|
+
} | {
|
|
304
|
+
readonly issues: ReadonlyArray<StandardSchemaIssue>;
|
|
305
|
+
};
|
|
306
|
+
/** A single validation failure — part of the error path. */
|
|
307
|
+
interface StandardSchemaIssue {
|
|
308
|
+
readonly message: string;
|
|
309
|
+
readonly path?: ReadonlyArray<PropertyKey | {
|
|
310
|
+
readonly key: PropertyKey;
|
|
311
|
+
}>;
|
|
312
|
+
}
|
|
313
|
+
type InferSchemaInput<Schema extends StandardSchemaV1> = Schema extends StandardSchemaV1<infer Input, unknown> ? Input : never;
|
|
314
|
+
type InferSchemaOutput<Schema extends StandardSchemaV1> = Schema extends StandardSchemaV1<unknown, infer Output> ? Output : never;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* A standalone client tool definition. Composable — combine into arrays
|
|
318
|
+
* and derive event types with `ClientEventsFrom`.
|
|
319
|
+
*
|
|
320
|
+
* At runtime this is just `{ type, name, description }` (exactly what the
|
|
321
|
+
* Runway session create payload expects). The `Args` generic is phantom —
|
|
322
|
+
* it only exists at the TypeScript level for type narrowing.
|
|
323
|
+
*
|
|
324
|
+
* When the tool is defined with a `schema` ([Standard Schema](https://standardschema.dev/)),
|
|
325
|
+
* the schema is attached internally (not serialized) for runtime validation
|
|
326
|
+
* and to infer `Args` from the schema output type.
|
|
327
|
+
*/
|
|
328
|
+
interface ClientToolDef<Name extends string = string, Args = unknown> {
|
|
329
|
+
readonly type: 'client_event';
|
|
330
|
+
readonly name: Name;
|
|
331
|
+
readonly description: string;
|
|
332
|
+
/** @internal phantom field — always `undefined` at runtime */
|
|
333
|
+
readonly _args?: Args;
|
|
334
|
+
}
|
|
335
|
+
type ClientToolArgs<Tool extends ClientToolDef> = Tool extends ClientToolDef<string, infer Args> ? Args : never;
|
|
336
|
+
type ClientEventFromTool<Tool extends ClientToolDef> = Tool extends ClientToolDef<infer Name, infer Args> ? ClientEvent<Name, Args> : never;
|
|
337
|
+
/**
|
|
338
|
+
* Derive a discriminated union of ClientEvent types from an array of tools.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* const tools = [showQuestion, playSound];
|
|
343
|
+
* type MyEvent = ClientEventsFrom<typeof tools>;
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
type ClientEventsFrom<T extends ReadonlyArray<ClientToolDef>> = T[number] extends infer U ? U extends ClientToolDef<infer Name, infer Args> ? ClientEvent<Name, Args> : never : never;
|
|
347
|
+
/**
|
|
348
|
+
* Return the Standard Schema associated with a tool, if any.
|
|
349
|
+
* Useful when composing validation outside of the SDK hooks.
|
|
350
|
+
*/
|
|
351
|
+
declare function getClientToolSchema(tool: ClientToolDef): StandardSchemaV1 | undefined;
|
|
352
|
+
/**
|
|
353
|
+
* Validate parsed client event args against a tool's schema.
|
|
354
|
+
*
|
|
355
|
+
* Returns the typed args on success, or `null` when the schema fails or
|
|
356
|
+
* when the schema would need to resolve asynchronously (Standard Schema
|
|
357
|
+
* allows async `validate`, but for fire-and-forget client events we only
|
|
358
|
+
* accept sync results here).
|
|
359
|
+
*
|
|
360
|
+
* Tools defined without a schema always validate successfully — the
|
|
361
|
+
* incoming args are returned as-is.
|
|
362
|
+
*/
|
|
363
|
+
declare function validateClientToolArgs<Tool extends ClientToolDef>(tool: Tool, args: unknown): ClientToolArgs<Tool> | null;
|
|
364
|
+
/**
|
|
365
|
+
* Define a single client tool.
|
|
366
|
+
*
|
|
367
|
+
* Returns a standalone object that can be composed into arrays and passed
|
|
368
|
+
* to `realtimeSessions.create({ tools })`.
|
|
369
|
+
*
|
|
370
|
+
* Two forms are supported:
|
|
371
|
+
*
|
|
372
|
+
* 1. **Schema-driven** (recommended) — pass a
|
|
373
|
+
* [Standard Schema](https://standardschema.dev/) (Zod, Valibot, ArkType, …)
|
|
374
|
+
* to infer `args` types and enable runtime validation of incoming events:
|
|
375
|
+
*
|
|
376
|
+
* ```typescript
|
|
377
|
+
* import { z } from 'zod';
|
|
378
|
+
* const showCaption = clientTool('show_caption', {
|
|
379
|
+
* description: 'Display a caption',
|
|
380
|
+
* schema: z.object({ text: z.string() }),
|
|
381
|
+
* });
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* 2. **Type-only** — pass an `args` type via a cast when you don't need
|
|
385
|
+
* runtime validation:
|
|
386
|
+
*
|
|
387
|
+
* ```typescript
|
|
388
|
+
* const showCaption = clientTool('show_caption', {
|
|
389
|
+
* description: 'Display a caption',
|
|
390
|
+
* args: {} as { text: string },
|
|
391
|
+
* });
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* Combine tools and derive event types with `ClientEventsFrom`:
|
|
395
|
+
*
|
|
396
|
+
* ```typescript
|
|
397
|
+
* const tools = [showCaption, playSound];
|
|
398
|
+
* type MyEvent = ClientEventsFrom<typeof tools>;
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
declare function clientTool<Name extends string, Schema extends StandardSchemaV1>(name: Name, config: {
|
|
402
|
+
description: string;
|
|
403
|
+
schema: Schema;
|
|
404
|
+
}): ClientToolDef<Name, InferSchemaOutput<Schema>>;
|
|
405
|
+
declare function clientTool<Name extends string, Args>(name: Name, config: {
|
|
406
|
+
description: string;
|
|
407
|
+
args: Args;
|
|
408
|
+
}): ClientToolDef<Name, Args>;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Parse and validate a data channel payload as a ClientEvent.
|
|
412
|
+
* Returns null for non-client-event messages, ack messages, or malformed payloads.
|
|
413
|
+
*/
|
|
414
|
+
declare function parseClientEvent(payload: Uint8Array): ClientEvent | null;
|
|
415
|
+
|
|
416
|
+
interface FlatDelta {
|
|
417
|
+
role: string;
|
|
418
|
+
turn: number;
|
|
419
|
+
textDelta: string;
|
|
420
|
+
}
|
|
421
|
+
interface FlatDeltaTurn {
|
|
422
|
+
id: string;
|
|
423
|
+
text: string;
|
|
424
|
+
participantIdentity: string;
|
|
425
|
+
}
|
|
426
|
+
interface FlatDeltaEmission {
|
|
427
|
+
/** Prior turns on the same role that were just promoted to final by this delta. */
|
|
428
|
+
finalized: Array<FlatDeltaTurn>;
|
|
429
|
+
/** The turn this delta belongs to — still streaming, always interim. */
|
|
430
|
+
active: FlatDeltaTurn;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Accumulates Runway flat-delta transcription fragments into coherent turns.
|
|
434
|
+
*
|
|
435
|
+
* The flat-delta protocol sends `{ role, turn, textDelta }` messages without
|
|
436
|
+
* an explicit end-of-turn signal, so we infer the end: when a delta arrives
|
|
437
|
+
* on a higher turn for the same role, prior turns on that role are done and
|
|
438
|
+
* get emitted once as final. The active turn is always interim.
|
|
439
|
+
*
|
|
440
|
+
* Identity is remembered per-turn, so finalized priors are attributed to
|
|
441
|
+
* whoever originally produced them — not to whoever triggered the role
|
|
442
|
+
* switch.
|
|
443
|
+
*/
|
|
444
|
+
declare class FlatDeltaAccumulator {
|
|
445
|
+
private readonly turns;
|
|
446
|
+
private readonly finalized;
|
|
447
|
+
ingest(delta: FlatDelta, participantIdentity: string): FlatDeltaEmission;
|
|
448
|
+
reset(): void;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
type DataChannelJSON = Record<string, unknown>;
|
|
452
|
+
declare function tryDecodeJSON(payload: Uint8Array): DataChannelJSON | null;
|
|
453
|
+
/**
|
|
454
|
+
* Parse LiveKit-style segment arrays: `{ segments: [{ id, text, final? }] }`
|
|
455
|
+
* Also handles wrapper shapes like `{ type: "transcription", segments: [...] }`
|
|
456
|
+
* and `{ data: { segments: [...] } }`.
|
|
457
|
+
*/
|
|
458
|
+
declare function tryParseSegmentArray(root: DataChannelJSON, participant?: {
|
|
459
|
+
identity: string;
|
|
460
|
+
}): Array<TranscriptionEntry> | null;
|
|
461
|
+
/**
|
|
462
|
+
* Parse Runway flat streaming deltas: `{ type: "transcription", role, turn, text }`
|
|
463
|
+
* These arrive one delta at a time and are accumulated per role+turn.
|
|
464
|
+
*/
|
|
465
|
+
declare function tryParseFlatDelta(root: DataChannelJSON): {
|
|
466
|
+
role: string;
|
|
467
|
+
turn: number;
|
|
468
|
+
textDelta: string;
|
|
469
|
+
} | null;
|
|
470
|
+
|
|
471
|
+
declare const toolDefs: readonly [ClientToolDef<"click", {
|
|
472
|
+
target: string;
|
|
473
|
+
}>, ClientToolDef<"scroll_to", {
|
|
474
|
+
target: string;
|
|
475
|
+
}>, ClientToolDef<"highlight", {
|
|
476
|
+
target: string;
|
|
477
|
+
duration?: number;
|
|
478
|
+
}>];
|
|
479
|
+
type PageActionEvent = ClientEventsFrom<typeof toolDefs>;
|
|
480
|
+
/**
|
|
481
|
+
* Pre-built tool definitions with `parameters` arrays, ready to spread
|
|
482
|
+
* into `realtimeSessions.create({ tools })`.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```ts
|
|
486
|
+
* import { pageActionTools } from '@runwayml/avatars-react/api';
|
|
487
|
+
*
|
|
488
|
+
* await client.realtimeSessions.create({
|
|
489
|
+
* model: 'gwm1_avatars',
|
|
490
|
+
* avatar: { type: 'runway-preset', presetId: 'music-superstar' },
|
|
491
|
+
* tools: [...pageActionTools, ...myCustomTools],
|
|
492
|
+
* });
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
declare const pageActionTools: ({
|
|
496
|
+
parameters: {
|
|
497
|
+
name: string;
|
|
498
|
+
type: string;
|
|
499
|
+
description: string;
|
|
500
|
+
}[];
|
|
501
|
+
type: "client_event";
|
|
502
|
+
name: "click";
|
|
503
|
+
description: string;
|
|
504
|
+
_args?: {
|
|
505
|
+
target: string;
|
|
506
|
+
} | undefined;
|
|
507
|
+
} | {
|
|
508
|
+
parameters: {
|
|
509
|
+
name: string;
|
|
510
|
+
type: string;
|
|
511
|
+
description: string;
|
|
512
|
+
}[];
|
|
513
|
+
type: "client_event";
|
|
514
|
+
name: "scroll_to";
|
|
515
|
+
description: string;
|
|
516
|
+
_args?: {
|
|
517
|
+
target: string;
|
|
518
|
+
} | undefined;
|
|
519
|
+
} | {
|
|
520
|
+
parameters: {
|
|
521
|
+
name: string;
|
|
522
|
+
type: string;
|
|
523
|
+
description: string;
|
|
524
|
+
}[];
|
|
525
|
+
type: "client_event";
|
|
526
|
+
name: "highlight";
|
|
527
|
+
description: string;
|
|
528
|
+
_args?: {
|
|
529
|
+
target: string;
|
|
530
|
+
duration?: number;
|
|
531
|
+
} | undefined;
|
|
532
|
+
})[];
|
|
533
|
+
|
|
534
|
+
export { type ActiveSpeaker, AvatarError, type AvatarErrorCode, AvatarEvent, type AvatarEventMap, AvatarSession, type ClientEvent, type ClientEventFromTool, type ClientEventHandler, type ClientEventsFrom, type ClientToolArgs, type ClientToolDef, type ConnectResponse, type ConnectionQuality, type ConsumeSessionOptions, type ConsumeSessionResponse, FlatDeltaAccumulator, type InferSchemaInput, type InferSchemaOutput, type MediaController, type MicPermissionState, type PageActionEvent, type ScreenShareController, type SessionCredentials, type SessionKeyResponse, type SessionState, type StandardSchemaIssue, type StandardSchemaResult, type StandardSchemaV1, TranscriptAccumulator, type TranscriptOptions, type TranscriptionEntry, type TranscriptionHandler, clientTool, connect, consumeSession, getClientToolSchema, pageActionTools, parseClientEvent, streamTo, tryDecodeJSON, tryParseFlatDelta, tryParseSegmentArray, validateClientToolArgs };
|