Mobile Apps (Expo)
Mobile Apps with Expo
@kernova/expo connects an Expo or React Native app to your Kernova agents. Your agents keep running on your Kernova server; the app talks to them over HTTP and shows replies as they stream in.
Phone (Expo app) ──HTTPS──▶ Kernova server (your agents, tools, memory) ──▶ model providers useChat() kernova dev / kernova deploy OpenAI, Claude, …The app never holds a model API key. Anything shipped inside an app can be extracted by whoever installs it, so keys stay on the server.
Start a new app
npx create-kernova-app my-app --expocd my-appnpm run dev # the agents, reachable from your phone on this Wi-Finpm run mobile # in a second terminal: Expo (scan the QR code with Expo Go)You get a Kernova project with an assistant agent, a mobile/ Expo app with a streaming chat screen, and sign-in already wired: the server’s auth accepts a development token generated for the project, which the app sends. Replace it with your own sign-in before you ship (see Signed-in users).
Add to an existing app
In your Expo app (SDK 52 or newer):
npx expo install @kernova/expo expo-constants# Optional, to keep the signed-in user's token in the Keychain / Keystore:npx expo install expo-secure-storeRun your agents
Start your Kernova project on your computer with --lan, so a phone on the same Wi-Fi can reach it:
kernova dev --lanIts agents are served on port 4555. Without --lan the development server only answers this computer. With it, anyone on the network can reach it, so pair it with auth.
Connect the app
Wrap your app in KernovaProvider and chat with useChat:
import { useState } from 'react';import { FlatList, Pressable, Text, TextInput, View } from 'react-native';import { KernovaProvider, useChat } from '@kernova/expo';
function Chat() { const { messages, send, streamingText, isLoading, stop, error } = useChat('assistant'); const [text, setText] = useState('');
return ( <View style={{ flex: 1, padding: 16 }}> <FlatList data={messages} keyExtractor={m => m.id} renderItem={({ item }) => <Text>{item.role === 'user' ? 'You' : 'AI'}: {item.content}</Text>} /> {isLoading && <Text>{streamingText || 'Thinking…'}</Text>} {error && <Text>{error.message}</Text>} <TextInput value={text} onChangeText={setText} placeholder="Message" /> <Pressable onPress={() => { send(text); setText(''); }}><Text>Send</Text></Pressable> {isLoading && <Pressable onPress={stop}><Text>Stop</Text></Pressable>} </View> );}
export default function App() { return ( <KernovaProvider baseUrl={process.env.EXPO_PUBLIC_KERNOVA_URL}> <Chat /> </KernovaProvider> );}'assistant' is the agent’s route: the file name of agents/assistant.agent.ts.
Where the app finds the server
KernovaProvider uses the first of these that’s set:
- The
baseUrlprop EXPO_PUBLIC_KERNOVA_URL(read it in your app code as above, so Expo builds it in)- In development only: your computer’s address as Metro sees it, on port 4555
So in development there’s nothing to configure: run kernova dev --lan and npx expo start on the same Wi-Fi. For production builds, point EXPO_PUBLIC_KERNOVA_URL at your deployed server, over HTTPS (Android release builds block plain HTTP by default).
If kernova dev uses another port, pass devPort.
The hooks
| Hook | What it gives you |
|---|---|
useChat(agent, options?) | messages, send(text), streamingText, isLoading, error, stop(), reset(), threadId |
useThreads() | The saved conversations: threads, refresh(), remove(id) |
useConnectionStatus() | status: 'checking', 'online', or 'offline', checked every 30 seconds |
useKernovaClient() | The underlying KernovaClient, for anything else |
useChat options:
threadId: resume a conversation; its earlier messages load from the servercontext: extra data sent with each messagestream: false: wait for the whole reply instead of streaming itonReply,onError: callbacks
stop() cancels the reply and keeps what arrived so far, marked stopped: true.
Signed-in users
On the server, add auth to kernova.config.ts. authenticate gets each request’s bearer token and returns the user it belongs to, or null:
export default defineConfig({ name: 'my-app', auth: { authenticate: async ({ token }) => { const session = await verifySession(token); // your own check: a JWT, a sessions table, … return session ? { id: session.userId } : null; }, },});With auth set:
- Requests without a valid token get 401 (
/healthstays open). - Each user sees and continues only their own conversations:
/threadslists theirs, and another user’s thread answers 404. - Agents, middleware, and tools get the signed-in user as
ctx.user. Auserthe request names for itself is ignored. - Admin routes (memory, tasks, logs, metrics) are for your own servers only, with
KERNOVA_API_KEY. A server holding that key may also act for a user by naming them inuser. required: falselets requests without a token run as anonymous, sharing the conversations that have no owner.
Conversations created before you turned auth on have no owner, so signed-in users don’t see them.
In the app, give KernovaProvider a getToken function. It runs before every request, and its token is sent as Authorization: Bearer <token>:
import { secureToken } from '@kernova/expo/secure-token';
const token = secureToken(); // kept in the Keychain (iOS) / Keystore (Android)
// After your sign-in flow:await token.set(sessionToken);
<KernovaProvider getToken={token.get}>Don’t put the server’s KERNOVA_API_KEY in the app: it’s a server-to-server key, and anyone with the app could extract it.
Without Expo
@kernova/expo is a thin layer over @kernova/client, which works in any JavaScript runtime. In a bare React Native app, or on the web, use it directly:
import { KernovaClient } from '@kernova/client';import { KernovaClientProvider, useChat } from '@kernova/client/react';
const client = new KernovaClient({ baseUrl: 'https://agents.myapp.com', getToken });
for await (const text of client.stream('assistant', 'Plan my week')) { process.stdout.write(text);}React Native’s built-in fetch can’t stream a response, so without a streaming fetch each reply arrives whole. @kernova/expo passes Expo’s streaming fetch for you.
Troubleshooting
- “Couldn’t reach the Kernova server at http://…:4555”: check that
kernova dev --lanis running and that the phone and computer are on the same Wi-Fi. Some office and public networks block devices from reaching each other. - “running through an Expo tunnel”:
npx expo start --tunnelsends the app through Expo’s servers, which can’t reach your computer’s port 4555. Use the same Wi-Fi without--tunnel, or setEXPO_PUBLIC_KERNOVA_URLto an address the phone can reach. - Replies appear all at once: you’re using a
fetchthat can’t stream. UseKernovaProviderfrom@kernova/expo, or passfetchfromexpo/fetchtoKernovaClient.