@guideai/react-native 0.3.0 → 0.6.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/voice.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import React from 'react';
2
+
1
3
  /** A picture drawn for an answer: a PNG to show, and the SVG it was drawn as. */
2
4
  interface HeadlessImage {
3
5
  url: string;
@@ -56,6 +58,8 @@ interface GuideAIVoiceRecording {
56
58
  interface GuideAIVoiceResult {
57
59
  /** What was heard, already sent as the next message; null when nothing was. */
58
60
  text: string | null;
61
+ /** The answer to it, as shown (Markdown); null when the turn failed. */
62
+ answer?: string | null;
59
63
  /** Why nothing was sent, in words to show the user. */
60
64
  error?: string;
61
65
  }
@@ -102,7 +106,7 @@ interface UseGuideAIResult {
102
106
  * Ignores empty text and calls made while a turn is in flight, so a
103
107
  * host does not have to guard their send button.
104
108
  */
105
- send(question?: string): Promise<void>;
109
+ send(question?: string): Promise<string | null>;
106
110
  /** True from send() until the turn settles. Drives a disabled state. */
107
111
  busy: boolean;
108
112
  /** Whether `send()` would do anything right now. */
@@ -111,7 +115,7 @@ interface UseGuideAIResult {
111
115
  status: string | null;
112
116
  /** Re-send the last user message. Useful after a failed turn. */
113
117
  retry(): Promise<void>;
114
- /** Drop the conversation and start over. */
118
+ /** Start a new conversation. The current one stays in the chat history (useConversations). */
115
119
  clear(): void;
116
120
  /** Approve the message's `pendingAction`; the agent carries it out. */
117
121
  confirm(messageId: string): Promise<void>;
@@ -126,13 +130,45 @@ interface UseGuideAIResult {
126
130
  transcribing: boolean;
127
131
  }
128
132
 
129
- interface UseVoiceInputOptions {
130
- /** BCP-47 language spoken, e.g. 'en-NG'. Defaults to the user profile's language. */
133
+ /** A language the user can speak in, as the picker shows it. */
134
+ interface VoiceLanguage {
135
+ /** Code the recognizer takes, e.g. 'en', 'fr', 'yo'. */
136
+ code: string;
137
+ /** Its name in that language, e.g. 'Français'. */
138
+ label: string;
139
+ }
140
+ /** Offered when the app gives no list. */
141
+ declare const DEFAULT_VOICE_LANGUAGES: VoiceLanguage[];
142
+ interface VoiceLanguageOptions {
143
+ /** The language spoken, fixed by the app. Given, the user is never asked. */
131
144
  languageCode?: string;
145
+ /** Languages the picker offers. Defaults to DEFAULT_VOICE_LANGUAGES. */
146
+ languages?: VoiceLanguage[];
147
+ }
148
+ interface VoiceLanguageFields {
149
+ /** The language the user speaks; null until they chose one. */
150
+ language: VoiceLanguage | null;
151
+ /** The languages to offer. */
152
+ languages: VoiceLanguage[];
153
+ /**
154
+ * Show the language picker (one for the app): the mic or live voice was
155
+ * started before a language was chosen, or `changeLanguage()` was called.
156
+ * Draw `languages`; a tap calls `chooseLanguage(code)`.
157
+ */
158
+ choosingLanguage: boolean;
159
+ /** Pick the language (remembered). Whatever asked for it then starts. */
160
+ chooseLanguage(code: string): Promise<void>;
161
+ /** Open the picker to change the language. */
162
+ changeLanguage(): void;
163
+ /** Close the picker without choosing. */
164
+ cancelLanguage(): void;
165
+ }
166
+
167
+ interface UseVoiceInputOptions extends VoiceLanguageOptions {
132
168
  /** A recording stops and is sent after this long. Default 60 s. */
133
169
  maxSeconds?: number;
134
170
  }
135
- interface UseVoiceInputResult {
171
+ interface UseVoiceInputResult extends VoiceLanguageFields {
136
172
  /** The mic is on. */
137
173
  recording: boolean;
138
174
  /** What was said is being turned into text (then sent). */
@@ -157,5 +193,215 @@ interface UseVoiceInputResult {
157
193
  */
158
194
  declare function useVoiceInput(chat: Pick<UseGuideAIResult, 'sendVoice' | 'transcribing' | 'busy'>, options?: UseVoiceInputOptions): UseVoiceInputResult;
159
195
 
160
- export { useVoiceInput };
161
- export type { UseVoiceInputOptions, UseVoiceInputResult };
196
+ /** Something that says a line aloud. `say` resolves when it finishes: true if it was heard. */
197
+ interface GuideAISpeech {
198
+ say(text: string): Promise<boolean>;
199
+ stop(): void;
200
+ }
201
+
202
+ /**
203
+ * GuideAI's natural voice, played on the device. `say` takes any length:
204
+ * it is cut into lines the endpoint takes, and the next line is fetched
205
+ * while the current one plays.
206
+ */
207
+ declare function createSpeech(): GuideAISpeech;
208
+
209
+ type LiveVoiceState =
210
+ /** Not in a call. */
211
+ 'off'
212
+ /** Waiting for the user to speak. */
213
+ | 'listening'
214
+ /** The user is speaking. */
215
+ | 'hearing'
216
+ /** What they said is being understood and answered. */
217
+ | 'thinking'
218
+ /** The answer is being read aloud. */
219
+ | 'speaking';
220
+ interface UseLiveVoiceOptions extends VoiceLanguageOptions {
221
+ /** A call with nobody speaking ends after this long. Default 30 s. */
222
+ idleSeconds?: number;
223
+ /** Silence that ends what the user is saying. Default 1.2 s. */
224
+ pauseSeconds?: number;
225
+ }
226
+ interface UseLiveVoiceResult extends VoiceLanguageFields {
227
+ state: LiveVoiceState;
228
+ /** In a call (any state but 'off'). */
229
+ active: boolean;
230
+ /** Mic level 0–1 while listening, for a pulsing button. */
231
+ level: number;
232
+ /** Why the call stopped or a turn failed, in words to show; null otherwise. */
233
+ error: string | null;
234
+ /** Start the call. False when the microphone was refused or no language is chosen yet. */
235
+ start(): Promise<boolean>;
236
+ /** End the call. */
237
+ stop(): void;
238
+ /** Cut the answer short and listen again. */
239
+ interrupt(): void;
240
+ }
241
+ /**
242
+ * A live voice call for a chat from `useGuideAI()`:
243
+ *
244
+ * const chat = useGuideAI();
245
+ * const live = useLiveVoice(chat);
246
+ * <Button onPress={live.active ? live.stop : live.start} title={live.active ? 'End' : 'Talk'} />
247
+ */
248
+ declare function useLiveVoice(chat: Pick<UseGuideAIResult, 'sendVoice' | 'busy' | 'transcribing'>, options?: UseLiveVoiceOptions): UseLiveVoiceResult;
249
+
250
+ /** The answer as plain words to say. */
251
+ declare function toSpeakable(markdown: string): string;
252
+
253
+ interface GuideAITheme {
254
+ /** Page background behind the conversation. */
255
+ background: string;
256
+ /** Secondary surfaces: the composer pill, assistant bubbles. */
257
+ surface: string;
258
+ /**
259
+ * An OPAQUE surface, for anything floating over app content — the
260
+ * nudge tooltip. `surface` is translucent by design, which would let
261
+ * the page show through the text behind it.
262
+ */
263
+ surfaceRaised: string;
264
+ /** Primary text. */
265
+ text: string;
266
+ /** Placeholder, status text, timestamps. */
267
+ textMuted: string;
268
+ /** Send button, links, list markers, the avatar glow. */
269
+ accent: string;
270
+ /** Text drawn on top of `accent`. */
271
+ onAccent: string;
272
+ /** The user's own message bubble. */
273
+ userBubble: string;
274
+ /** Text inside the user's bubble. */
275
+ onUserBubble: string;
276
+ /** Failed-message background. */
277
+ error: string;
278
+ /** Hairlines and dividers. */
279
+ border: string;
280
+ /** Corner radius for the composer and bubbles. */
281
+ radius: number;
282
+ /** Base body size; headings and code derive from it. */
283
+ fontSize: number;
284
+ }
285
+ /** A host's overrides, merged onto a base. */
286
+ type GuideAIThemeOverrides = Partial<GuideAITheme>;
287
+
288
+ interface GuideAIChatProps {
289
+ /** Colours and radii. Partial — unset tokens keep their defaults. */
290
+ theme?: GuideAIThemeOverrides;
291
+ placeholder?: string;
292
+ /** Greeting shown before the first message. */
293
+ greeting?: string;
294
+ /** Replaces the whole pre-conversation state, greeting included. */
295
+ emptyState?: React.ReactNode;
296
+ /**
297
+ * Show the mic (push-to-talk) and live voice buttons. They work in
298
+ * <GuideAIVoiceChat> from '@guideai/react-native/voice'; here, without
299
+ * voice, nothing is shown.
300
+ */
301
+ showMic?: boolean;
302
+ /** Show the chat history button (previous conversations, new chat). Default true. */
303
+ showHistory?: boolean;
304
+ /**
305
+ * Voice, wired by <GuideAIVoiceChat>. Called as a hook with this chat.
306
+ * Must not change between renders.
307
+ */
308
+ useVoice?: (chat: UseGuideAIResult) => GuideAIChatVoice;
309
+ /** Rendered at the left of the composer — an attach action, usually. */
310
+ leadingAccessory?: React.ReactNode;
311
+ /**
312
+ * Shown in the header beside the close button. Omitted, the header
313
+ * carries only the close control.
314
+ */
315
+ title?: string;
316
+ /**
317
+ * Called by the header's close button. Supplied automatically by
318
+ * <GuideAILauncher>; pass it yourself when embedding the chat in your
319
+ * own route.
320
+ *
321
+ * The header renders regardless — it carries the assistant's name and
322
+ * the Talk to a person action — but without this there is no close
323
+ * control, since an embedded chat that is a whole screen should be
324
+ * dismissed by the host's own navigation.
325
+ */
326
+ onClose?: () => void;
327
+ /**
328
+ * The visitor asked for a person.
329
+ *
330
+ * Mirrors the web SDK, where `handleRequestHuman()` closes the AI chat
331
+ * and dispatches `guideai:open-support` so the visitor ends up in one
332
+ * conversation rather than two. React Native has no support panel to
333
+ * hand off to, so the host supplies the destination — their own support
334
+ * route, Intercom, a phone dialler.
335
+ */
336
+ onTalkToHuman?: () => void;
337
+ /**
338
+ * Show the Talk to a person button without asking the backend.
339
+ *
340
+ * Left unset, the button appears only when the live-support service says
341
+ * a human is reachable — the same `support/public/status` check the web
342
+ * SDK's `refreshHelpSupport()` makes, so switching Live Support on in the
343
+ * dashboard takes effect without shipping a new build.
344
+ */
345
+ humanHandoverAvailable?: boolean;
346
+ /**
347
+ * Extra space above the navbar, for the status bar / notch.
348
+ *
349
+ * The sheet is presented `statusBarTranslucent` on Android, so its
350
+ * content starts at y=0 — underneath the clock and the notification
351
+ * icons. Defaulted rather than required because this package will not
352
+ * take a peer dependency on react-native-safe-area-context for one
353
+ * measurement; a host that already has it should pass the real inset:
354
+ *
355
+ * const { top } = useSafeAreaInsets();
356
+ * <GuideAIChat topInset={top} />
357
+ */
358
+ topInset?: number;
359
+ }
360
+ /** What <GuideAIVoiceChat> plugs in: push-to-talk and live voice. */
361
+ interface GuideAIChatVoice {
362
+ mic: UseVoiceInputResult;
363
+ live: UseLiveVoiceResult;
364
+ }
365
+
366
+ type GuideAIVoiceChatProps = Omit<GuideAIChatProps, 'useVoice'>;
367
+ declare function GuideAIVoiceChat(props: GuideAIVoiceChatProps): React.ReactElement;
368
+
369
+ /** Every word the panel shows, for translation. */
370
+ interface GuideAILiveVoiceLabels {
371
+ eyebrow: string;
372
+ listeningTitle: string;
373
+ listeningText: string;
374
+ hearingTitle: string;
375
+ hearingText: string;
376
+ thinkingTitle: string;
377
+ thinkingText: string;
378
+ speakingTitle: string;
379
+ speakingText: string;
380
+ end: string;
381
+ /** Before the language name: "Language" → "Language: English". */
382
+ language: string;
383
+ }
384
+ declare const DEFAULT_LIVE_VOICE_LABELS: GuideAILiveVoiceLabels;
385
+ interface GuideAILiveVoiceProps {
386
+ live: UseLiveVoiceResult;
387
+ theme?: GuideAIThemeOverrides;
388
+ labels?: Partial<GuideAILiveVoiceLabels>;
389
+ }
390
+ declare function GuideAILiveVoice({ live, theme: overrides, labels: given }: GuideAILiveVoiceProps): React.ReactElement | null;
391
+
392
+ interface GuideAILanguagePickerLabels {
393
+ title: string;
394
+ hint: string;
395
+ cancel: string;
396
+ }
397
+ declare const DEFAULT_LANGUAGE_PICKER_LABELS: GuideAILanguagePickerLabels;
398
+ interface GuideAILanguagePickerProps {
399
+ /** useVoiceInput() or useLiveVoice(): they share one choice and one picker. */
400
+ voice: VoiceLanguageFields;
401
+ theme?: GuideAIThemeOverrides;
402
+ labels?: Partial<GuideAILanguagePickerLabels>;
403
+ }
404
+ declare function GuideAILanguagePicker({ voice, theme: overrides, labels: given }: GuideAILanguagePickerProps): React.ReactElement | null;
405
+
406
+ export { DEFAULT_LANGUAGE_PICKER_LABELS, DEFAULT_LIVE_VOICE_LABELS, DEFAULT_VOICE_LANGUAGES, GuideAILanguagePicker, GuideAILiveVoice, GuideAIVoiceChat, createSpeech, toSpeakable, useLiveVoice, useVoiceInput };
407
+ export type { GuideAILanguagePickerLabels, GuideAILanguagePickerProps, GuideAILiveVoiceLabels, GuideAILiveVoiceProps, GuideAIVoiceChatProps, LiveVoiceState, UseLiveVoiceOptions, UseLiveVoiceResult, UseVoiceInputOptions, UseVoiceInputResult, VoiceLanguage };