@chatterfly/widget 0.1.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/LICENSE +21 -0
- package/README.md +41 -0
- package/dist/index.css +2840 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +706 -0
- package/dist/index.d.ts +706 -0
- package/dist/index.js +6323 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6288 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
interface WidgetConfig {
|
|
5
|
+
/** The run ID to connect to. */
|
|
6
|
+
runId: string;
|
|
7
|
+
/** Short-lived JWT issued by POST /runs or POST /runs/:id/tokens. */
|
|
8
|
+
participantToken: string;
|
|
9
|
+
/** Base URL of the Chatterfly backend. Defaults to http://localhost:8080. */
|
|
10
|
+
apiBase?: string;
|
|
11
|
+
/** Public deployment ID. When provided, the widget automatically starts a new run. */
|
|
12
|
+
deploymentId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Public workflow ID. Like `deploymentId`, auto-starts a new run — but resolves
|
|
15
|
+
* to the workflow's latest active public deployment at start time, so the embed
|
|
16
|
+
* never needs updating when the workflow is redeployed. Preferred over
|
|
17
|
+
* `deploymentId` for serverless embeds. Ignored if `deploymentId` or `runId` is set.
|
|
18
|
+
*/
|
|
19
|
+
workflowId?: string;
|
|
20
|
+
}
|
|
21
|
+
type RunStatus = "idle" | "connecting" | "replaying" | "running" | "awaiting_input" | "awaiting_voice" | "awaiting_form" | "awaiting_chat" | "awaiting_editor" | "completed" | "error" | "offline";
|
|
22
|
+
interface ValidationRule {
|
|
23
|
+
type: "required" | "min_length" | "max_length" | "min_selected" | "max_selected" | "min" | "max" | "pattern" | "email" | "url" | "phone" | "location" | "llm" | "and" | "or";
|
|
24
|
+
value?: number | string;
|
|
25
|
+
prompt?: string;
|
|
26
|
+
max_retries?: number;
|
|
27
|
+
rules?: ValidationRule[];
|
|
28
|
+
country?: string;
|
|
29
|
+
schemes?: string[];
|
|
30
|
+
require_fields?: string[];
|
|
31
|
+
}
|
|
32
|
+
interface FieldSpec {
|
|
33
|
+
id: string;
|
|
34
|
+
prompt: string;
|
|
35
|
+
input_type: string;
|
|
36
|
+
variant?: string;
|
|
37
|
+
format?: "plain" | "markdown";
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
max_length?: number;
|
|
40
|
+
rows?: number;
|
|
41
|
+
min?: number | string;
|
|
42
|
+
max?: number | string;
|
|
43
|
+
step?: number;
|
|
44
|
+
options?: string[];
|
|
45
|
+
scale?: number;
|
|
46
|
+
labels?: string[];
|
|
47
|
+
true_label?: string;
|
|
48
|
+
false_label?: string;
|
|
49
|
+
phone_default_country?: string;
|
|
50
|
+
phone_allowed_countries?: string[];
|
|
51
|
+
currency?: string;
|
|
52
|
+
currencies?: string[];
|
|
53
|
+
decimals?: number;
|
|
54
|
+
location_default_country?: string;
|
|
55
|
+
location_allowed_countries?: string[];
|
|
56
|
+
require_coords?: boolean;
|
|
57
|
+
multiple?: boolean;
|
|
58
|
+
max_file_size?: number;
|
|
59
|
+
max_duration_seconds?: number;
|
|
60
|
+
mime_types?: string[];
|
|
61
|
+
validation?: ValidationRule[];
|
|
62
|
+
voice?: VoiceFieldSpec;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Node-level voice rendering hints. Every field is optional and overrides the
|
|
66
|
+
* participant channel's defaults for this input only.
|
|
67
|
+
*/
|
|
68
|
+
interface VoiceFieldSpec {
|
|
69
|
+
hint?: string;
|
|
70
|
+
capture?: "continuous" | "push_to_talk" | "auto";
|
|
71
|
+
silence_ms?: number;
|
|
72
|
+
confidence_threshold?: number;
|
|
73
|
+
dtmf?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Optional surface-config knobs delivered alongside the surface.
|
|
77
|
+
* Voice transports accept style/tts/silence_ms/etc.; the "live" style accepts
|
|
78
|
+
* voice/language/model/etc.
|
|
79
|
+
*/
|
|
80
|
+
interface SurfaceConfig {
|
|
81
|
+
style?: "push_to_talk" | "continuous" | "live";
|
|
82
|
+
provider?: string;
|
|
83
|
+
hold_timeout?: number;
|
|
84
|
+
tts?: "browser" | "server" | "off";
|
|
85
|
+
auto_advance?: boolean;
|
|
86
|
+
silence_ms?: number;
|
|
87
|
+
confidence_threshold?: number;
|
|
88
|
+
max_reprompts?: number;
|
|
89
|
+
record_audio?: boolean;
|
|
90
|
+
model?: string;
|
|
91
|
+
voice?: string;
|
|
92
|
+
language?: string;
|
|
93
|
+
input_sample_rate?: number;
|
|
94
|
+
output_sample_rate?: number;
|
|
95
|
+
system_prompt_prefix?: string;
|
|
96
|
+
max_clarifying_questions?: number;
|
|
97
|
+
disable_training_data_retention?: boolean;
|
|
98
|
+
temperature?: number;
|
|
99
|
+
caller_id?: string;
|
|
100
|
+
barge_in?: boolean;
|
|
101
|
+
answering_machine_detection?: boolean;
|
|
102
|
+
transfer_to?: string;
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
}
|
|
105
|
+
interface RepeaterSpec {
|
|
106
|
+
id: string;
|
|
107
|
+
continue_prompt?: string;
|
|
108
|
+
min_rows?: number;
|
|
109
|
+
max_rows?: number;
|
|
110
|
+
children: FieldSpec[];
|
|
111
|
+
}
|
|
112
|
+
interface ChatMessage {
|
|
113
|
+
role: "human" | "assistant" | "system";
|
|
114
|
+
content: string;
|
|
115
|
+
}
|
|
116
|
+
interface HITLSession {
|
|
117
|
+
id: string;
|
|
118
|
+
step_id: string;
|
|
119
|
+
/** "direct" | "assisted" | "proxy" — see docs/dsl/05-hitl-patterns.md */
|
|
120
|
+
counterparty: string;
|
|
121
|
+
/** "sequential" | "form" | "editor" */
|
|
122
|
+
layout: string;
|
|
123
|
+
entry_context: Record<string, unknown>;
|
|
124
|
+
status: "open" | "handed_back" | "timed_out" | null;
|
|
125
|
+
messages?: ChatMessage[];
|
|
126
|
+
/** Current working document content (editor sessions only). */
|
|
127
|
+
document_content?: string | null;
|
|
128
|
+
}
|
|
129
|
+
type RunEvent = {
|
|
130
|
+
type: "run.started";
|
|
131
|
+
run_id: string;
|
|
132
|
+
} | {
|
|
133
|
+
type: "run.status_changed";
|
|
134
|
+
status: string;
|
|
135
|
+
} | {
|
|
136
|
+
type: "hitl.session_opened";
|
|
137
|
+
session_id: string;
|
|
138
|
+
step_id: string;
|
|
139
|
+
counterparty: string;
|
|
140
|
+
layout: string;
|
|
141
|
+
entry_context: Record<string, unknown>;
|
|
142
|
+
document_content?: string;
|
|
143
|
+
messages?: ChatMessage[];
|
|
144
|
+
} | {
|
|
145
|
+
type: "hitl.session_closed";
|
|
146
|
+
session_id: string;
|
|
147
|
+
} | {
|
|
148
|
+
type: "message.sent";
|
|
149
|
+
content: string;
|
|
150
|
+
participant_role: string;
|
|
151
|
+
} | {
|
|
152
|
+
type: "run.completed";
|
|
153
|
+
state?: Record<string, unknown>;
|
|
154
|
+
} | {
|
|
155
|
+
type: "run.cancelled";
|
|
156
|
+
} | {
|
|
157
|
+
type: "run.failed";
|
|
158
|
+
error: string;
|
|
159
|
+
} | {
|
|
160
|
+
type: "agent.token";
|
|
161
|
+
token: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: "timeline.replay";
|
|
164
|
+
payload: TimelineEntry[];
|
|
165
|
+
} | {
|
|
166
|
+
type: "timeline.entry";
|
|
167
|
+
payload: TimelineEntry;
|
|
168
|
+
};
|
|
169
|
+
interface TimelineEntry {
|
|
170
|
+
id: string;
|
|
171
|
+
run_id: string;
|
|
172
|
+
session_id: string | null;
|
|
173
|
+
seq: number;
|
|
174
|
+
event_type: "prompt" | "response" | "message" | "form_opened" | "form_submitted" | "status_change" | "delay_started" | "delay_resumed";
|
|
175
|
+
sender: "bot" | "user" | "system";
|
|
176
|
+
payload: Record<string, unknown>;
|
|
177
|
+
created_at: string;
|
|
178
|
+
}
|
|
179
|
+
interface InputComponentProps {
|
|
180
|
+
field: FieldSpec;
|
|
181
|
+
value: unknown;
|
|
182
|
+
onChange: (value: unknown) => void;
|
|
183
|
+
onSubmit?: (value?: unknown) => void;
|
|
184
|
+
disabled?: boolean;
|
|
185
|
+
/** Upload context for FileUpload inputs. */
|
|
186
|
+
uploadContext?: {
|
|
187
|
+
apiBase: string;
|
|
188
|
+
participantToken: string;
|
|
189
|
+
sessionId: string;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface ChatterflyWidgetProps extends Omit<WidgetConfig, "runId" | "participantToken"> {
|
|
194
|
+
/** The run ID to connect to. Required unless `deploymentId`/`workflowId` is provided. */
|
|
195
|
+
runId?: string;
|
|
196
|
+
/** Short-lived JWT issued by POST /runs. Required unless `deploymentId`/`workflowId` is provided. */
|
|
197
|
+
participantToken?: string;
|
|
198
|
+
className?: string;
|
|
199
|
+
onCompleted?: () => void;
|
|
200
|
+
onError?: (err: string) => void;
|
|
201
|
+
/**
|
|
202
|
+
* When true, automatically focuses the active input each time a new HITL
|
|
203
|
+
* session opens. Recommended for internal dashboard surfaces where the user
|
|
204
|
+
* is already engaged. Defaults to `false` for third-party embeds so the
|
|
205
|
+
* widget never steals focus from the host page.
|
|
206
|
+
*/
|
|
207
|
+
autoFocusInput?: boolean;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Top-level Chatterfly widget.
|
|
211
|
+
*
|
|
212
|
+
* Accepts either:
|
|
213
|
+
* - `runId` + `participantToken` (direct connection),
|
|
214
|
+
* - `workflowId` (auto-starts a run on the workflow's latest public deployment —
|
|
215
|
+
* preferred, survives redeploys), or
|
|
216
|
+
* - `deploymentId` (auto-starts a run on a specific pinned deployment).
|
|
217
|
+
*
|
|
218
|
+
* Delegates to ChatAdapter for the chat-first participant experience.
|
|
219
|
+
*/
|
|
220
|
+
declare function ChatterflyWidget(props: ChatterflyWidgetProps): react_jsx_runtime.JSX.Element;
|
|
221
|
+
|
|
222
|
+
interface ChatAdapterProps extends WidgetConfig {
|
|
223
|
+
className?: string;
|
|
224
|
+
onCompleted?: () => void;
|
|
225
|
+
onError?: (err: string) => void;
|
|
226
|
+
/** See ChatterflyWidgetProps.autoFocusInput. */
|
|
227
|
+
autoFocusInput?: boolean;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Chat-first participant experience.
|
|
231
|
+
*
|
|
232
|
+
* Renders the full conversation as a scrollable timeline of bot/user bubbles.
|
|
233
|
+
* The currently active input (from the latest HITL session) appears anchored
|
|
234
|
+
* at the bottom. Past interactions come from the server timeline.
|
|
235
|
+
*/
|
|
236
|
+
declare function ChatAdapter({ runId, participantToken, apiBase, className, onCompleted, onError, autoFocusInput, }: ChatAdapterProps): react_jsx_runtime.JSX.Element;
|
|
237
|
+
|
|
238
|
+
interface ChatTimelineProps {
|
|
239
|
+
entries: TimelineEntry[];
|
|
240
|
+
/** Show typing indicator when waiting for bot response */
|
|
241
|
+
showTyping?: boolean;
|
|
242
|
+
/** Accumulated LLM tokens for the in-progress message; empty when idle */
|
|
243
|
+
streamingText?: string;
|
|
244
|
+
}
|
|
245
|
+
declare function ChatTimeline({ entries, showTyping, streamingText }: ChatTimelineProps): react_jsx_runtime.JSX.Element;
|
|
246
|
+
|
|
247
|
+
type VoiceOrbState = "idle" | "listening" | "speaking" | "processing" | "confirming" | "error";
|
|
248
|
+
interface VoiceOrbProps {
|
|
249
|
+
state: VoiceOrbState;
|
|
250
|
+
onPress?: () => void;
|
|
251
|
+
onRelease?: () => void;
|
|
252
|
+
disabled?: boolean;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Animated orb button for voice interaction.
|
|
256
|
+
*
|
|
257
|
+
* States drive CSS classes that control keyframe animations:
|
|
258
|
+
* - idle: subtle breathe
|
|
259
|
+
* - listening: pulsing glow + audio-reactive ring
|
|
260
|
+
* - speaking: waveform ripple
|
|
261
|
+
* - processing: spinning arc
|
|
262
|
+
* - confirming: pop + success color
|
|
263
|
+
* - error: shake + red flash
|
|
264
|
+
*/
|
|
265
|
+
declare function VoiceOrb({ state, onPress, onRelease, disabled, }: VoiceOrbProps): react_jsx_runtime.JSX.Element;
|
|
266
|
+
|
|
267
|
+
interface VoicePromptCardProps {
|
|
268
|
+
field: FieldSpec;
|
|
269
|
+
/** Index of the option currently being spoken by TTS (for sequential highlight). */
|
|
270
|
+
speakingIndex?: number;
|
|
271
|
+
/** The option that was matched from voice input (highlight in success color). */
|
|
272
|
+
matchedValue?: string;
|
|
273
|
+
/** Transcript text shown while/after listening. */
|
|
274
|
+
transcript?: string;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* On-screen visual display of the current question + options/scale/labels
|
|
278
|
+
* alongside the voice interaction. The TTS reads these aloud while the
|
|
279
|
+
* card shows them visually for dual-modality.
|
|
280
|
+
*/
|
|
281
|
+
declare function VoicePromptCard({ field, speakingIndex, matchedValue, transcript, }: VoicePromptCardProps): react_jsx_runtime.JSX.Element;
|
|
282
|
+
|
|
283
|
+
interface VoiceRendererProps {
|
|
284
|
+
field: FieldSpec;
|
|
285
|
+
voiceHint?: string;
|
|
286
|
+
apiBase: string;
|
|
287
|
+
participantToken: string;
|
|
288
|
+
onValue: (value: unknown) => void;
|
|
289
|
+
disabled?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* When true, TTS prompts are synthesized server-side via
|
|
292
|
+
* POST /api/participant/tts. Falls back to the browser's SpeechSynthesis
|
|
293
|
+
* API on fetch or decode error.
|
|
294
|
+
*/
|
|
295
|
+
useServerTTS?: boolean;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Orchestrates the full voice interaction cycle for a single Input field:
|
|
299
|
+
* 1. TTS reads the prompt (with visual card on-screen)
|
|
300
|
+
* 2. User holds orb to record
|
|
301
|
+
* 3. Audio sent to /transcribe → transcript
|
|
302
|
+
* 4. VoiceValueExtractor parses typed value from transcript
|
|
303
|
+
* 5. On success → confirming state → onValue callback
|
|
304
|
+
* 6. On failure → error state → re-prompt
|
|
305
|
+
*/
|
|
306
|
+
declare function VoiceRenderer({ field, voiceHint, apiBase, participantToken, onValue, disabled, useServerTTS, }: VoiceRendererProps): react_jsx_runtime.JSX.Element;
|
|
307
|
+
|
|
308
|
+
interface VoiceContinuousRendererProps {
|
|
309
|
+
field: FieldSpec;
|
|
310
|
+
voiceHint?: string;
|
|
311
|
+
apiBase: string;
|
|
312
|
+
participantToken: string;
|
|
313
|
+
onValue: (value: unknown) => void;
|
|
314
|
+
disabled?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Controls when to auto-submit valid values.
|
|
317
|
+
* - "immediate": submit as soon as confident extraction occurs
|
|
318
|
+
* - "confirm": show "Got it!" state with 1s delay before submit (default)
|
|
319
|
+
* - "manual": require user voice confirmation ("Yes to confirm")
|
|
320
|
+
*/
|
|
321
|
+
autoSubmitMode?: "immediate" | "confirm" | "manual";
|
|
322
|
+
/** Confidence threshold for auto-submit (0-1, default: 0.7) */
|
|
323
|
+
confidenceThreshold?: number;
|
|
324
|
+
/** Silence duration before auto-capture in ms (default: 1500) */
|
|
325
|
+
silenceTimeoutMs?: number;
|
|
326
|
+
/** Minimum speech duration before processing in ms (default: 500) */
|
|
327
|
+
minSpeechDurationMs?: number;
|
|
328
|
+
/**
|
|
329
|
+
* Enqueue text on the parent's shared speech queue. The parent owns the only
|
|
330
|
+
* SpeechSynthesis instance so agent Message nodes and this Input prompt never
|
|
331
|
+
* interrupt one another. Resolves when the enqueued utterance finishes.
|
|
332
|
+
*/
|
|
333
|
+
enqueueSpeak: (text: string) => Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* True while ANY speech (message or prompt) is playing. Drives the VAD
|
|
336
|
+
* `paused` guard so the mic never captures audio while speaking.
|
|
337
|
+
*/
|
|
338
|
+
isSpeaking: boolean;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Hands-free, continuous voice interaction without manual recording controls.
|
|
342
|
+
*
|
|
343
|
+
* Flow:
|
|
344
|
+
* 1. TTS speaks the prompt
|
|
345
|
+
* 2. Stream opens, VAD continuously monitors for speech
|
|
346
|
+
* 3. When user stops speaking (silence timeout), auto-transcribe
|
|
347
|
+
* 4. Extract value and validate
|
|
348
|
+
* 5. If confident, show "Got it!" and auto-submit (or require confirmation)
|
|
349
|
+
* 6. Auto-listen for next question
|
|
350
|
+
*/
|
|
351
|
+
declare function VoiceContinuousRenderer({ field, voiceHint, apiBase, participantToken, onValue, disabled, autoSubmitMode, confidenceThreshold, silenceTimeoutMs, minSpeechDurationMs, enqueueSpeak, isSpeaking, }: VoiceContinuousRendererProps): react_jsx_runtime.JSX.Element;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Phase 78 — Gemini Live continuous voice renderer.
|
|
355
|
+
*
|
|
356
|
+
* Mirrors the surface area of `VoiceContinuousRenderer` from the host's
|
|
357
|
+
* perspective (same field/onValue contract) but delegates VAD, TTS, STT,
|
|
358
|
+
* and value extraction to the backend voice-live proxy. The renderer is
|
|
359
|
+
* intentionally thin: it surfaces transcripts, the active prompt, and the
|
|
360
|
+
* voice orb state. Field-level retry, silence timeouts, and confirmation
|
|
361
|
+
* dialogs are all handled upstream by the model.
|
|
362
|
+
*/
|
|
363
|
+
interface VoiceLiveRendererProps {
|
|
364
|
+
field: FieldSpec;
|
|
365
|
+
voiceHint?: string;
|
|
366
|
+
apiBase: string;
|
|
367
|
+
participantToken: string;
|
|
368
|
+
/** HITL session id; the proxy resolves field, channel, and tokens from it. */
|
|
369
|
+
sessionId: string;
|
|
370
|
+
/** Resolved widget/voice live tunables (config.style "live"). May be empty — defaults are server-side. */
|
|
371
|
+
liveConfig?: SurfaceConfig;
|
|
372
|
+
onValue: (value: unknown) => void;
|
|
373
|
+
disabled?: boolean;
|
|
374
|
+
}
|
|
375
|
+
declare function VoiceLiveRenderer({ field, apiBase, participantToken, sessionId, liveConfig, onValue, disabled, }: VoiceLiveRendererProps): react_jsx_runtime.JSX.Element;
|
|
376
|
+
|
|
377
|
+
interface RequiredConnection {
|
|
378
|
+
slug: string;
|
|
379
|
+
name: string;
|
|
380
|
+
service_type: string;
|
|
381
|
+
auth_type: string;
|
|
382
|
+
description?: string;
|
|
383
|
+
provided: boolean;
|
|
384
|
+
}
|
|
385
|
+
interface UseParticipantConnectionsResult {
|
|
386
|
+
/** Connections the participant needs to provide credentials for. */
|
|
387
|
+
connections: RequiredConnection[];
|
|
388
|
+
/** Whether all required connections have been provided. */
|
|
389
|
+
allProvided: boolean;
|
|
390
|
+
/** Whether the connections are still loading. */
|
|
391
|
+
loading: boolean;
|
|
392
|
+
/** Error message if loading failed. */
|
|
393
|
+
error: string | null;
|
|
394
|
+
/** Re-fetch the connection status. */
|
|
395
|
+
refresh: () => void;
|
|
396
|
+
/** Disconnect a specific connection (remove credentials). */
|
|
397
|
+
disconnect: (slug: string) => Promise<boolean>;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Hook to fetch required participant-fulfillment connections for a run.
|
|
401
|
+
* Returns the list of connections the participant needs to authorize.
|
|
402
|
+
*/
|
|
403
|
+
declare function useParticipantConnections(runId: string, participantToken: string, apiBase?: string): UseParticipantConnectionsResult;
|
|
404
|
+
|
|
405
|
+
interface ConnectionOnboardingProps {
|
|
406
|
+
/** Connections that need to be authorized. */
|
|
407
|
+
connections: RequiredConnection[];
|
|
408
|
+
/** Base URL of the Chatterfly backend/frontend for OAuth redirects. */
|
|
409
|
+
appBase: string;
|
|
410
|
+
/** The participant's JWT token. */
|
|
411
|
+
participantToken: string;
|
|
412
|
+
/** Called when the user clicks "Continue later" or closes the onboarding. */
|
|
413
|
+
onSkip?: () => void;
|
|
414
|
+
/** Called to disconnect a connection. */
|
|
415
|
+
onDisconnect?: (slug: string) => Promise<boolean>;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Connection onboarding screen shown when a participant needs to authorize
|
|
419
|
+
* OAuth connections before proceeding with the workflow.
|
|
420
|
+
*/
|
|
421
|
+
declare function ConnectionOnboarding({ connections, appBase, participantToken, onSkip, onDisconnect, }: ConnectionOnboardingProps): react_jsx_runtime.JSX.Element | null;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Phase 78 — Gemini Live streaming voice session.
|
|
425
|
+
*
|
|
426
|
+
* Opens a WebSocket to the backend voice-live proxy
|
|
427
|
+
* (`/api/participant/inbox/{sessionId}/voice-stream`) using the
|
|
428
|
+
* `chatterfly.voice.v1` subprotocol. Sends captured PCM16 frames as binary
|
|
429
|
+
* messages and plays back synthesised PCM audio chunks the proxy forwards
|
|
430
|
+
* from Gemini Live. Control messages (state, transcripts, value, errors)
|
|
431
|
+
* are JSON text frames.
|
|
432
|
+
*
|
|
433
|
+
* The hook is intentionally narrower than `useContinuousVoiceSession` —
|
|
434
|
+
* VAD, silence timeouts, retry, and TTS are all delegated to the Gemini
|
|
435
|
+
* Live model, so the widget only manages the audio pipes and surfaces
|
|
436
|
+
* transparency events to the UI.
|
|
437
|
+
*/
|
|
438
|
+
type LiveVoiceState = "idle" | "connecting" | "listening" | "speaking" | "muted" | "completed" | "error";
|
|
439
|
+
interface LiveTranscript {
|
|
440
|
+
/** "user" for input transcription, "assistant" for output transcription. */
|
|
441
|
+
who: "user" | "assistant";
|
|
442
|
+
text: string;
|
|
443
|
+
/** Final transcripts arrive once per utterance; partials may stream. */
|
|
444
|
+
final: boolean;
|
|
445
|
+
}
|
|
446
|
+
interface LiveSessionConfig {
|
|
447
|
+
apiBase: string;
|
|
448
|
+
participantToken: string;
|
|
449
|
+
sessionId: string;
|
|
450
|
+
/** Mic capture rate sent upstream. Should match channel.live.input_sample_rate. */
|
|
451
|
+
inputSampleRate?: number;
|
|
452
|
+
/** Playback decode rate. Should match channel.live.output_sample_rate. */
|
|
453
|
+
outputSampleRate?: number;
|
|
454
|
+
}
|
|
455
|
+
interface LiveSessionResult {
|
|
456
|
+
state: LiveVoiceState;
|
|
457
|
+
transcripts: LiveTranscript[];
|
|
458
|
+
/** Latest assistant text bubble (for prompts the model speaks). */
|
|
459
|
+
assistantText: string;
|
|
460
|
+
/** Latest field id reported by the proxy via field_change. */
|
|
461
|
+
activeFieldId: string | null;
|
|
462
|
+
/** The committed value, set when the proxy emits a value envelope. */
|
|
463
|
+
lastValue: unknown;
|
|
464
|
+
isMuted: boolean;
|
|
465
|
+
toggleMute: () => void;
|
|
466
|
+
error: string | null;
|
|
467
|
+
}
|
|
468
|
+
declare function useGeminiLiveSession(cfg: LiveSessionConfig, onValue: (value: unknown) => void): LiveSessionResult;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Text input with variants:
|
|
472
|
+
* plain (default) | email | phone | url | password
|
|
473
|
+
*
|
|
474
|
+
* Phone variant: enforces `tel` keyboard; full E.164 validation is done via the
|
|
475
|
+
* validate() helper and server-side. Country selector and libphonenumber-based
|
|
476
|
+
* masking are a progressive enhancement (planned).
|
|
477
|
+
*/
|
|
478
|
+
declare function InputText({ field, value, onChange, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* TextArea input with variants:
|
|
482
|
+
* plain (default) — plain textarea
|
|
483
|
+
* rich — textarea with minimal markdown toolbar hint (full WYSIWYG can be
|
|
484
|
+
* layered later via custom input type registration)
|
|
485
|
+
*/
|
|
486
|
+
declare function InputTextArea({ field, value, onChange, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Number input with variants:
|
|
490
|
+
* input (default) — plain numeric input
|
|
491
|
+
* slider — range slider with value bubble (requires min + max)
|
|
492
|
+
* stepper — number display with ± buttons
|
|
493
|
+
* currency — number input + currency selector, outputs { amount, currency }
|
|
494
|
+
*/
|
|
495
|
+
declare function InputNumber({ field, value, onChange, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Date input with variants:
|
|
499
|
+
* date (default) | time | datetime | month | week
|
|
500
|
+
* Maps to the corresponding HTML5 input type. min/max accept ISO strings
|
|
501
|
+
* matching the variant format.
|
|
502
|
+
*/
|
|
503
|
+
declare function InputDate({ field, value, onChange, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Boolean input with variants:
|
|
507
|
+
* yes-no (default) — inline Yes/No buttons; auto-submits on click
|
|
508
|
+
* checkbox — single checkbox with label (prior default)
|
|
509
|
+
* toggle — iOS-style switch
|
|
510
|
+
*
|
|
511
|
+
* true_label / false_label override the Yes/No labels for yes-no variant.
|
|
512
|
+
*/
|
|
513
|
+
declare function InputBoolean({ field, value, onChange, onSubmit, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Single-select input with variants:
|
|
517
|
+
* buttons (default) — inline pills; auto-submits on click
|
|
518
|
+
* dropdown — native <select>
|
|
519
|
+
* radio — vertical radio list with labels
|
|
520
|
+
*/
|
|
521
|
+
declare function InputSingleSelect({ field, value, onChange, onSubmit, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Multi-select input with variants:
|
|
525
|
+
* checkboxes (default) — vertical checkbox list
|
|
526
|
+
* buttons — toggle-style pills
|
|
527
|
+
* dropdown — native multi-select
|
|
528
|
+
*/
|
|
529
|
+
declare function InputMultiSelect({ field, value, onChange, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Rating input with variants:
|
|
533
|
+
* stars (default) — cumulative fill (stars 1..n filled when value=n)
|
|
534
|
+
* numeric — numbered buttons 1..scale; single-select, auto-submits
|
|
535
|
+
* nps — hardcoded 0–10 Net Promoter Score, single-select, auto-submits
|
|
536
|
+
* faces — emoji scale, single-select, auto-submits
|
|
537
|
+
*/
|
|
538
|
+
declare function InputRating({ field, value, onChange, onSubmit, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
539
|
+
|
|
540
|
+
declare function InputFileUpload({ field, value, onChange, disabled, uploadContext, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
541
|
+
|
|
542
|
+
declare function InputLocation({ field, value, onChange, disabled, }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Display input type — shows the prompt with a "Continue" button.
|
|
546
|
+
* No user input is captured; clicking Continue submits immediately.
|
|
547
|
+
*/
|
|
548
|
+
declare function InputDisplay({ onSubmit, disabled }: InputComponentProps): react_jsx_runtime.JSX.Element;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Resolve an input_type string to its React component.
|
|
552
|
+
* Falls back to custom x-* types from the registry, then to InputTextArea.
|
|
553
|
+
*/
|
|
554
|
+
declare function getInputComponent(inputType: string): ComponentType<InputComponentProps>;
|
|
555
|
+
|
|
556
|
+
interface ValidationError {
|
|
557
|
+
field: string;
|
|
558
|
+
message: string;
|
|
559
|
+
}
|
|
560
|
+
interface UseRunStreamResult {
|
|
561
|
+
status: RunStatus;
|
|
562
|
+
activeSession: HITLSession | null;
|
|
563
|
+
messages: ChatMessage[];
|
|
564
|
+
timeline: TimelineEntry[];
|
|
565
|
+
lastSeq: number;
|
|
566
|
+
/** Accumulated streaming text from in-progress LLM generation. Empty when idle. */
|
|
567
|
+
streamingText: string;
|
|
568
|
+
sendMessage: (content: string) => Promise<void>;
|
|
569
|
+
submitHandback: (output?: unknown, idempotencyKey?: string) => Promise<ValidationError[] | null>;
|
|
570
|
+
}
|
|
571
|
+
declare function useRunStream(config: WidgetConfig): UseRunStreamResult;
|
|
572
|
+
|
|
573
|
+
type SynthState = "idle" | "speaking" | "paused";
|
|
574
|
+
interface UseSpeechSynthesisResult {
|
|
575
|
+
state: SynthState;
|
|
576
|
+
speak: (text: string) => Promise<void>;
|
|
577
|
+
cancel: () => void;
|
|
578
|
+
supported: boolean;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Optional server-TTS configuration. When provided, speak() first attempts to
|
|
582
|
+
* synthesize via POST {apiBase}/api/participant/tts (Phase 76.3) and plays the
|
|
583
|
+
* returned audio blob. If the fetch or decode fails, speak() falls back to the
|
|
584
|
+
* browser SpeechSynthesis API so callers never lose audio output.
|
|
585
|
+
*/
|
|
586
|
+
interface ServerTTSConfig {
|
|
587
|
+
apiBase: string;
|
|
588
|
+
participantToken: string;
|
|
589
|
+
voice?: string;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Thin wrapper around the browser SpeechSynthesis API.
|
|
593
|
+
* Returns a promise that resolves when the utterance finishes.
|
|
594
|
+
*
|
|
595
|
+
* Pass `server` to route TTS through the backend (channel.tts === "server").
|
|
596
|
+
*/
|
|
597
|
+
declare function useSpeechSynthesis(server?: ServerTTSConfig): UseSpeechSynthesisResult;
|
|
598
|
+
|
|
599
|
+
type RecordingState = "idle" | "recording" | "processing";
|
|
600
|
+
interface UseVoiceRecorderResult {
|
|
601
|
+
recordingState: RecordingState;
|
|
602
|
+
startRecording: () => void;
|
|
603
|
+
stopRecording: () => Promise<Blob | null>;
|
|
604
|
+
supported: boolean;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Captures audio via MediaRecorder and returns a Blob on stop.
|
|
608
|
+
*/
|
|
609
|
+
declare function useVoiceRecorder(): UseVoiceRecorderResult;
|
|
610
|
+
|
|
611
|
+
interface ServerExtraction {
|
|
612
|
+
value: unknown;
|
|
613
|
+
display: string;
|
|
614
|
+
}
|
|
615
|
+
interface TranscribeResult {
|
|
616
|
+
transcript: string;
|
|
617
|
+
extraction: ServerExtraction | null;
|
|
618
|
+
}
|
|
619
|
+
interface UseTranscribeResult {
|
|
620
|
+
transcribe: (audio: Blob, fieldSpec?: FieldSpec) => Promise<TranscribeResult>;
|
|
621
|
+
loading: boolean;
|
|
622
|
+
error: string | null;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Sends an audio Blob to POST /api/participant/transcribe and returns the transcript.
|
|
626
|
+
* When a fieldSpec is provided, the server also attempts LLM-based value extraction.
|
|
627
|
+
*/
|
|
628
|
+
declare function useTranscribe(apiBase: string, participantToken: string): UseTranscribeResult;
|
|
629
|
+
|
|
630
|
+
type ContinuousVoiceState = "idle" | "connecting" | "listening" | "detecting_speech" | "capturing" | "silence_timeout" | "processing" | "muted";
|
|
631
|
+
interface ContinuousVoiceSessionResult {
|
|
632
|
+
state: ContinuousVoiceState;
|
|
633
|
+
transcript: string;
|
|
634
|
+
confidence: number;
|
|
635
|
+
isMuted: boolean;
|
|
636
|
+
toggleMute: () => void;
|
|
637
|
+
resetSession: () => void;
|
|
638
|
+
clearCapturedBlob: () => void;
|
|
639
|
+
audioLevel: number;
|
|
640
|
+
supported: boolean;
|
|
641
|
+
error: string | null;
|
|
642
|
+
capturedBlob: Blob | null;
|
|
643
|
+
}
|
|
644
|
+
interface Config {
|
|
645
|
+
silenceThreshold?: number;
|
|
646
|
+
silenceTimeoutMs?: number;
|
|
647
|
+
minSpeechDurationMs?: number;
|
|
648
|
+
autoTranscribeOnSilence?: boolean;
|
|
649
|
+
onSilenceTimeout?: (blob: Blob) => void;
|
|
650
|
+
/**
|
|
651
|
+
* External pause (e.g. while TTS is speaking). When true, VAD ignores audio
|
|
652
|
+
* and no capture fires. The stream stays alive; resuming is instant.
|
|
653
|
+
*/
|
|
654
|
+
paused?: boolean;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Manages continuous voice listening with voice activity detection.
|
|
658
|
+
*/
|
|
659
|
+
declare function useContinuousVoiceSession(config?: Config): ContinuousVoiceSessionResult;
|
|
660
|
+
|
|
661
|
+
interface InputTypeProps {
|
|
662
|
+
value: unknown;
|
|
663
|
+
onChange: (value: unknown) => void;
|
|
664
|
+
fieldSpec: FieldSpec;
|
|
665
|
+
validation?: ValidationRule[];
|
|
666
|
+
disabled?: boolean;
|
|
667
|
+
}
|
|
668
|
+
declare function registerInputType(typeName: string, component: ComponentType<InputTypeProps>): void;
|
|
669
|
+
declare function resolveInputType(typeName: string): ComponentType<InputTypeProps> | undefined;
|
|
670
|
+
interface SessionRendererProps {
|
|
671
|
+
entryContext: Record<string, unknown>;
|
|
672
|
+
onHandback: (output?: unknown) => void;
|
|
673
|
+
}
|
|
674
|
+
declare function registerSessionRenderer(typeName: string, component: ComponentType<SessionRendererProps>): void;
|
|
675
|
+
declare function resolveSessionRenderer(typeName: string): ComponentType<SessionRendererProps> | undefined;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Result of attempting to extract a typed value from a transcript.
|
|
679
|
+
*/
|
|
680
|
+
interface ExtractionResult {
|
|
681
|
+
/** Whether extraction succeeded. */
|
|
682
|
+
ok: boolean;
|
|
683
|
+
/** The extracted and typed value (string, number, boolean, string[]). */
|
|
684
|
+
value?: unknown;
|
|
685
|
+
/** Display-friendly representation of the matched value. */
|
|
686
|
+
display?: string;
|
|
687
|
+
/** Confidence score 0-1 (1 = exact match). */
|
|
688
|
+
confidence: number;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Extracts a typed value from a voice transcript based on the FieldSpec.
|
|
692
|
+
*
|
|
693
|
+
* Uses fuzzy matching (normalized Levenshtein) for options and simple
|
|
694
|
+
* keyword/number extraction for other types.
|
|
695
|
+
*/
|
|
696
|
+
declare function extractValue(transcript: string, field: FieldSpec): ExtractionResult;
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Builds a spoken-text prompt from a FieldSpec.
|
|
700
|
+
*
|
|
701
|
+
* Prefers `field.voice.hint`, falls back to an explicit `voiceHint` argument,
|
|
702
|
+
* and finally auto-generates from the field's prompt + options/scale.
|
|
703
|
+
*/
|
|
704
|
+
declare function buildSpokenPrompt(field: FieldSpec, voiceHint?: string): string;
|
|
705
|
+
|
|
706
|
+
export { ChatAdapter, type ChatAdapterProps, type ChatMessage, ChatTimeline, type ChatTimelineProps, ChatterflyWidget, type ChatterflyWidgetProps, ConnectionOnboarding, type ConnectionOnboardingProps, type ContinuousVoiceSessionResult, type ContinuousVoiceState, type ExtractionResult, type FieldSpec, type HITLSession, InputBoolean, type InputComponentProps, InputDate, InputDisplay, InputFileUpload, InputLocation, InputMultiSelect, InputNumber, InputRating, InputSingleSelect, InputText, InputTextArea, type InputTypeProps, type LiveSessionConfig, type LiveSessionResult, type LiveTranscript, type LiveVoiceState, type RecordingState, type RepeaterSpec, type RequiredConnection, type RunEvent, type RunStatus, type SessionRendererProps, type SynthState, type TimelineEntry, type UseParticipantConnectionsResult, type UseRunStreamResult, type UseSpeechSynthesisResult, type UseTranscribeResult, type UseVoiceRecorderResult, type ValidationError, type ValidationRule, VoiceContinuousRenderer, type VoiceContinuousRendererProps, VoiceLiveRenderer, type VoiceLiveRendererProps, VoiceOrb, type VoiceOrbProps, type VoiceOrbState, VoicePromptCard, type VoicePromptCardProps, VoiceRenderer, type VoiceRendererProps, type WidgetConfig, buildSpokenPrompt, extractValue, getInputComponent, registerInputType, registerSessionRenderer, resolveInputType, resolveSessionRenderer, useContinuousVoiceSession, useGeminiLiveSession, useParticipantConnections, useRunStream, useSpeechSynthesis, useTranscribe, useVoiceRecorder };
|