react-native-ai-hooks 0.5.0 → 0.6.1
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 +28 -60
- package/docs/assets/architecture.png +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
[](https://npmjs.com/package/react-native-ai-hooks)
|
|
3
|
-
[](https://github.com/nikapkh/react-native-ai-hooks)
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
1
|
+
# React Native AI Hooks
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-ai-hooks)
|
|
4
|
+
[](https://www.npmjs.com/package/react-native-ai-hooks)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Architecture Visual
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="./docs/assets/architecture.png" alt="React Native AI Hooks architecture diagram" width="1100" />
|
|
11
|
+
</p>
|
|
12
|
+
<p align="center">
|
|
13
|
+
<em>Production flow: App Layer -> Hooks -> ProviderFactory -> fetchWithRetry -> Anthropic, OpenAI, Gemini</em>
|
|
14
|
+
</p>
|
|
11
15
|
|
|
12
|
-
##
|
|
16
|
+
## The Core Problem
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
Mobile AI is fragile in production. Network volatility, provider rate-limits, and intermittent API failures can degrade UX quickly.
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
- Retry, timeout, and error edge cases
|
|
18
|
-
- Streaming token parsing
|
|
19
|
-
- State handling for loading, cancellation, and failures
|
|
20
|
+
React Native AI Hooks is the Resilience Layer for those failure modes. It standardizes provider integration, hardens request execution, and gives product teams a clean hooks-first interface so reliability is built in from day one.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
## What's New in v0.6.0 (The Highlights)
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
| Avoid provider lock-in | Unified interface across providers |
|
|
27
|
-
| Handle real-world failures | Built-in retries, backoff, timeout, abort |
|
|
28
|
-
| Keep code clean | Strong TypeScript types and predictable APIs |
|
|
24
|
+
- Production-Grade Resilience: Exponential backoff plus jitter for 429 and 5xx failures, with retry and timeout controls.
|
|
25
|
+
- Unified Provider Factory: Anthropic, OpenAI, and Gemini behind one standardized API surface.
|
|
26
|
+
- 100% Logic Coverage: Hardened with Jest and continuously verified in GitHub Actions.
|
|
29
27
|
|
|
30
28
|
## Quick Start
|
|
31
29
|
|
|
32
30
|
```tsx
|
|
33
|
-
// npm install react-native-ai-hooks
|
|
34
|
-
|
|
35
31
|
import { useAIChat } from 'react-native-ai-hooks';
|
|
36
32
|
|
|
37
33
|
export function Assistant() {
|
|
@@ -41,57 +37,29 @@ export function Assistant() {
|
|
|
41
37
|
model: 'claude-sonnet-4-20250514',
|
|
42
38
|
});
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
await sendMessage('Draft a warm onboarding message for new users.');
|
|
40
|
+
async function ask() {
|
|
41
|
+
await sendMessage('Summarize the top product risks from this sprint.');
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
return null;
|
|
50
45
|
}
|
|
51
46
|
```
|
|
52
47
|
|
|
53
|
-
##
|
|
54
|
-
|
|
55
|
-
- 💬 useAIChat: multi-turn conversation
|
|
56
|
-
- ⚡ useAIStream: token streaming
|
|
57
|
-
- 👁️ useImageAnalysis: image and vision workflows
|
|
58
|
-
- 📝 useAIForm: AI-assisted form validation
|
|
59
|
-
- 🎙️ useAIVoice: speech-to-text plus AI response
|
|
60
|
-
- 🌍 useAITranslate: real-time translation
|
|
61
|
-
- 📄 useAISummarize: concise text summaries
|
|
62
|
-
- 🧠 useAICode: generate and explain code
|
|
63
|
-
|
|
64
|
-
## Provider Support
|
|
65
|
-
|
|
66
|
-
| Provider | Chat | Stream | Vision | Voice |
|
|
67
|
-
|---|---|---|---|---|
|
|
68
|
-
| Anthropic Claude | ✅ | ✅ | ✅ | ✅ |
|
|
69
|
-
| OpenAI | ✅ | ✅ | ✅ | ✅ |
|
|
70
|
-
| Gemini | ✅ | ✅ | 🔜 | 🔜 |
|
|
48
|
+
## Documentation
|
|
71
49
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Use a backend proxy in production. Do not ship permanent provider API keys in app binaries.
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
const { sendMessage } = useAIChat({
|
|
78
|
-
baseUrl: 'https://your-backend.com/api/ai',
|
|
79
|
-
});
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Example App
|
|
83
|
-
|
|
84
|
-
See [example](./example) for a full app with provider switching, API key settings, and streaming chat.
|
|
85
|
-
|
|
86
|
-
## Deep Technical Docs
|
|
87
|
-
|
|
88
|
-
Detailed architecture and implementation references now live in [docs](./docs):
|
|
50
|
+
For deep technical specs and implementation details, see [docs](./docs):
|
|
89
51
|
|
|
90
52
|
- [Architecture Guide](./docs/ARCHITECTURE_GUIDE.md)
|
|
91
53
|
- [Technical Specification](./docs/TECHNICAL_SPECIFICATION.md)
|
|
92
54
|
- [Implementation Summary](./docs/IMPLEMENTATION_COMPLETE.md)
|
|
93
55
|
- [Internal Architecture Notes](./docs/ARCHITECTURE.md)
|
|
94
56
|
|
|
57
|
+
## Support
|
|
58
|
+
|
|
59
|
+
If this project helps your team ship reliable mobile AI features, please consider leaving a star:
|
|
60
|
+
|
|
61
|
+
[Star react-native-ai-hooks on GitHub](https://github.com/nikapkh/react-native-ai-hooks)
|
|
62
|
+
|
|
95
63
|
## License
|
|
96
64
|
|
|
97
65
|
MIT © [nikapkh](https://github.com/nikapkh)
|
|
Binary file
|
package/package.json
CHANGED