expo-ai-core 1.0.0 β†’ 1.0.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 CHANGED
@@ -1,162 +1,445 @@
1
- # expo-ai-core ⚑
1
+ # expo-ai-core
2
2
 
3
- > Add AI (ChatGPT-style chat, streaming, voice) to your Expo app in **5 lines of code**
3
+ > Production-ready AI for Expo and React Native, built for chat, streaming, voice, tools, memory, plugins, agents, and custom providers.
4
4
 
5
- ---
5
+ `expo-ai-core` is a TypeScript-first AI SDK for Expo apps. It is designed to stay Expo Go compatible, avoid Node-only APIs, and give you a small but capable surface for shipping AI features in production.
6
6
 
7
- ## πŸš€ Why this exists
7
+ Version 1.0.1 refreshes the model registry, provider catalogs, and documentation so the package is easier to adopt, easier to extend, and clearer to maintain.
8
8
 
9
- Building AI features in Expo is painful:
9
+ ## What is new in 1.0.1
10
10
 
11
- - Too much boilerplate
12
- - No streaming support
13
- - Voice is messy
14
- - UI takes forever
11
+ - Updated model catalog ordering by release series and popularity.
12
+ - Registry-backed provider discovery with runtime registration.
13
+ - Lazy provider loading so unused providers do not inflate bundles.
14
+ - Stable root exports for hooks, UI, providers, registry helpers, tools, plugins, memory, and agents.
15
+ - More detailed documentation for config, model discovery, custom providers, and Expo-native voice support.
15
16
 
16
- **expo-ai-core fixes all of that.**
17
+ ## Why use expo-ai-core
17
18
 
18
- ---
19
+ - Expo Go compatible
20
+ - Client-side only networking using `fetch`
21
+ - Strong TypeScript types and autocomplete-friendly APIs
22
+ - Built-in support for chat, streaming, voice, tools, memory, plugins, and agents
23
+ - Provider architecture inspired by the Vercel AI SDK pattern, but tailored for Expo and React Native
24
+ - Backward compatible with existing `useAIChat` integrations
19
25
 
20
- ## ⚑ Quick Demo
26
+ ## Install
27
+
28
+ Core package:
29
+
30
+ ```bash
31
+ npm install expo-ai-core
32
+ ```
33
+
34
+ Recommended Expo-native peers for the full experience:
35
+
36
+ ```bash
37
+ npm install expo-speech expo-av @react-native-async-storage/async-storage
38
+ ```
39
+
40
+ Optional UX helpers:
41
+
42
+ ```bash
43
+ npm install expo-clipboard expo-haptics
44
+ ```
45
+
46
+ If you use a package manager with strict peer handling, install the optional packages up front so copy actions and haptics work without extra setup.
47
+
48
+ ## Quick start
21
49
 
22
50
  ```tsx
23
51
  import { AIChatView, useAIChat } from "expo-ai-core";
24
52
 
25
53
  export default function Screen() {
26
54
  const chat = useAIChat({
55
+ apiKey: process.env.EXPO_PUBLIC_OPENAI_API_KEY as string,
27
56
  provider: "openai",
28
- apiKey: "YOUR_API_KEY",
57
+ model: "gpt-4o-mini",
29
58
  });
30
59
 
31
- return <AIChatView {...chat} />;
60
+ return <AIChatView {...chat} title="Assistant" subtitle="Expo AI Core" />;
32
61
  }
33
62
  ```
34
63
 
35
- πŸ‘‰ That’s it. You now have a working AI chat UI.
64
+ Send a message manually:
36
65
 
37
- ---
66
+ ```tsx
67
+ await chat.sendMessage("Summarize this screen for me.");
68
+ ```
38
69
 
39
- ## ✨ Features
70
+ ## Getting started with configuration
71
+
72
+ You can set app-wide defaults once and let every hook inherit them:
73
+
74
+ ```tsx
75
+ import { configureAI } from "expo-ai-core";
40
76
 
41
- - 🧠 **AI Chat Hook** β†’ `useAIChat`
42
- - ⚑ **Streaming Responses** (real-time typing effect)
43
- - 🎀 **Voice Input + TTS**
44
- - πŸ”Œ **Multi-Provider Support**
45
- - OpenAI
46
- - Google Gemini
77
+ configureAI({
78
+ defaultProvider: "openai",
79
+ defaultModel: "gpt-4o-mini",
80
+ debug: false,
81
+ themeMode: "system",
82
+ });
83
+ ```
47
84
 
48
- - πŸ’¬ **Prebuilt UI Components**
49
- - πŸ’Ύ **Offline Cache + Persistence**
50
- - βš™οΈ **Zero Backend Required**
51
- - πŸ“¦ **Tiny & Tree-shakable**
85
+ `configureAI()` currently controls these defaults:
52
86
 
53
- ---
87
+ - `defaultProvider`
88
+ - `defaultModel`
89
+ - `debug`
90
+ - `themeMode`
54
91
 
55
- ## πŸ“¦ Installation
92
+ Those values are merged with per-hook overrides when you call `useAIChat()`.
56
93
 
57
- ```bash
58
- npm install expo-ai-core
59
- npm install expo-speech expo-av @react-native-async-storage/async-storage
60
- ```
94
+ ## Public API at a glance
61
95
 
62
- ---
96
+ Root exports include:
63
97
 
64
- ## πŸ”§ Providers
98
+ - `useAIChat`, `useAIVoice`
99
+ - `AIChatView`, `AIInput`, `AIMessageBubble`, `AITypingIndicator`, `MarkdownText`
100
+ - `configureAI`, `getAIConfig`
101
+ - `registerProvider`, `unregisterProvider`, `getProvider`, `getRegisteredProvider`, `getProviderOrThrow`, `getModels`, `listProviders`, `listRegisteredProviders`
102
+ - `createProvider`, `createOpenAIProvider`, `createGeminiProvider`, `createAnthropicProvider`, `createGroqProvider`, `createTogetherProvider`, `createOllamaProvider`
103
+ - `createPlugin`, `collectPluginTools`, `runPluginHandlers`
104
+ - `createAgent`, `runAgent`
105
+ - `parseToolCall`, `executeToolCall`, `mergeTools`, `buildToolResultMessage`
106
+ - `lightTheme`, `darkTheme`, `resolveTheme`
107
+ - `memory`, `tools`, and `utils` helpers
65
108
 
66
- ### OpenAI
109
+ ## Chat
110
+
111
+ `useAIChat()` is the main orchestration hook. It handles message state, streaming, retries, regeneration, tool calls, caching, multi-conversation flows, and provider switching.
67
112
 
68
113
  ```tsx
69
- useAIChat({
114
+ import { useAIChat } from "expo-ai-core";
115
+
116
+ const chat = useAIChat({
117
+ apiKey: process.env.EXPO_PUBLIC_OPENAI_API_KEY as string,
70
118
  provider: "openai",
71
- apiKey: process.env.EXPO_PUBLIC_OPENAI_API_KEY!,
72
119
  model: "gpt-4o-mini",
120
+ systemPrompt: "You are a concise mobile assistant.",
121
+ typingSpeed: "normal",
122
+ haptics: true,
73
123
  });
74
124
  ```
75
125
 
76
- ### Gemini
126
+ Useful options:
127
+
128
+ - `provider`, `apiKey`, `model`
129
+ - `systemPrompt`
130
+ - `initialMessages`
131
+ - `cacheKey`, `enableCache`
132
+ - `timeoutMs`
133
+ - `tools`, `plugins`, `memory`
134
+ - `typingSpeed`
135
+ - `themeMode`
136
+ - `haptics`
137
+ - `maxToolIterations`
138
+ - `onDebugEvent`
139
+ - `routing: "auto"`
140
+
141
+ Useful return values:
142
+
143
+ - `messages`, `input`, `setInput`
144
+ - `sendMessage()`, `isLoading`, `error`
145
+ - `stopGenerating()`, `clearMessages()`
146
+ - `retryLastMessage()`, `retryMessage()`
147
+ - `regenerateResponse()`
148
+ - `copyMessage()`
149
+ - `generateImage()`
150
+ - `createChat()`, `switchChat()`, `deleteChat()`, `setConversationTitle()`
151
+ - `setProvider()`, `setModel()`, `setThemeMode()`
152
+ - `conversations`, `currentConversationId`
153
+ - `debugState`
154
+
155
+ ### Example: provider switching at runtime
77
156
 
78
157
  ```tsx
79
- useAIChat({
80
- provider: "gemini",
81
- apiKey: process.env.EXPO_PUBLIC_GEMINI_API_KEY!,
82
- model: "gemini-2.5-flash",
158
+ const chat = useAIChat({
159
+ apiKey: process.env.EXPO_PUBLIC_OPENAI_API_KEY as string,
160
+ provider: "openai",
161
+ model: "gpt-4o-mini",
83
162
  });
163
+
164
+ chat.setProvider("gemini");
165
+ chat.setModel("gemini-3.1-flash");
166
+ ```
167
+
168
+ ### Example: streaming and recovery controls
169
+
170
+ ```tsx
171
+ await chat.sendMessage("Draft a release note.");
172
+
173
+ chat.stopGenerating();
174
+ await chat.retryLastMessage();
175
+ await chat.regenerateResponse();
84
176
  ```
85
177
 
86
- ---
178
+ ## Voice
87
179
 
88
- ## 🎀 Voice (Speech-to-Text + TTS)
180
+ `useAIVoice()` wraps speech input and speech output in a React hook that stays Expo-friendly.
89
181
 
90
182
  ```tsx
91
183
  import { useAIVoice } from "expo-ai-core";
92
184
 
93
- const voice = useAIVoice();
185
+ const voice = useAIVoice({
186
+ language: "en-US",
187
+ autoSpeak: true,
188
+ loop: false,
189
+ speechRate: 1,
190
+ speechPitch: 1,
191
+ });
192
+ ```
193
+
194
+ Options:
195
+
196
+ - `language`
197
+ - `continuous`
198
+ - `interimResults`
199
+ - `autoSpeak`
200
+ - `speechRate`
201
+ - `speechPitch`
202
+ - `loop`
203
+ - `onTranscript`
204
+ - `onVoiceError`
205
+
206
+ Return values:
207
+
208
+ - `startListening()`, `stopListening()`
209
+ - `transcript`
210
+ - `isListening`
211
+ - `recordingUri`
212
+ - `error`
213
+ - `speak()`
214
+ - `clearTranscript()`
215
+
216
+ ## UI components
217
+
218
+ The package includes lightweight UI primitives you can use directly or adapt into your own design system.
219
+
220
+ - `AIChatView` - full chat screen composition
221
+ - `AIInput` - message input and send control
222
+ - `AIMessageBubble` - message rendering with copy support
223
+ - `AITypingIndicator` - assistant typing state
224
+ - `MarkdownText` - markdown-aware message content renderer
225
+
226
+ `AIChatView` accepts the full `AIChatReturn` surface, plus optional title, subtitle, custom renderers, and theme overrides.
227
+
228
+ ## Providers
229
+
230
+ `expo-ai-core` ships with built-in providers and a registry so you can add your own provider without modifying the package internals.
231
+
232
+ Built-in providers:
233
+
234
+ - OpenAI
235
+ - Gemini
236
+ - Anthropic
237
+ - Groq
238
+ - Together
239
+ - Ollama
240
+
241
+ ### Provider helpers
242
+
243
+ Use the built-in creator helpers if you want to assemble providers manually:
94
244
 
95
- await voice.startListening();
96
- await voice.stopListening();
97
- await voice.speak("Hello from Expo");
245
+ ```tsx
246
+ import {
247
+ createOpenAIProvider,
248
+ createGeminiProvider,
249
+ createAnthropicProvider,
250
+ createGroqProvider,
251
+ createTogetherProvider,
252
+ createOllamaProvider,
253
+ } from "expo-ai-core";
98
254
  ```
99
255
 
100
- ---
256
+ ### Registry helpers
257
+
258
+ ```tsx
259
+ import {
260
+ registerProvider,
261
+ unregisterProvider,
262
+ getProvider,
263
+ getProviderOrThrow,
264
+ listProviders,
265
+ getModels,
266
+ } from "expo-ai-core";
267
+ ```
268
+
269
+ `getModels(provider)` returns the curated catalog for that provider. The lists in v1.0.1 are intentionally ordered so the most relevant models appear first.
270
+
271
+ ## Model catalog in v1.0.1
272
+
273
+ These are the default provider model lists bundled with the package.
274
+
275
+ ### OpenAI
276
+
277
+ `gpt-5.4`, `gpt-5.4-pro`, `gpt-5.4-mini`, `o3-thinking`, `gpt-4.1`
278
+
279
+ ### Gemini
280
+
281
+ `gemini-3.1-pro`, `gemini-3.1-flash`, `gemini-3.1-flash-lite`, `gemini-2.5-pro`, `nano-banana-2`
282
+
283
+ ### Anthropic
101
284
 
102
- ## 🧩 Components
285
+ `claude-opus-4.6`, `claude-sonnet-4.6`, `claude-haiku-4.5`, `claude-sonnet-4.0`, `claude-mythos-preview`
103
286
 
104
- - `AIChatView` β†’ full chat UI
105
- - `AIInput` β†’ input box
106
- - `AIMessageBubble` β†’ messages
107
- - `AITypingIndicator` β†’ streaming state
287
+ ### Groq
108
288
 
109
- All components are:
289
+ `llama-4-maverick`, `llama-4-scout-17b`, `llama-3.3-70b-versatile`, `qwen3-32b`, `gpt-oss-120b`
110
290
 
111
- - Customizable
112
- - NativeWind-compatible
113
- - Lightweight
291
+ ### Together
114
292
 
115
- ---
293
+ `Qwen/Qwen3.5-122B`, `Mistral-4-Small`, `meta-llama/Llama-3.3-70B-Instruct-Turbo`, `deepseek-v3.2`, `meta-muse-spark`
116
294
 
117
- ## 🧠 How it works
295
+ ### Ollama
118
296
 
119
- - Uses `fetch` (no backend needed)
120
- - Streams tokens in real-time
121
- - Stores chats via AsyncStorage
122
- - Works in Expo Go
297
+ `llama4`, `gemma4`, `qwen3`, `mistral-large-2`, `phi-4`
123
298
 
124
- ---
299
+ If you need a different list, register your own provider or replace the catalog at the app layer.
125
300
 
126
- ## ⚠️ Notes
301
+ ## Custom providers
127
302
 
128
- - Native speech recognition requires platform support
129
- - Works best with Expo SDK 50+
130
- - No Node.js APIs used
303
+ You can register a custom provider and keep the rest of the SDK unchanged.
131
304
 
132
- ---
305
+ ```tsx
306
+ import { createProvider, registerProvider } from "expo-ai-core";
307
+
308
+ registerProvider(
309
+ createProvider({
310
+ name: "custom",
311
+ sendMessage: async () => ({
312
+ content: "Hello from a custom provider",
313
+ }),
314
+ }),
315
+ );
316
+ ```
317
+
318
+ If you already have your own network layer, `createProvider()` is the easiest way to normalize it into the `AIProvider` interface.
319
+
320
+ ## Tools
321
+
322
+ Tools let the model call typed local functions on-device.
323
+
324
+ ```tsx
325
+ const chat = useAIChat({
326
+ apiKey: process.env.EXPO_PUBLIC_OPENAI_API_KEY as string,
327
+ tools: {
328
+ getLocation: async () => ({ lat: 40.7128, lng: -74.006 }),
329
+ getTime: () => new Date().toISOString(),
330
+ },
331
+ });
332
+ ```
333
+
334
+ Tool execution is handled through the package helpers and the `tools` option on `useAIChat()`.
335
+
336
+ ## Memory
133
337
 
134
- ## πŸ“± Example App
338
+ `memory` gives you persistence-aware conversation behavior. The bundled strategies support a rolling window and a summary mode.
135
339
 
136
- See `/example` for a full working demo.
340
+ ```tsx
341
+ const chat = useAIChat({
342
+ apiKey: process.env.EXPO_PUBLIC_OPENAI_API_KEY as string,
343
+ memory: {
344
+ enabled: true,
345
+ strategy: "summary",
346
+ windowSize: 20,
347
+ maxSummaryLength: 1200,
348
+ },
349
+ });
350
+ ```
137
351
 
138
- ---
352
+ Recommended use cases:
139
353
 
140
- ## πŸ’‘ Coming Soon
354
+ - `window` for short lived, recent-context conversations
355
+ - `summary` for longer sessions where you want to compress history
356
+
357
+ ## Plugins
358
+
359
+ Plugins let you package reusable behavior, tools, and handlers.
360
+
361
+ ```tsx
362
+ import { createPlugin } from "expo-ai-core";
363
+
364
+ const weatherPlugin = createPlugin({
365
+ name: "weather",
366
+ tools: {
367
+ getWeather: async () => ({ tempC: 24, condition: "clear" }),
368
+ },
369
+ });
370
+ ```
371
+
372
+ Use plugins when you want to share a feature bundle across screens or products.
373
+
374
+ ## Agents
375
+
376
+ Agents are useful for multi-step workflows that need a goal, several instructions, and optional tool execution.
377
+
378
+ ```tsx
379
+ import { createAgent } from "expo-ai-core";
380
+
381
+ const agent = createAgent({
382
+ goal: "Plan a product launch summary",
383
+ steps: [
384
+ { id: "research", instruction: "Summarize the launch context." },
385
+ { id: "draft", instruction: "Write a short launch brief." },
386
+ ],
387
+ provider,
388
+ });
389
+ ```
390
+
391
+ ## Themes
392
+
393
+ The package includes light and dark theme presets plus a small resolver helper.
394
+
395
+ ```tsx
396
+ import { darkTheme, lightTheme, resolveTheme } from "expo-ai-core";
397
+ ```
398
+
399
+ You can also pass partial theme overrides into `AIChatView`, `AIMessageBubble`, and related UI primitives.
400
+
401
+ ## Example app
402
+
403
+ The local `example` folder contains an Expo integration reference app.
404
+
405
+ See the demo repository here: https://github.com/ArhanAnsari/expo-ai-core-demo
406
+
407
+ ## Typical import patterns
408
+
409
+ ```tsx
410
+ import {
411
+ AIChatView,
412
+ AIMessageBubble,
413
+ configureAI,
414
+ createProvider,
415
+ getModels,
416
+ registerProvider,
417
+ useAIChat,
418
+ useAIVoice,
419
+ } from "expo-ai-core";
420
+ ```
141
421
 
142
- - Image generation support
143
- - Markdown + code block rendering
144
- - Better voice transcription
145
- - More providers
422
+ ## Troubleshooting
146
423
 
147
- ---
424
+ - Make sure your provider key is available at runtime, usually through an Expo public environment variable.
425
+ - Install the optional peers if you want clipboard, haptics, speech, or recording features.
426
+ - If a provider is not registered, `useAIChat()` falls back to the built-in lazy loader for that provider name.
427
+ - If you need a model that is not in the bundled catalog, register a custom provider or update the provider list in your app layer.
148
428
 
149
- ## ⭐ Support
429
+ ## Roadmap
150
430
 
151
- If this helped you:
431
+ - Structured output helpers
432
+ - Attachment and multimodal abstractions
433
+ - Provider capability introspection
434
+ - More agent orchestration utilities
152
435
 
153
- - Star the repo ⭐
154
- - Share on Twitter/X
155
- - Build something cool πŸš€
436
+ ## Contributing
156
437
 
157
- ---
438
+ 1. Fork the repo
439
+ 2. Create a feature branch
440
+ 3. Add tests and docs
441
+ 4. Open a pull request with a clear description and reproduction steps
158
442
 
159
- ## πŸ§‘β€πŸ’» Author
443
+ ## License
160
444
 
161
- Built by Arhan Ansari
162
- [Twitter](https://twitter.com/codewitharhan) | [GitHub](https://github.com/ArhanAnsari)
445
+ MIT