@avatarfactory/react 0.1.40
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/LICENSE +84 -0
- package/README.md +424 -0
- package/THIRD_PARTY_LICENSES.md +316 -0
- package/dist/AvatarProvider-BXaeG3PZ.d.mts +1397 -0
- package/dist/AvatarProvider-Cll_r1hx.d.ts +1397 -0
- package/dist/chunk-E7HVSIHB.mjs +4 -0
- package/dist/chunk-HRSHBEAW.js +4 -0
- package/dist/chunk-OANDIUVQ.mjs +16 -0
- package/dist/chunk-YOMHPKHO.js +16 -0
- package/dist/embed/embed.js +12 -0
- package/dist/embed/meeting.js +93 -0
- package/dist/embed/runtime.js +101 -0
- package/dist/index.css +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/moodWorkerSource-FWBYYI2O.js +2 -0
- package/dist/moodWorkerSource-HWJNKKU5.mjs +2 -0
- package/dist/page.d.mts +52 -0
- package/dist/page.d.ts +52 -0
- package/dist/page.js +1 -0
- package/dist/page.mjs +1 -0
- package/dist/public/mood-worker.js +1 -0
- package/dist/public/pcm-worklet.js +14 -0
- package/dist/public/vad-worker.js +1 -0
- package/dist/remotePageSurface-ao95kNYE.d.mts +165 -0
- package/dist/remotePageSurface-ao95kNYE.d.ts +165 -0
- package/dist/unstable.css +1 -0
- package/dist/unstable.d.mts +461 -0
- package/dist/unstable.d.ts +461 -0
- package/dist/unstable.js +1 -0
- package/dist/unstable.mjs +1 -0
- package/dist/vadWorkerSource-SV2FM4Q3.mjs +1 -0
- package/dist/vadWorkerSource-XJPY733L.js +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,1397 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { d as PageReadResult, A as Awaitable, P as PageSurfaceCall, I as IPageSurface } from './remotePageSurface-ao95kNYE.js';
|
|
3
|
+
|
|
4
|
+
/** Error codes, grouped by who fixes it. Coarse on purpose: they split where the
|
|
5
|
+
* remedy splits, not where our internals do — detail lives in message/cause. */
|
|
6
|
+
type AvatarErrorCode =
|
|
7
|
+
/** getSessionToken() rejected or returned nothing. See `cause`. */
|
|
8
|
+
"SESSION_TOKEN_FETCH_FAILED"
|
|
9
|
+
/** Method not supported in the current mode. */
|
|
10
|
+
| "INVALID_MODE"
|
|
11
|
+
/** Bad argument: empty/oversized text, context, or audio. Call was dropped. */
|
|
12
|
+
| "INVALID_INPUT"
|
|
13
|
+
/** Method needs a live session. Call was dropped; session unaffected. */
|
|
14
|
+
| "NOT_CONNECTED"
|
|
15
|
+
/** Mic refused (call mode). Needs a browser/OS setting change, not a retry. */
|
|
16
|
+
| "MIC_PERMISSION_DENIED"
|
|
17
|
+
/** Could not reach or stay connected — open failed, transport error, or drop. */
|
|
18
|
+
| "CONNECTION_FAILED"
|
|
19
|
+
/** The service errored. `message` carries its reason. */
|
|
20
|
+
| "SERVER_ERROR"
|
|
21
|
+
/** The service ended the session deliberately (expired auth, policy). */
|
|
22
|
+
| "SERVER_CLOSE_REQUESTED"
|
|
23
|
+
/** Config or .riv could not be resolved/fetched/parsed. Nothing is painted. */
|
|
24
|
+
| "AVATAR_LOAD_FAILED"
|
|
25
|
+
/** One turn produced no response. Never fatal; the call continues. */
|
|
26
|
+
| "BRAIN_ERROR"
|
|
27
|
+
/** The server closed an idle session (4008). Offer a reconnect. */
|
|
28
|
+
| "SESSION_IDLE_TIMEOUT"
|
|
29
|
+
/** Nothing else fit. Inspect `message`/`cause`. */
|
|
30
|
+
| "UNKNOWN";
|
|
31
|
+
/** Diagnostic only — `code` is what you branch on. */
|
|
32
|
+
type AvatarErrorSource = "sdk" | "server" | "network";
|
|
33
|
+
type AvatarError = {
|
|
34
|
+
/** What went wrong, in terms of what you can do. Branch on this. */
|
|
35
|
+
code: AvatarErrorCode;
|
|
36
|
+
/** Written for developers ("Failed to fetch session token"). Log, don't render. */
|
|
37
|
+
message: string;
|
|
38
|
+
source: AvatarErrorSource;
|
|
39
|
+
cause?: unknown;
|
|
40
|
+
/** Whether the session is over. The runtime tears down off this same flag, so
|
|
41
|
+
* it can never claim the session survived when it didn't. */
|
|
42
|
+
fatal: boolean;
|
|
43
|
+
/** Whether start() could plausibly succeed; only meaningful when `fatal`. For
|
|
44
|
+
* showing a retry button — not for auto-retrying (idle would re-idle on a loop). */
|
|
45
|
+
retryable: boolean;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type CharTiming = {
|
|
49
|
+
char: string;
|
|
50
|
+
start: number;
|
|
51
|
+
end: number;
|
|
52
|
+
visemeId: number;
|
|
53
|
+
};
|
|
54
|
+
type BatchedTtsJob = {
|
|
55
|
+
/** Only the chunks that arrived since the last emit — never the whole job. */
|
|
56
|
+
audioChunks: string[];
|
|
57
|
+
alignments: (NormalizedAlignment | null)[];
|
|
58
|
+
/** Parallel to `alignments`: the server's `display_alignment` for the transcript, null
|
|
59
|
+
* where the chunk shows exactly what it says. Never drives the mouth. */
|
|
60
|
+
displayAlignments?: (NormalizedAlignment | null)[];
|
|
61
|
+
/** Parallel to `alignments`: the server's visemes for the chunk. Null where it sent none,
|
|
62
|
+
* and the renderer derives them from the alignment instead. */
|
|
63
|
+
visemes?: (CharTiming[] | null)[];
|
|
64
|
+
isGreeting?: boolean;
|
|
65
|
+
turnId: number;
|
|
66
|
+
sessionId: number;
|
|
67
|
+
jobId: number;
|
|
68
|
+
/** Absolute index of audioChunks[0] within this jobId; the dedupe key. */
|
|
69
|
+
chunkOffset: number;
|
|
70
|
+
};
|
|
71
|
+
/** A role the SDK puts the avatar in. The rig controls behind each come from the server. */
|
|
72
|
+
type PerformanceRole = "idle" | "listening" | "thinking" | "talking";
|
|
73
|
+
/** The controls one role drives. `gate` null: the role is every gate off (idle).
|
|
74
|
+
* `acts`: the act ids the role picks from; empty when `act` is null. */
|
|
75
|
+
type PerformanceBranch = {
|
|
76
|
+
gate: string | null;
|
|
77
|
+
act: string | null;
|
|
78
|
+
acts: number[];
|
|
79
|
+
/** Played instead when the rig lacks this role's gate (a rig with no thinking state). */
|
|
80
|
+
fallback?: PerformanceRole;
|
|
81
|
+
};
|
|
82
|
+
/** How the avatar moves between roles, sent by the server with the avatar config. */
|
|
83
|
+
type PerformancePolicy = {
|
|
84
|
+
version: number;
|
|
85
|
+
branches: Partial<Record<PerformanceRole, PerformanceBranch>>;
|
|
86
|
+
/** Listening with nothing from the user this long settles into idle. 0: never. */
|
|
87
|
+
quietToIdleMs: number;
|
|
88
|
+
/** While idle, a new act id this often. 0: never. */
|
|
89
|
+
idleCycleMs: number;
|
|
90
|
+
/** Idle this long turns playful: each cycle picks a role from `playfulRoles`. 0: never. */
|
|
91
|
+
playfulAfterMs: number;
|
|
92
|
+
playfulRoles: PerformanceRole[];
|
|
93
|
+
/** Thinking with no reply this long returns to listening. */
|
|
94
|
+
thinkingMaxMs: number;
|
|
95
|
+
/** A conformed rig's idle acts; replaces the idle branch and its fixed cycle when present. */
|
|
96
|
+
idleActs?: IdleActsPolicy;
|
|
97
|
+
/** The rig's playful_ gestures, one per click on the avatar; absent on a rig without any. */
|
|
98
|
+
playful?: PlayfulPolicy;
|
|
99
|
+
/** Triggers the idle rotation plays over the idle pose, each only if the rig has it (`waiting`). */
|
|
100
|
+
idleTriggers?: string[];
|
|
101
|
+
};
|
|
102
|
+
/** A playful_ timeline's trigger and its length (Blueprint 1.2). */
|
|
103
|
+
type PlayfulGesture = {
|
|
104
|
+
trigger: string;
|
|
105
|
+
ms: number;
|
|
106
|
+
};
|
|
107
|
+
/** Picked by the server in a call, by the SDK before or after one (see pickPlayfulGesture). */
|
|
108
|
+
type PlayfulPolicy = {
|
|
109
|
+
gestures: PlayfulGesture[];
|
|
110
|
+
};
|
|
111
|
+
/** One idle act: `ms` is one full cycle of its timeline (there and back for a ping-pong);
|
|
112
|
+
* `timeline` is the state name the rig reports on entering it. */
|
|
113
|
+
type IdleAct = {
|
|
114
|
+
id: number;
|
|
115
|
+
ms: number;
|
|
116
|
+
loop: "oneShot" | "loop" | "pingPong";
|
|
117
|
+
timeline?: string;
|
|
118
|
+
};
|
|
119
|
+
type IdleActsPolicy = {
|
|
120
|
+
gate: string;
|
|
121
|
+
act: string;
|
|
122
|
+
acts: IdleAct[];
|
|
123
|
+
/** Each window plays acts whole, filling at least the min and never past the max; an act
|
|
124
|
+
* longer than the max plays alone. */
|
|
125
|
+
windowMinMs: number;
|
|
126
|
+
windowMaxMs: number;
|
|
127
|
+
};
|
|
128
|
+
type ViewModelEntry = {
|
|
129
|
+
index: number;
|
|
130
|
+
name: string;
|
|
131
|
+
properties: Record<string, string | number | boolean>;
|
|
132
|
+
};
|
|
133
|
+
/** How a semantic action name (e.g. "wave") maps to a rig property/input.
|
|
134
|
+
* Delivered per-avatar in avatar_config so rig-internal names stay server-side. */
|
|
135
|
+
type GestureBinding = {
|
|
136
|
+
/** Rig property/input name to drive, e.g. "GestureWave". */
|
|
137
|
+
input: string;
|
|
138
|
+
/** Firing mechanism. Defaults to the rig's pipelineMode when omitted. */
|
|
139
|
+
binding?: "data-binding" | "input";
|
|
140
|
+
/** Property kind. Defaults to "trigger" (one-shot). */
|
|
141
|
+
type?: "trigger" | "boolean" | "number";
|
|
142
|
+
/** Value for boolean/number types. Defaults to 1 (true). */
|
|
143
|
+
value?: number;
|
|
144
|
+
/** For boolean types: auto-reset to false after this many ms. */
|
|
145
|
+
resetMs?: number;
|
|
146
|
+
/** Data-binding rigs only: ms after firing before the rig is returned to
|
|
147
|
+
* "normal". Defaults to {@link GESTURE_RETURN_MS}; too short truncates the pose. */
|
|
148
|
+
returnMs?: number;
|
|
149
|
+
};
|
|
150
|
+
/** Semantic action name → rig binding, e.g. { wave: { input: "GestureWave" } }. */
|
|
151
|
+
type GestureMap = Record<string, GestureBinding>;
|
|
152
|
+
type RiveRenderConfig = {
|
|
153
|
+
artboard: string;
|
|
154
|
+
stateMachine: string;
|
|
155
|
+
layout: {
|
|
156
|
+
[key: string]: string;
|
|
157
|
+
};
|
|
158
|
+
viewModel?: ViewModelEntry[];
|
|
159
|
+
gestures?: GestureMap;
|
|
160
|
+
};
|
|
161
|
+
/** A property of the `.riv`, tuned by an admin against that rig's own geometry — never
|
|
162
|
+
* user-editable. */
|
|
163
|
+
type LipSyncMotionConfig = {
|
|
164
|
+
offsetMs: number;
|
|
165
|
+
mouthSpeed: number;
|
|
166
|
+
/** Jaw-only multiplier, applied on top of `mouthSpeed`. 1 leaves the jaw
|
|
167
|
+
* moving at whatever `mouthSpeed` already sets. */
|
|
168
|
+
jawSpeed: number;
|
|
169
|
+
mouthOpenness: number;
|
|
170
|
+
mouthHold: number;
|
|
171
|
+
mouthRest: number;
|
|
172
|
+
};
|
|
173
|
+
/** Three layers with three owners: `visemeMs` shapes the viseme data before any engine
|
|
174
|
+
* sees it, `smoothing` is forwarded to the TTS provider. */
|
|
175
|
+
type LipSyncConfig = {
|
|
176
|
+
visemeMs?: number;
|
|
177
|
+
smoothing?: number;
|
|
178
|
+
} & Partial<LipSyncMotionConfig>;
|
|
179
|
+
/** Painted config the renderer consumes: the cacheable render body plus the locally
|
|
180
|
+
* resolved blob `src` and the session-applied `watermark`. */
|
|
181
|
+
type AvatarConfigFromServer = {
|
|
182
|
+
avatarId: string;
|
|
183
|
+
configVersion?: number;
|
|
184
|
+
pipelineMode?: "data-binding" | "input";
|
|
185
|
+
rive: RiveRenderConfig & {
|
|
186
|
+
src: string;
|
|
187
|
+
/** Applied fresh each connect from the payload's session-level watermark. */
|
|
188
|
+
watermark?: boolean;
|
|
189
|
+
};
|
|
190
|
+
lipSync?: LipSyncConfig;
|
|
191
|
+
performance?: PerformancePolicy;
|
|
192
|
+
rivUrl?: string;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
type NormalizedAlignment = {
|
|
196
|
+
characters: string[];
|
|
197
|
+
character_start_times_seconds: number[];
|
|
198
|
+
character_end_times_seconds: number[];
|
|
199
|
+
};
|
|
200
|
+
type AvatarSpeech = {
|
|
201
|
+
audioChunks: string[];
|
|
202
|
+
alignments: NormalizedAlignment[];
|
|
203
|
+
isGreeting?: boolean;
|
|
204
|
+
};
|
|
205
|
+
/** Language of the avatar's built-in greeting text. */
|
|
206
|
+
type GreetingLanguage = "en" | "es" | "fr" | "de" | "hi" | "ru" | "pt" | "ja" | "it";
|
|
207
|
+
/** Opening line the avatar speaks once the session goes live. */
|
|
208
|
+
type GreetingConfig = {
|
|
209
|
+
enabled: boolean;
|
|
210
|
+
/** Overrides the built-in greeting text. */
|
|
211
|
+
message?: string;
|
|
212
|
+
language?: GreetingLanguage;
|
|
213
|
+
};
|
|
214
|
+
/** Ringback played while the session connects — the "waiting for someone to pick
|
|
215
|
+
* up" tone. Stops once the avatar is painted AND the session is live. */
|
|
216
|
+
type ConnectToneConfig = {
|
|
217
|
+
/** Default false — the tone plays only when asked for. */
|
|
218
|
+
enabled: boolean;
|
|
219
|
+
/** URL or data URI. Omit for the built-in ringtone. Web only; RN has no decoder
|
|
220
|
+
* and always plays the built-in. */
|
|
221
|
+
src?: string;
|
|
222
|
+
/** Loop until the connect completes. Default true. */
|
|
223
|
+
loop?: boolean;
|
|
224
|
+
/** 0–1. Default 0.4 — a ringback sits under the conversation, not over it. */
|
|
225
|
+
volume?: number;
|
|
226
|
+
/** Fade-out on stop, in ms. Default 350 — a hard cut clicks. */
|
|
227
|
+
fadeOutMs?: number;
|
|
228
|
+
};
|
|
229
|
+
type AvatarMode = "tts" | "audio" | "call";
|
|
230
|
+
/** Adds the unpublished `player` mode. Reachable only through each platform
|
|
231
|
+
* package's `/unstable` entry — the public `.d.ts` must never name it. */
|
|
232
|
+
type AvatarModeWithPlayer = AvatarMode | "player";
|
|
233
|
+
/** How the avatar is mounted, reported in `init`. Declared by the component that
|
|
234
|
+
* renders it. Says nothing about framing; `init.framed` is the separate fact. */
|
|
235
|
+
type AvatarSurface = "widget" | "inline";
|
|
236
|
+
/** Where the page itself runs. `"meeting"`: a bot's browser in a Zoom/Meet/Teams call,
|
|
237
|
+
* with no user to click, whose tab is the bot's camera and whose audio is its voice. */
|
|
238
|
+
type AvatarEnvironment = "meeting";
|
|
239
|
+
/** Who decides a turn is over: `"auto"` the server's endpointer, from the audio;
|
|
240
|
+
* `"push-to-talk"` the user, by holding a button. Call mode only. */
|
|
241
|
+
type TurnTakingMode = "auto" | "push-to-talk";
|
|
242
|
+
/** Distinct from {@link AvatarMode}: `mode` is what kind of conversation this is,
|
|
243
|
+
* `turnTaking` is who ends a turn inside it. */
|
|
244
|
+
type TurnTakingConfig = {
|
|
245
|
+
/** Default `"auto"`. */
|
|
246
|
+
mode?: TurnTakingMode;
|
|
247
|
+
/** Hold spacebar as well as the button. Web only, default true. Set false when
|
|
248
|
+
* the host page binds space itself — the SDK swallows the key while connected. */
|
|
249
|
+
spacebar?: boolean;
|
|
250
|
+
/** Hold back mic audio that could be the avatar's own echo. Default true; turn off
|
|
251
|
+
* only where the mic source already excludes the avatar's voice. */
|
|
252
|
+
echoGate?: boolean;
|
|
253
|
+
/** Detect barge-in on the device. Default true. False leaves interruption to the
|
|
254
|
+
* server's own end-of-speech detection and claims no sensor here. */
|
|
255
|
+
clientBargeIn?: boolean;
|
|
256
|
+
};
|
|
257
|
+
type TtsProvider = "elevenlabs" | "inworld";
|
|
258
|
+
/** Known LLM vendors. Open-ended: the server validates, so newer
|
|
259
|
+
* providers can be passed as a plain string without an SDK release. */
|
|
260
|
+
type BrainProvider = "openai" | "anthropic" | "groq";
|
|
261
|
+
/** Selects the LLM ("brain") that powers the conversation. */
|
|
262
|
+
type AvatarBrain = {
|
|
263
|
+
provider: BrainProvider | (string & {});
|
|
264
|
+
model?: string;
|
|
265
|
+
/** Bill LLM work to your own vendor key instead of ours. The key is resolved
|
|
266
|
+
* server-side from your account — never passed through the SDK. */
|
|
267
|
+
useOwnBrain?: boolean;
|
|
268
|
+
};
|
|
269
|
+
/** Supported conversation languages (ISO 639-1 codes).
|
|
270
|
+
* Closed set for now; the server defaults to English when omitted. */
|
|
271
|
+
type AvatarLanguage = "en" | "es" | "fr" | "de" | "hi" | "ru" | "pt" | "ja" | "it" | "nl";
|
|
272
|
+
/** Language(s) the conversation may use: `"auto"` (server detects/switches) or a
|
|
273
|
+
* fixed list of {@link AvatarLanguage}s. Omitted → server defaults to English. */
|
|
274
|
+
type AvatarLanguages = "auto" | AvatarLanguage[];
|
|
275
|
+
/** What the notice is about. Open-ended so the server can add kinds without an
|
|
276
|
+
* SDK release; the known set today is demo/plan/test key expiry. */
|
|
277
|
+
type NoticeKind = "demo" | "plan" | "test" | (string & {});
|
|
278
|
+
/** What the consumer's CTA should offer in response to a notice. */
|
|
279
|
+
type NoticeAction = "add_key" | "upgrade" | (string & {});
|
|
280
|
+
/** A non-fatal, server-initiated message the avatar speaks (e.g. limit reached).
|
|
281
|
+
* Distinct from AvatarError: the session isn't failing, it's ending gracefully. */
|
|
282
|
+
type SessionNotice = {
|
|
283
|
+
kind: NoticeKind;
|
|
284
|
+
action?: NoticeAction;
|
|
285
|
+
message: string;
|
|
286
|
+
};
|
|
287
|
+
/** Fault domains health can be about. `ingest`/`downlink` are the user's to act
|
|
288
|
+
* on; the rest are our/vendor legs. `downlink` is written only by the client's
|
|
289
|
+
* own watchdog — a report of a jam cannot travel through the jam it describes. */
|
|
290
|
+
type HealthService = "ingest" | "stt" | "llm" | "tts" | "downlink";
|
|
291
|
+
/** `degraded` still works, slower or lossy; `failed` does not. Neither is fatal:
|
|
292
|
+
* the session stays open and the server drives recovery back to `ok`. */
|
|
293
|
+
type HealthState = "ok" | "degraded" | "failed";
|
|
294
|
+
/** The blame-resolved conclusion the UI should show, or null when all is well.
|
|
295
|
+
* `scope` is the actionability axis: `network` is the user's to fix, `device` their
|
|
296
|
+
* machine, `service` ours. A bad link suppresses downstream faults as its symptoms. */
|
|
297
|
+
type HealthConcern = {
|
|
298
|
+
scope: "network" | "device" | "service";
|
|
299
|
+
service: HealthService;
|
|
300
|
+
state: Exclude<HealthState, "ok">;
|
|
301
|
+
/** Exact fault code — a log/dashboard join key, not for logic. */
|
|
302
|
+
code?: string;
|
|
303
|
+
} | null;
|
|
304
|
+
/** Live view of connection health: one state per service plus the blame-resolved
|
|
305
|
+
* `concern` the banner renders from. Recomputed on every `stream_health`. */
|
|
306
|
+
type ConnectionHealth = {
|
|
307
|
+
services: Record<HealthService, HealthState>;
|
|
308
|
+
concern: HealthConcern;
|
|
309
|
+
};
|
|
310
|
+
/** The banner anchors to one of the four corners (no center). */
|
|
311
|
+
type StatusBannerPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
312
|
+
/** Built-in connectivity banner, driven by `stream_health`. On by default; pass
|
|
313
|
+
* `{ enabled: false }` to render your own from `useAvatar().health`. */
|
|
314
|
+
type StatusBannerConfig = {
|
|
315
|
+
/** Default true — the banner shows unless explicitly disabled. */
|
|
316
|
+
enabled?: boolean;
|
|
317
|
+
/** Anchor corner for the banner. Default "bottom-left". */
|
|
318
|
+
position?: StatusBannerPosition;
|
|
319
|
+
};
|
|
320
|
+
/** Where the thinking indicator is anchored inside the avatar frame. Same anchor
|
|
321
|
+
* set as captions. */
|
|
322
|
+
type ThinkingIndicatorPosition = CaptionPosition;
|
|
323
|
+
/** Built-in thinking indicator, shown only when a turn is dragging. A liveness cue,
|
|
324
|
+
* not a warning. On by default; `useAvatar().isResponseSlow` drives a custom one. */
|
|
325
|
+
type ThinkingIndicatorConfig = {
|
|
326
|
+
/** Default true — the indicator shows unless explicitly disabled. */
|
|
327
|
+
enabled?: boolean;
|
|
328
|
+
/** Anchor for the indicator. Default "top-left" — a top corner stays visible
|
|
329
|
+
* over custom controls, which sit at the bottom. */
|
|
330
|
+
position?: ThinkingIndicatorPosition;
|
|
331
|
+
};
|
|
332
|
+
/** Where the screen-share prompt and "sharing" pill sit inside the avatar frame. */
|
|
333
|
+
type ScreenSharePosition = CaptionPosition;
|
|
334
|
+
/** The built-in screen-share UI (React only), shown when `perception.screen` is on. */
|
|
335
|
+
type ScreenShareUiConfig = {
|
|
336
|
+
/** Default "top-center", clear of the default bottom-center captions; move it when
|
|
337
|
+
* your captions sit at the top. The bottom anchors lift clear of the controls bar. */
|
|
338
|
+
position?: ScreenSharePosition;
|
|
339
|
+
};
|
|
340
|
+
/** Who produced a transcript line. Only user lines are tagged in the UI. */
|
|
341
|
+
type TranscriptSpeaker = "user" | "avatar";
|
|
342
|
+
/** A word and when it is heard, in seconds on the utterance's audio clock.
|
|
343
|
+
* Avatar words carry real timings (from the TTS alignment); user words don't —
|
|
344
|
+
* their speech has already been said by the time the ASR result lands. */
|
|
345
|
+
type TranscriptWord = {
|
|
346
|
+
text: string;
|
|
347
|
+
start: number;
|
|
348
|
+
end: number;
|
|
349
|
+
};
|
|
350
|
+
/** One line of the conversation. Rewritten in place while it grows (interim ASR
|
|
351
|
+
* or an in-flight TTS utterance), then closed with `isFinal`. */
|
|
352
|
+
type TranscriptEntry = {
|
|
353
|
+
id: string;
|
|
354
|
+
speaker: TranscriptSpeaker;
|
|
355
|
+
text: string;
|
|
356
|
+
words: TranscriptWord[];
|
|
357
|
+
isFinal: boolean;
|
|
358
|
+
turnId: number;
|
|
359
|
+
createdAt: number;
|
|
360
|
+
};
|
|
361
|
+
/** Where the caption overlay is anchored inside the avatar frame. */
|
|
362
|
+
type CaptionPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
363
|
+
/** Live transcript of the conversation. Off unless `enabled` — no transcript is
|
|
364
|
+
* assembled and no captions are rendered. */
|
|
365
|
+
type TranscriptConfig = {
|
|
366
|
+
enabled: boolean;
|
|
367
|
+
/** Render the built-in caption overlay. Set false to keep the transcript data
|
|
368
|
+
* but draw your own UI from `useAvatar().transcript`. Default true. */
|
|
369
|
+
captions?: boolean;
|
|
370
|
+
/** Anchor for the caption overlay. Default "bottom-center". The bottom anchors
|
|
371
|
+
* lift clear of the controls bar when it is on screen. */
|
|
372
|
+
position?: CaptionPosition;
|
|
373
|
+
/** Lines retained in `transcript`. Default 50. */
|
|
374
|
+
maxEntries?: number;
|
|
375
|
+
};
|
|
376
|
+
interface AvatarEventMap {
|
|
377
|
+
start: () => void;
|
|
378
|
+
stop: () => void;
|
|
379
|
+
interrupt: () => void;
|
|
380
|
+
error: (error: AvatarError) => void;
|
|
381
|
+
speaking: () => void;
|
|
382
|
+
ready: () => void;
|
|
383
|
+
/** A graceful, server-initiated notice (limit/plan/test-key). The avatar will
|
|
384
|
+
* speak it and the session then closes — not an error. */
|
|
385
|
+
notice: (notice: SessionNotice) => void;
|
|
386
|
+
/** The conversation transcript, re-emitted as a snapshot on every change.
|
|
387
|
+
* Only fires when `transcript.enabled` is set on the config. */
|
|
388
|
+
transcript: (entries: TranscriptEntry[]) => void;
|
|
389
|
+
/** Connection health, re-emitted on every `stream_health` message. Carries the
|
|
390
|
+
* full per-service map and the blame-resolved `concern` for the banner. */
|
|
391
|
+
health: (health: ConnectionHealth) => void;
|
|
392
|
+
}
|
|
393
|
+
type AvatarVoiceSettings = {
|
|
394
|
+
provider?: TtsProvider;
|
|
395
|
+
voiceId?: string;
|
|
396
|
+
useOwnVoice?: boolean;
|
|
397
|
+
visimeMs?: number;
|
|
398
|
+
voiceSpeed?: number;
|
|
399
|
+
voiceStability?: number;
|
|
400
|
+
similarityBoost?: number;
|
|
401
|
+
/** Per-rig mouth motion for this session only, overriding the saved values.
|
|
402
|
+
* Applied on emit and never persisted — for trying a rig before saving it. */
|
|
403
|
+
lipSync?: Partial<LipSyncMotionConfig>;
|
|
404
|
+
};
|
|
405
|
+
type LiveContextArgs = {
|
|
406
|
+
context: string;
|
|
407
|
+
update?: boolean;
|
|
408
|
+
};
|
|
409
|
+
/** When an app event is allowed to take a turn. `idle_only` is the default: an avatar
|
|
410
|
+
* that talks over the user because they scrolled is worse than one that stays quiet. */
|
|
411
|
+
type AppEventPolicy = "idle_only" | "queue" | "interrupt" | "context_only";
|
|
412
|
+
/** Something the user did in the host app, offered to the avatar as a turn. */
|
|
413
|
+
type AppEventArgs = {
|
|
414
|
+
/** Stable slug (`^[a-z0-9][a-z0-9_.]{0,63}$`), never prose — it is what the
|
|
415
|
+
* brain is told happened. */
|
|
416
|
+
name: string;
|
|
417
|
+
/** Structured detail, serialized and fenced as untrusted reference data. */
|
|
418
|
+
data?: Record<string, unknown> | string;
|
|
419
|
+
/** Default `"idle_only"`. */
|
|
420
|
+
policy?: AppEventPolicy;
|
|
421
|
+
/** Speak this verbatim and skip the brain. An escape hatch for scripted lines;
|
|
422
|
+
* the brain-mediated form is what keeps the avatar in persona. */
|
|
423
|
+
say?: string;
|
|
424
|
+
/** Per-name gap before this event may fire again. */
|
|
425
|
+
cooldownMs?: number;
|
|
426
|
+
};
|
|
427
|
+
type ActionParamType = "string" | "email" | "phone" | "date" | "datetime" | "number" | "boolean" | "enum";
|
|
428
|
+
/** `date` arrives as `YYYY-MM-DD` and `datetime` as `YYYY-MM-DDTHH:mm:ss`, both the
|
|
429
|
+
* user's local time with no zone — `new Date(value)` already reads them as local. */
|
|
430
|
+
type ActionParam = {
|
|
431
|
+
type: ActionParamType;
|
|
432
|
+
/** ≤ 120 chars, written for the model. */
|
|
433
|
+
description?: string;
|
|
434
|
+
/** Default `true`. */
|
|
435
|
+
required?: boolean;
|
|
436
|
+
/** `enum` only, 1–20 values. */
|
|
437
|
+
values?: string[];
|
|
438
|
+
/** Vet each value with the action's `check` before it is read back (a slot still
|
|
439
|
+
* free). Needs a `check` function; not for lookups. */
|
|
440
|
+
check?: boolean;
|
|
441
|
+
};
|
|
442
|
+
/** What the host's `check` says about one value. `suggestions` are alternatives in the
|
|
443
|
+
* param's own type (for a `datetime`, `YYYY-MM-DDTHH:mm:ss`), which the avatar offers.
|
|
444
|
+
* `param` names another param as what is wrong (a product that needs its option
|
|
445
|
+
* chosen): the checked value is kept, and the avatar asks for that one instead.
|
|
446
|
+
* A passing `value` is the host's own name for it ("any" → "Blue"), read back instead;
|
|
447
|
+
* `null` says it adds nothing, and an optional param is left out of the read-back. */
|
|
448
|
+
type ActionCheckResult = {
|
|
449
|
+
ok: true;
|
|
450
|
+
value?: unknown;
|
|
451
|
+
} | {
|
|
452
|
+
ok: false;
|
|
453
|
+
reason?: string;
|
|
454
|
+
suggestions?: unknown[];
|
|
455
|
+
param?: string;
|
|
456
|
+
};
|
|
457
|
+
/** `"lookup"` only finds something out, so it runs at once, without a read-back or a
|
|
458
|
+
* yes. It must change nothing: the server cannot tell. */
|
|
459
|
+
type ActionKind = "action" | "lookup";
|
|
460
|
+
/** What the host shows on screen for this action. Hints for the avatar ("you can also
|
|
461
|
+
* type it"); input is accepted for any declared param either way. */
|
|
462
|
+
type ActionUi = {
|
|
463
|
+
/** Params the host shows an input for, or `"*"` for all of them. */
|
|
464
|
+
inputs?: string[] | "*";
|
|
465
|
+
/** The host shows the details with Confirm / Cancel during the read-back. */
|
|
466
|
+
review?: boolean;
|
|
467
|
+
};
|
|
468
|
+
/** Every stage the server reports. New stages may arrive from a newer server; a card
|
|
469
|
+
* should ignore one it does not know. */
|
|
470
|
+
type ActionFlowStage = "collecting" | "review" | "running" | "done" | "cancelled" | "expired" | (string & {});
|
|
471
|
+
/** What the avatar is waiting for right now: the cue for which card to show. */
|
|
472
|
+
type ActionAwaiting = {
|
|
473
|
+
kind: "input";
|
|
474
|
+
param: string;
|
|
475
|
+
type: ActionParamType;
|
|
476
|
+
description?: string;
|
|
477
|
+
values?: string[];
|
|
478
|
+
} | {
|
|
479
|
+
kind: "check";
|
|
480
|
+
param: string;
|
|
481
|
+
} | {
|
|
482
|
+
kind: "confirm";
|
|
483
|
+
} | {
|
|
484
|
+
kind: string & {};
|
|
485
|
+
[key: string]: unknown;
|
|
486
|
+
};
|
|
487
|
+
/** One action from its first question to its outcome, as the server last reported it.
|
|
488
|
+
* The whole state every time, never a diff. */
|
|
489
|
+
type ActionFlow = {
|
|
490
|
+
actionId: string;
|
|
491
|
+
/** Rises on every report. Confirm sends it back, so a card showing old details
|
|
492
|
+
* cannot agree to new ones. */
|
|
493
|
+
revision: number;
|
|
494
|
+
name: string;
|
|
495
|
+
stage: ActionFlowStage;
|
|
496
|
+
/** Exact values so far, in the shapes the handler receives. */
|
|
497
|
+
args: Record<string, unknown>;
|
|
498
|
+
missing: string[];
|
|
499
|
+
awaiting: ActionAwaiting | null;
|
|
500
|
+
/** On `"done"`: how the handler's run went, in its own words. */
|
|
501
|
+
outcome?: {
|
|
502
|
+
ok: boolean;
|
|
503
|
+
message: string;
|
|
504
|
+
};
|
|
505
|
+
};
|
|
506
|
+
/** Something the user did on the host's screen during a flow. */
|
|
507
|
+
type ActionUiOp = "input" | "confirm" | "cancel";
|
|
508
|
+
/** Passed to a handler. `signal` aborts when the client gives up on the run. */
|
|
509
|
+
type ActionContext = {
|
|
510
|
+
callId: string;
|
|
511
|
+
signal: AbortSignal;
|
|
512
|
+
};
|
|
513
|
+
/** `result` / `error` are what the avatar is told happened, so write them as plain
|
|
514
|
+
* words. Both are capped at 1000 chars. */
|
|
515
|
+
type ActionResult = {
|
|
516
|
+
ok: true;
|
|
517
|
+
result?: string;
|
|
518
|
+
} | {
|
|
519
|
+
ok: false;
|
|
520
|
+
error: string;
|
|
521
|
+
};
|
|
522
|
+
/** Something the avatar can do in the host app once the user has said yes to the
|
|
523
|
+
* details. Only `name`, `description` and `params` leave the device. */
|
|
524
|
+
type ActionDefinition = {
|
|
525
|
+
/** `^[a-z][a-z0-9_]{0,63}$` — becomes an LLM tool name, so no dots. */
|
|
526
|
+
name: string;
|
|
527
|
+
/** ≤ 300 chars: what it does, written for the model. */
|
|
528
|
+
description: string;
|
|
529
|
+
/** ≤ 8. Names match `^[a-zA-Z][a-zA-Z0-9_]{0,39}$`. */
|
|
530
|
+
params?: Record<string, ActionParam>;
|
|
531
|
+
/** Default `"action"`: read back and confirmed before it runs. */
|
|
532
|
+
kind?: ActionKind;
|
|
533
|
+
/** The user can undo it themselves in a tap, like a cart edit. Asked for outright, it
|
|
534
|
+
* runs without the read-back; in every other case it is still confirmed first. */
|
|
535
|
+
undoable?: boolean;
|
|
536
|
+
ui?: ActionUi;
|
|
537
|
+
/** Runs only after the user confirmed these exact args (a lookup: at once). A throw is
|
|
538
|
+
* reported as a failure. */
|
|
539
|
+
handler: (args: Record<string, unknown>, context: ActionContext) => Promise<ActionResult> | ActionResult;
|
|
540
|
+
/** Vets a `check: true` param's value before the read-back. Gets 2.5s; a throw or a
|
|
541
|
+
* timeout lets the value through, so keep the handler's own re-check. */
|
|
542
|
+
check?: (param: string, value: unknown, args: Record<string, unknown>) => Promise<ActionCheckResult> | ActionCheckResult;
|
|
543
|
+
};
|
|
544
|
+
/** Opt-in perception. Camera is OFF unless the operator enables it, and even then
|
|
545
|
+
* the SDK opens it only just-in-time, on a server `request_vision`. */
|
|
546
|
+
type PerceptionConfig = {
|
|
547
|
+
camera?: boolean;
|
|
548
|
+
/** Screen sharing on a server `request_screen`. Desktop browsers only; every share
|
|
549
|
+
* goes through the browser's own picker. */
|
|
550
|
+
screen?: boolean;
|
|
551
|
+
};
|
|
552
|
+
/** Outcome of a server `command`, sent back as `command_status`. "unsupported" =
|
|
553
|
+
* unknown command or the platform can't do it; "failed" = tried and errored. */
|
|
554
|
+
type CommandOutcome = "ok" | "failed" | "unsupported";
|
|
555
|
+
/** One axis of a commanded move, shared by `[widget]` and `[scroll]`. `relative`
|
|
556
|
+
* moves from where the thing stands; absolute is a destination. `percent` reads
|
|
557
|
+
* against the viewport, except an absolute scroll, which uses the scroll range. */
|
|
558
|
+
type AxisMove = {
|
|
559
|
+
value: number;
|
|
560
|
+
percent: boolean;
|
|
561
|
+
relative: boolean;
|
|
562
|
+
};
|
|
563
|
+
/** Two independent axes: the session (isIdle → isConnecting → isConnected) and
|
|
564
|
+
* the avatar (isReady/isLoading/isFailed). Never infer one from the other. */
|
|
565
|
+
interface UseAvatarResult {
|
|
566
|
+
/** The avatar is on screen and animating. The paint axis — unaffected by a
|
|
567
|
+
* session starting or ending. */
|
|
568
|
+
isReady: boolean;
|
|
569
|
+
/** The avatar is still coming up: resolving config, or painting. Paint axis. */
|
|
570
|
+
isLoading: boolean;
|
|
571
|
+
/** start() is in flight — token, config, socket, and init ack, end to end. */
|
|
572
|
+
isConnecting: boolean;
|
|
573
|
+
isConnected: boolean;
|
|
574
|
+
isSpeaking: boolean;
|
|
575
|
+
isListening: boolean;
|
|
576
|
+
/** The avatar is processing the user's turn (server thinking), between
|
|
577
|
+
* listening and speaking. */
|
|
578
|
+
isThinking: boolean;
|
|
579
|
+
/** The current turn is slow (LLM/TTS), not broken. Auto-clears when speech starts
|
|
580
|
+
* or the turn ends. */
|
|
581
|
+
isResponseSlow: boolean;
|
|
582
|
+
/** No session; start() is available. Says nothing about the avatar — true
|
|
583
|
+
* while it is still loading, since start() waits the load out. */
|
|
584
|
+
isIdle: boolean;
|
|
585
|
+
/** The avatar could not be loaded; nothing is on screen. Paint axis, so it survives
|
|
586
|
+
* a session ending. */
|
|
587
|
+
isFailed: boolean;
|
|
588
|
+
/** Outbound audio is dropped, so the server hears silence. "call" mode only. */
|
|
589
|
+
isMicMuted: boolean;
|
|
590
|
+
/** True while the avatar's spoken audio is muted (silent playback; lip-sync
|
|
591
|
+
* still animates). */
|
|
592
|
+
isSpeakerMuted: boolean;
|
|
593
|
+
/** Mute/unmute the user's mic. */
|
|
594
|
+
setMicMuted: (muted: boolean) => void;
|
|
595
|
+
/** Mute/unmute the avatar's spoken audio. */
|
|
596
|
+
setSpeakerMuted: (muted: boolean) => void;
|
|
597
|
+
/** This session can read the user's mood: a call with `perception.camera` and the
|
|
598
|
+
* avatar's camera grant. Web only. Show a custom "Detect mood" toggle only while true. */
|
|
599
|
+
isMoodDetectionAvailable: boolean;
|
|
600
|
+
/** The user's "Detect mood" switch, off until they turn it on. Reads happen only while on
|
|
601
|
+
* and the camera is live; the built-in self-view switch shares this state. */
|
|
602
|
+
isMoodDetectionOn: boolean;
|
|
603
|
+
/** Flip the "Detect mood" switch. The server is told, so the avatar answers "you
|
|
604
|
+
* turned it off" rather than guessing. */
|
|
605
|
+
setMoodDetection: (on: boolean) => void;
|
|
606
|
+
/** `turnTaking.mode` is `"push-to-talk"`. Static for the session. */
|
|
607
|
+
isPushToTalk: boolean;
|
|
608
|
+
/** The user is holding the talk button, so their audio is reaching the server. */
|
|
609
|
+
isTalking: boolean;
|
|
610
|
+
/** The press: start uploading mic audio, cutting the avatar off if it was speaking. */
|
|
611
|
+
startTalking: () => void;
|
|
612
|
+
/** The release: end the user's turn. No-op if no turn is open. */
|
|
613
|
+
stopTalking: () => void;
|
|
614
|
+
avatarId?: string;
|
|
615
|
+
error: AvatarError | null;
|
|
616
|
+
controls: {
|
|
617
|
+
enabled: boolean;
|
|
618
|
+
stopSpeaking?: boolean;
|
|
619
|
+
};
|
|
620
|
+
on<E extends keyof AvatarEventMap>(event: E, handler: AvatarEventMap[E]): void;
|
|
621
|
+
off<E extends keyof AvatarEventMap>(event: E, handler: AvatarEventMap[E]): void;
|
|
622
|
+
start(): void;
|
|
623
|
+
speakText?: (sentence: string) => void;
|
|
624
|
+
speakAudio?: (audio: ArrayBuffer | Float32Array | Blob) => void;
|
|
625
|
+
addLiveContext?: (args: LiveContextArgs) => void;
|
|
626
|
+
/** Tell the avatar something happened in the host app, so it can take a turn about
|
|
627
|
+
* it unprompted. Rate-limited; a dropped event is logged, never thrown. */
|
|
628
|
+
notify?: (event: AppEventArgs) => void;
|
|
629
|
+
/** Read the host page into a handle index and send it as page context. Null when
|
|
630
|
+
* the platform has no page surface, or no page is reachable. Runs on its own on connect. */
|
|
631
|
+
readPage?: () => Promise<PageReadResult | null>;
|
|
632
|
+
/** Offer the avatar an action it can run once the user confirms the details.
|
|
633
|
+
* Returns the unregister function. `useAvatarAction` wraps this for components. */
|
|
634
|
+
registerAction?: (action: ActionDefinition) => () => void;
|
|
635
|
+
/** Fire a rig gesture by name (must be one of `availableActions`). */
|
|
636
|
+
triggerAction?: (name: string) => void;
|
|
637
|
+
/** Retune the rig's mouth motion live. Lands on the next animation frame, mid
|
|
638
|
+
* sentence if need be; nothing is persisted and nothing reaches the server. */
|
|
639
|
+
setLipSyncTuning?: (tuning: Partial<LipSyncMotionConfig>) => void;
|
|
640
|
+
/** Gesture names the loaded rig advertises via avatar_config. */
|
|
641
|
+
availableActions?: string[];
|
|
642
|
+
/** Last server notice (limit/plan/test-key), or null. Drives the CTA. */
|
|
643
|
+
notice?: SessionNotice | null;
|
|
644
|
+
/** `health.concern` is the blame-resolved banner state (null when all is ok);
|
|
645
|
+
* `health.services` is the raw per-service map. Interactive modes only. */
|
|
646
|
+
health?: ConnectionHealth;
|
|
647
|
+
/** Conversation lines, oldest first. Empty unless `transcript.enabled`. */
|
|
648
|
+
transcript?: TranscriptEntry[];
|
|
649
|
+
stop(): void;
|
|
650
|
+
interrupt(): void;
|
|
651
|
+
/** Cut the avatar off mid-sentence and go back to listening. A manual interrupt. */
|
|
652
|
+
stopSpeaking(): void;
|
|
653
|
+
}
|
|
654
|
+
/** The `/unstable` entry's hook result: adds `play()`, which only `player` mode
|
|
655
|
+
* answers. Same object at runtime — the public result just cannot name it. */
|
|
656
|
+
interface UseAvatarResultWithPlayer extends UseAvatarResult {
|
|
657
|
+
play?(job: AvatarSpeech): void;
|
|
658
|
+
}
|
|
659
|
+
type AvatarConfigBase = {
|
|
660
|
+
mode?: AvatarMode;
|
|
661
|
+
/** Who ends a turn. Session wiring, not `avatar`: the same avatar can run
|
|
662
|
+
* hands-free in one app and push-to-talk in another. */
|
|
663
|
+
turnTaking?: TurnTakingConfig;
|
|
664
|
+
/** A preset for where the page runs; it defaults the options below and anything set
|
|
665
|
+
* here explicitly still wins. */
|
|
666
|
+
environment?: AvatarEnvironment;
|
|
667
|
+
/** Call `start()` on mount. Default false — the start normally needs a user gesture
|
|
668
|
+
* for audio to play. */
|
|
669
|
+
autoStart?: boolean;
|
|
670
|
+
debug?: boolean;
|
|
671
|
+
controls?: {
|
|
672
|
+
enabled: boolean;
|
|
673
|
+
/** A "stop talking" button in the built-in controls, shown only while the avatar
|
|
674
|
+
* speaks. Off by default; `useAvatar().stopSpeaking()` drives a custom one. */
|
|
675
|
+
stopSpeaking?: boolean;
|
|
676
|
+
};
|
|
677
|
+
perception?: PerceptionConfig;
|
|
678
|
+
transcript?: TranscriptConfig;
|
|
679
|
+
statusBanner?: StatusBannerConfig;
|
|
680
|
+
thinkingIndicator?: ThinkingIndicatorConfig;
|
|
681
|
+
screenShare?: ScreenShareUiConfig;
|
|
682
|
+
connectTone?: ConnectToneConfig;
|
|
683
|
+
avatar: {
|
|
684
|
+
avatarId: string;
|
|
685
|
+
layout?: Record<string, string>;
|
|
686
|
+
voiceSettings?: AvatarVoiceSettings;
|
|
687
|
+
brain?: AvatarBrain;
|
|
688
|
+
languages?: AvatarLanguages;
|
|
689
|
+
systemPrompt?: string;
|
|
690
|
+
greeting?: GreetingConfig;
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
/** Exactly one of the three credentials. Named so both config shapes below share
|
|
694
|
+
* it — intersecting a union member-by-member is what keeps them discriminated. */
|
|
695
|
+
type AvatarCredentials = {
|
|
696
|
+
apiKey: string;
|
|
697
|
+
getSessionToken?: never;
|
|
698
|
+
deployId?: never;
|
|
699
|
+
} | {
|
|
700
|
+
getSessionToken: () => Promise<string>;
|
|
701
|
+
apiKey?: never;
|
|
702
|
+
deployId?: never;
|
|
703
|
+
} | {
|
|
704
|
+
deployId: string;
|
|
705
|
+
apiKey?: never;
|
|
706
|
+
getSessionToken?: never;
|
|
707
|
+
};
|
|
708
|
+
type AvatarConfig = AvatarConfigBase & AvatarCredentials;
|
|
709
|
+
/** The `/unstable` entry's config: identical, plus `player` mode. */
|
|
710
|
+
type AvatarConfigWithPlayer = Omit<AvatarConfigBase, "mode"> & {
|
|
711
|
+
mode?: AvatarModeWithPlayer;
|
|
712
|
+
} & AvatarCredentials;
|
|
713
|
+
|
|
714
|
+
/** Corner the widget docks to. No center anchors — a launcher lives in a corner. */
|
|
715
|
+
type WidgetPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
716
|
+
/** "avatar" idles the real rig and is the differentiator; "poster" is a still image. */
|
|
717
|
+
type WidgetLauncherStyle = "avatar" | "poster" | "icon";
|
|
718
|
+
/** "sheet" takes the viewport, "corner" keeps the desktop treatment. */
|
|
719
|
+
type WidgetMobileMode = "sheet" | "corner";
|
|
720
|
+
/** Distinct from session state: a widget can be "expanded" with no session. */
|
|
721
|
+
type WidgetStage = "dormant" | "expanding" | "expanded" | "connecting" | "live" | "ended";
|
|
722
|
+
/** The nine places on a screen a person names. Unlike {@link WidgetPosition} — the corner
|
|
723
|
+
* an operator docks to — these are where the avatar can send itself. */
|
|
724
|
+
type WidgetSpot = "top-left" | "top-center" | "top-right" | "middle-left" | "center" | "middle-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
725
|
+
/** "forever" has to be asked for by name — a bare `bounce` is one gesture, not a loop. */
|
|
726
|
+
type WidgetBounce = number | "forever";
|
|
727
|
+
/** What the avatar was asked to do to its own widget. Core parses, the platform performs.
|
|
728
|
+
* An axis left undefined stays where it is. */
|
|
729
|
+
type WidgetAction = {
|
|
730
|
+
kind: "spot";
|
|
731
|
+
spot: WidgetSpot;
|
|
732
|
+
} | {
|
|
733
|
+
kind: "move";
|
|
734
|
+
x?: AxisMove;
|
|
735
|
+
y?: AxisMove;
|
|
736
|
+
} | {
|
|
737
|
+
kind: "stage";
|
|
738
|
+
open: boolean;
|
|
739
|
+
}
|
|
740
|
+
/** Split from `stop` so `times` exists only on the arm where it means something. */
|
|
741
|
+
| {
|
|
742
|
+
kind: "effect";
|
|
743
|
+
effect: "bounce";
|
|
744
|
+
times: WidgetBounce;
|
|
745
|
+
} | {
|
|
746
|
+
kind: "effect";
|
|
747
|
+
effect: "stop";
|
|
748
|
+
};
|
|
749
|
+
/** The pill beside the collapsed bubble. Silent — audio before a user gesture is
|
|
750
|
+
* impossible, so attract behaviour is visual. Its click is the bubble's click. */
|
|
751
|
+
type WidgetTeaser = {
|
|
752
|
+
text: string;
|
|
753
|
+
delayMs?: number;
|
|
754
|
+
};
|
|
755
|
+
type WidgetPanelSize = {
|
|
756
|
+
w: number;
|
|
757
|
+
h: number;
|
|
758
|
+
};
|
|
759
|
+
type WidgetOffset = {
|
|
760
|
+
x: number;
|
|
761
|
+
y: number;
|
|
762
|
+
};
|
|
763
|
+
/** Every field is optional and defaulted, so a deployment that sets none still renders. */
|
|
764
|
+
type WidgetAppearance = {
|
|
765
|
+
position?: WidgetPosition;
|
|
766
|
+
offset?: WidgetOffset;
|
|
767
|
+
bubbleSize?: number;
|
|
768
|
+
panel?: WidgetPanelSize;
|
|
769
|
+
/** Ring, controls and focus colour. Falls back to an avatar-derived tone. */
|
|
770
|
+
accent?: string;
|
|
771
|
+
/** Panel backdrop once expanded. The collapsed launcher stays transparent so the rig
|
|
772
|
+
* composites onto the host page. */
|
|
773
|
+
panelBackground?: string;
|
|
774
|
+
/** Fraction of the panel the rig fills, 0–1. Below 1 it is inset so gestures reaching
|
|
775
|
+
* outside the body are not clipped. */
|
|
776
|
+
avatarScale?: number;
|
|
777
|
+
/** Once moved it stops docking to `position`, and the panel expands from where dropped. */
|
|
778
|
+
draggable?: boolean;
|
|
779
|
+
launcher?: WidgetLauncherStyle;
|
|
780
|
+
/** Shown before the rig decodes, and as the whole launcher when style is "poster". */
|
|
781
|
+
posterUrl?: string;
|
|
782
|
+
teaser?: WidgetTeaser;
|
|
783
|
+
mobile?: WidgetMobileMode;
|
|
784
|
+
/** Default 2147483000 — just under the max, so a host can still win if it must. */
|
|
785
|
+
zIndex?: number;
|
|
786
|
+
};
|
|
787
|
+
/** Each maps onto an existing runtime config; the widget does not invent its own. */
|
|
788
|
+
type WidgetBehaviour = {
|
|
789
|
+
greeting?: GreetingConfig;
|
|
790
|
+
connectTone?: ConnectToneConfig;
|
|
791
|
+
transcript?: TranscriptConfig;
|
|
792
|
+
};
|
|
793
|
+
/** Everything defaults to off: a deployment that sets nothing here reads nothing at all. */
|
|
794
|
+
type WidgetContextPolicy = {
|
|
795
|
+
/** Tier 0 — path, title, description, h1. Off unless explicitly enabled. */
|
|
796
|
+
pageIdentity?: boolean;
|
|
797
|
+
stripQuery?: boolean;
|
|
798
|
+
/** Tier 2 — scoped body extraction. Empty means no body reading, ever. */
|
|
799
|
+
selectors?: string[];
|
|
800
|
+
};
|
|
801
|
+
/** Spend ceilings. Advisory on the client; the server enforces them. */
|
|
802
|
+
type WidgetLimits = {
|
|
803
|
+
maxSessionMinutes?: number;
|
|
804
|
+
maxConcurrent?: number;
|
|
805
|
+
};
|
|
806
|
+
/** Resolved from props on the React path, or the deployment document on the embed path. */
|
|
807
|
+
type WidgetConfig = {
|
|
808
|
+
appearance?: WidgetAppearance;
|
|
809
|
+
behaviour?: WidgetBehaviour;
|
|
810
|
+
context?: WidgetContextPolicy;
|
|
811
|
+
limits?: WidgetLimits;
|
|
812
|
+
/** Played on a visitor's first click, after the greeting. Plain data, so a deployment
|
|
813
|
+
* can carry one as well as a prop. */
|
|
814
|
+
tour?: WidgetTour;
|
|
815
|
+
};
|
|
816
|
+
/** A strict allowlist: never ownerId, budgets, usage, or the raw document. */
|
|
817
|
+
type WidgetDeploymentProjection = {
|
|
818
|
+
deployId: string;
|
|
819
|
+
avatarId: string;
|
|
820
|
+
mode: AvatarMode;
|
|
821
|
+
/** Bumped on every deployment edit — drives config and .riv cache invalidation. */
|
|
822
|
+
configVersion: number;
|
|
823
|
+
} & WidgetConfig;
|
|
824
|
+
/** Single source of truth for defaults, shared by the SDK and the platform so the builder
|
|
825
|
+
* preview and the live widget cannot disagree. */
|
|
826
|
+
declare const WIDGET_DEFAULTS: {
|
|
827
|
+
readonly position: WidgetPosition;
|
|
828
|
+
readonly offset: WidgetOffset;
|
|
829
|
+
readonly bubbleSize: 64;
|
|
830
|
+
readonly panel: WidgetPanelSize;
|
|
831
|
+
readonly panelBackground: "#F4F2EE";
|
|
832
|
+
/** Cover crops to fill, so a rig gesturing past its body meets the frame edge. */
|
|
833
|
+
readonly avatarScale: 0.6;
|
|
834
|
+
readonly draggable: false;
|
|
835
|
+
readonly launcher: "avatar";
|
|
836
|
+
readonly mobile: WidgetMobileMode;
|
|
837
|
+
readonly zIndex: 2147483000;
|
|
838
|
+
readonly teaserDelayMs: 8000;
|
|
839
|
+
readonly mobileBreakpointPx: 640;
|
|
840
|
+
readonly stripQuery: true;
|
|
841
|
+
readonly maxSessionMinutes: 15;
|
|
842
|
+
};
|
|
843
|
+
/** Fold partial appearance over the defaults so every consumer resolves identically. */
|
|
844
|
+
declare const resolveWidgetAppearance: (appearance?: WidgetAppearance) => Required<Pick<WidgetAppearance, "position" | "offset" | "bubbleSize" | "panel" | "panelBackground" | "avatarScale" | "draggable" | "launcher" | "mobile" | "zIndex">> & WidgetAppearance;
|
|
845
|
+
|
|
846
|
+
/** The side of the target the avatar stands on; it points the other way ("above" points down). */
|
|
847
|
+
type TourSide = "above" | "below" | "left" | "right";
|
|
848
|
+
/** Something to stand beside. Text alone lets the avatar pick the side that fits. */
|
|
849
|
+
type TourTarget = {
|
|
850
|
+
target: string;
|
|
851
|
+
from?: TourSide;
|
|
852
|
+
};
|
|
853
|
+
/** Where a step puts the avatar. At most one — it can't stand in two places. */
|
|
854
|
+
type TourStepPlace = {
|
|
855
|
+
point?: string | TourTarget;
|
|
856
|
+
go?: never;
|
|
857
|
+
spot?: never;
|
|
858
|
+
} | {
|
|
859
|
+
go?: string | TourTarget;
|
|
860
|
+
point?: never;
|
|
861
|
+
spot?: never;
|
|
862
|
+
} | {
|
|
863
|
+
spot?: WidgetSpot;
|
|
864
|
+
point?: never;
|
|
865
|
+
go?: never;
|
|
866
|
+
};
|
|
867
|
+
/** A highlight swept behind the text as it is said. `strong` is for the one thing the
|
|
868
|
+
* visitor must not miss. */
|
|
869
|
+
type TourHighlight = {
|
|
870
|
+
target: string;
|
|
871
|
+
strong?: boolean;
|
|
872
|
+
};
|
|
873
|
+
/** One sentence, and what to show while it is said. Targets are the page's visible
|
|
874
|
+
* text; every action runs as the sentence starts. */
|
|
875
|
+
type TourStep = TourStepPlace & {
|
|
876
|
+
say: string;
|
|
877
|
+
/** Text alone means a normal highlight of that text. */
|
|
878
|
+
highlight?: string | TourHighlight;
|
|
879
|
+
/** Scroll this into view without moving the avatar. */
|
|
880
|
+
scroll?: string;
|
|
881
|
+
/** A rig gesture; ignored by a rig without it. */
|
|
882
|
+
gesture?: string;
|
|
883
|
+
};
|
|
884
|
+
/** A guided tour the widget plays on a visitor's first click. `steps` wins; `generate`
|
|
885
|
+
* writes one from the page when no steps are given. */
|
|
886
|
+
type WidgetTour = {
|
|
887
|
+
steps?: TourStep[];
|
|
888
|
+
generate?: boolean;
|
|
889
|
+
/** Said while the avatar returns to its corner and the page scrolls to the top.
|
|
890
|
+
* `false` ends silently. */
|
|
891
|
+
closing?: string | false;
|
|
892
|
+
/** "visitor" remembers across visits, "session" for this tab only, false replays. */
|
|
893
|
+
once?: "visitor" | "session" | false;
|
|
894
|
+
/** The avatar's greeting before the tour (default true). `false` lets the tour open the
|
|
895
|
+
* session instead; every later session greets as configured. */
|
|
896
|
+
greeting?: boolean;
|
|
897
|
+
/** Any CSS colour for the highlighter. `strong` uses it as given, a normal highlight a
|
|
898
|
+
* lighter tint of it. Default: marker yellow. */
|
|
899
|
+
highlightColor?: string;
|
|
900
|
+
};
|
|
901
|
+
type TourState = "idle" | "starting" | "playing" | "done";
|
|
902
|
+
|
|
903
|
+
declare enum SessionPhase {
|
|
904
|
+
Idle = "idle",// no session; start() is available
|
|
905
|
+
Connecting = "connecting",// start() in flight: token → config → socket → init ack
|
|
906
|
+
Active = "active"
|
|
907
|
+
}
|
|
908
|
+
declare enum PaintPhase {
|
|
909
|
+
None = "none",// nothing resolved yet
|
|
910
|
+
Loading = "loading",// resolving avatar config + riv asset
|
|
911
|
+
Painted = "painted",// config resolved; the avatar can render
|
|
912
|
+
Failed = "failed"
|
|
913
|
+
}
|
|
914
|
+
declare enum TurnPhase {
|
|
915
|
+
Idle = "idle",
|
|
916
|
+
Greeting = "greeting",
|
|
917
|
+
Listening = "listening",
|
|
918
|
+
Thinking = "thinking",
|
|
919
|
+
Speaking = "speaking"
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
type BrowserAction = "search" | "open" | "new_tab" | "switch" | "close" | "reload";
|
|
923
|
+
type BrowserCommand = {
|
|
924
|
+
action: BrowserAction;
|
|
925
|
+
target?: string;
|
|
926
|
+
};
|
|
927
|
+
/** `not_found`: no open tab matches. `blocked`: not a web address it may open. */
|
|
928
|
+
type BrowserOutcome = "ok" | "not_found" | "blocked" | "failed";
|
|
929
|
+
/** Tabs and search around the page, for a host that drives the browser itself (the
|
|
930
|
+
* Chrome extension). Its presence is what tells the server it may send them. */
|
|
931
|
+
interface IBrowserHost {
|
|
932
|
+
run(command: BrowserCommand): Awaitable<BrowserOutcome>;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/** `kept` is the server's sealed snapshot from the page before, sent back once in init.
|
|
936
|
+
* `onState` gets each newer one, for the host page to hold. */
|
|
937
|
+
type EmbedResume = {
|
|
938
|
+
kept?: {
|
|
939
|
+
token: string;
|
|
940
|
+
led: boolean;
|
|
941
|
+
};
|
|
942
|
+
onState: (token: string) => void;
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
interface AvatarPublicProps {
|
|
946
|
+
className?: string;
|
|
947
|
+
style?: React.CSSProperties;
|
|
948
|
+
/** Shown while the avatar is still resolving. */
|
|
949
|
+
loader?: React.ReactNode;
|
|
950
|
+
/** Shown when the avatar failed to load at all. A session that ends after the
|
|
951
|
+
* avatar is painted keeps the avatar, so it never reaches this. */
|
|
952
|
+
errorFallback?: React.ReactNode;
|
|
953
|
+
captionClassName?: string;
|
|
954
|
+
captionStyle?: React.CSSProperties;
|
|
955
|
+
/** Styling hooks for the status banner (shown when statusBanner.enabled is on). */
|
|
956
|
+
statusBannerClassName?: string;
|
|
957
|
+
statusBannerStyle?: React.CSSProperties;
|
|
958
|
+
/** Styling hooks for the thinking indicator (shown unless thinkingIndicator.enabled is false). */
|
|
959
|
+
thinkingIndicatorClassName?: string;
|
|
960
|
+
thinkingIndicatorStyle?: React.CSSProperties;
|
|
961
|
+
/** Styling hooks for the screen-share prompt and pill (shown when perception.screen is on). */
|
|
962
|
+
screenShareClassName?: string;
|
|
963
|
+
screenShareStyle?: React.CSSProperties;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
type CameraPreviewCorner = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
967
|
+
|
|
968
|
+
type AvatarProps = {
|
|
969
|
+
className?: string;
|
|
970
|
+
style?: React.CSSProperties;
|
|
971
|
+
loader?: React.ReactNode;
|
|
972
|
+
errorFallback?: React.ReactNode;
|
|
973
|
+
/** Where the self-view sits while the camera session is open. Ignored in PiP. */
|
|
974
|
+
cameraPreviewCorner?: CameraPreviewCorner;
|
|
975
|
+
/** Hide the built-in self-view. Discouraged: it is how the user sees the camera is on. */
|
|
976
|
+
hideCameraPreview?: boolean;
|
|
977
|
+
/** Camera on the stage, avatar in the corner. Takes precedence over the two above. */
|
|
978
|
+
usePictureInPicture?: boolean;
|
|
979
|
+
/** Avatar's corner in PiP. Independent of `cameraPreviewCorner`. */
|
|
980
|
+
pictureInPictureCorner?: CameraPreviewCorner;
|
|
981
|
+
/** Styling hooks for the caption overlay (shown when transcript.captions is on). */
|
|
982
|
+
captionClassName?: string;
|
|
983
|
+
captionStyle?: React.CSSProperties;
|
|
984
|
+
/** Styling hooks for the status banner (shown when statusBanner.enabled is on). */
|
|
985
|
+
statusBannerClassName?: string;
|
|
986
|
+
statusBannerStyle?: React.CSSProperties;
|
|
987
|
+
/** Styling hooks for the thinking indicator (shown unless thinkingIndicator.enabled is false). */
|
|
988
|
+
thinkingIndicatorClassName?: string;
|
|
989
|
+
thinkingIndicatorStyle?: React.CSSProperties;
|
|
990
|
+
/** Styling hooks for the screen-share prompt and pill (shown when perception.screen is on). */
|
|
991
|
+
screenShareClassName?: string;
|
|
992
|
+
screenShareStyle?: React.CSSProperties;
|
|
993
|
+
/** Overrides the server's rive fit. Leave unset to use what the avatar was published
|
|
994
|
+
* with. */
|
|
995
|
+
fit?: string;
|
|
996
|
+
};
|
|
997
|
+
declare const Avatar: (props: AvatarProps) => react_jsx_runtime.JSX.Element;
|
|
998
|
+
|
|
999
|
+
type AvatarConnectingLoaderProps = {
|
|
1000
|
+
/** Word spelled out under the orb. Letters animate one per character. */
|
|
1001
|
+
label?: string;
|
|
1002
|
+
className?: string;
|
|
1003
|
+
style?: React.CSSProperties;
|
|
1004
|
+
};
|
|
1005
|
+
/** Rotating orb with the label spelled out inside it. Sized off a container
|
|
1006
|
+
* query, so one node works in a 64px bubble and a full-bleed stage. */
|
|
1007
|
+
declare const AvatarConnectingLoader: ({ label, className, style, }: AvatarConnectingLoaderProps) => react_jsx_runtime.JSX.Element;
|
|
1008
|
+
|
|
1009
|
+
type WidgetBox = {
|
|
1010
|
+
w: number;
|
|
1011
|
+
h: number;
|
|
1012
|
+
position: WidgetPosition;
|
|
1013
|
+
/** True when the panel has taken the viewport instead of docking to a corner. */
|
|
1014
|
+
sheet: boolean;
|
|
1015
|
+
/** Null means the corner in `position` still docks it. The embed loader positions
|
|
1016
|
+
* from this. */
|
|
1017
|
+
left: number | null;
|
|
1018
|
+
top: number | null;
|
|
1019
|
+
/** Embed only: the transparent margin the frame keeps around the widget for its shadow. */
|
|
1020
|
+
gutter?: number;
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
type TargetRect = {
|
|
1024
|
+
left: number;
|
|
1025
|
+
top: number;
|
|
1026
|
+
width: number;
|
|
1027
|
+
height: number;
|
|
1028
|
+
};
|
|
1029
|
+
/** The page a tour runs on when it is not this document — the embed's host page. The
|
|
1030
|
+
* avatar's frame follows it there, placed from where the host reports each target. */
|
|
1031
|
+
type TourPage = {
|
|
1032
|
+
/** What a played tour is remembered under. */
|
|
1033
|
+
seenKey: string;
|
|
1034
|
+
/** Where the target landed in the host viewport, or null when the page lacked it. */
|
|
1035
|
+
scroll: (target: string) => Promise<TargetRect | null>;
|
|
1036
|
+
mark: (target: string, strong: boolean) => Promise<boolean>;
|
|
1037
|
+
clear: () => void;
|
|
1038
|
+
scrollTop: () => void;
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
type AvatarWidgetProps = WidgetConfig & {
|
|
1042
|
+
/** Panel heading. Defaults to nothing — most widgets don't need one. */
|
|
1043
|
+
title?: string;
|
|
1044
|
+
/** Label for the collapsed launcher, read by screen readers. */
|
|
1045
|
+
launcherLabel?: string;
|
|
1046
|
+
/** Mode-driven panel affordance (a text composer for tts, say). In call mode the
|
|
1047
|
+
* widget's own call dock fills it unless this is passed. */
|
|
1048
|
+
composer?: React.ReactNode;
|
|
1049
|
+
/** Omit to let the widget own it; pass this only to hold the state yourself. */
|
|
1050
|
+
open?: boolean;
|
|
1051
|
+
onOpenChange?: (open: boolean) => void;
|
|
1052
|
+
/** Default true — and it must ride that same gesture, or autoplay policy leaves the
|
|
1053
|
+
* avatar mute. */
|
|
1054
|
+
autoStart?: boolean;
|
|
1055
|
+
/** Fires on every box change. The embed loader resizes the iframe from this. */
|
|
1056
|
+
onResize?: (box: WidgetBox) => void;
|
|
1057
|
+
onStageChange?: (stage: WidgetStage) => void;
|
|
1058
|
+
/** Only honoured while expanded — the collapsed bubble is too small for two views. */
|
|
1059
|
+
usePictureInPicture?: boolean;
|
|
1060
|
+
/** Embed runtime only: the host page's viewport, since inside the iframe `window` is
|
|
1061
|
+
* the widget's own box. */
|
|
1062
|
+
hostViewport?: {
|
|
1063
|
+
w: number;
|
|
1064
|
+
h: number;
|
|
1065
|
+
};
|
|
1066
|
+
/** Embed runtime only: the loader moves the iframe wherever this box says, so the widget
|
|
1067
|
+
* docks inside the frame and is dragged in host-page coordinates. */
|
|
1068
|
+
framed?: boolean;
|
|
1069
|
+
/** Embed runtime only: the host page the tour scrolls and highlights. */
|
|
1070
|
+
tourPage?: TourPage;
|
|
1071
|
+
className?: string;
|
|
1072
|
+
style?: React.CSSProperties;
|
|
1073
|
+
};
|
|
1074
|
+
declare const AvatarWidget: ({ appearance, title, launcherLabel, composer, open, onOpenChange, autoStart, onResize, onStageChange, usePictureInPicture, hostViewport, framed, tour, tourPage, className, style, }: AvatarWidgetProps) => react_jsx_runtime.JSX.Element;
|
|
1075
|
+
|
|
1076
|
+
type UseAvatarWidgetResult = {
|
|
1077
|
+
/** Panel expanded. Independent of the session: a call survives a collapse. */
|
|
1078
|
+
isOpen: boolean;
|
|
1079
|
+
stage: WidgetStage;
|
|
1080
|
+
open: () => void;
|
|
1081
|
+
close: () => void;
|
|
1082
|
+
toggle: () => void;
|
|
1083
|
+
/** Expand and connect in one task. Call it from a real click handler — a session
|
|
1084
|
+
* started outside a user gesture connects but stays mute under autoplay policy. */
|
|
1085
|
+
openAndStart: () => void;
|
|
1086
|
+
tourState: TourState;
|
|
1087
|
+
/** Plays the widget's `tour`, seen or not. From a click, for the same autoplay reason. */
|
|
1088
|
+
startTour: () => void;
|
|
1089
|
+
stopTour: () => void;
|
|
1090
|
+
};
|
|
1091
|
+
/** Programmatic control of the widget's presentation. Session control stays on
|
|
1092
|
+
* `useAvatar()` — start/stop/interrupt work from anywhere under the provider. */
|
|
1093
|
+
declare function useAvatarWidget(): UseAvatarWidgetResult;
|
|
1094
|
+
|
|
1095
|
+
/** An action as the loader declares it. The handler and check stay in the host page. */
|
|
1096
|
+
type BridgeActionDeclaration = Omit<ActionDefinition, "handler" | "check">;
|
|
1097
|
+
/** What the page embedding the avatar chose on its script tag. Every field is optional,
|
|
1098
|
+
* and the runtime re-checks each one: the host page is not trusted with anything else. */
|
|
1099
|
+
type EmbedHostConfig = {
|
|
1100
|
+
/** "inline" fills a box in the page; the default is the floating widget. */
|
|
1101
|
+
layout?: "widget" | "inline";
|
|
1102
|
+
/** Laid over the deployment's own appearance. */
|
|
1103
|
+
appearance?: Pick<WidgetAppearance, "position" | "offset" | "bubbleSize" | "panel" | "accent" | "draggable" | "mobile">;
|
|
1104
|
+
/** A tour written from the page, on a visitor's first click. Every page load is a new
|
|
1105
|
+
* frame, so "session" is the most often a multi-page site can replay it. */
|
|
1106
|
+
tour?: {
|
|
1107
|
+
once: "visitor" | "session";
|
|
1108
|
+
};
|
|
1109
|
+
/** The page answers `page.call`, so the avatar can read and scroll it. */
|
|
1110
|
+
pageAccess?: boolean;
|
|
1111
|
+
};
|
|
1112
|
+
/** Where a tour's target stands in the host viewport once scrolled to. */
|
|
1113
|
+
type TourRect = {
|
|
1114
|
+
left: number;
|
|
1115
|
+
top: number;
|
|
1116
|
+
width: number;
|
|
1117
|
+
height: number;
|
|
1118
|
+
};
|
|
1119
|
+
/** What a tour asks of the host page: it holds the text the steps name. */
|
|
1120
|
+
type TourPageOp = {
|
|
1121
|
+
op: "scroll";
|
|
1122
|
+
target: string;
|
|
1123
|
+
} | {
|
|
1124
|
+
op: "mark";
|
|
1125
|
+
target: string;
|
|
1126
|
+
strong: boolean;
|
|
1127
|
+
color?: string;
|
|
1128
|
+
} | {
|
|
1129
|
+
op: "clear";
|
|
1130
|
+
} | {
|
|
1131
|
+
op: "top";
|
|
1132
|
+
};
|
|
1133
|
+
/** The only two constants both documents must agree on. Bump BRIDGE_VERSION only
|
|
1134
|
+
* for a breaking envelope change — the receiver drops mismatched versions. */
|
|
1135
|
+
declare const BRIDGE_NAMESPACE: "avatarfactory";
|
|
1136
|
+
declare const BRIDGE_VERSION: 1;
|
|
1137
|
+
/** Loader → runtime. A closed allowlist: anything else is dropped, not forwarded. */
|
|
1138
|
+
type LoaderMessage = {
|
|
1139
|
+
type: "host.info";
|
|
1140
|
+
payload: {
|
|
1141
|
+
url: string;
|
|
1142
|
+
viewport: {
|
|
1143
|
+
w: number;
|
|
1144
|
+
h: number;
|
|
1145
|
+
};
|
|
1146
|
+
reducedMotion: boolean;
|
|
1147
|
+
theme?: "light" | "dark";
|
|
1148
|
+
frameLayout?: number;
|
|
1149
|
+
config?: EmbedHostConfig;
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
/** Answers one `page.call`: the host page's surface method's return, or why it failed. */
|
|
1153
|
+
| {
|
|
1154
|
+
type: "page.result";
|
|
1155
|
+
payload: {
|
|
1156
|
+
callId: string;
|
|
1157
|
+
ok: boolean;
|
|
1158
|
+
value?: unknown;
|
|
1159
|
+
error?: string;
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
/** The host page navigated in place, so the avatar's read of it is stale. */
|
|
1163
|
+
| {
|
|
1164
|
+
type: "page.changed";
|
|
1165
|
+
payload: Record<string, never>;
|
|
1166
|
+
}
|
|
1167
|
+
/** Answers one `tour.do`: whether the page had the text the step named, and where it is. */
|
|
1168
|
+
| {
|
|
1169
|
+
type: "tour.result";
|
|
1170
|
+
payload: {
|
|
1171
|
+
seq: number;
|
|
1172
|
+
found: boolean;
|
|
1173
|
+
rect?: TourRect;
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
/** Replaces the page-state snapshot. Tier 0 or Tier 1. */
|
|
1177
|
+
| {
|
|
1178
|
+
type: "context.set";
|
|
1179
|
+
payload: {
|
|
1180
|
+
context: string;
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
/** Appends a discrete event, leaving the snapshot in place. */
|
|
1184
|
+
| {
|
|
1185
|
+
type: "context.event";
|
|
1186
|
+
payload: {
|
|
1187
|
+
name: string;
|
|
1188
|
+
context: string;
|
|
1189
|
+
};
|
|
1190
|
+
} | {
|
|
1191
|
+
type: "cmd.open";
|
|
1192
|
+
payload: Record<string, never>;
|
|
1193
|
+
} | {
|
|
1194
|
+
type: "cmd.close";
|
|
1195
|
+
payload: Record<string, never>;
|
|
1196
|
+
} | {
|
|
1197
|
+
type: "cmd.start";
|
|
1198
|
+
payload: Record<string, never>;
|
|
1199
|
+
} | {
|
|
1200
|
+
type: "cmd.stop";
|
|
1201
|
+
payload: Record<string, never>;
|
|
1202
|
+
} | {
|
|
1203
|
+
type: "cmd.destroy";
|
|
1204
|
+
payload: Record<string, never>;
|
|
1205
|
+
}
|
|
1206
|
+
/** Replaces the whole set. The runtime registers each as a local action whose
|
|
1207
|
+
* handler relays `action.run` back here. */
|
|
1208
|
+
| {
|
|
1209
|
+
type: "action.set";
|
|
1210
|
+
payload: {
|
|
1211
|
+
actions: BridgeActionDeclaration[];
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
/** Answers one `action.run`. A late or missing one is the runtime's timeout, not ours. */
|
|
1215
|
+
| {
|
|
1216
|
+
type: "action.result";
|
|
1217
|
+
payload: {
|
|
1218
|
+
callId: string;
|
|
1219
|
+
ok: boolean;
|
|
1220
|
+
result?: string;
|
|
1221
|
+
error?: string;
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
/** The host page's own card: a typed detail, Confirm or Cancel. */
|
|
1225
|
+
| {
|
|
1226
|
+
type: "action.ui";
|
|
1227
|
+
payload: {
|
|
1228
|
+
op: ActionUiOp;
|
|
1229
|
+
args?: Record<string, unknown>;
|
|
1230
|
+
name?: string;
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
/** Answers one `action.check`. Late or missing lets the value through, unverified. */
|
|
1234
|
+
| {
|
|
1235
|
+
type: "action.check_result";
|
|
1236
|
+
payload: {
|
|
1237
|
+
checkId: string;
|
|
1238
|
+
ok: boolean;
|
|
1239
|
+
reason?: string;
|
|
1240
|
+
suggestions?: unknown[];
|
|
1241
|
+
param?: string;
|
|
1242
|
+
value?: unknown;
|
|
1243
|
+
};
|
|
1244
|
+
};
|
|
1245
|
+
type RuntimeMessage = {
|
|
1246
|
+
type: "ready";
|
|
1247
|
+
payload: {
|
|
1248
|
+
configVersion: number;
|
|
1249
|
+
mode: string;
|
|
1250
|
+
position: WidgetPosition;
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
/** `offset` is the deployment's, paid by the loader when it docks the frame. `left`/`top`
|
|
1254
|
+
* are the widget's host-viewport spot once moved, and `gutter` the transparent margin
|
|
1255
|
+
* around it inside the frame; both only for a loader announcing FRAME_LAYOUT_FREE. */
|
|
1256
|
+
| {
|
|
1257
|
+
type: "resize";
|
|
1258
|
+
payload: {
|
|
1259
|
+
w: number;
|
|
1260
|
+
h: number;
|
|
1261
|
+
position: WidgetPosition;
|
|
1262
|
+
sheet: boolean;
|
|
1263
|
+
offset: WidgetOffset;
|
|
1264
|
+
left?: number | null;
|
|
1265
|
+
top?: number | null;
|
|
1266
|
+
gutter?: number;
|
|
1267
|
+
};
|
|
1268
|
+
} | {
|
|
1269
|
+
type: "state";
|
|
1270
|
+
payload: {
|
|
1271
|
+
stage: WidgetStage;
|
|
1272
|
+
};
|
|
1273
|
+
} | {
|
|
1274
|
+
type: "event";
|
|
1275
|
+
payload: {
|
|
1276
|
+
name: string;
|
|
1277
|
+
detail?: Record<string, unknown>;
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
/** One-time install verification, plus any CSP breakage worth surfacing. */
|
|
1281
|
+
| {
|
|
1282
|
+
type: "beacon";
|
|
1283
|
+
payload: {
|
|
1284
|
+
origin: string;
|
|
1285
|
+
blocked?: "wasm" | "worker" | "socket";
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
/** The user confirmed these args; run the host page's handler. */
|
|
1289
|
+
| {
|
|
1290
|
+
type: "action.run";
|
|
1291
|
+
payload: {
|
|
1292
|
+
callId: string;
|
|
1293
|
+
name: string;
|
|
1294
|
+
args: Record<string, unknown>;
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
/** Every change to the live action flow, so the host page can render its own cards. */
|
|
1298
|
+
| {
|
|
1299
|
+
type: "action.flow";
|
|
1300
|
+
payload: {
|
|
1301
|
+
flow: ActionFlow | null;
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
/** Vet one value with the host page's `check` before it is read back. */
|
|
1305
|
+
| {
|
|
1306
|
+
type: "action.check";
|
|
1307
|
+
payload: {
|
|
1308
|
+
checkId: string;
|
|
1309
|
+
name: string;
|
|
1310
|
+
param: string;
|
|
1311
|
+
value: unknown;
|
|
1312
|
+
args: Record<string, unknown>;
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
/** Run one page-surface method on the host page. Refused unless it set `pageAccess`. */
|
|
1316
|
+
| {
|
|
1317
|
+
type: "page.call";
|
|
1318
|
+
payload: {
|
|
1319
|
+
callId: string;
|
|
1320
|
+
call: PageSurfaceCall;
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
/** One step of a tour, shown on the host page. */
|
|
1324
|
+
| {
|
|
1325
|
+
type: "tour.do";
|
|
1326
|
+
payload: {
|
|
1327
|
+
seq: number;
|
|
1328
|
+
} & TourPageOp;
|
|
1329
|
+
};
|
|
1330
|
+
type BridgeMessage = LoaderMessage | RuntimeMessage;
|
|
1331
|
+
type BridgeEnvelope<M extends BridgeMessage = BridgeMessage> = {
|
|
1332
|
+
ns: typeof BRIDGE_NAMESPACE;
|
|
1333
|
+
v: typeof BRIDGE_VERSION;
|
|
1334
|
+
deployId: string;
|
|
1335
|
+
} & M;
|
|
1336
|
+
declare const buildEnvelope: <M extends BridgeMessage>(deployId: string, message: M) => BridgeEnvelope<M>;
|
|
1337
|
+
/** The single validation gate for anything crossing the origin boundary. A message must
|
|
1338
|
+
* clear every check to be acted on — a page can host other frames as well as ours. */
|
|
1339
|
+
declare const parseBridgeMessage: <M extends BridgeMessage>(event: MessageEvent, expect: {
|
|
1340
|
+
origin: string;
|
|
1341
|
+
deployId: string;
|
|
1342
|
+
direction: "from-loader" | "from-runtime";
|
|
1343
|
+
source?: MessageEventSource | null;
|
|
1344
|
+
}) => M | null;
|
|
1345
|
+
/** Always an explicit targetOrigin — never "*", in either document. */
|
|
1346
|
+
declare const postBridgeMessage: <M extends BridgeMessage>(target: Window, targetOrigin: string, deployId: string, message: M) => void;
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* subscribe to an avatar event with automatic cleanup.
|
|
1350
|
+
*/
|
|
1351
|
+
declare function useAvatarEvent<E extends keyof AvatarEventMap>(event: E, handler: AvatarEventMap[E]): void;
|
|
1352
|
+
|
|
1353
|
+
/** Offer the avatar an action while this component is mounted. A new handler closure
|
|
1354
|
+
* is picked up without re-declaring; only a schema change re-sends the declaration. */
|
|
1355
|
+
declare function useAvatarAction(action: ActionDefinition): void;
|
|
1356
|
+
|
|
1357
|
+
type UseAvatarActionFlowResult = {
|
|
1358
|
+
/** The live flow, or null. Render a card from `flow.stage` and `flow.awaiting`. */
|
|
1359
|
+
flow: ActionFlow | null;
|
|
1360
|
+
/** Send what the user typed or picked. Starts the action if none is in progress. */
|
|
1361
|
+
input: (args: Record<string, unknown>) => boolean;
|
|
1362
|
+
/** The user tapped Confirm on the details shown. */
|
|
1363
|
+
confirm: () => boolean;
|
|
1364
|
+
/** The user backed out, at any stage before the run. */
|
|
1365
|
+
cancel: () => boolean;
|
|
1366
|
+
};
|
|
1367
|
+
/** An action's progress for the host's own UI: which detail the avatar is asking for,
|
|
1368
|
+
* the read-back, the run, the outcome. With `name`, only that action's flow. Voice
|
|
1369
|
+
* keeps working whether or not anything here is rendered. */
|
|
1370
|
+
declare function useAvatarActionFlow(name?: string): UseAvatarActionFlowResult;
|
|
1371
|
+
|
|
1372
|
+
/** The page the avatar reads and acts on, when it is not this document (an extension's
|
|
1373
|
+
* tab). Read once at construction, like the rest of the runtime's adapters. */
|
|
1374
|
+
type PageHost = {
|
|
1375
|
+
surface: IPageSurface;
|
|
1376
|
+
/** Calls back whenever the page changed under the avatar; returns the unsubscribe. */
|
|
1377
|
+
watch: (onChange: () => void) => () => void;
|
|
1378
|
+
/** The call goes live only once the server holds this page. */
|
|
1379
|
+
pageBeforeLive?: boolean;
|
|
1380
|
+
/** Tabs and search around the page, for a host that drives the browser. */
|
|
1381
|
+
browser?: IBrowserHost;
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
type AvatarProviderProps = {
|
|
1385
|
+
config: AvatarConfig;
|
|
1386
|
+
children: React.ReactNode;
|
|
1387
|
+
};
|
|
1388
|
+
/** `pageHost`, `embedHostOrigin` and `embedResume` are first-party only: the published
|
|
1389
|
+
* entry types them away. */
|
|
1390
|
+
declare const AvatarHostProvider: ({ config, children, pageHost, embedHostOrigin, embedResume, }: AvatarProviderProps & {
|
|
1391
|
+
pageHost?: PageHost;
|
|
1392
|
+
embedHostOrigin?: string;
|
|
1393
|
+
embedResume?: EmbedResume;
|
|
1394
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
1395
|
+
declare const AvatarProvider: (props: AvatarProviderProps) => ReturnType<typeof AvatarHostProvider>;
|
|
1396
|
+
|
|
1397
|
+
export { type TranscriptEntry as $, type ActionAwaiting as A, BRIDGE_NAMESPACE as B, type BridgeActionDeclaration as C, type BridgeEnvelope as D, type BridgeMessage as E, type CaptionPosition as F, type ConnectionHealth as G, type HealthConcern as H, type HealthService as I, type HealthState as J, type ScreenShareUiConfig as K, type LoaderMessage as L, SessionPhase as M, type StatusBannerConfig as N, type StatusBannerPosition as O, PaintPhase as P, type ThinkingIndicatorPosition as Q, type RuntimeMessage as R, type ScreenSharePosition as S, type ThinkingIndicatorConfig as T, type UseAvatarResult as U, type TourHighlight as V, type TourSide as W, type TourState as X, type TourStep as Y, type TourTarget as Z, type TranscriptConfig as _, type ActionCheckResult as a, type TranscriptSpeaker as a0, type TranscriptWord as a1, TurnPhase as a2, type UseAvatarActionFlowResult as a3, type UseAvatarWidgetResult as a4, WIDGET_DEFAULTS as a5, type WidgetAppearance as a6, type WidgetBehaviour as a7, type WidgetBox as a8, type WidgetConfig as a9, type CommandOutcome as aA, type AvatarConfigFromServer as aB, type AvatarConfigWithPlayer as aC, type IBrowserHost as aD, type PageHost as aE, AvatarHostProvider as aF, type AvatarSpeech as aG, type BrowserCommand as aH, type BrowserOutcome as aI, type WidgetContextPolicy as aa, type WidgetDeploymentProjection as ab, type WidgetLauncherStyle as ac, type WidgetLimits as ad, type WidgetMobileMode as ae, type WidgetOffset as af, type WidgetPanelSize as ag, type WidgetPosition as ah, type WidgetStage as ai, type WidgetTeaser as aj, type WidgetTour as ak, buildEnvelope as al, parseBridgeMessage as am, postBridgeMessage as an, resolveWidgetAppearance as ao, useAvatarAction as ap, useAvatarActionFlow as aq, useAvatarEvent as ar, useAvatarWidget as as, type LipSyncConfig as at, type LipSyncMotionConfig as au, type UseAvatarResultWithPlayer as av, type BatchedTtsJob as aw, type AvatarModeWithPlayer as ax, type AvatarSurface as ay, type WidgetAction as az, type ActionContext as b, type ActionDefinition as c, type ActionFlow as d, type ActionFlowStage as e, type ActionKind as f, type ActionParam as g, type ActionParamType as h, type ActionResult as i, type ActionUi as j, type ActionUiOp as k, type AppEventArgs as l, type AppEventPolicy as m, Avatar as n, AvatarConnectingLoader as o, type AvatarConnectingLoaderProps as p, type AvatarEnvironment as q, type AvatarError as r, type AvatarErrorCode as s, type AvatarErrorSource as t, type AvatarEventMap as u, AvatarProvider as v, type AvatarPublicProps as w, AvatarWidget as x, type AvatarWidgetProps as y, BRIDGE_VERSION as z };
|