@mobileai/react-native 0.5.3 → 0.5.4
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 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -172,12 +172,35 @@ import { useAction } from '@mobileai/react-native';
|
|
|
172
172
|
// or: import { useAction } from 'react-native-agentic-ai';
|
|
173
173
|
|
|
174
174
|
function CartScreen() {
|
|
175
|
-
const { clearCart, getTotal } = useCart();
|
|
175
|
+
const { cart, clearCart, getTotal } = useCart();
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
// 'checkout' = tool name the AI calls, description = how the AI decides when to use it
|
|
178
|
+
useAction('checkout', 'Place the order and checkout', {}, async () => {
|
|
179
|
+
// Guard: return early with a failure message so the AI knows why
|
|
180
|
+
if (cart.length === 0) {
|
|
181
|
+
return { success: false, message: 'Cart is empty' };
|
|
182
|
+
}
|
|
178
183
|
const total = getTotal();
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
|
|
185
|
+
// Human-in-the-loop: the AI's execution pauses here until the user taps Confirm/Cancel.
|
|
186
|
+
// This is how you prevent the AI from performing critical actions without explicit approval.
|
|
187
|
+
return new Promise((resolve) => {
|
|
188
|
+
Alert.alert(
|
|
189
|
+
'Confirm Order by AI',
|
|
190
|
+
`Do you want the AI to place your order for $${total}?`,
|
|
191
|
+
[
|
|
192
|
+
{ text: 'Cancel', style: 'cancel',
|
|
193
|
+
onPress: () => resolve({ success: false, message: 'User denied the checkout.' }) },
|
|
194
|
+
{ text: 'Confirm', style: 'default',
|
|
195
|
+
onPress: () => {
|
|
196
|
+
clearCart();
|
|
197
|
+
// Return success: true so the AI knows the action completed
|
|
198
|
+
resolve({ success: true, message: `Order placed! Total: $${total}` });
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
]
|
|
202
|
+
);
|
|
203
|
+
});
|
|
181
204
|
});
|
|
182
205
|
}
|
|
183
206
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobileai/react-native",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
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",
|