npm package: @solveo-ai/react-native
Description: React Native SDK for Solveo AI platform
Author: Solveo AI
Latest version: 0.2.0

# @solveo-ai/react-native

React Native SDK for the Solveo AI platform. Build AI-powered chat experiences in your mobile apps.

**Supports both React Native CLI and Expo projects.**

## Installation

```bash
npm install @solveo-ai/react-native @solveo-ai/sdk-core
# or
yarn add @solveo-ai/react-native @solveo-ai/sdk-core
```

### React Native CLI Setup

For projects created with `react-native init` or Expo Dev Clients:

```bash
# Install Firebase for push notifications
npm install @react-native-firebase/app @react-native-firebase/messaging

# Install AsyncStorage (already bundled with this SDK)
npm install @react-native-async-storage/async-storage
```

**Firebase Configuration:**

1. **Android:**
   - Download `google-services.json` from Firebase Console
   - Place it in `android/app/`
   - Add the Google Services plugin to `android/app/build.gradle`:
     ```gradle
     apply plugin: 'com.google.gms.google-services'
     ```
   - Add classpath to `android/build.gradle`:
     ```gradle
     classpath 'com.google.gms:google-services:4.3.15'
     ```

2. **iOS:**
   - Download `GoogleService-Info.plist` from Firebase Console
   - Place it in your Xcode project
   - Enable "Push Notifications" capability in Xcode
   - Add to `ios/YourProject/AppDelegate.m`:
     ```objc
     #import <Firebase.h>
     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       [FIRApp configure];
       [UNUserNotificationCenter currentNotificationCenter].delegate = self;
       [application registerForRemoteNotifications];
       return YES;
     }
     ```

### Expo Setup

For Expo projects (including Expo Go):

```bash
npx expo install expo-notifications
```

**Note:** For push notifications in production, you'll need to configure [Expo Application Services (EAS)](https://docs.expo.dev/push-notifications/overview/).

## Quick Start

```tsx
import { SolveoProvider, useChat } from '@solveo-ai/react-native';

// Wrap your app
function App() {
  return (
    <SolveoProvider
      config={{
        apiUrl: 'https://api.solveoai.io',
        widgetId: 'your-widget-id',
      }}
    >
      <ChatScreen />
    </SolveoProvider>
  );
}

// Use in any component
function ChatScreen() {
  const { conversation, messages, sendMessage, createConversation } = useChat();

  useEffect(() => {
    createConversation();
  }, []);

  return (
    <View>
      {messages.map((msg) => (
        <Text key={msg.id}>{msg.content}</Text>
      ))}
    </View>
  );
}
```

## Push Notifications

The SDK automatically detects which push notification system is available and uses the appropriate one.

### Setup for React Native CLI

Follow the Firebase configuration steps above, then use the `usePushNotifications` hook:

```tsx
import { usePushNotifications } from '@solveo-ai/react-native';

function ChatScreen() {
  const { registerDevice } = usePushNotifications({
    mode: 'widget',
    conversationId: 'your-conversation-id',
    autoRegister: true,
  });

  // Device will automatically register when permission is granted
}
```

### Setup for Expo

```tsx
import { usePushNotifications } from '@solveo-ai/react-native';

function ChatScreen() {
  const { requestPermission, registerDevice } = usePushNotifications({
    mode: 'widget',
    conversationId: 'your-conversation-id',
  });

  useEffect(() => {
    requestPermission().then(granted => {
      if (granted) {
        registerDevice();
      }
    });
  }, [requestPermission, registerDevice]);
}
```

## Development

From the repo root (monorepo), install and build:

```bash
# From platform root
npm install
npm run build --workspace=@solveo-ai/react-native
```

Or from this package:

```bash
cd sdks/react-native
npm install
npm run build
```

This produces `dist/index.js`, `dist/index.mjs`, and `dist/index.d.ts`. Type declarations are included; `prepublishOnly` runs the build before publishing so published packages include `dist` and types.

## Documentation

See [full documentation](https://docs.solveoai.io/sdk/react-native).

## License

MIT