Skip to content

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

Terminal window
npx create-kernova-app my-app --expo
cd my-app
npm run dev # the agents, reachable from your phone on this Wi-Fi
npm 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):

Terminal window
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-store

Run your agents

Start your Kernova project on your computer with --lan, so a phone on the same Wi-Fi can reach it:

Terminal window
kernova dev --lan

Its 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:

  1. The baseUrl prop
  2. EXPO_PUBLIC_KERNOVA_URL (read it in your app code as above, so Expo builds it in)
  3. 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

HookWhat 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 server
  • context: extra data sent with each message
  • stream: false: wait for the whole reply instead of streaming it
  • onReply, 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 (/health stays open).
  • Each user sees and continues only their own conversations: /threads lists theirs, and another user’s thread answers 404.
  • Agents, middleware, and tools get the signed-in user as ctx.user. A user the 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 in user.
  • required: false lets 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 --lan is 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 --tunnel sends the app through Expo’s servers, which can’t reach your computer’s port 4555. Use the same Wi-Fi without --tunnel, or set EXPO_PUBLIC_KERNOVA_URL to an address the phone can reach.
  • Replies appear all at once: you’re using a fetch that can’t stream. Use KernovaProvider from @kernova/expo, or pass fetch from expo/fetch to KernovaClient.