@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/README.md +72 -20
- package/dist/GuideAIChat-CxyWFl_o.cjs +2493 -0
- package/dist/GuideAIChat-CxyWFl_o.cjs.map +1 -0
- package/dist/GuideAIChat-DOC4zx-a.js +2494 -0
- package/dist/GuideAIChat-DOC4zx-a.js.map +1 -0
- package/dist/index.cjs +19 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +68 -4
- package/dist/index.mjs +6 -7
- package/dist/index.mjs.map +1 -1
- package/dist/ui.cjs +22 -2029
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.ts +257 -4
- package/dist/ui.mjs +14 -2020
- package/dist/ui.mjs.map +1 -1
- package/dist/{setup-CkXajERE.js → useConversations-B_7km_uH.js} +975 -52
- package/dist/useConversations-B_7km_uH.js.map +1 -0
- package/dist/{setup-Bl0ZLz8B.cjs → useConversations-CTbQBTz-.cjs} +974 -51
- package/dist/useConversations-CTbQBTz-.cjs.map +1 -0
- package/dist/voice.cjs +466 -15
- package/dist/voice.cjs.map +1 -1
- package/dist/voice.d.ts +253 -7
- package/dist/voice.mjs +469 -17
- package/dist/voice.mjs.map +1 -1
- package/package.json +15 -10
- package/dist/setup-Bl0ZLz8B.cjs.map +0 -1
- package/dist/setup-CkXajERE.js.map +0 -1
- package/dist/useOnboarding-BAKQq8T_.js +0 -677
- package/dist/useOnboarding-BAKQq8T_.js.map +0 -1
- package/dist/useOnboarding-CFxofFst.cjs +0 -676
- package/dist/useOnboarding-CFxofFst.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
# @guideai/react-native
|
|
2
2
|
|
|
3
|
-
Your GuideAI agent inside a React Native app, in assistant mode.
|
|
3
|
+
Your GuideAI agent inside a React Native app, in assistant mode. We run everything: the conversation, calls to your API as the signed-in user, follow-up suggestions, the whiteboard and its voice, push-to-talk, live voice and chat history. You draw the UI, or use ours.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install @guideai/react-native
|
|
7
|
+
# voice (mic, live voice, the whiteboard's voice) also needs:
|
|
8
|
+
npx expo install expo-audio expo-file-system
|
|
9
|
+
# pictures on the whiteboard:
|
|
10
|
+
npx expo install react-native-svg
|
|
7
11
|
```
|
|
8
12
|
|
|
9
|
-
React ≥ 18 and React Native ≥ 0.73. No native module of its own, so it works in
|
|
13
|
+
React ≥ 18 and React Native ≥ 0.73. No native module of its own: voice uses expo-audio and expo-file-system, which Expo apps already ship, so it works in a dev build and over OTA updates.
|
|
14
|
+
|
|
15
|
+
## The quickest way: our chat, with voice
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
19
|
+
import { GuideAI } from '@guideai/react-native';
|
|
20
|
+
import { GuideAIVoiceChat } from '@guideai/react-native/voice';
|
|
21
|
+
|
|
22
|
+
GuideAI.configure({ apiKey: 'pk_live_…', origin: 'https://app.example.com', storage: AsyncStorage });
|
|
23
|
+
|
|
24
|
+
<GuideAIVoiceChat title="Tutor" />
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
That screen has streaming answers, follow-up chips, Explain on whiteboard (spoken), the mic (asks which language once), live voice, and a chat history (new chat, previous chats). `<GuideAIChat />` from `@guideai/react-native/ui` is the same without voice. Colours come from `theme`.
|
|
10
28
|
|
|
11
29
|
## Set up once, at startup
|
|
12
30
|
|
|
@@ -21,6 +39,9 @@ GuideAI.configure({
|
|
|
21
39
|
getAuthToken: () => AsyncStorage.getItem('accessToken'),
|
|
22
40
|
onAuthExpired: () => refreshSession(), // return the new token
|
|
23
41
|
userProfile: { age: 12, class: 'JSS1', country: 'Nigeria', language: 'en' },
|
|
42
|
+
storage: AsyncStorage, // chat history and the voice language survive a relaunch
|
|
43
|
+
speech: createSpeech(), // from '@guideai/react-native/voice': the whiteboard speaks
|
|
44
|
+
followUps: ['Explain it differently', 'Give me an example'], // chips when an answer has none of its own
|
|
24
45
|
});
|
|
25
46
|
```
|
|
26
47
|
|
|
@@ -57,31 +78,42 @@ Use `http://10.0.2.2:8000` from an Android emulator.
|
|
|
57
78
|
|
|
58
79
|
## Draw your own chat
|
|
59
80
|
|
|
81
|
+
The hooks give you finished data and plain callbacks; your components only draw.
|
|
82
|
+
|
|
60
83
|
```tsx
|
|
61
|
-
import { useGuideAI } from '@guideai/react-native';
|
|
84
|
+
import { useConversations, useGuideAI } from '@guideai/react-native';
|
|
85
|
+
import { GuideAILanguagePicker, GuideAILiveVoice, GuideAIWhiteboard } from '@guideai/react-native/ui';
|
|
86
|
+
import { useLiveVoice, useVoiceInput } from '@guideai/react-native/voice';
|
|
62
87
|
|
|
63
88
|
function Tutor() {
|
|
64
89
|
const chat = useGuideAI();
|
|
90
|
+
const mic = useVoiceInput(chat);
|
|
91
|
+
const live = useLiveVoice(chat);
|
|
92
|
+
const history = useConversations();
|
|
65
93
|
return (
|
|
66
94
|
<>
|
|
95
|
+
<HistoryDrawer items={history.conversations} onOpen={history.openConversation}
|
|
96
|
+
onNew={history.newConversation} onDelete={history.deleteConversation} />
|
|
67
97
|
{chat.messages.map((m) => (
|
|
68
98
|
<View key={m.id}>
|
|
69
|
-
<YourMarkdown text={m.content} />
|
|
70
|
-
{m.
|
|
71
|
-
|
|
72
|
-
))}
|
|
99
|
+
<YourMarkdown text={m.content} /> {/* pictures are Markdown images here */}
|
|
100
|
+
<Text>{formatTime(m.createdAt)}</Text>
|
|
101
|
+
{m.whiteboard && <Button title="Explain on whiteboard" onPress={() => chat.explainOnWhiteboard(m.id)} />}
|
|
73
102
|
{m.pendingAction && (
|
|
74
|
-
<ApproveBar
|
|
75
|
-
|
|
76
|
-
onApprove={() => chat.confirm(m.id)}
|
|
77
|
-
onCancel={() => chat.cancel(m.id)}
|
|
78
|
-
/>
|
|
103
|
+
<ApproveBar label={m.pendingAction.label}
|
|
104
|
+
onApprove={() => chat.confirm(m.id)} onCancel={() => chat.cancel(m.id)} />
|
|
79
105
|
)}
|
|
80
106
|
</View>
|
|
81
107
|
))}
|
|
108
|
+
{chat.typing && <TypingDots />}
|
|
109
|
+
{chat.followUps.map((s) => <Chip key={s} label={s} onPress={() => chat.send(s)} />)}
|
|
82
110
|
<TextInput value={chat.input} onChangeText={chat.setInput} />
|
|
83
111
|
<Button title="Send" disabled={!chat.canSend} onPress={() => chat.send()} />
|
|
84
|
-
{
|
|
112
|
+
<MicButton recording={mic.recording} busy={mic.transcribing} onPress={mic.toggle} />
|
|
113
|
+
<CallButton active={live.active} onPress={live.active ? live.stop : live.start} />
|
|
114
|
+
<GuideAILiveVoice live={live} labels={{ end: t('End') }} /> {/* the call panel: orb, state, End */}
|
|
115
|
+
<GuideAILanguagePicker voice={mic} /> {/* opens itself on the first mic or live tap */}
|
|
116
|
+
<GuideAIWhiteboard /> {/* mount once */}
|
|
85
117
|
</>
|
|
86
118
|
);
|
|
87
119
|
}
|
|
@@ -89,15 +121,35 @@ function Tutor() {
|
|
|
89
121
|
|
|
90
122
|
| On `useGuideAI()` | |
|
|
91
123
|
|---|---|
|
|
92
|
-
| `messages` | `{ id, role, content, streaming, error, suggestions, images, pendingAction }` |
|
|
93
|
-
| `
|
|
124
|
+
| `messages` | Ready to draw: `{ id, role, content, createdAt, question, streaming, error, suggestions, whiteboard, images, pendingAction }`. An answer with no text yet is left out (`typing`). |
|
|
125
|
+
| `typing`, `followUps` | Typing indicator; chips under the latest answer (its suggestions, else `followUps` from configure). |
|
|
126
|
+
| `explainOnWhiteboard(id)`, `whiteboardAvailable` | The board for an answer, with the question it answered. |
|
|
127
|
+
| `send(text?)`, `input`, `setInput`, `canSend`, `busy`, `status` | The conversation. `send` resolves with the answer. |
|
|
94
128
|
| `confirm(id)`, `cancel(id)` | Answer a `pendingAction`. Nothing is written until `confirm`. |
|
|
95
|
-
| `
|
|
96
|
-
|
|
129
|
+
| `retry()`, `clear()` | `clear()` starts a new chat; the old one stays in the history. |
|
|
130
|
+
|
|
131
|
+
| On `useVoiceInput(chat)` (push-to-talk) | |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `toggle()`, `start()`, `stop()`, `cancel()` | We ask for the mic, record, transcribe and send. |
|
|
134
|
+
| `recording`, `transcribing`, `error` | Draw the button; `error` is in words to show. |
|
|
135
|
+
| `choosingLanguage`, `languages`, `language`, `chooseLanguage(code)`, `changeLanguage()`, `cancelLanguage()` | Asked once, before the first recording; remembered. Shared with live voice. |
|
|
136
|
+
|
|
137
|
+
| On `useLiveVoice(chat)` (a hands-free call) | |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `start()`, `stop()`, `interrupt()` | Listens, hears you finish, answers aloud, listens again. |
|
|
140
|
+
| `state`, `active`, `level`, `error` | `'listening' \| 'hearing' \| 'thinking' \| 'speaking' \| 'off'`; `level` 0–1 for a pulsing button. |
|
|
141
|
+
| the language fields | As on `useVoiceInput`. |
|
|
142
|
+
|
|
143
|
+
| On `useConversations()` (chat history) | |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `conversations`, `activeId` | Kept on the device, newest first, titled by the first question. |
|
|
146
|
+
| `newConversation()`, `openConversation(id)`, `deleteConversation(id)` | Opening one carries on where it left off; the agent remembers it too. |
|
|
147
|
+
|
|
148
|
+
`<GuideAILiveVoice>` and `<GuideAILanguagePicker>` are our UI for the call and the language: pass `theme` for your colours and `labels` for your words. Or draw your own from the hook fields.
|
|
97
149
|
|
|
98
|
-
`suggestions` appear when the agent's Blueprint has the **Suggest follow-ups** node, and `images` when it has **Draw images**.
|
|
150
|
+
`suggestions` appear when the agent's Blueprint has the **Suggest follow-ups** node, `whiteboard` when it has **Explain on a whiteboard**, and `images` when it has **Draw images**. The whiteboard reads each step aloud when `speech` is configured. A board shows complex things the way a teacher would: drawn by the pen from a line drawing found on the web, or as the real photo, with labels on their parts (an arrow, a ring or a box). Nothing on a board is ever generated.
|
|
99
151
|
|
|
100
|
-
## Or
|
|
152
|
+
## Or a floating button
|
|
101
153
|
|
|
102
154
|
```tsx
|
|
103
155
|
import { GuideAILauncher } from '@guideai/react-native/ui';
|
|
@@ -116,7 +168,7 @@ import { GuideAIScreen, useGuideAIElement } from '@guideai/react-native';
|
|
|
116
168
|
## Build
|
|
117
169
|
|
|
118
170
|
```
|
|
119
|
-
pnpm build # dist/: index + ui, ESM and CommonJS, bundled types
|
|
171
|
+
pnpm build # dist/: index + ui + voice, ESM and CommonJS, bundled types
|
|
120
172
|
pnpm test
|
|
121
173
|
pnpm typecheck
|
|
122
174
|
```
|