@mobileai/react-native 0.5.3 → 0.5.5
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 +27 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,8 +34,6 @@ Wrap your navigation with `<AIAgent>`. The AI automatically understands your ent
|
|
|
34
34
|
### 🎤 Voice Mode (Live Agent)
|
|
35
35
|
- 🗣️ **Real-time voice chat** — Bidirectional audio with Gemini Live API. Speak naturally, the agent responds with voice.
|
|
36
36
|
- 🔄 **Screen change detection** — The agent automatically detects when the screen changes (e.g., loading finishes) and updates its context — no polling tool needed.
|
|
37
|
-
- 🛡️ **Tool-first protocol** — Tool calls are emitted before speech to prevent server crashes (Gemini Live API limitation).
|
|
38
|
-
- 🔇 **Audio gating** — Mic is automatically paused during tool execution and resumed after, preventing race conditions.
|
|
39
37
|
- 🚫 **Auto-navigation guard** — Code-level gate rejects tool calls before the user speaks, preventing the model from acting on screen context alone.
|
|
40
38
|
|
|
41
39
|
### Security & Production
|
|
@@ -172,12 +170,35 @@ import { useAction } from '@mobileai/react-native';
|
|
|
172
170
|
// or: import { useAction } from 'react-native-agentic-ai';
|
|
173
171
|
|
|
174
172
|
function CartScreen() {
|
|
175
|
-
const { clearCart, getTotal } = useCart();
|
|
173
|
+
const { cart, clearCart, getTotal } = useCart();
|
|
176
174
|
|
|
177
|
-
|
|
175
|
+
// 'checkout' = tool name the AI calls, description = how the AI decides when to use it
|
|
176
|
+
useAction('checkout', 'Place the order and checkout', {}, async () => {
|
|
177
|
+
// Guard: return early with a failure message so the AI knows why
|
|
178
|
+
if (cart.length === 0) {
|
|
179
|
+
return { success: false, message: 'Cart is empty' };
|
|
180
|
+
}
|
|
178
181
|
const total = getTotal();
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
|
|
183
|
+
// Human-in-the-loop: the AI's execution pauses here until the user taps Confirm/Cancel.
|
|
184
|
+
// This is how you prevent the AI from performing critical actions without explicit approval.
|
|
185
|
+
return new Promise((resolve) => {
|
|
186
|
+
Alert.alert(
|
|
187
|
+
'Confirm Order by AI',
|
|
188
|
+
`Do you want the AI to place your order for $${total}?`,
|
|
189
|
+
[
|
|
190
|
+
{ text: 'Cancel', style: 'cancel',
|
|
191
|
+
onPress: () => resolve({ success: false, message: 'User denied the checkout.' }) },
|
|
192
|
+
{ text: 'Confirm', style: 'default',
|
|
193
|
+
onPress: () => {
|
|
194
|
+
clearCart();
|
|
195
|
+
// Return success: true so the AI knows the action completed
|
|
196
|
+
resolve({ success: true, message: `Order placed! Total: $${total}` });
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
]
|
|
200
|
+
);
|
|
201
|
+
});
|
|
181
202
|
});
|
|
182
203
|
}
|
|
183
204
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobileai/react-native",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Build autonomous AI agents for React Native and Expo apps. Provides AI-native UI traversal, tool calling, and structured reasoning.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"source": "./src/index.ts",
|