@journeyrewards/hive-react-native 1.0.0

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 ADDED
@@ -0,0 +1,257 @@
1
+ # @journeyrewards/hive-react-native
2
+
3
+ React Native SDK for the Journey Hive Agent Orchestration API. Provides hooks, streaming support, and offline capabilities for building AI-powered mobile applications.
4
+
5
+ ## Installation
6
+
7
+ ### Expo
8
+
9
+ ```bash
10
+ npx expo install @journeyrewards/hive-react-native
11
+ ```
12
+
13
+ ### Bare React Native
14
+
15
+ ```bash
16
+ npm install @journeyrewards/hive-react-native
17
+ ```
18
+
19
+ No native module linking is required. The SDK uses pure JavaScript with React Native-compatible fetch APIs.
20
+
21
+ ## Quick Start
22
+
23
+ ### Provider Setup
24
+
25
+ Wrap your app with `JourneyHiveProvider`:
26
+
27
+ ```tsx
28
+ import { JourneyHiveProvider } from '@journeyrewards/hive-react-native';
29
+
30
+ export default function App() {
31
+ return (
32
+ <JourneyHiveProvider apiKey="jh_live_..." baseUrl="https://your-api.com">
33
+ <MainNavigator />
34
+ </JourneyHiveProvider>
35
+ );
36
+ }
37
+ ```
38
+
39
+ ### Streaming Chat Example
40
+
41
+ ```tsx
42
+ import { View, Text, TextInput, TouchableOpacity } from 'react-native';
43
+ import { useResponse } from '@journeyrewards/hive-react-native';
44
+ import { useState } from 'react';
45
+
46
+ function ChatScreen() {
47
+ const [input, setInput] = useState('');
48
+ const { streamedText, isStreaming, isLoading, error, send } = useResponse({
49
+ agent_id: 'your-agent-id',
50
+ });
51
+
52
+ const handleSend = () => {
53
+ if (input.trim()) {
54
+ send(input.trim());
55
+ setInput('');
56
+ }
57
+ };
58
+
59
+ return (
60
+ <View style={{ flex: 1, padding: 16 }}>
61
+ <View style={{ flex: 1 }}>
62
+ {streamedText ? <Text>{streamedText}</Text> : null}
63
+ {isLoading && !isStreaming ? <Text>Loading...</Text> : null}
64
+ {error ? <Text style={{ color: 'red' }}>{error.message}</Text> : null}
65
+ </View>
66
+ <View style={{ flexDirection: 'row', gap: 8 }}>
67
+ <TextInput
68
+ value={input}
69
+ onChangeText={setInput}
70
+ placeholder="Type a message..."
71
+ style={{ flex: 1, borderWidth: 1, borderColor: '#ccc', padding: 8, borderRadius: 8 }}
72
+ />
73
+ <TouchableOpacity onPress={handleSend} style={{ padding: 12, backgroundColor: '#007AFF', borderRadius: 8 }}>
74
+ <Text style={{ color: 'white' }}>Send</Text>
75
+ </TouchableOpacity>
76
+ </View>
77
+ </View>
78
+ );
79
+ }
80
+ ```
81
+
82
+ ### Conversation View
83
+
84
+ ```tsx
85
+ import { useConversation } from '@journeyrewards/hive-react-native';
86
+
87
+ function ConversationScreen({ conversationId }) {
88
+ const { messages, isLoading, sendMessage } = useConversation(conversationId);
89
+
90
+ return (
91
+ <View style={{ flex: 1 }}>
92
+ <FlatList
93
+ data={messages}
94
+ keyExtractor={(item) => item.id}
95
+ renderItem={({ item }) => (
96
+ <View style={{ padding: 8 }}>
97
+ <Text style={{ fontWeight: 'bold' }}>{item.role}</Text>
98
+ <Text>{item.content[0]?.text}</Text>
99
+ </View>
100
+ )}
101
+ />
102
+ <ChatInput onSend={sendMessage} />
103
+ </View>
104
+ );
105
+ }
106
+ ```
107
+
108
+ ### Agent Management
109
+
110
+ ```tsx
111
+ import { useAgents, useAgent } from '@journeyrewards/hive-react-native';
112
+
113
+ function AgentListScreen() {
114
+ const { agents, isLoading } = useAgents();
115
+
116
+ if (isLoading) return <ActivityIndicator />;
117
+
118
+ return (
119
+ <FlatList
120
+ data={agents}
121
+ keyExtractor={(item) => item.id}
122
+ renderItem={({ item }) => <Text>{item.name} - {item.status}</Text>}
123
+ />
124
+ );
125
+ }
126
+ ```
127
+
128
+ ## Offline Support
129
+
130
+ The SDK automatically queues messages when the device is offline and sends them when connectivity is restored.
131
+
132
+ ### Connection Status Hook
133
+
134
+ ```tsx
135
+ import { useConnectionStatus } from '@journeyrewards/hive-react-native';
136
+
137
+ function ConnectionBanner() {
138
+ const { isConnected } = useConnectionStatus();
139
+
140
+ if (isConnected) return null;
141
+
142
+ return (
143
+ <View style={{ backgroundColor: '#f59e0b', padding: 8 }}>
144
+ <Text style={{ textAlign: 'center', color: 'white' }}>
145
+ You are offline. Messages will be sent when connected.
146
+ </Text>
147
+ </View>
148
+ );
149
+ }
150
+ ```
151
+
152
+ ### Manual Connection Management
153
+
154
+ If you use `@react-native-community/netinfo`, connect it to the client:
155
+
156
+ ```tsx
157
+ import NetInfo from '@react-native-community/netinfo';
158
+ import { useJourneyHive } from '@journeyrewards/hive-react-native';
159
+ import { useEffect } from 'react';
160
+
161
+ function NetworkSync() {
162
+ const client = useJourneyHive();
163
+
164
+ useEffect(() => {
165
+ const unsubscribe = NetInfo.addEventListener((state) => {
166
+ client.setConnectionStatus(!!state.isConnected);
167
+ });
168
+ return unsubscribe;
169
+ }, [client]);
170
+
171
+ return null;
172
+ }
173
+ ```
174
+
175
+ ### App Lifecycle
176
+
177
+ Connect app state changes to pause/resume operations:
178
+
179
+ ```tsx
180
+ import { AppState } from 'react-native';
181
+ import { useJourneyHive } from '@journeyrewards/hive-react-native';
182
+ import { useEffect } from 'react';
183
+
184
+ function AppLifecycle() {
185
+ const client = useJourneyHive();
186
+
187
+ useEffect(() => {
188
+ const subscription = AppState.addEventListener('change', (state) => {
189
+ client.setAppState(state);
190
+ });
191
+ return () => subscription.remove();
192
+ }, [client]);
193
+
194
+ return null;
195
+ }
196
+ ```
197
+
198
+ ## Direct Client Usage
199
+
200
+ For non-hook scenarios (background tasks, services):
201
+
202
+ ```tsx
203
+ import { JourneyHiveRNClient } from '@journeyrewards/hive-react-native';
204
+
205
+ const client = new JourneyHiveRNClient({
206
+ apiKey: 'jh_live_...',
207
+ baseUrl: 'https://your-api.com',
208
+ });
209
+
210
+ const agents = await client.listAgents();
211
+ const response = await client.createResponse({
212
+ agent_id: 'agent-id',
213
+ input: 'Hello!',
214
+ });
215
+ ```
216
+
217
+ ## Expo Compatibility
218
+
219
+ This SDK is fully compatible with Expo (SDK 49+). No native modules or custom dev clients are required. It uses:
220
+
221
+ - Standard `fetch` API (available in all React Native environments)
222
+ - `ReadableStream` for SSE parsing (supported in Hermes engine)
223
+ - No native dependencies
224
+
225
+ For Expo Go, the SDK works out of the box with no additional configuration.
226
+
227
+ ## API Reference
228
+
229
+ ### Hooks
230
+
231
+ | Hook | Returns | Description |
232
+ |------|---------|-------------|
233
+ | `useJourneyHive()` | `JourneyHiveRNClient` | Access the client instance |
234
+ | `useResponse(params?)` | `{ data, isLoading, isStreaming, streamedText, error, send }` | Streaming responses |
235
+ | `useConversation(id)` | `{ conversation, messages, isLoading, error, sendMessage }` | Manage conversations |
236
+ | `useAgent(id)` | `{ agent, isLoading, error, update }` | Fetch/update an agent |
237
+ | `useAgents()` | `{ agents, isLoading, error }` | List agents |
238
+ | `useConnectionStatus()` | `{ isConnected }` | Track connectivity |
239
+
240
+ ### Client Methods
241
+
242
+ | Method | Description |
243
+ |--------|-------------|
244
+ | `createResponse(params)` | Send a message to an agent |
245
+ | `createStreamingResponse(params)` | Stream a response (async generator) |
246
+ | `getAgent(id)` | Get agent details |
247
+ | `listAgents()` | List available agents |
248
+ | `updateAgent(id, params)` | Update agent configuration |
249
+ | `createConversation(params)` | Start a new conversation |
250
+ | `getConversation(id)` | Get conversation details |
251
+ | `getMessages(id)` | Get conversation messages |
252
+ | `setConnectionStatus(bool)` | Update connectivity state |
253
+ | `setAppState(state)` | Update app lifecycle state |
254
+
255
+ ## License
256
+
257
+ MIT
@@ -0,0 +1,167 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface SSEEvent {
5
+ event: string;
6
+ data: any;
7
+ }
8
+ declare function parseSSEFromFetch(response: Response): AsyncGenerator<SSEEvent>;
9
+ declare class RNEventSource {
10
+ private url;
11
+ private headers;
12
+ private abortController;
13
+ onmessage: ((event: SSEEvent) => void) | null;
14
+ onerror: ((error: Error) => void) | null;
15
+ onopen: (() => void) | null;
16
+ constructor(url: string, headers?: Record<string, string>);
17
+ connect(body?: any): Promise<void>;
18
+ close(): void;
19
+ }
20
+
21
+ interface QueuedMessage {
22
+ id: string;
23
+ params: CreateResponseParams;
24
+ resolve: (value: any) => void;
25
+ reject: (reason: any) => void;
26
+ }
27
+ interface CreateResponseParams {
28
+ agent_id?: string;
29
+ input: string;
30
+ conversation_id?: string;
31
+ stream?: boolean;
32
+ instructions?: string;
33
+ metadata?: Record<string, unknown>;
34
+ }
35
+ interface JourneyHiveRNConfig {
36
+ apiKey: string;
37
+ baseUrl?: string;
38
+ timeout?: number;
39
+ defaultAgentId?: string;
40
+ debug?: boolean;
41
+ }
42
+ type ConnectionListener = (isConnected: boolean) => void;
43
+ type AppStateListener = (state: "active" | "background" | "inactive") => void;
44
+ declare class JourneyHiveRNClient {
45
+ private baseUrl;
46
+ private apiKey;
47
+ private timeout;
48
+ private defaultAgentId?;
49
+ private debug;
50
+ private offlineQueue;
51
+ private isConnected;
52
+ private connectionListeners;
53
+ private appStateListeners;
54
+ private appState;
55
+ constructor(config: JourneyHiveRNConfig);
56
+ private resolveAgentId;
57
+ private get headers();
58
+ private log;
59
+ private request;
60
+ createResponse(params: CreateResponseParams): Promise<unknown>;
61
+ createStreamingResponse(params: CreateResponseParams): AsyncGenerator<SSEEvent>;
62
+ getAgent(agentId: string): Promise<unknown>;
63
+ listAgents(): Promise<{
64
+ data: any[];
65
+ }>;
66
+ updateAgent(agentId: string, params: any): Promise<unknown>;
67
+ createConversation(params: {
68
+ agent_id?: string;
69
+ external_user_id?: string;
70
+ metadata?: Record<string, unknown>;
71
+ }): Promise<unknown>;
72
+ getConversation(conversationId: string): Promise<unknown>;
73
+ getMessages(conversationId: string): Promise<{
74
+ data: any[];
75
+ }>;
76
+ setConnectionStatus(connected: boolean): void;
77
+ getConnectionStatus(): boolean;
78
+ onConnectionChange(listener: ConnectionListener): () => void;
79
+ setAppState(state: "active" | "background" | "inactive"): void;
80
+ onAppStateChange(listener: AppStateListener): () => void;
81
+ getQueuedMessages(): QueuedMessage[];
82
+ clearQueue(): void;
83
+ private flushOfflineQueue;
84
+ }
85
+
86
+ interface Agent {
87
+ id: string;
88
+ object: "agent";
89
+ name: string;
90
+ slug: string;
91
+ type: string;
92
+ status: string;
93
+ external_access: string;
94
+ model: string;
95
+ created_at: number;
96
+ metadata?: Record<string, unknown>;
97
+ }
98
+ interface Conversation {
99
+ id: string;
100
+ object: "conversation";
101
+ agent_id: string;
102
+ status: string;
103
+ channel: string;
104
+ external_user_id: string | null;
105
+ created_at: number;
106
+ updated_at: number;
107
+ metadata?: Record<string, unknown>;
108
+ }
109
+ interface ContentPart {
110
+ type: string;
111
+ text?: string;
112
+ }
113
+ interface Message {
114
+ id: string;
115
+ object: "message";
116
+ role: string;
117
+ content: ContentPart[];
118
+ created_at: number;
119
+ metadata?: Record<string, unknown>;
120
+ }
121
+ interface JourneyHiveProviderProps {
122
+ apiKey: string;
123
+ baseUrl?: string;
124
+ children: ReactNode;
125
+ }
126
+ declare function JourneyHiveProvider({ apiKey, baseUrl, children }: JourneyHiveProviderProps): react.FunctionComponentElement<react.ProviderProps<JourneyHiveRNClient | null>>;
127
+ declare function useJourneyHive(): JourneyHiveRNClient;
128
+ interface UseResponseReturn {
129
+ data: any | null;
130
+ isLoading: boolean;
131
+ isStreaming: boolean;
132
+ streamedText: string;
133
+ error: Error | null;
134
+ send: (input: string) => Promise<void>;
135
+ }
136
+ declare function useResponse(params?: {
137
+ agent_id?: string;
138
+ conversation_id?: string;
139
+ instructions?: string;
140
+ }): UseResponseReturn;
141
+ interface UseConversationReturn {
142
+ conversation: Conversation | null;
143
+ messages: Message[];
144
+ isLoading: boolean;
145
+ error: Error | null;
146
+ sendMessage: (input: string) => Promise<void>;
147
+ }
148
+ declare function useConversation(conversationId: string): UseConversationReturn;
149
+ interface UseAgentReturn {
150
+ agent: Agent | null;
151
+ isLoading: boolean;
152
+ error: Error | null;
153
+ update: (params: any) => Promise<void>;
154
+ }
155
+ declare function useAgent(agentId: string): UseAgentReturn;
156
+ interface UseAgentsReturn {
157
+ agents: Agent[];
158
+ isLoading: boolean;
159
+ error: Error | null;
160
+ }
161
+ declare function useAgents(): UseAgentsReturn;
162
+ interface UseConnectionStatusReturn {
163
+ isConnected: boolean;
164
+ }
165
+ declare function useConnectionStatus(): UseConnectionStatusReturn;
166
+
167
+ export { JourneyHiveProvider, JourneyHiveRNClient, RNEventSource, type SSEEvent, parseSSEFromFetch, useAgent, useAgents, useConnectionStatus, useConversation, useJourneyHive, useResponse };
@@ -0,0 +1,167 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface SSEEvent {
5
+ event: string;
6
+ data: any;
7
+ }
8
+ declare function parseSSEFromFetch(response: Response): AsyncGenerator<SSEEvent>;
9
+ declare class RNEventSource {
10
+ private url;
11
+ private headers;
12
+ private abortController;
13
+ onmessage: ((event: SSEEvent) => void) | null;
14
+ onerror: ((error: Error) => void) | null;
15
+ onopen: (() => void) | null;
16
+ constructor(url: string, headers?: Record<string, string>);
17
+ connect(body?: any): Promise<void>;
18
+ close(): void;
19
+ }
20
+
21
+ interface QueuedMessage {
22
+ id: string;
23
+ params: CreateResponseParams;
24
+ resolve: (value: any) => void;
25
+ reject: (reason: any) => void;
26
+ }
27
+ interface CreateResponseParams {
28
+ agent_id?: string;
29
+ input: string;
30
+ conversation_id?: string;
31
+ stream?: boolean;
32
+ instructions?: string;
33
+ metadata?: Record<string, unknown>;
34
+ }
35
+ interface JourneyHiveRNConfig {
36
+ apiKey: string;
37
+ baseUrl?: string;
38
+ timeout?: number;
39
+ defaultAgentId?: string;
40
+ debug?: boolean;
41
+ }
42
+ type ConnectionListener = (isConnected: boolean) => void;
43
+ type AppStateListener = (state: "active" | "background" | "inactive") => void;
44
+ declare class JourneyHiveRNClient {
45
+ private baseUrl;
46
+ private apiKey;
47
+ private timeout;
48
+ private defaultAgentId?;
49
+ private debug;
50
+ private offlineQueue;
51
+ private isConnected;
52
+ private connectionListeners;
53
+ private appStateListeners;
54
+ private appState;
55
+ constructor(config: JourneyHiveRNConfig);
56
+ private resolveAgentId;
57
+ private get headers();
58
+ private log;
59
+ private request;
60
+ createResponse(params: CreateResponseParams): Promise<unknown>;
61
+ createStreamingResponse(params: CreateResponseParams): AsyncGenerator<SSEEvent>;
62
+ getAgent(agentId: string): Promise<unknown>;
63
+ listAgents(): Promise<{
64
+ data: any[];
65
+ }>;
66
+ updateAgent(agentId: string, params: any): Promise<unknown>;
67
+ createConversation(params: {
68
+ agent_id?: string;
69
+ external_user_id?: string;
70
+ metadata?: Record<string, unknown>;
71
+ }): Promise<unknown>;
72
+ getConversation(conversationId: string): Promise<unknown>;
73
+ getMessages(conversationId: string): Promise<{
74
+ data: any[];
75
+ }>;
76
+ setConnectionStatus(connected: boolean): void;
77
+ getConnectionStatus(): boolean;
78
+ onConnectionChange(listener: ConnectionListener): () => void;
79
+ setAppState(state: "active" | "background" | "inactive"): void;
80
+ onAppStateChange(listener: AppStateListener): () => void;
81
+ getQueuedMessages(): QueuedMessage[];
82
+ clearQueue(): void;
83
+ private flushOfflineQueue;
84
+ }
85
+
86
+ interface Agent {
87
+ id: string;
88
+ object: "agent";
89
+ name: string;
90
+ slug: string;
91
+ type: string;
92
+ status: string;
93
+ external_access: string;
94
+ model: string;
95
+ created_at: number;
96
+ metadata?: Record<string, unknown>;
97
+ }
98
+ interface Conversation {
99
+ id: string;
100
+ object: "conversation";
101
+ agent_id: string;
102
+ status: string;
103
+ channel: string;
104
+ external_user_id: string | null;
105
+ created_at: number;
106
+ updated_at: number;
107
+ metadata?: Record<string, unknown>;
108
+ }
109
+ interface ContentPart {
110
+ type: string;
111
+ text?: string;
112
+ }
113
+ interface Message {
114
+ id: string;
115
+ object: "message";
116
+ role: string;
117
+ content: ContentPart[];
118
+ created_at: number;
119
+ metadata?: Record<string, unknown>;
120
+ }
121
+ interface JourneyHiveProviderProps {
122
+ apiKey: string;
123
+ baseUrl?: string;
124
+ children: ReactNode;
125
+ }
126
+ declare function JourneyHiveProvider({ apiKey, baseUrl, children }: JourneyHiveProviderProps): react.FunctionComponentElement<react.ProviderProps<JourneyHiveRNClient | null>>;
127
+ declare function useJourneyHive(): JourneyHiveRNClient;
128
+ interface UseResponseReturn {
129
+ data: any | null;
130
+ isLoading: boolean;
131
+ isStreaming: boolean;
132
+ streamedText: string;
133
+ error: Error | null;
134
+ send: (input: string) => Promise<void>;
135
+ }
136
+ declare function useResponse(params?: {
137
+ agent_id?: string;
138
+ conversation_id?: string;
139
+ instructions?: string;
140
+ }): UseResponseReturn;
141
+ interface UseConversationReturn {
142
+ conversation: Conversation | null;
143
+ messages: Message[];
144
+ isLoading: boolean;
145
+ error: Error | null;
146
+ sendMessage: (input: string) => Promise<void>;
147
+ }
148
+ declare function useConversation(conversationId: string): UseConversationReturn;
149
+ interface UseAgentReturn {
150
+ agent: Agent | null;
151
+ isLoading: boolean;
152
+ error: Error | null;
153
+ update: (params: any) => Promise<void>;
154
+ }
155
+ declare function useAgent(agentId: string): UseAgentReturn;
156
+ interface UseAgentsReturn {
157
+ agents: Agent[];
158
+ isLoading: boolean;
159
+ error: Error | null;
160
+ }
161
+ declare function useAgents(): UseAgentsReturn;
162
+ interface UseConnectionStatusReturn {
163
+ isConnected: boolean;
164
+ }
165
+ declare function useConnectionStatus(): UseConnectionStatusReturn;
166
+
167
+ export { JourneyHiveProvider, JourneyHiveRNClient, RNEventSource, type SSEEvent, parseSSEFromFetch, useAgent, useAgents, useConnectionStatus, useConversation, useJourneyHive, useResponse };