@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.
@@ -0,0 +1,200 @@
1
+ import * as react from 'react';
2
+ import { SessionToken, AgentSessionOptions, EndReason } from '@fishaudio/agent-client';
3
+ import { CallNotification, AudioOutputRoute } from '@fishaudio/agent-react-native';
4
+ import { ImageSourcePropType, StyleProp, ViewStyle } from 'react-native';
5
+
6
+ /**
7
+ * Widget settings shared by the web and React Native widgets: UI strings, the
8
+ * remote config shape, and resolution. Precedence:
9
+ * host-supplied value > remote widget config (platform endpoint) > built-in default.
10
+ */
11
+
12
+ type WidgetPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
13
+ /**
14
+ * Host-supplied token fetcher for private agents, called before every session
15
+ * start. Fetch the session token from your backend — with whatever auth
16
+ * headers, body, or credentials the request needs — and return it verbatim.
17
+ */
18
+ type SessionTokenProvider = () => SessionToken | Promise<SessionToken>;
19
+ interface WidgetTextContents {
20
+ statusConnecting: string;
21
+ statusReconnecting: string;
22
+ statusLive: string;
23
+ statusEnded: string;
24
+ greeting: string;
25
+ homeHint: string;
26
+ startVoice: string;
27
+ restartVoice: string;
28
+ continueWithText: string;
29
+ endedDividerLabel: string;
30
+ composerPlaceholder: string;
31
+ consentTitle: string;
32
+ consentBody: string;
33
+ consentAgree: string;
34
+ consentDecline: string;
35
+ poweredBy: string;
36
+ listening: string;
37
+ thinking: string;
38
+ speaking: string;
39
+ errorMicDenied: string;
40
+ errorOrigin: string;
41
+ errorUnavailable: string;
42
+ errorConnection: string;
43
+ openLabel: string;
44
+ closeLabel: string;
45
+ minimizeLabel: string;
46
+ expandLabel: string;
47
+ sendLabel: string;
48
+ muteLabel: string;
49
+ unmuteLabel: string;
50
+ muteShort: string;
51
+ unmuteShort: string;
52
+ endCallLabel: string;
53
+ dismissLabel: string;
54
+ toolRunning: string;
55
+ toolDone: string;
56
+ toolFailed: string;
57
+ }
58
+
59
+ /**
60
+ * Widget colors and sizes, the React Native counterpart of the web widget's
61
+ * `--fish-*` CSS custom properties. Pass any subset as the `theme` prop.
62
+ */
63
+ interface WidgetTheme {
64
+ accent: string;
65
+ accentText: string;
66
+ orbColor1: string;
67
+ orbColor2: string;
68
+ background: string;
69
+ text: string;
70
+ textSecondary: string;
71
+ border: string;
72
+ bubbleAgentBackground: string;
73
+ bubbleAgentText: string;
74
+ bubbleUserBackground: string;
75
+ bubbleUserText: string;
76
+ danger: string;
77
+ live: string;
78
+ /** Panel corner radius (the card, not the full-screen sheet). */
79
+ radius: number;
80
+ fabSize: number;
81
+ /** Distance from the screen edges, added to the safe-area insets. */
82
+ offset: number;
83
+ }
84
+
85
+ /** `onError` payload. `stage` and `recovered` come with in-call runtime errors that report them. */
86
+ interface FishAgentWidgetErrorDetail {
87
+ code: string;
88
+ message: string;
89
+ stage?: string;
90
+ recovered?: boolean;
91
+ }
92
+ /**
93
+ * Where the consent answer is remembered, e.g. `@react-native-async-storage/async-storage`.
94
+ * Without one, consent lasts until the app restarts.
95
+ */
96
+ interface ConsentStorage {
97
+ getItem(key: string): string | null | Promise<string | null>;
98
+ setItem(key: string, value: string): void | Promise<void>;
99
+ }
100
+ interface WidgetInsets {
101
+ top?: number;
102
+ bottom?: number;
103
+ left?: number;
104
+ right?: number;
105
+ }
106
+ interface FishAgentWidgetProps {
107
+ /** Public agent id. Exactly one of `agentId` / `sessionTokenProvider` is required. */
108
+ agentId?: string;
109
+ /**
110
+ * @experimental Public agents that restrict origins: one of the agent's
111
+ * allowed origins, sent because an app has no web origin of its own. Not
112
+ * needed otherwise. May change or be removed in a minor release; prefer
113
+ * `sessionTokenProvider` in production.
114
+ */
115
+ origin?: string;
116
+ /** Fetches the session token from your backend (private agents); called before every session start. */
117
+ sessionTokenProvider?: SessionTokenProvider;
118
+ serverUrl?: string;
119
+ /** Your end-user identifier, stored on the session. */
120
+ userId?: string;
121
+ language?: AgentSessionOptions["language"];
122
+ dynamicVariables?: Record<string, string>;
123
+ agentName?: string;
124
+ greeting?: string;
125
+ proactiveMessage?: string;
126
+ /** Seconds before the proactive bubble shows (default 3). */
127
+ proactiveDelay?: number;
128
+ transcript?: boolean;
129
+ textInput?: boolean;
130
+ micMuting?: boolean;
131
+ consent?: boolean;
132
+ consentKey?: string;
133
+ consentText?: string;
134
+ termsUrl?: string;
135
+ privacyUrl?: string;
136
+ /** Corner of the floating button (default `bottom-right`). */
137
+ position?: WidgetPosition;
138
+ /**
139
+ * Image shown instead of the orb in the header, home screen, call screen and
140
+ * minimized pill, e.g. `require("./avatar.png")` or `{ uri }`. Cropped to a
141
+ * circle; the listening, thinking and speaking animation stays around it.
142
+ * Falls back to the orb if it fails to load.
143
+ */
144
+ avatar?: ImageSourcePropType;
145
+ /** Image filling the floating button instead of its icon. Falls back to the icon if it fails to load. */
146
+ launcherIcon?: ImageSourcePropType;
147
+ /** Overrides for any UI string (keys of `DEFAULT_TEXTS`). */
148
+ textContents?: Partial<WidgetTextContents>;
149
+ /** Colors and sizes; any subset, applied over the light or dark defaults. */
150
+ theme?: Partial<WidgetTheme>;
151
+ /** Default `light`, like the web widget. `system` follows the device setting. */
152
+ colorScheme?: "light" | "dark" | "system";
153
+ /** Safe-area insets, e.g. from react-native-safe-area-context's `useSafeAreaInsets()`. */
154
+ insets?: WidgetInsets;
155
+ /**
156
+ * Let the user drag the button (and the minimized call pill). It snaps to the
157
+ * nearer side on release and keeps its place for the app's run. Default `false`.
158
+ */
159
+ draggable?: boolean;
160
+ /** Remembers the consent answer across launches. */
161
+ consentStorage?: ConsentStorage;
162
+ /** Android: the ongoing notification during voice calls (see `useConversation`). */
163
+ callNotification?: CallNotification | false;
164
+ /** Initial audio route (see `useConversation`). */
165
+ audioOutput?: AudioOutputRoute;
166
+ /** Client tools for every session. */
167
+ clientTools?: AgentSessionOptions["clientTools"];
168
+ /** Runs right before a session starts; mutate `options` to adjust anything. */
169
+ onCall?(options: AgentSessionOptions): void;
170
+ onConnect?(event: {
171
+ sessionId: string;
172
+ }): void;
173
+ onDisconnect?(event: {
174
+ reason: EndReason;
175
+ }): void;
176
+ onError?(event: FishAgentWidgetErrorDetail): void;
177
+ /**
178
+ * Style of the full-screen overlay the widget positions itself in. Defaults
179
+ * to `elevation: 1000, zIndex: 1000` so it stays above the app on Android;
180
+ * pass your own values to change that.
181
+ */
182
+ style?: StyleProp<ViewStyle>;
183
+ }
184
+ interface FishAgentWidgetHandle {
185
+ /** Opens the panel, as tapping the floating button does. */
186
+ expand(): void;
187
+ }
188
+ /**
189
+ * The Fish Audio voice-agent widget for React Native: a floating button that
190
+ * opens a call panel with live transcript, text input, mute and consent, the
191
+ * counterpart of the web `<fish-agent>` element. Render it last in your root
192
+ * view so it floats above the app; it fills the screen without blocking
193
+ * touches outside its button and panel.
194
+ */
195
+ declare const FishAgentWidget: react.ForwardRefExoticComponent<FishAgentWidgetProps & react.RefAttributes<FishAgentWidgetHandle>>;
196
+
197
+ /** The widget's built-in UI strings; override any of them with `textContents`. */
198
+ declare const DEFAULT_TEXTS: WidgetTextContents;
199
+
200
+ export { type ConsentStorage, DEFAULT_TEXTS, FishAgentWidget, type FishAgentWidgetErrorDetail, type FishAgentWidgetHandle, type FishAgentWidgetProps, type SessionTokenProvider, type WidgetInsets, type WidgetPosition, type WidgetTextContents, type WidgetTheme };