@guideai/react-native 0.3.0 → 0.7.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/ui.d.ts CHANGED
@@ -1,5 +1,205 @@
1
1
  import React from 'react';
2
2
 
3
+ /** A picture drawn for an answer: a PNG to show, and the SVG it was drawn as. */
4
+ interface HeadlessImage {
5
+ url: string;
6
+ svg: string | null;
7
+ alt: string;
8
+ width: number;
9
+ height: number;
10
+ }
11
+
12
+ interface GuideAIMessage {
13
+ id: string;
14
+ role: 'user' | 'assistant';
15
+ content: string;
16
+ /** When the message was sent or the answer started (ms since epoch). */
17
+ createdAt: number;
18
+ /** On an answer: the user message it replied to. */
19
+ question?: string;
20
+ /** True while tokens are still arriving for this message. */
21
+ streaming?: boolean;
22
+ error?: boolean;
23
+ /**
24
+ * Follow-up suggestions to draw as chips. A tap is just
25
+ * `send(suggestion)`. The site's own when the agent offered some,
26
+ * otherwise the `followUps` the app configured.
27
+ */
28
+ suggestions?: string[];
29
+ /**
30
+ * This answer can be explained on the whiteboard (the Blueprint has the
31
+ * block, and the answer is finished). Draw a button that calls
32
+ * `explainOnWhiteboard(id)`.
33
+ */
34
+ whiteboard?: boolean;
35
+ /**
36
+ * Pictures the agent drew. They are also in `content` as Markdown
37
+ * images where they belong; use this list to place them yourself.
38
+ */
39
+ images?: HeadlessImage[];
40
+ /**
41
+ * A change to the user's data waiting for their yes ("Create the
42
+ * course"). Draw Approve / Cancel and call `confirm(id)` or `cancel(id)`.
43
+ */
44
+ pendingAction?: {
45
+ label: string;
46
+ tool: string;
47
+ };
48
+ }
49
+ /** A recording the host made (expo-audio or any recorder) and saved to a file. */
50
+ interface GuideAIVoiceRecording {
51
+ /** `file://…` URI of the finished recording. */
52
+ uri: string;
53
+ /** e.g. 'audio/m4a'. Omitted: guessed from the file extension. */
54
+ mimeType?: string;
55
+ /** BCP-47 language the user spoke, e.g. 'en-NG'. Defaults to 'en-US'. */
56
+ languageCode?: string;
57
+ }
58
+ interface GuideAIVoiceResult {
59
+ /** What was heard, already sent as the next message; null when nothing was. */
60
+ text: string | null;
61
+ /** The answer to it, as shown (Markdown); null when the turn failed. */
62
+ answer?: string | null;
63
+ /** Why nothing was sent, in words to show the user. */
64
+ error?: string;
65
+ }
66
+ /**
67
+ * Everything a custom chat UI needs, and nothing about how to draw it.
68
+ *
69
+ * A host owns two things — their design, and the text the user typed.
70
+ * This hook owns the rest: the conversation, the streaming, the tool
71
+ * calls, the transport. That split is what lets the agent be upgraded
72
+ * underneath a host's UI without them changing a line.
73
+ */
74
+ interface UseGuideAIResult {
75
+ /**
76
+ * The conversation so far, oldest first, ready to draw. An answer that
77
+ * has not produced any text yet is left out; `typing` covers it.
78
+ */
79
+ messages: GuideAIMessage[];
80
+ /** An answer is on its way but has no text yet: draw a typing indicator. */
81
+ typing: boolean;
82
+ /**
83
+ * Chips to draw under the latest answer: its suggestions, or the app's
84
+ * `followUps`. Empty while a turn runs and before the first answer.
85
+ */
86
+ followUps: string[];
87
+ /** The Blueprint has the whiteboard block. */
88
+ whiteboardAvailable: boolean;
89
+ /**
90
+ * Explain an answer on the whiteboard, with the question it answered.
91
+ * Mount `<GuideAIWhiteboard />` once to show the board.
92
+ */
93
+ explainOnWhiteboard(messageId: string): Promise<boolean>;
94
+ /**
95
+ * The current input text, and its setter.
96
+ *
97
+ * Managed here so a host binds it straight to their TextInput rather
98
+ * than reimplementing "clear on send, block while busy" — the two
99
+ * rules every chat UI needs and each one gets subtly wrong.
100
+ */
101
+ input: string;
102
+ setInput(text: string): void;
103
+ /**
104
+ * Send `input`, or an explicit string.
105
+ *
106
+ * Ignores empty text and calls made while a turn is in flight, so a
107
+ * host does not have to guard their send button.
108
+ */
109
+ send(question?: string): Promise<string | null>;
110
+ /** True from send() until the turn settles. Drives a disabled state. */
111
+ busy: boolean;
112
+ /** Whether `send()` would do anything right now. */
113
+ canSend: boolean;
114
+ /** Status text from the agent loop ("Thinking", "Reading cart"). */
115
+ status: string | null;
116
+ /** Re-send the last user message. Useful after a failed turn. */
117
+ retry(): Promise<void>;
118
+ /** Start a new conversation. The current one stays in the chat history (useConversations). */
119
+ clear(): void;
120
+ /** Approve the message's `pendingAction`; the agent carries it out. */
121
+ confirm(messageId: string): Promise<void>;
122
+ /** Decline the message's `pendingAction`. Nothing is changed. */
123
+ cancel(messageId: string): void;
124
+ /**
125
+ * Push-to-talk: transcribe a recording and send it as the next message.
126
+ * Recording is the host's (no native module here); this uploads it.
127
+ */
128
+ sendVoice(recording: GuideAIVoiceRecording): Promise<GuideAIVoiceResult>;
129
+ /** True while a recording is being transcribed. */
130
+ transcribing: boolean;
131
+ }
132
+
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
+ interface VoiceLanguageFields {
141
+ /** The language the user speaks; null until they chose one. */
142
+ language: VoiceLanguage | null;
143
+ /** The languages to offer. */
144
+ languages: VoiceLanguage[];
145
+ /**
146
+ * Show the language picker (one for the app): the mic or live voice was
147
+ * started before a language was chosen, or `changeLanguage()` was called.
148
+ * Draw `languages`; a tap calls `chooseLanguage(code)`.
149
+ */
150
+ choosingLanguage: boolean;
151
+ /** Pick the language (remembered). Whatever asked for it then starts. */
152
+ chooseLanguage(code: string): Promise<void>;
153
+ /** Open the picker to change the language. */
154
+ changeLanguage(): void;
155
+ /** Close the picker without choosing. */
156
+ cancelLanguage(): void;
157
+ }
158
+
159
+ interface UseVoiceInputResult extends VoiceLanguageFields {
160
+ /** The mic is on. */
161
+ recording: boolean;
162
+ /** What was said is being turned into text (then sent). */
163
+ transcribing: boolean;
164
+ /** Why the last attempt failed, in words to show the user; null when it didn't. */
165
+ error: string | null;
166
+ /** Start recording. False when the microphone was refused or is busy. */
167
+ start(): Promise<boolean>;
168
+ /** Stop, transcribe and send. Resolves with what was heard, or null. */
169
+ stop(): Promise<string | null>;
170
+ /** Stop and throw the recording away. */
171
+ cancel(): Promise<void>;
172
+ /** Start when idle, stop and send when recording: one mic button. */
173
+ toggle(): Promise<void>;
174
+ }
175
+
176
+ type LiveVoiceState =
177
+ /** Not in a call. */
178
+ 'off'
179
+ /** Waiting for the user to speak. */
180
+ | 'listening'
181
+ /** The user is speaking. */
182
+ | 'hearing'
183
+ /** What they said is being understood and answered. */
184
+ | 'thinking'
185
+ /** The answer is being read aloud. */
186
+ | 'speaking';
187
+ interface UseLiveVoiceResult extends VoiceLanguageFields {
188
+ state: LiveVoiceState;
189
+ /** In a call (any state but 'off'). */
190
+ active: boolean;
191
+ /** Mic level 0–1 while listening, for a pulsing button. */
192
+ level: number;
193
+ /** Why the call stopped or a turn failed, in words to show; null otherwise. */
194
+ error: string | null;
195
+ /** Start the call. False when the microphone was refused or no language is chosen yet. */
196
+ start(): Promise<boolean>;
197
+ /** End the call. */
198
+ stop(): void;
199
+ /** Cut the answer short and listen again. */
200
+ interrupt(): void;
201
+ }
202
+
3
203
  interface GuideAITheme {
4
204
  /** Page background behind the conversation. */
5
205
  background: string;
@@ -56,8 +256,19 @@ interface GuideAIChatProps {
56
256
  greeting?: string;
57
257
  /** Replaces the whole pre-conversation state, greeting included. */
58
258
  emptyState?: React.ReactNode;
59
- /** Show the mic button. Inert until voice ships. */
259
+ /**
260
+ * Show the mic (push-to-talk) and live voice buttons. They work in
261
+ * <GuideAIVoiceChat> from '@guideai/react-native/voice'; here, without
262
+ * voice, nothing is shown.
263
+ */
60
264
  showMic?: boolean;
265
+ /** Show the chat history button (previous conversations, new chat). Default true. */
266
+ showHistory?: boolean;
267
+ /**
268
+ * Voice, wired by <GuideAIVoiceChat>. Called as a hook with this chat.
269
+ * Must not change between renders.
270
+ */
271
+ useVoice?: (chat: UseGuideAIResult) => GuideAIChatVoice;
61
272
  /** Rendered at the left of the composer — an attach action, usually. */
62
273
  leadingAccessory?: React.ReactNode;
63
274
  /**
@@ -109,7 +320,12 @@ interface GuideAIChatProps {
109
320
  */
110
321
  topInset?: number;
111
322
  }
112
- declare function GuideAIChat({ theme: overrides, placeholder, greeting, emptyState, showMic, leadingAccessory, title, onClose, onTalkToHuman, humanHandoverAvailable, topInset, }: GuideAIChatProps): React.ReactElement;
323
+ /** What <GuideAIVoiceChat> plugs in: push-to-talk and live voice. */
324
+ interface GuideAIChatVoice {
325
+ mic: UseVoiceInputResult;
326
+ live: UseLiveVoiceResult;
327
+ }
328
+ declare function GuideAIChat({ theme: overrides, placeholder, greeting, emptyState, showMic, showHistory, useVoice, leadingAccessory, title, onClose, onTalkToHuman, humanHandoverAvailable, topInset, }: GuideAIChatProps): React.ReactElement;
113
329
 
114
330
  interface SheetControls {
115
331
  open(): void;
@@ -213,5 +429,42 @@ interface MarkdownProps {
213
429
  }
214
430
  declare function Markdown({ children, color, accentColor, fontSize, }: MarkdownProps): React.ReactElement;
215
431
 
216
- export { GuideAIButton, GuideAIChat, GuideAILauncher, GuideAISupportChat, GuideAIWhiteboard, Markdown, darkTheme, lightTheme, resolveTheme, useGuideAISheet };
217
- export type { GuideAIChatProps, GuideAILauncherProps, GuideAISupportChatProps, GuideAITheme, GuideAIThemeOverrides, GuideAIWhiteboardProps, MarkdownProps };
432
+ /** Every word the panel shows, for translation. */
433
+ interface GuideAILiveVoiceLabels {
434
+ eyebrow: string;
435
+ listeningTitle: string;
436
+ listeningText: string;
437
+ hearingTitle: string;
438
+ hearingText: string;
439
+ thinkingTitle: string;
440
+ thinkingText: string;
441
+ speakingTitle: string;
442
+ speakingText: string;
443
+ end: string;
444
+ /** Before the language name: "Language" → "Language: English". */
445
+ language: string;
446
+ }
447
+ declare const DEFAULT_LIVE_VOICE_LABELS: GuideAILiveVoiceLabels;
448
+ interface GuideAILiveVoiceProps {
449
+ live: UseLiveVoiceResult;
450
+ theme?: GuideAIThemeOverrides;
451
+ labels?: Partial<GuideAILiveVoiceLabels>;
452
+ }
453
+ declare function GuideAILiveVoice({ live, theme: overrides, labels: given }: GuideAILiveVoiceProps): React.ReactElement | null;
454
+
455
+ interface GuideAILanguagePickerLabels {
456
+ title: string;
457
+ hint: string;
458
+ cancel: string;
459
+ }
460
+ declare const DEFAULT_LANGUAGE_PICKER_LABELS: GuideAILanguagePickerLabels;
461
+ interface GuideAILanguagePickerProps {
462
+ /** useVoiceInput() or useLiveVoice(): they share one choice and one picker. */
463
+ voice: VoiceLanguageFields;
464
+ theme?: GuideAIThemeOverrides;
465
+ labels?: Partial<GuideAILanguagePickerLabels>;
466
+ }
467
+ declare function GuideAILanguagePicker({ voice, theme: overrides, labels: given }: GuideAILanguagePickerProps): React.ReactElement | null;
468
+
469
+ export { DEFAULT_LANGUAGE_PICKER_LABELS, DEFAULT_LIVE_VOICE_LABELS, GuideAIButton, GuideAIChat, GuideAILanguagePicker, GuideAILauncher, GuideAILiveVoice, GuideAISupportChat, GuideAIWhiteboard, Markdown, darkTheme, lightTheme, resolveTheme, useGuideAISheet };
470
+ export type { GuideAIChatProps, GuideAILanguagePickerLabels, GuideAILanguagePickerProps, GuideAILauncherProps, GuideAILiveVoiceLabels, GuideAILiveVoiceProps, GuideAISupportChatProps, GuideAITheme, GuideAIThemeOverrides, GuideAIWhiteboardProps, MarkdownProps };