@fishaudio/agent-widget-react-native 0.0.0-stage → 1.2.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/dist/index.cjs ADDED
@@ -0,0 +1,1926 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ DEFAULT_TEXTS: () => DEFAULT_TEXTS2,
30
+ FishAgentWidget: () => FishAgentWidget
31
+ });
32
+ module.exports = __toCommonJS(src_exports);
33
+
34
+ // src/widget.tsx
35
+ var import_agent_react_native = require("@fishaudio/agent-react-native");
36
+
37
+ // ../widget-shared/dist/index.js
38
+ var import_agent_client = require("@fishaudio/agent-client");
39
+ var __typeError2 = (msg) => {
40
+ throw TypeError(msg);
41
+ };
42
+ var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
43
+ var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
44
+ var __privateAdd2 = (obj, member, value) => member.has(obj) ? __typeError2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
45
+ var __privateSet = (obj, member, value, setter) => (__accessCheck2(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
46
+ var __privateMethod = (obj, member, method) => (__accessCheck2(obj, member, "access private method"), method);
47
+ var __privateWrapper = (obj, member, setter, getter) => ({
48
+ set _(value) {
49
+ __privateSet(obj, member, value, setter);
50
+ },
51
+ get _() {
52
+ return __privateGet2(obj, member, getter);
53
+ }
54
+ });
55
+ var DEFAULT_TEXTS = {
56
+ statusConnecting: "Connecting\u2026",
57
+ statusReconnecting: "Reconnecting\u2026",
58
+ statusLive: "Live",
59
+ statusEnded: "Call ended",
60
+ greeting: "Hey! How can I help?",
61
+ homeHint: "Start a voice chat, or type below.",
62
+ startVoice: "Start a voice chat",
63
+ restartVoice: "Start a new voice chat",
64
+ continueWithText: "Or continue by typing",
65
+ endedDividerLabel: "Call ended",
66
+ composerPlaceholder: "Or type a message\u2026",
67
+ consentTitle: "Before you start",
68
+ consentBody: "This conversation is powered by Fish Audio. Your voice is processed in real time to run the call. By continuing, you agree to our Terms of Service and Privacy Policy.",
69
+ consentAgree: "Agree & continue",
70
+ consentDecline: "Not now",
71
+ poweredBy: "Powered by Fish Audio",
72
+ listening: "Listening",
73
+ thinking: "Thinking",
74
+ speaking: "Speaking",
75
+ errorMicDenied: "Microphone access was denied \u2014 check your browser settings.",
76
+ errorOrigin: "This site isn't allowed to talk to this agent.",
77
+ errorUnavailable: "This agent is temporarily unavailable.",
78
+ errorConnection: "Connection failed \u2014 please try again.",
79
+ openLabel: "Open assistant",
80
+ closeLabel: "Close",
81
+ minimizeLabel: "Minimize",
82
+ expandLabel: "Expand",
83
+ sendLabel: "Send",
84
+ muteLabel: "Mute microphone",
85
+ unmuteLabel: "Unmute microphone",
86
+ muteShort: "mute",
87
+ unmuteShort: "unmute",
88
+ endCallLabel: "End call",
89
+ dismissLabel: "Dismiss",
90
+ toolRunning: "Running",
91
+ toolDone: "Done",
92
+ toolFailed: "Failed"
93
+ };
94
+ function resolveSettings(attrs, remote) {
95
+ const texts = {
96
+ ...DEFAULT_TEXTS,
97
+ ...remote?.text_contents,
98
+ ...attrs.texts
99
+ };
100
+ const greeting = attrs.greeting ?? attrs.texts?.greeting ?? remote?.greeting;
101
+ if (greeting !== void 0) {
102
+ texts.greeting = greeting;
103
+ }
104
+ const consentBody = attrs.consentText ?? attrs.texts?.consentBody ?? remote?.consent_text;
105
+ if (consentBody !== void 0) {
106
+ texts.consentBody = consentBody;
107
+ }
108
+ return {
109
+ agentId: attrs.agentId,
110
+ serverUrl: attrs.serverUrl,
111
+ userId: attrs.userId,
112
+ language: attrs.language,
113
+ dynamicVariables: attrs.dynamicVariables,
114
+ agentName: attrs.agentName ?? remote?.agent_name ?? "Agent",
115
+ proactiveMessage: attrs.proactiveMessage ?? remote?.proactive_message,
116
+ proactiveDelaySeconds: attrs.proactiveDelaySeconds ?? 3,
117
+ transcript: attrs.transcript ?? remote?.transcript_enabled ?? true,
118
+ textInput: attrs.textInput ?? remote?.text_input_enabled ?? true,
119
+ micMuting: attrs.micMuting ?? remote?.mic_muting_enabled ?? true,
120
+ consent: attrs.consent ?? remote?.consent_required ?? false,
121
+ consentKey: attrs.consentKey ?? "fish-agent-consent",
122
+ termsUrl: attrs.termsUrl,
123
+ privacyUrl: attrs.privacyUrl,
124
+ position: attrs.position ?? "bottom-right",
125
+ avatarUrl: attrs.avatarUrl,
126
+ launcherIconUrl: attrs.launcherIconUrl,
127
+ texts
128
+ };
129
+ }
130
+ var _entries;
131
+ var _listeners;
132
+ var _generation;
133
+ var _dividerCount;
134
+ var _TranscriptStore_instances;
135
+ var upsertSpeech_fn;
136
+ var upsertTool_fn;
137
+ var upsert_fn;
138
+ var emit_fn;
139
+ var TranscriptStore = class {
140
+ constructor() {
141
+ __privateAdd2(this, _TranscriptStore_instances);
142
+ __privateAdd2(this, _entries, []);
143
+ __privateAdd2(this, _listeners, /* @__PURE__ */ new Set());
144
+ __privateAdd2(this, _generation, 0);
145
+ __privateAdd2(this, _dividerCount, 0);
146
+ }
147
+ get entries() {
148
+ return __privateGet2(this, _entries);
149
+ }
150
+ subscribe(listener) {
151
+ __privateGet2(this, _listeners).add(listener);
152
+ return () => __privateGet2(this, _listeners).delete(listener);
153
+ }
154
+ clear() {
155
+ if (__privateGet2(this, _entries).length > 0) {
156
+ __privateSet(this, _entries, []);
157
+ __privateMethod(this, _TranscriptStore_instances, emit_fn).call(this);
158
+ }
159
+ }
160
+ /** Append an end-of-call divider (no-op on an empty transcript). */
161
+ pushDivider(label) {
162
+ if (__privateGet2(this, _entries).length === 0) {
163
+ return;
164
+ }
165
+ const id = `divider:${++__privateWrapper(this, _dividerCount)._}`;
166
+ __privateMethod(this, _TranscriptStore_instances, upsert_fn).call(this, id, { kind: "divider", id, label });
167
+ }
168
+ /** Wire a live session; returns the detach function. */
169
+ attach(session) {
170
+ const generation = ++__privateWrapper(this, _generation)._;
171
+ const scoped = (id) => `${generation}:${id}`;
172
+ const onUserTranscript = ({
173
+ segmentId,
174
+ text,
175
+ final
176
+ }) => __privateMethod(this, _TranscriptStore_instances, upsertSpeech_fn).call(this, scoped(`u:${segmentId}`), "user", text, final);
177
+ const onAgentDelta = ({ segmentId, text }) => __privateMethod(this, _TranscriptStore_instances, upsertSpeech_fn).call(this, scoped(`a:${segmentId}`), "agent", text, false);
178
+ const onAgentResponse = ({ segmentId, text }) => __privateMethod(this, _TranscriptStore_instances, upsertSpeech_fn).call(this, scoped(`a:${segmentId}`), "agent", text, true);
179
+ const onToolStarted = (event) => __privateMethod(this, _TranscriptStore_instances, upsertTool_fn).call(this, {
180
+ kind: "tool",
181
+ id: scoped(`t:${event.callId}`),
182
+ callId: event.callId,
183
+ toolName: event.toolName,
184
+ source: event.source,
185
+ status: "running",
186
+ input: event.input,
187
+ inputTruncated: event.inputTruncated
188
+ });
189
+ const onToolCompleted = (event) => __privateMethod(this, _TranscriptStore_instances, upsertTool_fn).call(this, {
190
+ kind: "tool",
191
+ id: scoped(`t:${event.callId}`),
192
+ callId: event.callId,
193
+ toolName: event.toolName,
194
+ source: event.source,
195
+ status: "done",
196
+ output: event.output,
197
+ outputTruncated: event.outputTruncated
198
+ });
199
+ const onToolFailed = (event) => __privateMethod(this, _TranscriptStore_instances, upsertTool_fn).call(this, {
200
+ kind: "tool",
201
+ id: scoped(`t:${event.callId}`),
202
+ callId: event.callId,
203
+ toolName: event.toolName,
204
+ source: event.source,
205
+ status: "error",
206
+ error: event.error
207
+ });
208
+ session.on("userTranscript", onUserTranscript);
209
+ session.on("agentResponseDelta", onAgentDelta);
210
+ session.on("agentResponse", onAgentResponse);
211
+ session.on("toolCallStarted", onToolStarted);
212
+ session.on("toolCallCompleted", onToolCompleted);
213
+ session.on("toolCallFailed", onToolFailed);
214
+ return () => {
215
+ session.off("userTranscript", onUserTranscript);
216
+ session.off("agentResponseDelta", onAgentDelta);
217
+ session.off("agentResponse", onAgentResponse);
218
+ session.off("toolCallStarted", onToolStarted);
219
+ session.off("toolCallCompleted", onToolCompleted);
220
+ session.off("toolCallFailed", onToolFailed);
221
+ };
222
+ }
223
+ };
224
+ _entries = /* @__PURE__ */ new WeakMap();
225
+ _listeners = /* @__PURE__ */ new WeakMap();
226
+ _generation = /* @__PURE__ */ new WeakMap();
227
+ _dividerCount = /* @__PURE__ */ new WeakMap();
228
+ _TranscriptStore_instances = /* @__PURE__ */ new WeakSet();
229
+ upsertSpeech_fn = function(id, role, text, final) {
230
+ const entry = { kind: "message", id, role, text, final };
231
+ __privateMethod(this, _TranscriptStore_instances, upsert_fn).call(this, id, entry);
232
+ };
233
+ upsertTool_fn = function(entry) {
234
+ const existing = __privateGet2(this, _entries).find(
235
+ (candidate) => candidate.kind === "tool" && candidate.id === entry.id
236
+ );
237
+ __privateMethod(this, _TranscriptStore_instances, upsert_fn).call(this, entry.id, existing ? { ...existing, ...entry } : entry);
238
+ };
239
+ upsert_fn = function(id, entry) {
240
+ const index = __privateGet2(this, _entries).findIndex((candidate) => candidate.id === id);
241
+ const next = [...__privateGet2(this, _entries)];
242
+ if (index === -1) {
243
+ next.push(entry);
244
+ } else {
245
+ next[index] = entry;
246
+ }
247
+ __privateSet(this, _entries, next);
248
+ __privateMethod(this, _TranscriptStore_instances, emit_fn).call(this);
249
+ };
250
+ emit_fn = function() {
251
+ for (const listener of __privateGet2(this, _listeners)) {
252
+ listener();
253
+ }
254
+ };
255
+ async function fetchRemoteConfig(serverUrl, agentId, origin) {
256
+ const base = (serverUrl ?? import_agent_client.DEFAULT_SERVER_URL).replace(/\/$/, "");
257
+ try {
258
+ const response = await fetch(
259
+ `${base}/v1/agent/agents/${encodeURIComponent(agentId)}/widget`,
260
+ {
261
+ headers: { Accept: "application/json", ...origin ? { Origin: origin } : {} },
262
+ signal: typeof AbortSignal.timeout === "function" ? AbortSignal.timeout(3e3) : void 0
263
+ }
264
+ );
265
+ if (!response.ok) {
266
+ return null;
267
+ }
268
+ const body = await response.json();
269
+ return typeof body === "object" && body !== null ? body : null;
270
+ } catch {
271
+ return null;
272
+ }
273
+ }
274
+ function formatTimer(seconds) {
275
+ const minutes = Math.floor(seconds / 60);
276
+ const rest = seconds % 60;
277
+ return `${minutes}:${rest.toString().padStart(2, "0")}`;
278
+ }
279
+ function showsErrorBanner(error) {
280
+ return error.recovered !== true && error.code !== "tool_failed" && error.code !== "tool_timeout";
281
+ }
282
+ function errorText(texts, code) {
283
+ switch (code) {
284
+ case "mic_permission_denied":
285
+ return texts.errorMicDenied;
286
+ case "origin_forbidden":
287
+ case "agent_not_public":
288
+ return texts.errorOrigin;
289
+ case "insufficient_credit":
290
+ return texts.errorUnavailable;
291
+ default:
292
+ return texts.errorConnection;
293
+ }
294
+ }
295
+ function formatToolPayload(payload, truncated) {
296
+ if (!truncated) {
297
+ try {
298
+ return JSON.stringify(JSON.parse(payload), null, 1);
299
+ } catch {
300
+ }
301
+ }
302
+ return payload;
303
+ }
304
+
305
+ // src/widget.tsx
306
+ var import_react6 = require("react");
307
+ var import_react_native4 = require("react-native");
308
+
309
+ // src/texts.ts
310
+ var MOBILE_TEXTS = {
311
+ errorMicDenied: "Microphone access was denied. Turn it on in Settings.",
312
+ errorOrigin: "This app isn't allowed to talk to this agent."
313
+ };
314
+ var DEFAULT_TEXTS2 = { ...DEFAULT_TEXTS, ...MOBILE_TEXTS };
315
+
316
+ // src/images.ts
317
+ var import_react = require("react");
318
+ var ImagesContext = (0, import_react.createContext)({});
319
+ function useWidgetImages() {
320
+ return (0, import_react.useContext)(ImagesContext);
321
+ }
322
+ function sourceKey(source) {
323
+ if (source === void 0 || source === null) {
324
+ return void 0;
325
+ }
326
+ return typeof source === "number" ? `asset:${source}` : JSON.stringify(source);
327
+ }
328
+ var loadedKeys = /* @__PURE__ */ new Set();
329
+ function useImageWithFallback(source) {
330
+ const key = sourceKey(source);
331
+ const [failedKey, setFailedKey] = (0, import_react.useState)(void 0);
332
+ const [loadedKey, setLoadedKey] = (0, import_react.useState)(void 0);
333
+ const usable = key !== void 0 && failedKey !== key;
334
+ return {
335
+ source: usable ? source : void 0,
336
+ loaded: usable && (loadedKey === key || loadedKeys.has(key)),
337
+ onLoad: () => {
338
+ if (key !== void 0) {
339
+ loadedKeys.add(key);
340
+ setLoadedKey(key);
341
+ }
342
+ },
343
+ onError: () => setFailedKey(key)
344
+ };
345
+ }
346
+
347
+ // src/theme.ts
348
+ var import_react2 = require("react");
349
+ var LIGHT_THEME = {
350
+ accent: "#0f0e0d",
351
+ accentText: "#ffffff",
352
+ orbColor1: "#7cc4ff",
353
+ orbColor2: "#0a3f8f",
354
+ background: "#ffffff",
355
+ text: "#141414",
356
+ textSecondary: "#8a8a86",
357
+ border: "#ebeae8",
358
+ bubbleAgentBackground: "#0f0e0d",
359
+ bubbleAgentText: "#ffffff",
360
+ bubbleUserBackground: "#f4f3f1",
361
+ bubbleUserText: "#141414",
362
+ danger: "#e5484d",
363
+ live: "#30a46c",
364
+ radius: 20,
365
+ fabSize: 60,
366
+ offset: 20
367
+ };
368
+ var DARK_THEME = {
369
+ ...LIGHT_THEME,
370
+ accent: "#f4f3f1",
371
+ accentText: "#0f0e0d",
372
+ background: "#1a1918",
373
+ text: "#f4f3f1",
374
+ textSecondary: "#9a9994",
375
+ border: "#2e2d2b",
376
+ bubbleAgentBackground: "#f4f3f1",
377
+ bubbleAgentText: "#0f0e0d",
378
+ bubbleUserBackground: "#2a2927",
379
+ bubbleUserText: "#f4f3f1"
380
+ };
381
+ var ThemeContext = (0, import_react2.createContext)(LIGHT_THEME);
382
+ function useTheme() {
383
+ return (0, import_react2.useContext)(ThemeContext);
384
+ }
385
+
386
+ // src/drag.tsx
387
+ var import_react3 = require("react");
388
+ var import_react_native = require("react-native");
389
+ var import_jsx_runtime = require("react/jsx-runtime");
390
+ var DRAG_SLOP = 6;
391
+ var SNAP_MS = 200;
392
+ function restingPoint(position, bounds, size) {
393
+ const x = position.side === "left" ? bounds.left : bounds.width - bounds.right - size.width;
394
+ const minY = bounds.top;
395
+ const maxY = Math.max(minY, bounds.height - bounds.bottom - size.height);
396
+ const y = position.edge === "top" ? position.distance : bounds.height - position.distance - size.height;
397
+ return { x, y: Math.min(Math.max(y, minY), maxY) };
398
+ }
399
+ function snapPosition(rect, bounds) {
400
+ const side = rect.x + rect.width / 2 < bounds.width / 2 ? "left" : "right";
401
+ const centerY = rect.y + rect.height / 2;
402
+ if (centerY < bounds.height / 2) {
403
+ return { side, edge: "top", distance: Math.max(bounds.top, rect.y) };
404
+ }
405
+ return { side, edge: "bottom", distance: Math.max(bounds.bottom, bounds.height - rect.y - rect.height) };
406
+ }
407
+ function Draggable({
408
+ cornerStyle,
409
+ position,
410
+ bounds,
411
+ enabled,
412
+ onDragStart,
413
+ onDragEnd,
414
+ anchorSize,
415
+ children
416
+ }) {
417
+ const [point, setPoint] = (0, import_react3.useState)(null);
418
+ const [size, setSize] = (0, import_react3.useState)(null);
419
+ const current = (0, import_react3.useRef)({ x: 0, y: 0 });
420
+ const cornerRect = (0, import_react3.useRef)(null);
421
+ const start = (0, import_react3.useRef)({ x: 0, y: 0 });
422
+ const busy = (0, import_react3.useRef)(false);
423
+ const frame = (0, import_react3.useRef)(null);
424
+ const latest = (0, import_react3.useRef)({ bounds, size, onDragStart, onDragEnd, cornerStyle, anchorSize });
425
+ latest.current = { bounds, size, onDragStart, onDragEnd, cornerStyle, anchorSize };
426
+ const placedRef = (0, import_react3.useRef)(false);
427
+ const place = (next) => {
428
+ current.current = next;
429
+ placedRef.current = true;
430
+ setPoint(next);
431
+ };
432
+ const stopGlide = () => {
433
+ if (frame.current !== null) {
434
+ cancelAnimationFrame(frame.current);
435
+ frame.current = null;
436
+ }
437
+ };
438
+ (0, import_react3.useEffect)(() => stopGlide, []);
439
+ const rest = position && bounds && size ? restingPoint(position, bounds, size) : null;
440
+ (0, import_react3.useEffect)(() => {
441
+ if (rest && !busy.current) {
442
+ place(rest);
443
+ }
444
+ }, [rest?.x, rest?.y]);
445
+ const responder = (0, import_react3.useMemo)(
446
+ () => import_react_native.PanResponder.create({
447
+ // Capture, so a drag that starts on the button's Pressable still moves the launcher.
448
+ onMoveShouldSetPanResponderCapture: (_, g) => Math.abs(g.dx) > DRAG_SLOP || Math.abs(g.dy) > DRAG_SLOP,
449
+ onPanResponderGrant: () => {
450
+ busy.current = true;
451
+ stopGlide();
452
+ const corner = cornerRect.current;
453
+ if (corner && !placedRef.current) {
454
+ const a = latest.current.anchorSize ?? corner;
455
+ const c = latest.current.cornerStyle;
456
+ current.current = {
457
+ x: c.right !== void 0 ? corner.x + corner.width - a.width : corner.x,
458
+ y: c.bottom !== void 0 ? corner.y + corner.height - a.height : corner.y
459
+ };
460
+ }
461
+ start.current = { ...current.current };
462
+ latest.current.onDragStart();
463
+ },
464
+ onPanResponderMove: (_, g) => {
465
+ place({ x: start.current.x + g.dx, y: start.current.y + g.dy });
466
+ },
467
+ onPanResponderRelease: () => {
468
+ const { bounds: b, size: s, onDragEnd: done } = latest.current;
469
+ if (!b || !s) {
470
+ busy.current = false;
471
+ return;
472
+ }
473
+ const next = snapPosition({ ...current.current, ...s }, b);
474
+ const from = { ...current.current };
475
+ const to = restingPoint(next, b, s);
476
+ const began = Date.now();
477
+ const step = () => {
478
+ const t = Math.min(1, (Date.now() - began) / SNAP_MS);
479
+ const k = 1 - (1 - t) ** 3;
480
+ place({ x: from.x + (to.x - from.x) * k, y: from.y + (to.y - from.y) * k });
481
+ if (t < 1) {
482
+ frame.current = requestAnimationFrame(step);
483
+ } else {
484
+ frame.current = null;
485
+ busy.current = false;
486
+ }
487
+ };
488
+ frame.current = requestAnimationFrame(step);
489
+ done(next);
490
+ },
491
+ onPanResponderTerminate: () => {
492
+ busy.current = false;
493
+ },
494
+ onPanResponderTerminationRequest: () => false
495
+ }),
496
+ []
497
+ );
498
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
499
+ import_react_native.View,
500
+ {
501
+ ...enabled ? responder.panHandlers : {},
502
+ onLayout: (e) => {
503
+ const { x, y, width, height } = e.nativeEvent.layout;
504
+ if (point === null) {
505
+ cornerRect.current = { x, y, width, height };
506
+ }
507
+ setSize((old) => old && old.width === width && old.height === height ? old : { width, height });
508
+ },
509
+ style: point ? { position: "absolute", left: point.x, top: point.y } : (
510
+ // A remembered position waits for the size before showing, instead of flashing in the corner.
511
+ [cornerStyle, position ? { opacity: 0 } : null]
512
+ ),
513
+ children
514
+ }
515
+ );
516
+ }
517
+
518
+ // src/views.tsx
519
+ var import_react5 = require("react");
520
+ var import_react_native3 = require("react-native");
521
+
522
+ // src/icons.tsx
523
+ var import_react_native_svg = require("react-native-svg");
524
+ var import_jsx_runtime2 = require("react/jsx-runtime");
525
+ function icon(children) {
526
+ return function Icon({ size = 16, color }) {
527
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
528
+ import_react_native_svg.Svg,
529
+ {
530
+ width: size,
531
+ height: size,
532
+ viewBox: "0 0 24 24",
533
+ fill: "none",
534
+ stroke: color,
535
+ strokeWidth: 2,
536
+ strokeLinecap: "round",
537
+ strokeLinejoin: "round",
538
+ children
539
+ }
540
+ );
541
+ };
542
+ }
543
+ var IconAudioLines = icon(
544
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
545
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M2 10v3" }),
546
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M6 6v11" }),
547
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M10 3v18" }),
548
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M14 8v7" }),
549
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M18 5v13" }),
550
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M22 10v3" })
551
+ ] })
552
+ );
553
+ var IconX = icon(
554
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
555
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M18 6 6 18" }),
556
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "m6 6 12 12" })
557
+ ] })
558
+ );
559
+ var IconMinimize = icon(
560
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
561
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Polyline, { points: "4 14 10 14 10 20" }),
562
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Polyline, { points: "20 10 14 10 14 4" }),
563
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Line, { x1: "14", x2: "21", y1: "10", y2: "3" }),
564
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Line, { x1: "3", x2: "10", y1: "21", y2: "14" })
565
+ ] })
566
+ );
567
+ var IconSend = icon(
568
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
569
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "m22 2-7 20-4-9-9-4Z" }),
570
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M22 2 11 13" })
571
+ ] })
572
+ );
573
+ var IconMic = icon(
574
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
575
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" }),
576
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
577
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Line, { x1: "12", x2: "12", y1: "19", y2: "22" })
578
+ ] })
579
+ );
580
+ var IconMicOff = icon(
581
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
582
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" }),
583
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
584
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Line, { x1: "12", x2: "12", y1: "19", y2: "22" }),
585
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Line, { x1: "3", x2: "21", y1: "3", y2: "21" })
586
+ ] })
587
+ );
588
+ var IconPhone = icon(
589
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z" })
590
+ );
591
+ var IconPhoneOff = icon(
592
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
593
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-3.33-2.67m-2.67-3.34a19.79 19.79 0 0 1-3.07-8.63A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91" }),
594
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Line, { x1: "22", x2: "2", y1: "2", y2: "22" })
595
+ ] })
596
+ );
597
+ var IconChevronDown = icon(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_svg.Path, { d: "m6 9 6 6 6-6" }));
598
+
599
+ // src/parts.tsx
600
+ var import_react4 = require("react");
601
+ var import_react_native2 = require("react-native");
602
+ var import_react_native_svg2 = require("react-native-svg");
603
+ var import_jsx_runtime3 = require("react/jsx-runtime");
604
+ var MONO = import_react_native2.Platform.select({ ios: "Menlo", default: "monospace" });
605
+ function useReducedMotion() {
606
+ const [reduced, setReduced] = (0, import_react4.useState)(false);
607
+ (0, import_react4.useEffect)(() => {
608
+ let active = true;
609
+ void import_react_native2.AccessibilityInfo.isReduceMotionEnabled?.().then((value) => active && setReduced(value)).catch(() => void 0);
610
+ const subscription = import_react_native2.AccessibilityInfo.addEventListener?.("reduceMotionChanged", setReduced);
611
+ return () => {
612
+ active = false;
613
+ subscription?.remove();
614
+ };
615
+ }, []);
616
+ return reduced;
617
+ }
618
+ function useLoop(running, duration, easing = import_react_native2.Easing.linear) {
619
+ const value = (0, import_react4.useRef)(new import_react_native2.Animated.Value(0)).current;
620
+ (0, import_react4.useEffect)(() => {
621
+ if (!running) {
622
+ value.setValue(0);
623
+ return;
624
+ }
625
+ const loop = import_react_native2.Animated.loop(
626
+ import_react_native2.Animated.timing(value, { toValue: 1, duration, easing, useNativeDriver: true })
627
+ );
628
+ loop.start();
629
+ return () => loop.stop();
630
+ }, [running, duration, easing, value]);
631
+ return running ? value : null;
632
+ }
633
+ function Orb({ size, mode }) {
634
+ const theme = useTheme();
635
+ const reduced = useReducedMotion();
636
+ const gradientId = `fa-orb-${(0, import_react4.useId)().replace(/[^a-zA-Z0-9_-]/g, "")}`;
637
+ const animate = mode !== void 0 && !reduced;
638
+ const pulse = useLoop(animate && mode === "listening", 1800, import_react_native2.Easing.out(import_react_native2.Easing.ease));
639
+ const spin = useLoop(animate && mode === "thinking", 900);
640
+ const glow = useLoop(animate && mode === "speaking", 1200, import_react_native2.Easing.inOut(import_react_native2.Easing.ease));
641
+ const ring = size + 10;
642
+ const avatar = useImageWithFallback(useWidgetImages().avatar);
643
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
644
+ import_react_native2.View,
645
+ {
646
+ style: { width: size, height: size, alignItems: "center", justifyContent: "center" },
647
+ accessibilityElementsHidden: true,
648
+ importantForAccessibility: "no-hide-descendants",
649
+ children: [
650
+ mode === "speaking" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
651
+ import_react_native2.Animated.View,
652
+ {
653
+ style: [
654
+ styles.ring,
655
+ {
656
+ width: ring + 6,
657
+ height: ring + 6,
658
+ borderRadius: (ring + 6) / 2,
659
+ backgroundColor: theme.orbColor1,
660
+ opacity: glow ? glow.interpolate({ inputRange: [0, 0.5, 1], outputRange: [0.18, 0.4, 0.18] }) : 0.3,
661
+ transform: glow ? [{ scale: glow.interpolate({ inputRange: [0, 0.5, 1], outputRange: [0.92, 1.05, 0.92] }) }] : []
662
+ }
663
+ ]
664
+ }
665
+ ) : null,
666
+ avatar.loaded ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native_svg2.Svg, { width: size, height: size, children: [
667
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_svg2.Defs, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native_svg2.RadialGradient, { id: gradientId, cx: "32%", cy: "30%", r: "80%", fx: "32%", fy: "30%", children: [
668
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_svg2.Stop, { offset: "0", stopColor: theme.orbColor1 }),
669
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_svg2.Stop, { offset: "0.72", stopColor: theme.orbColor2 })
670
+ ] }) }),
671
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_svg2.Circle, { cx: size / 2, cy: size / 2, r: size / 2, fill: `url(#${gradientId})` })
672
+ ] }),
673
+ avatar.source !== void 0 ? (
674
+ // Mounted while the orb shows so it can load; hidden until it has.
675
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
676
+ import_react_native2.Image,
677
+ {
678
+ source: avatar.source,
679
+ onLoad: avatar.onLoad,
680
+ onError: avatar.onError,
681
+ fadeDuration: 0,
682
+ resizeMode: "cover",
683
+ style: [
684
+ avatar.loaded ? null : styles.loading,
685
+ { width: size, height: size, borderRadius: size / 2, backgroundColor: theme.background }
686
+ ]
687
+ }
688
+ )
689
+ ) : null,
690
+ mode === "listening" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
691
+ import_react_native2.Animated.View,
692
+ {
693
+ style: [
694
+ styles.ring,
695
+ {
696
+ width: ring,
697
+ height: ring,
698
+ borderRadius: ring / 2,
699
+ borderColor: theme.orbColor1,
700
+ opacity: pulse ? pulse.interpolate({ inputRange: [0, 0.7, 1], outputRange: [0.9, 0, 0] }) : 0.7,
701
+ transform: pulse ? [{ scale: pulse.interpolate({ inputRange: [0, 0.7, 1], outputRange: [0.92, 1.14, 1.14] }) }] : []
702
+ }
703
+ ]
704
+ }
705
+ ) : null,
706
+ mode === "thinking" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
707
+ import_react_native2.Animated.View,
708
+ {
709
+ style: [
710
+ styles.ring,
711
+ {
712
+ width: ring,
713
+ height: ring,
714
+ borderRadius: ring / 2,
715
+ borderColor: "transparent",
716
+ borderTopColor: theme.orbColor2,
717
+ transform: spin ? [{ rotate: spin.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "360deg"] }) }] : []
718
+ }
719
+ ]
720
+ }
721
+ ) : null
722
+ ]
723
+ }
724
+ );
725
+ }
726
+ var IDLE_LEVELS = [6, 10, 16, 22, 18, 12, 8, 14, 20, 16, 10, 6, 12, 18, 10, 6].map((h) => h / 22);
727
+ function Waveform({ active, bars = 16, barWidth = 3, gap = 3, height = 22, color }) {
728
+ const reduced = useReducedMotion();
729
+ const wave = useLoop(active && !reduced, 1400);
730
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
731
+ import_react_native2.View,
732
+ {
733
+ style: { flexDirection: "row", alignItems: "center", height, gap },
734
+ accessibilityElementsHidden: true,
735
+ importantForAccessibility: "no-hide-descendants",
736
+ children: Array.from({ length: bars }, (_, index) => {
737
+ const level = IDLE_LEVELS[index % IDLE_LEVELS.length];
738
+ const base = Math.max(3, level * height);
739
+ const phase = index / bars;
740
+ const scale = wave ? wave.interpolate({
741
+ inputRange: [0, phase * 0.5, phase * 0.5 + 0.25, phase * 0.5 + 0.5, 1],
742
+ outputRange: [0.45, 0.45, 1, 0.45, 0.45]
743
+ }) : 1;
744
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
745
+ import_react_native2.Animated.View,
746
+ {
747
+ style: {
748
+ width: barWidth,
749
+ height: base,
750
+ borderRadius: barWidth / 2,
751
+ backgroundColor: color,
752
+ transform: [{ scaleY: scale }]
753
+ }
754
+ },
755
+ index
756
+ );
757
+ })
758
+ }
759
+ );
760
+ }
761
+ function ToolChip({ entry, texts }) {
762
+ const theme = useTheme();
763
+ const [expanded, setExpanded] = (0, import_react4.useState)(false);
764
+ const statusLabel = entry.status === "running" ? texts.toolRunning : entry.status === "done" ? texts.toolDone : texts.toolFailed;
765
+ const dotColor = entry.status === "running" ? "#f5a623" : entry.status === "done" ? theme.live : theme.danger;
766
+ const detail = (label, value) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native2.View, { children: [
767
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.Text, { style: [styles.toolDetailLabel, { color: theme.textSecondary }], children: label }),
768
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.Text, { style: [styles.toolDetailText, { color: theme.text }], children: value })
769
+ ] }, label);
770
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native2.View, { style: styles.tool, children: [
771
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
772
+ import_react_native2.Pressable,
773
+ {
774
+ accessibilityRole: "button",
775
+ accessibilityLabel: `${entry.toolName}, ${statusLabel}`,
776
+ accessibilityState: { expanded },
777
+ onPress: () => setExpanded((value) => !value),
778
+ style: [styles.toolChip, { borderColor: theme.border, backgroundColor: theme.background }],
779
+ children: [
780
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.View, { style: [styles.toolDot, { backgroundColor: dotColor }] }),
781
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.Text, { style: [styles.toolName, { color: theme.text }], children: entry.toolName }),
782
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.View, { style: expanded ? styles.rotated : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconChevronDown, { size: 12, color: theme.textSecondary }) })
783
+ ]
784
+ }
785
+ ),
786
+ expanded ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
787
+ import_react_native2.ScrollView,
788
+ {
789
+ style: [styles.toolDetail, { backgroundColor: theme.bubbleUserBackground }],
790
+ contentContainerStyle: { gap: 6 },
791
+ nestedScrollEnabled: true,
792
+ children: [
793
+ entry.input !== void 0 ? detail("input", formatToolPayload(entry.input, entry.inputTruncated)) : null,
794
+ entry.output !== void 0 ? detail("output", formatToolPayload(entry.output, entry.outputTruncated)) : null,
795
+ entry.error !== void 0 ? detail("error", entry.error) : null
796
+ ]
797
+ }
798
+ ) : null
799
+ ] });
800
+ }
801
+ function Transcript({
802
+ entries,
803
+ texts
804
+ }) {
805
+ const theme = useTheme();
806
+ const ref = (0, import_react4.useRef)(null);
807
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
808
+ import_react_native2.ScrollView,
809
+ {
810
+ ref,
811
+ style: styles.transcript,
812
+ contentContainerStyle: styles.transcriptContent,
813
+ onContentSizeChange: () => ref.current?.scrollToEnd({ animated: true }),
814
+ keyboardShouldPersistTaps: "handled",
815
+ accessibilityLiveRegion: "polite",
816
+ children: entries.map(
817
+ (entry) => entry.kind === "message" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
818
+ import_react_native2.View,
819
+ {
820
+ style: [
821
+ styles.bubble,
822
+ entry.role === "agent" ? [styles.bubbleAgent, { backgroundColor: theme.bubbleAgentBackground }] : [styles.bubbleUser, { backgroundColor: theme.bubbleUserBackground }]
823
+ ],
824
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
825
+ import_react_native2.Text,
826
+ {
827
+ selectable: true,
828
+ style: [
829
+ styles.bubbleText,
830
+ { color: entry.role === "agent" ? theme.bubbleAgentText : theme.bubbleUserText }
831
+ ],
832
+ children: entry.text
833
+ }
834
+ )
835
+ },
836
+ entry.id
837
+ ) : entry.kind === "divider" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native2.View, { style: styles.divider, accessibilityRole: "text", children: [
838
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.View, { style: [styles.dividerLine, { backgroundColor: theme.border }] }),
839
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.Text, { style: [styles.dividerText, { color: theme.textSecondary }], children: entry.label }),
840
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native2.View, { style: [styles.dividerLine, { backgroundColor: theme.border }] })
841
+ ] }, entry.id) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolChip, { entry, texts }, entry.id)
842
+ )
843
+ }
844
+ );
845
+ }
846
+ function Composer({ placeholder, sendLabel, disabled, divided, onSend, onActivity }) {
847
+ const theme = useTheme();
848
+ const [value, setValue] = (0, import_react4.useState)("");
849
+ const canSend = !disabled && value.trim().length > 0;
850
+ const submit = () => {
851
+ const text = value.trim();
852
+ if (!text || disabled) {
853
+ return;
854
+ }
855
+ setValue("");
856
+ onSend(text);
857
+ };
858
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native2.View, { style: [styles.composer, divided ? { borderTopWidth: 1, borderTopColor: theme.border } : null], children: [
859
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
860
+ import_react_native2.TextInput,
861
+ {
862
+ style: [styles.input, { borderColor: theme.border, color: theme.text, backgroundColor: theme.background }],
863
+ value,
864
+ placeholder,
865
+ placeholderTextColor: theme.textSecondary,
866
+ editable: !disabled,
867
+ returnKeyType: "send",
868
+ submitBehavior: "submit",
869
+ onSubmitEditing: submit,
870
+ onChangeText: (text) => {
871
+ setValue(text);
872
+ onActivity?.();
873
+ }
874
+ }
875
+ ),
876
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
877
+ import_react_native2.Pressable,
878
+ {
879
+ accessibilityRole: "button",
880
+ accessibilityLabel: sendLabel,
881
+ accessibilityState: { disabled: !canSend },
882
+ disabled: !canSend,
883
+ onPress: submit,
884
+ style: [styles.send, { backgroundColor: theme.accent, opacity: canSend ? 1 : 0.4 }],
885
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconSend, { size: 16, color: theme.accentText })
886
+ }
887
+ )
888
+ ] });
889
+ }
890
+ var styles = import_react_native2.StyleSheet.create({
891
+ ring: { position: "absolute", borderWidth: 2 },
892
+ loading: { position: "absolute", opacity: 0 },
893
+ tool: { alignSelf: "flex-start", maxWidth: "100%" },
894
+ toolChip: {
895
+ flexDirection: "row",
896
+ alignItems: "center",
897
+ alignSelf: "flex-start",
898
+ gap: 8,
899
+ borderWidth: 1,
900
+ borderRadius: 999,
901
+ paddingVertical: 6,
902
+ paddingHorizontal: 12
903
+ },
904
+ toolDot: { width: 8, height: 8, borderRadius: 4 },
905
+ toolName: { fontFamily: MONO, fontSize: 12 },
906
+ rotated: { transform: [{ rotate: "180deg" }] },
907
+ toolDetail: { marginTop: 6, maxHeight: 140, borderRadius: 12, paddingVertical: 10, paddingHorizontal: 12 },
908
+ toolDetailLabel: { fontSize: 11 },
909
+ toolDetailText: { fontFamily: MONO, fontSize: 11.5, lineHeight: 17 },
910
+ transcript: { flex: 1 },
911
+ transcriptContent: { padding: 16, gap: 10 },
912
+ bubble: { maxWidth: "80%", paddingVertical: 10, paddingHorizontal: 14 },
913
+ bubbleAgent: {
914
+ alignSelf: "flex-start",
915
+ borderTopLeftRadius: 6,
916
+ borderTopRightRadius: 24,
917
+ borderBottomLeftRadius: 24,
918
+ borderBottomRightRadius: 24
919
+ },
920
+ bubbleUser: {
921
+ alignSelf: "flex-end",
922
+ borderTopLeftRadius: 24,
923
+ borderTopRightRadius: 6,
924
+ borderBottomLeftRadius: 24,
925
+ borderBottomRightRadius: 24
926
+ },
927
+ bubbleText: { fontSize: 15, lineHeight: 21 },
928
+ divider: { flexDirection: "row", alignItems: "center", gap: 10, marginVertical: 6 },
929
+ dividerLine: { flex: 1, height: import_react_native2.StyleSheet.hairlineWidth },
930
+ dividerText: { fontSize: 12 },
931
+ composer: { flexDirection: "row", alignItems: "center", gap: 8, paddingVertical: 12, paddingHorizontal: 16 },
932
+ input: { flex: 1, minWidth: 0, height: 40, borderWidth: 1, borderRadius: 999, paddingHorizontal: 16, fontSize: 15 },
933
+ send: { width: 40, height: 40, borderRadius: 20, alignItems: "center", justifyContent: "center" }
934
+ });
935
+
936
+ // src/views.tsx
937
+ var import_jsx_runtime4 = require("react/jsx-runtime");
938
+ function shadow(theme, radius, opacity) {
939
+ return {
940
+ shadowColor: "#0f0e0d",
941
+ shadowOpacity: opacity,
942
+ shadowRadius: radius,
943
+ shadowOffset: { width: 0, height: radius / 3 },
944
+ elevation: Math.round(radius / 2),
945
+ backgroundColor: theme.background
946
+ };
947
+ }
948
+ function openUrl(url) {
949
+ void import_react_native3.Linking.openURL(url).catch(() => void 0);
950
+ }
951
+ function FabView({ settings, proactiveVisible, alignEnd, onOpen, onDismissProactive }) {
952
+ const theme = useTheme();
953
+ const launcherIcon = useImageWithFallback(useWidgetImages().launcherIcon);
954
+ const top = settings.position.startsWith("top");
955
+ const bubble = proactiveVisible && settings.proactiveMessage ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
956
+ import_react_native3.View,
957
+ {
958
+ style: [
959
+ styles2.proactive,
960
+ shadow(theme, 20, 0.14),
961
+ { borderColor: theme.border },
962
+ top ? { marginTop: 12 } : { marginBottom: 12 }
963
+ ],
964
+ children: [
965
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.proactiveText, { color: theme.text }], children: settings.proactiveMessage }),
966
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
967
+ import_react_native3.Pressable,
968
+ {
969
+ accessibilityRole: "button",
970
+ accessibilityLabel: settings.texts.dismissLabel,
971
+ hitSlop: 10,
972
+ onPress: onDismissProactive,
973
+ style: [
974
+ styles2.proactiveDismiss,
975
+ alignEnd ? { right: -9 } : { left: -9 },
976
+ { borderColor: theme.border, backgroundColor: theme.background }
977
+ ],
978
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconX, { size: 11, color: theme.textSecondary })
979
+ }
980
+ )
981
+ ]
982
+ }
983
+ ) : null;
984
+ const fab = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
985
+ import_react_native3.Pressable,
986
+ {
987
+ accessibilityRole: "button",
988
+ accessibilityLabel: settings.texts.openLabel,
989
+ onPress: onOpen,
990
+ style: ({ pressed }) => [
991
+ shadow(theme, 24, 0.22),
992
+ {
993
+ width: theme.fabSize,
994
+ height: theme.fabSize,
995
+ borderRadius: theme.fabSize / 2,
996
+ backgroundColor: theme.accent,
997
+ alignItems: "center",
998
+ justifyContent: "center",
999
+ transform: [{ scale: pressed ? 0.95 : 1 }]
1000
+ }
1001
+ ],
1002
+ children: [
1003
+ launcherIcon.loaded ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconAudioLines, { size: 26, color: theme.accentText }),
1004
+ launcherIcon.source !== void 0 ? (
1005
+ // Mounted while the default icon shows so it can load; hidden until it has.
1006
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1007
+ import_react_native3.Image,
1008
+ {
1009
+ source: launcherIcon.source,
1010
+ onLoad: launcherIcon.onLoad,
1011
+ onError: launcherIcon.onError,
1012
+ fadeDuration: 0,
1013
+ resizeMode: "cover",
1014
+ style: {
1015
+ position: launcherIcon.loaded ? "relative" : "absolute",
1016
+ opacity: launcherIcon.loaded ? 1 : 0,
1017
+ width: theme.fabSize,
1018
+ height: theme.fabSize,
1019
+ borderRadius: theme.fabSize / 2
1020
+ }
1021
+ }
1022
+ )
1023
+ ) : null
1024
+ ]
1025
+ }
1026
+ );
1027
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: { alignItems: alignEnd ? "flex-end" : "flex-start" }, children: [
1028
+ top ? fab : bubble,
1029
+ top ? bubble : fab
1030
+ ] });
1031
+ }
1032
+ function PanelShell({
1033
+ settings,
1034
+ status,
1035
+ mode,
1036
+ live,
1037
+ starting,
1038
+ muted,
1039
+ onToggleMute,
1040
+ onEnd,
1041
+ onMinimize,
1042
+ onClose,
1043
+ style,
1044
+ children
1045
+ }) {
1046
+ const theme = useTheme();
1047
+ const { texts } = settings;
1048
+ const inCall = live || starting;
1049
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: [styles2.panel, { backgroundColor: theme.background, borderColor: theme.border }, style], children: [
1050
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: [styles2.header, { borderBottomColor: theme.border }], children: [
1051
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: styles2.headerLeft, children: [
1052
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Orb, { size: 32, mode }),
1053
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: styles2.headerNames, children: [
1054
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { numberOfLines: 1, style: [styles2.headerTitle, { color: theme.text }], children: settings.agentName }),
1055
+ status != null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: styles2.headerStatus, children: status }) : null
1056
+ ] })
1057
+ ] }),
1058
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: styles2.headerActions, children: [
1059
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconButton, { label: texts.minimizeLabel, onPress: onMinimize, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconMinimize, { size: 16, color: theme.textSecondary }) }),
1060
+ inCall ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1061
+ settings.micMuting ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1062
+ import_react_native3.Pressable,
1063
+ {
1064
+ accessibilityRole: "button",
1065
+ accessibilityLabel: muted ? texts.unmuteLabel : texts.muteLabel,
1066
+ accessibilityState: { selected: muted, disabled: !live },
1067
+ disabled: !live,
1068
+ onPress: onToggleMute,
1069
+ style: [
1070
+ styles2.headerPill,
1071
+ { backgroundColor: muted ? theme.accent : "rgba(128, 128, 128, 0.14)", opacity: live ? 1 : 0.5 }
1072
+ ],
1073
+ children: [
1074
+ muted ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconMic, { size: 13, color: theme.accentText }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconMicOff, { size: 13, color: theme.text }),
1075
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.headerPillText, { color: muted ? theme.accentText : theme.text }], children: muted ? texts.unmuteShort : texts.muteShort })
1076
+ ]
1077
+ }
1078
+ ) : null,
1079
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1080
+ import_react_native3.Pressable,
1081
+ {
1082
+ accessibilityRole: "button",
1083
+ accessibilityLabel: texts.endCallLabel,
1084
+ hitSlop: 6,
1085
+ onPress: onEnd,
1086
+ style: [styles2.headerEnd, { backgroundColor: theme.danger }],
1087
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconPhoneOff, { size: 15, color: "#ffffff" })
1088
+ }
1089
+ )
1090
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconButton, { label: texts.closeLabel, onPress: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconX, { size: 16, color: theme.textSecondary }) })
1091
+ ] })
1092
+ ] }),
1093
+ children,
1094
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Pressable, { accessibilityRole: "link", onPress: () => openUrl("https://fish.audio"), style: styles2.footer, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.footerText, { color: theme.textSecondary }], children: texts.poweredBy }) })
1095
+ ] });
1096
+ }
1097
+ function IconButton({ label, onPress, children }) {
1098
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1099
+ import_react_native3.Pressable,
1100
+ {
1101
+ accessibilityRole: "button",
1102
+ accessibilityLabel: label,
1103
+ hitSlop: 6,
1104
+ onPress,
1105
+ style: ({ pressed }) => [styles2.iconButton, pressed ? { opacity: 0.6 } : null],
1106
+ children
1107
+ }
1108
+ );
1109
+ }
1110
+ function LiveStatus({ label, color, dot }) {
1111
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1112
+ dot ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: [styles2.liveDot, { backgroundColor: dot }] }) : null,
1113
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.headerStatusText, { color }], children: label })
1114
+ ] });
1115
+ }
1116
+ function ErrorLine({ error }) {
1117
+ const theme = useTheme();
1118
+ return error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { accessibilityRole: "alert", style: [styles2.error, { color: theme.danger }], children: error }) : null;
1119
+ }
1120
+ function Cta({ label, wide, onPress }) {
1121
+ const theme = useTheme();
1122
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1123
+ import_react_native3.Pressable,
1124
+ {
1125
+ accessibilityRole: "button",
1126
+ onPress,
1127
+ style: ({ pressed }) => [
1128
+ styles2.cta,
1129
+ wide ? styles2.ctaWide : null,
1130
+ { backgroundColor: theme.accent, opacity: pressed ? 0.85 : 1 }
1131
+ ],
1132
+ children: [
1133
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconPhone, { size: 16, color: theme.accentText }),
1134
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.ctaText, { color: theme.accentText }], children: label })
1135
+ ]
1136
+ }
1137
+ );
1138
+ }
1139
+ function HomeView({ settings, fill, error, onStartVoice, onSendText }) {
1140
+ const theme = useTheme();
1141
+ const { texts } = settings;
1142
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1143
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: [styles2.home, fill ? styles2.fill : null], children: [
1144
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Orb, { size: 72 }),
1145
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.homeGreeting, { color: theme.text }], children: texts.greeting }),
1146
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.homeHint, { color: theme.textSecondary }], children: settings.textInput ? texts.homeHint : texts.startVoice }),
1147
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Cta, { label: texts.startVoice, onPress: onStartVoice })
1148
+ ] }),
1149
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorLine, { error }),
1150
+ settings.textInput ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Composer, { placeholder: texts.composerPlaceholder, sendLabel: texts.sendLabel, onSend: onSendText }) : null
1151
+ ] });
1152
+ }
1153
+ function ConsentView({ settings, fill, onAgree, onDecline }) {
1154
+ const theme = useTheme();
1155
+ const { texts, termsUrl, privacyUrl } = settings;
1156
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: [styles2.consent, fill ? styles2.fill : null], children: [
1157
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.consentTitle, { color: theme.text }], children: texts.consentTitle }),
1158
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.consentTerms, { color: theme.text, backgroundColor: theme.bubbleUserBackground }], children: texts.consentBody }),
1159
+ termsUrl || privacyUrl ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: styles2.consentLinks, children: [
1160
+ termsUrl ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { accessibilityRole: "link", onPress: () => openUrl(termsUrl), style: [styles2.link, { color: theme.text }], children: "Terms of Service" }) : null,
1161
+ privacyUrl ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1162
+ import_react_native3.Text,
1163
+ {
1164
+ accessibilityRole: "link",
1165
+ onPress: () => openUrl(privacyUrl),
1166
+ style: [styles2.link, { color: theme.text }],
1167
+ children: "Privacy Policy"
1168
+ }
1169
+ ) : null
1170
+ ] }) : null,
1171
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: styles2.consentButtons, children: [
1172
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1173
+ import_react_native3.Pressable,
1174
+ {
1175
+ accessibilityRole: "button",
1176
+ onPress: onDecline,
1177
+ style: [styles2.button, { borderWidth: 1, borderColor: theme.border, backgroundColor: theme.background }],
1178
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.buttonText, { color: theme.text }], children: texts.consentDecline })
1179
+ }
1180
+ ),
1181
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Pressable, { accessibilityRole: "button", onPress: onAgree, style: [styles2.button, { backgroundColor: theme.accent }], children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.buttonText, { color: theme.accentText, fontWeight: "500" }], children: texts.consentAgree }) })
1182
+ ] })
1183
+ ] });
1184
+ }
1185
+ function CallView({
1186
+ settings,
1187
+ entries,
1188
+ phase,
1189
+ mode,
1190
+ error,
1191
+ onRestartVoice,
1192
+ onSendText,
1193
+ onActivity
1194
+ }) {
1195
+ const theme = useTheme();
1196
+ const { texts } = settings;
1197
+ const live = phase === "live";
1198
+ const ended = phase === "ended";
1199
+ const [typingRevealed, setTypingRevealed] = (0, import_react5.useState)(false);
1200
+ (0, import_react5.useEffect)(() => {
1201
+ if (!ended) {
1202
+ setTypingRevealed(false);
1203
+ }
1204
+ }, [ended]);
1205
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1206
+ settings.transcript ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Transcript, { entries, texts }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: [styles2.home, { flex: 1, justifyContent: "center" }], children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Orb, { size: 72, mode: live ? mode : void 0 }) }),
1207
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorLine, { error }),
1208
+ !ended ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: [styles2.modeStatus, { borderTopColor: theme.border }], children: [
1209
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Waveform, { active: live, bars: 5, barWidth: 2, gap: 3, height: 12, color: theme.textSecondary }),
1210
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.modeStatusText, { color: theme.textSecondary }], children: live ? texts[mode] : texts.statusConnecting })
1211
+ ] }) : null,
1212
+ settings.textInput && (!ended || typingRevealed) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1213
+ Composer,
1214
+ {
1215
+ placeholder: texts.composerPlaceholder,
1216
+ sendLabel: texts.sendLabel,
1217
+ disabled: phase === "starting",
1218
+ divided: ended,
1219
+ onSend: onSendText,
1220
+ onActivity
1221
+ }
1222
+ ) : null,
1223
+ ended ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: [styles2.ended, { borderTopColor: theme.border }], children: [
1224
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Cta, { label: texts.restartVoice, wide: true, onPress: onRestartVoice }),
1225
+ settings.textInput && !typingRevealed ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Pressable, { accessibilityRole: "button", onPress: () => setTypingRevealed(true), style: styles2.linkButton, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.linkButtonText, { color: theme.textSecondary }], children: texts.continueWithText }) }) : null
1226
+ ] }) : null
1227
+ ] });
1228
+ }
1229
+ function MinimizedPill({ settings, seconds, live, onExpand, onEnd }) {
1230
+ const theme = useTheme();
1231
+ const { texts } = settings;
1232
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: [styles2.pill, shadow(theme, 24, 0.18), { borderColor: theme.border }], children: [
1233
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.Pressable, { accessibilityRole: "button", accessibilityLabel: texts.expandLabel, onPress: onExpand, style: styles2.pillExpand, children: [
1234
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Orb, { size: 32, mode: "speaking" }),
1235
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Waveform, { active: live, bars: 6, barWidth: 2.5, gap: 2.5, height: 18, color: theme.text }),
1236
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: [styles2.pillTimer, { color: theme.text }], children: formatTimer(seconds) })
1237
+ ] }),
1238
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1239
+ import_react_native3.Pressable,
1240
+ {
1241
+ accessibilityRole: "button",
1242
+ accessibilityLabel: texts.endCallLabel,
1243
+ onPress: onEnd,
1244
+ style: [styles2.pillEnd, { backgroundColor: theme.danger }],
1245
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconPhoneOff, { size: 14, color: "#ffffff" })
1246
+ }
1247
+ )
1248
+ ] });
1249
+ }
1250
+ var styles2 = import_react_native3.StyleSheet.create({
1251
+ proactive: {
1252
+ maxWidth: 260,
1253
+ borderWidth: 1,
1254
+ borderRadius: 14,
1255
+ paddingVertical: 12,
1256
+ paddingHorizontal: 16
1257
+ },
1258
+ proactiveText: { fontSize: 14, lineHeight: 20 },
1259
+ proactiveDismiss: {
1260
+ position: "absolute",
1261
+ top: -9,
1262
+ width: 22,
1263
+ height: 22,
1264
+ borderRadius: 11,
1265
+ borderWidth: 1,
1266
+ alignItems: "center",
1267
+ justifyContent: "center"
1268
+ },
1269
+ panel: { overflow: "hidden", flexDirection: "column" },
1270
+ header: {
1271
+ flexDirection: "row",
1272
+ alignItems: "center",
1273
+ justifyContent: "space-between",
1274
+ gap: 12,
1275
+ paddingVertical: 14,
1276
+ paddingHorizontal: 16,
1277
+ borderBottomWidth: import_react_native3.StyleSheet.hairlineWidth
1278
+ },
1279
+ headerLeft: { flexDirection: "row", alignItems: "center", gap: 10, flexShrink: 1 },
1280
+ headerNames: { flexShrink: 1 },
1281
+ headerTitle: { fontSize: 15, fontWeight: "600" },
1282
+ headerStatus: { flexDirection: "row", alignItems: "center", gap: 5 },
1283
+ headerStatusText: { fontSize: 12 },
1284
+ liveDot: { width: 6, height: 6, borderRadius: 3 },
1285
+ headerActions: { flexDirection: "row", alignItems: "center", gap: 6 },
1286
+ iconButton: { width: 32, height: 32, borderRadius: 8, alignItems: "center", justifyContent: "center" },
1287
+ headerPill: {
1288
+ flexDirection: "row",
1289
+ alignItems: "center",
1290
+ gap: 6,
1291
+ height: 30,
1292
+ paddingHorizontal: 11,
1293
+ borderRadius: 999
1294
+ },
1295
+ headerPillText: { fontSize: 13 },
1296
+ headerEnd: { width: 30, height: 30, borderRadius: 15, alignItems: "center", justifyContent: "center" },
1297
+ modeStatus: {
1298
+ flexDirection: "row",
1299
+ alignItems: "center",
1300
+ justifyContent: "center",
1301
+ gap: 8,
1302
+ paddingTop: 10,
1303
+ paddingBottom: 4,
1304
+ paddingHorizontal: 16,
1305
+ borderTopWidth: import_react_native3.StyleSheet.hairlineWidth
1306
+ },
1307
+ modeStatusText: { fontSize: 12 },
1308
+ footer: { paddingTop: 6, paddingBottom: 10, alignItems: "center" },
1309
+ footerText: { fontSize: 12 },
1310
+ error: { fontSize: 13, textAlign: "center", paddingTop: 8, paddingHorizontal: 16 },
1311
+ fill: { flex: 1, justifyContent: "center" },
1312
+ home: { paddingTop: 36, paddingBottom: 28, paddingHorizontal: 24, alignItems: "center", gap: 6 },
1313
+ homeGreeting: { marginTop: 14, fontSize: 16, fontWeight: "600", textAlign: "center" },
1314
+ homeHint: { fontSize: 14, textAlign: "center" },
1315
+ cta: {
1316
+ marginTop: 16,
1317
+ flexDirection: "row",
1318
+ alignItems: "center",
1319
+ justifyContent: "center",
1320
+ gap: 8,
1321
+ height: 44,
1322
+ paddingHorizontal: 22,
1323
+ borderRadius: 999
1324
+ },
1325
+ ctaWide: { marginTop: 0, alignSelf: "stretch" },
1326
+ ctaText: { fontSize: 15, fontWeight: "500" },
1327
+ consent: { paddingTop: 24, paddingBottom: 28, paddingHorizontal: 24, alignItems: "center", gap: 14 },
1328
+ consentTitle: { fontSize: 16, fontWeight: "600" },
1329
+ consentTerms: { borderRadius: 12, padding: 14, fontSize: 13, lineHeight: 20, overflow: "hidden" },
1330
+ consentLinks: { flexDirection: "row", gap: 12 },
1331
+ link: { fontSize: 13, textDecorationLine: "underline" },
1332
+ consentButtons: { flexDirection: "row", gap: 10 },
1333
+ button: { height: 42, paddingHorizontal: 18, borderRadius: 999, alignItems: "center", justifyContent: "center" },
1334
+ buttonText: { fontSize: 15 },
1335
+ ended: {
1336
+ alignItems: "center",
1337
+ gap: 4,
1338
+ paddingTop: 12,
1339
+ paddingBottom: 14,
1340
+ paddingHorizontal: 16,
1341
+ borderTopWidth: import_react_native3.StyleSheet.hairlineWidth
1342
+ },
1343
+ linkButton: { paddingVertical: 6, paddingHorizontal: 8 },
1344
+ linkButtonText: { fontSize: 14 },
1345
+ pill: {
1346
+ flexDirection: "row",
1347
+ alignItems: "center",
1348
+ gap: 10,
1349
+ borderWidth: 1,
1350
+ borderRadius: 999,
1351
+ padding: 10
1352
+ },
1353
+ pillExpand: { flexDirection: "row", alignItems: "center", gap: 10 },
1354
+ pillTimer: { fontSize: 14, fontVariant: ["tabular-nums"] },
1355
+ pillEnd: { width: 34, height: 34, borderRadius: 17, alignItems: "center", justifyContent: "center" }
1356
+ });
1357
+
1358
+ // src/widget.tsx
1359
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1360
+ var SHEET_BELOW_WIDTH = 600;
1361
+ var CARD_WIDTH = 380;
1362
+ var CARD_MAX_HEIGHT = 600;
1363
+ var proactiveDismissed = false;
1364
+ var draggedPosition = null;
1365
+ var acceptedConsentKeys = /* @__PURE__ */ new Set();
1366
+ var _handlers;
1367
+ var CallbackBridge = class {
1368
+ constructor() {
1369
+ __privateAdd(this, _handlers, /* @__PURE__ */ new Map());
1370
+ }
1371
+ on(event, handler) {
1372
+ let set = __privateGet(this, _handlers).get(event);
1373
+ if (!set) {
1374
+ set = /* @__PURE__ */ new Set();
1375
+ __privateGet(this, _handlers).set(event, set);
1376
+ }
1377
+ set.add(handler);
1378
+ return this;
1379
+ }
1380
+ off(event, handler) {
1381
+ __privateGet(this, _handlers).get(event)?.delete(handler);
1382
+ return this;
1383
+ }
1384
+ emit(event, payload) {
1385
+ for (const handler of __privateGet(this, _handlers).get(event) ?? []) {
1386
+ handler(payload);
1387
+ }
1388
+ }
1389
+ };
1390
+ _handlers = new WeakMap();
1391
+ var BRIDGED_EVENTS = [
1392
+ "userTranscript",
1393
+ "agentResponseDelta",
1394
+ "agentResponse",
1395
+ "toolCallStarted",
1396
+ "toolCallCompleted",
1397
+ "toolCallFailed"
1398
+ ];
1399
+ function mergeCallbacks(ours, theirs) {
1400
+ const merged = { ...ours };
1401
+ for (const [key, callback] of Object.entries(theirs ?? {})) {
1402
+ if (typeof callback !== "function") {
1403
+ continue;
1404
+ }
1405
+ const own = merged[key];
1406
+ merged[key] = own ? (payload) => {
1407
+ own(payload);
1408
+ callback(payload);
1409
+ } : callback;
1410
+ }
1411
+ return merged;
1412
+ }
1413
+ function isAbort(error) {
1414
+ return error instanceof Error && error.name === "AbortError";
1415
+ }
1416
+ async function ensureMicrophonePermission() {
1417
+ if (import_react_native4.Platform.OS !== "android") {
1418
+ return true;
1419
+ }
1420
+ const permission = import_react_native4.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
1421
+ if (await import_react_native4.PermissionsAndroid.check(permission)) {
1422
+ return true;
1423
+ }
1424
+ return await import_react_native4.PermissionsAndroid.request(permission) === import_react_native4.PermissionsAndroid.RESULTS.GRANTED;
1425
+ }
1426
+ var FishAgentWidget = (0, import_react6.forwardRef)(
1427
+ function FishAgentWidget2(props, ref) {
1428
+ const propsRef = (0, import_react6.useRef)(props);
1429
+ propsRef.current = props;
1430
+ const systemScheme = (0, import_react_native4.useColorScheme)();
1431
+ const scheme = props.colorScheme === "system" ? systemScheme ?? "light" : props.colorScheme ?? "light";
1432
+ const theme = (0, import_react6.useMemo)(
1433
+ () => ({ ...scheme === "dark" ? DARK_THEME : LIGHT_THEME, ...props.theme }),
1434
+ [scheme, props.theme]
1435
+ );
1436
+ const avatarKey = sourceKey(props.avatar);
1437
+ const launcherIconKey = sourceKey(props.launcherIcon);
1438
+ const images = (0, import_react6.useMemo)(
1439
+ () => ({ avatar: props.avatar, launcherIcon: props.launcherIcon }),
1440
+ [avatarKey, launcherIconKey]
1441
+ );
1442
+ const [remote, setRemote] = (0, import_react6.useState)(null);
1443
+ const attributes = {
1444
+ agentId: props.agentId,
1445
+ serverUrl: props.serverUrl,
1446
+ userId: props.userId,
1447
+ language: props.language,
1448
+ dynamicVariables: props.dynamicVariables,
1449
+ agentName: props.agentName,
1450
+ greeting: props.greeting,
1451
+ proactiveMessage: props.proactiveMessage,
1452
+ proactiveDelaySeconds: props.proactiveDelay,
1453
+ transcript: props.transcript,
1454
+ textInput: props.textInput,
1455
+ micMuting: props.micMuting,
1456
+ consent: props.consent,
1457
+ consentKey: props.consentKey,
1458
+ consentText: props.consentText,
1459
+ termsUrl: props.termsUrl,
1460
+ privacyUrl: props.privacyUrl,
1461
+ position: props.position,
1462
+ texts: props.textContents
1463
+ };
1464
+ const settings = resolveSettings(attributes, remote);
1465
+ for (const [key, value] of Object.entries(MOBILE_TEXTS)) {
1466
+ if (remote?.text_contents?.[key] === void 0 && props.textContents?.[key] === void 0) {
1467
+ settings.texts[key] = value;
1468
+ }
1469
+ }
1470
+ const { texts } = settings;
1471
+ const conversation = (0, import_agent_react_native.useConversation)(
1472
+ {},
1473
+ { callNotification: props.callNotification, audioOutput: props.audioOutput }
1474
+ );
1475
+ const [open, setOpen] = (0, import_react6.useState)(false);
1476
+ const [dragged, setDragged] = (0, import_react6.useState)(draggedPosition);
1477
+ const [container, setContainer] = (0, import_react6.useState)(null);
1478
+ const [phase, setPhase] = (0, import_react6.useState)("idle");
1479
+ const [pending, setPending] = (0, import_react6.useState)(null);
1480
+ const [seconds, setSeconds] = (0, import_react6.useState)(0);
1481
+ const [error, setError] = (0, import_react6.useState)(null);
1482
+ const [pendingText, setPendingText] = (0, import_react6.useState)(null);
1483
+ const [proactiveVisible, setProactiveVisible] = (0, import_react6.useState)(false);
1484
+ const storeRef = (0, import_react6.useRef)(null);
1485
+ storeRef.current ?? (storeRef.current = new TranscriptStore());
1486
+ const store = storeRef.current;
1487
+ const [entries, setEntries] = (0, import_react6.useState)(store.entries);
1488
+ const secondsRef = (0, import_react6.useRef)(0);
1489
+ const liveRef = (0, import_react6.useRef)(null);
1490
+ const detachRef = (0, import_react6.useRef)(null);
1491
+ const attemptRef = (0, import_react6.useRef)(null);
1492
+ const startingRef = (0, import_react6.useRef)(false);
1493
+ const consentAcceptedRef = (0, import_react6.useRef)(false);
1494
+ const lastActivityRef = (0, import_react6.useRef)(0);
1495
+ (0, import_react6.useImperativeHandle)(ref, () => ({ expand: () => setOpen(true) }), []);
1496
+ (0, import_react6.useEffect)(() => store.subscribe(() => setEntries(store.entries)), [store]);
1497
+ (0, import_react6.useEffect)(() => {
1498
+ const agentId = props.agentId;
1499
+ if (!agentId) {
1500
+ return;
1501
+ }
1502
+ let stale = false;
1503
+ void fetchRemoteConfig(props.serverUrl, agentId, props.origin).then((config) => {
1504
+ if (!stale && config) {
1505
+ setRemote(config);
1506
+ }
1507
+ });
1508
+ return () => {
1509
+ stale = true;
1510
+ };
1511
+ }, [props.agentId, props.serverUrl, props.origin]);
1512
+ (0, import_react6.useEffect)(() => {
1513
+ const storage = props.consentStorage;
1514
+ if (!settings.consent || !storage) {
1515
+ return;
1516
+ }
1517
+ let stale = false;
1518
+ void Promise.resolve().then(() => storage.getItem(settings.consentKey)).then((value) => {
1519
+ if (!stale && value === "accepted") {
1520
+ consentAcceptedRef.current = true;
1521
+ }
1522
+ }).catch(() => void 0);
1523
+ return () => {
1524
+ stale = true;
1525
+ };
1526
+ }, [settings.consent, settings.consentKey, props.consentStorage]);
1527
+ (0, import_react6.useEffect)(() => {
1528
+ if (open || !settings.proactiveMessage || proactiveDismissed) {
1529
+ setProactiveVisible(false);
1530
+ return;
1531
+ }
1532
+ const timer = setTimeout(() => setProactiveVisible(true), settings.proactiveDelaySeconds * 1e3);
1533
+ return () => clearTimeout(timer);
1534
+ }, [open, settings.proactiveMessage, settings.proactiveDelaySeconds]);
1535
+ (0, import_react6.useEffect)(() => {
1536
+ if (phase !== "live") {
1537
+ return;
1538
+ }
1539
+ setSeconds(0);
1540
+ secondsRef.current = 0;
1541
+ const startedAt = Date.now();
1542
+ const timer = setInterval(() => {
1543
+ const elapsed = Math.floor((Date.now() - startedAt) / 1e3);
1544
+ secondsRef.current = elapsed;
1545
+ setSeconds(elapsed);
1546
+ }, 500);
1547
+ return () => clearInterval(timer);
1548
+ }, [phase]);
1549
+ (0, import_react6.useEffect)(() => {
1550
+ if (!open) {
1551
+ return;
1552
+ }
1553
+ const subscription = import_react_native4.BackHandler.addEventListener("hardwareBackPress", () => {
1554
+ setOpen(false);
1555
+ return true;
1556
+ });
1557
+ return () => subscription.remove();
1558
+ }, [open]);
1559
+ (0, import_react6.useEffect)(
1560
+ () => () => {
1561
+ if (attemptRef.current) {
1562
+ attemptRef.current.cancelled = true;
1563
+ }
1564
+ detachRef.current?.();
1565
+ },
1566
+ []
1567
+ );
1568
+ const reportError = (detail) => propsRef.current.onError?.(detail);
1569
+ const needsConsent = () => settings.consent && !consentAcceptedRef.current && !acceptedConsentKeys.has(settings.consentKey);
1570
+ const restingPhase = () => store.entries.length > 0 ? "ended" : "idle";
1571
+ const startCall = async (kind, firstText) => {
1572
+ if (startingRef.current || liveRef.current || phase === "starting" || phase === "live") {
1573
+ return;
1574
+ }
1575
+ startingRef.current = true;
1576
+ setError(null);
1577
+ setPendingText(firstText ?? null);
1578
+ setPhase("starting");
1579
+ const attempt = { cancelled: false };
1580
+ attemptRef.current = attempt;
1581
+ const bridge = new CallbackBridge();
1582
+ try {
1583
+ const current = propsRef.current;
1584
+ const options = { microphone: kind === "voice" };
1585
+ if (current.sessionTokenProvider) {
1586
+ options.sessionToken = await current.sessionTokenProvider();
1587
+ } else if (settings.agentId) {
1588
+ options.agentId = settings.agentId;
1589
+ if (current.origin) {
1590
+ options.origin = current.origin;
1591
+ }
1592
+ if (settings.serverUrl) {
1593
+ options.serverUrl = settings.serverUrl;
1594
+ }
1595
+ if (settings.language) {
1596
+ options.language = settings.language;
1597
+ }
1598
+ if (settings.dynamicVariables) {
1599
+ options.dynamicVariables = settings.dynamicVariables;
1600
+ }
1601
+ if (settings.userId) {
1602
+ options.endUserId = settings.userId;
1603
+ }
1604
+ } else {
1605
+ console.error("[fish-agent] set agentId or sessionTokenProvider to start a session");
1606
+ throw new Error("missing configuration");
1607
+ }
1608
+ if (attempt.cancelled) {
1609
+ throw Object.assign(new Error("cancelled"), { name: "AbortError" });
1610
+ }
1611
+ if (current.clientTools) {
1612
+ options.clientTools = current.clientTools;
1613
+ }
1614
+ current.onCall?.(options);
1615
+ const ours = {
1616
+ onDisconnect: ({ reason }) => {
1617
+ if (liveRef.current !== bridge) {
1618
+ return;
1619
+ }
1620
+ liveRef.current = null;
1621
+ detachRef.current?.();
1622
+ detachRef.current = null;
1623
+ store.pushDivider(`${texts.endedDividerLabel} \xB7 ${formatTimer(secondsRef.current)}`);
1624
+ setPhase("ended");
1625
+ propsRef.current.onDisconnect?.({ reason });
1626
+ },
1627
+ onError: (sessionError) => {
1628
+ if (liveRef.current !== bridge) {
1629
+ return;
1630
+ }
1631
+ if (showsErrorBanner(sessionError)) {
1632
+ setError(errorText(texts, sessionError.code));
1633
+ }
1634
+ reportError({
1635
+ code: sessionError.code,
1636
+ message: sessionError.message,
1637
+ ...sessionError.stage !== void 0 ? { stage: sessionError.stage } : {},
1638
+ ...sessionError.recovered !== void 0 ? { recovered: sessionError.recovered } : {}
1639
+ });
1640
+ }
1641
+ };
1642
+ for (const event of BRIDGED_EVENTS) {
1643
+ const key = `on${event.charAt(0).toUpperCase()}${event.slice(1)}`;
1644
+ ours[key] = (payload) => bridge.emit(event, payload);
1645
+ }
1646
+ options.callbacks = mergeCallbacks(ours, options.callbacks);
1647
+ detachRef.current?.();
1648
+ detachRef.current = store.attach(bridge);
1649
+ const sessionId = await conversation.startSession(options);
1650
+ if (attempt.cancelled) {
1651
+ throw Object.assign(new Error("cancelled"), { name: "AbortError" });
1652
+ }
1653
+ liveRef.current = bridge;
1654
+ setPendingText(null);
1655
+ setPhase("live");
1656
+ if (firstText) {
1657
+ conversation.sendUserMessage(firstText);
1658
+ }
1659
+ propsRef.current.onConnect?.({ sessionId });
1660
+ } catch (startError) {
1661
+ if (liveRef.current !== bridge) {
1662
+ detachRef.current?.();
1663
+ detachRef.current = null;
1664
+ }
1665
+ setPendingText(null);
1666
+ setPhase(restingPhase());
1667
+ if (attempt.cancelled || isAbort(startError)) {
1668
+ return;
1669
+ }
1670
+ const code = startError.code;
1671
+ setError(errorText(texts, code));
1672
+ reportError({
1673
+ code: code ?? "connection_failed",
1674
+ message: startError instanceof Error ? startError.message : String(startError)
1675
+ });
1676
+ } finally {
1677
+ startingRef.current = false;
1678
+ if (attemptRef.current === attempt) {
1679
+ attemptRef.current = null;
1680
+ }
1681
+ }
1682
+ };
1683
+ const gate = (action) => {
1684
+ if (needsConsent()) {
1685
+ setPending(action);
1686
+ return;
1687
+ }
1688
+ void startCall(action.kind, action.kind === "text" ? action.text : void 0);
1689
+ };
1690
+ const requestVoice = () => gate({ kind: "voice" });
1691
+ const requestText = (text) => {
1692
+ if (phase === "live" && liveRef.current) {
1693
+ conversation.sendUserMessage(text);
1694
+ return;
1695
+ }
1696
+ gate({ kind: "text", text });
1697
+ };
1698
+ const agreeConsent = () => {
1699
+ consentAcceptedRef.current = true;
1700
+ acceptedConsentKeys.add(settings.consentKey);
1701
+ const storage = propsRef.current.consentStorage;
1702
+ if (storage) {
1703
+ void Promise.resolve().then(() => storage.setItem(settings.consentKey, "accepted")).catch(() => void 0);
1704
+ }
1705
+ const action = pending;
1706
+ setPending(null);
1707
+ if (action) {
1708
+ void startCall(action.kind, action.kind === "text" ? action.text : void 0);
1709
+ }
1710
+ };
1711
+ const toggleMute = async () => {
1712
+ if (!liveRef.current) {
1713
+ return;
1714
+ }
1715
+ const next = !conversation.micMuted;
1716
+ try {
1717
+ if (!next && !await ensureMicrophonePermission()) {
1718
+ setError(texts.errorMicDenied);
1719
+ reportError({ code: "mic_permission_denied", message: "Microphone permission was denied" });
1720
+ return;
1721
+ }
1722
+ await conversation.setMicMuted(next);
1723
+ setError(null);
1724
+ } catch (muteError) {
1725
+ const code = muteError.code;
1726
+ if (code === "mic_permission_denied") {
1727
+ setError(texts.errorMicDenied);
1728
+ }
1729
+ reportError({
1730
+ code: code ?? "connection_failed",
1731
+ message: muteError instanceof Error ? muteError.message : String(muteError)
1732
+ });
1733
+ }
1734
+ };
1735
+ const endCall = () => {
1736
+ if (attemptRef.current) {
1737
+ attemptRef.current.cancelled = true;
1738
+ }
1739
+ void conversation.endSession().catch(() => void 0);
1740
+ };
1741
+ const closePanel = () => {
1742
+ endCall();
1743
+ setError(null);
1744
+ setPending(null);
1745
+ setOpen(false);
1746
+ };
1747
+ const dismissProactive = () => {
1748
+ proactiveDismissed = true;
1749
+ setProactiveVisible(false);
1750
+ };
1751
+ const onActivity = () => {
1752
+ if (phase !== "live") {
1753
+ return;
1754
+ }
1755
+ const now = Date.now();
1756
+ if (now - lastActivityRef.current > 1500) {
1757
+ lastActivityRef.current = now;
1758
+ conversation.sendUserActivity();
1759
+ }
1760
+ };
1761
+ const screen = (0, import_react_native4.useWindowDimensions)();
1762
+ const insets = props.insets ?? {};
1763
+ const top = settings.position.startsWith("top");
1764
+ const draggable = props.draggable === true;
1765
+ const position = draggable ? dragged : null;
1766
+ const alignEnd = position ? position.side === "right" : settings.position.endsWith("right");
1767
+ const corner = {
1768
+ position: "absolute",
1769
+ [top ? "top" : "bottom"]: theme.offset + ((top ? insets.top : insets.bottom) ?? 0),
1770
+ [alignEnd ? "right" : "left"]: theme.offset + ((alignEnd ? insets.right : insets.left) ?? 0)
1771
+ };
1772
+ const bounds = container && {
1773
+ ...container,
1774
+ left: theme.offset + (insets.left ?? 0),
1775
+ right: theme.offset + (insets.right ?? 0),
1776
+ top: theme.offset + (insets.top ?? 0),
1777
+ bottom: theme.offset + (insets.bottom ?? 0)
1778
+ };
1779
+ const launcher = (children, anchorSize) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1780
+ Draggable,
1781
+ {
1782
+ anchorSize,
1783
+ cornerStyle: corner,
1784
+ position,
1785
+ bounds,
1786
+ enabled: draggable,
1787
+ onDragStart: () => {
1788
+ if (proactiveVisible) {
1789
+ dismissProactive();
1790
+ }
1791
+ },
1792
+ onDragEnd: (next) => {
1793
+ draggedPosition = next;
1794
+ setDragged(next);
1795
+ },
1796
+ children
1797
+ }
1798
+ );
1799
+ let content;
1800
+ if (!open) {
1801
+ content = phase === "live" || phase === "starting" ? launcher(
1802
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1803
+ MinimizedPill,
1804
+ {
1805
+ settings,
1806
+ seconds,
1807
+ live: phase === "live",
1808
+ onExpand: () => setOpen(true),
1809
+ onEnd: endCall
1810
+ }
1811
+ )
1812
+ ) : launcher(
1813
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1814
+ FabView,
1815
+ {
1816
+ settings,
1817
+ proactiveVisible,
1818
+ alignEnd,
1819
+ onOpen: () => setOpen(true),
1820
+ onDismissProactive: dismissProactive
1821
+ }
1822
+ ),
1823
+ { width: theme.fabSize, height: theme.fabSize }
1824
+ );
1825
+ } else {
1826
+ const reconnecting = conversation.status === "reconnecting";
1827
+ const status = phase === "starting" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LiveStatus, { label: texts.statusConnecting, color: theme.textSecondary }) : phase === "live" ? reconnecting ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LiveStatus, { label: texts.statusReconnecting, color: theme.textSecondary }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1828
+ LiveStatus,
1829
+ {
1830
+ label: `${texts.statusLive} \xB7 ${formatTimer(seconds)}`,
1831
+ color: theme.textSecondary,
1832
+ dot: theme.live
1833
+ }
1834
+ ) : phase === "ended" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LiveStatus, { label: texts.statusEnded, color: theme.textSecondary }) : null;
1835
+ const inCall = phase !== "idle" && pending === null;
1836
+ const sheet = screen.width < SHEET_BELOW_WIDTH;
1837
+ const callHeight = Math.min(CARD_MAX_HEIGHT, screen.height - 2 * theme.offset - (insets.top ?? 0) - (insets.bottom ?? 0));
1838
+ const panelStyle = sheet ? { flex: 1 } : [
1839
+ styles3.card,
1840
+ { width: CARD_WIDTH, borderRadius: theme.radius, maxHeight: callHeight },
1841
+ inCall && settings.transcript ? { height: callHeight } : null
1842
+ ];
1843
+ const panel = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1844
+ PanelShell,
1845
+ {
1846
+ settings,
1847
+ status,
1848
+ mode: phase === "live" ? conversation.mode : void 0,
1849
+ live: phase === "live",
1850
+ starting: phase === "starting",
1851
+ muted: conversation.micMuted,
1852
+ onToggleMute: () => void toggleMute(),
1853
+ onEnd: endCall,
1854
+ onMinimize: () => setOpen(false),
1855
+ onClose: closePanel,
1856
+ style: panelStyle,
1857
+ children: pending !== null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ConsentView, { settings, fill: sheet, onAgree: agreeConsent, onDecline: () => setPending(null) }) : phase === "idle" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(HomeView, { settings, fill: sheet, error, onStartVoice: requestVoice, onSendText: requestText }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1858
+ CallView,
1859
+ {
1860
+ settings,
1861
+ entries: pendingText !== null && phase === "starting" ? [...entries, { kind: "message", id: "pending:first", role: "user", text: pendingText, final: true }] : entries,
1862
+ phase,
1863
+ mode: conversation.mode,
1864
+ error,
1865
+ onRestartVoice: requestVoice,
1866
+ onSendText: requestText,
1867
+ onActivity
1868
+ }
1869
+ )
1870
+ }
1871
+ );
1872
+ content = sheet ? (
1873
+ // Insets on an outer view: KeyboardAvoidingView sets its own paddingBottom.
1874
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1875
+ import_react_native4.View,
1876
+ {
1877
+ style: [
1878
+ import_react_native4.StyleSheet.absoluteFill,
1879
+ {
1880
+ backgroundColor: theme.background,
1881
+ paddingTop: insets.top ?? 0,
1882
+ paddingBottom: insets.bottom ?? 0,
1883
+ paddingLeft: insets.left ?? 0,
1884
+ paddingRight: insets.right ?? 0
1885
+ }
1886
+ ],
1887
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native4.KeyboardAvoidingView, { behavior: "padding", style: styles3.fill, children: panel })
1888
+ }
1889
+ )
1890
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native4.KeyboardAvoidingView, { behavior: "padding", style: corner, children: panel });
1891
+ }
1892
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ThemeContext.Provider, { value: theme, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ImagesContext.Provider, { value: images, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1893
+ import_react_native4.View,
1894
+ {
1895
+ pointerEvents: "box-none",
1896
+ style: [import_react_native4.StyleSheet.absoluteFill, styles3.layer, props.style],
1897
+ onLayout: (e) => setContainer({ width: e.nativeEvent.layout.width, height: e.nativeEvent.layout.height }),
1898
+ children: content
1899
+ }
1900
+ ) }) });
1901
+ }
1902
+ );
1903
+ var styles3 = import_react_native4.StyleSheet.create({
1904
+ fill: { flex: 1 },
1905
+ // Android draws higher elevation on top regardless of render order, so an
1906
+ // app's elevated views (Button, cards) would otherwise cover the panel.
1907
+ layer: { elevation: 1e3, zIndex: 1e3 },
1908
+ card: {
1909
+ borderWidth: 1,
1910
+ shadowColor: "#0f0e0d",
1911
+ shadowOpacity: 0.18,
1912
+ shadowRadius: 48,
1913
+ shadowOffset: { width: 0, height: 16 },
1914
+ elevation: 16
1915
+ }
1916
+ });
1917
+ // Annotate the CommonJS export names for ESM import in node:
1918
+ 0 && (module.exports = {
1919
+ DEFAULT_TEXTS,
1920
+ FishAgentWidget
1921
+ });
1922
+ /*!
1923
+ * Icon path data from lucide (https://lucide.dev), used under the ISC license.
1924
+ * See THIRD-PARTY-NOTICES.txt in this package for the full notice.
1925
+ */
1926
+ //# sourceMappingURL=index.cjs.map