@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 +257 -0
- package/dist/index.d.mts +167 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.js +475 -0
- package/dist/index.mjs +447 -0
- package/package.json +49 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
JourneyHiveProvider: () => JourneyHiveProvider,
|
|
24
|
+
JourneyHiveRNClient: () => JourneyHiveRNClient,
|
|
25
|
+
RNEventSource: () => RNEventSource,
|
|
26
|
+
parseSSEFromFetch: () => parseSSEFromFetch,
|
|
27
|
+
useAgent: () => useAgent,
|
|
28
|
+
useAgents: () => useAgents,
|
|
29
|
+
useConnectionStatus: () => useConnectionStatus,
|
|
30
|
+
useConversation: () => useConversation,
|
|
31
|
+
useJourneyHive: () => useJourneyHive,
|
|
32
|
+
useResponse: () => useResponse
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
|
|
36
|
+
// src/streaming.ts
|
|
37
|
+
async function* parseSSEFromFetch(response) {
|
|
38
|
+
const reader = response.body?.getReader();
|
|
39
|
+
if (!reader) {
|
|
40
|
+
throw new Error("Response body is not readable");
|
|
41
|
+
}
|
|
42
|
+
let buffer = "";
|
|
43
|
+
let currentEvent = "";
|
|
44
|
+
const decode = (chunk) => {
|
|
45
|
+
let result = "";
|
|
46
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
47
|
+
result += String.fromCharCode(chunk[i]);
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
while (true) {
|
|
53
|
+
const { done, value } = await reader.read();
|
|
54
|
+
if (done) break;
|
|
55
|
+
buffer += value instanceof Uint8Array ? decode(value) : String(value);
|
|
56
|
+
const lines = buffer.split("\n");
|
|
57
|
+
buffer = lines.pop() || "";
|
|
58
|
+
for (const line of lines) {
|
|
59
|
+
const trimmed = line.trim();
|
|
60
|
+
if (trimmed === "") {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (trimmed.startsWith("event: ")) {
|
|
64
|
+
currentEvent = trimmed.slice(7).trim();
|
|
65
|
+
} else if (trimmed.startsWith("data: ")) {
|
|
66
|
+
const dataStr = trimmed.slice(6);
|
|
67
|
+
try {
|
|
68
|
+
const data = JSON.parse(dataStr);
|
|
69
|
+
yield { event: currentEvent, data };
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (buffer.trim()) {
|
|
76
|
+
const remaining = buffer.trim();
|
|
77
|
+
if (remaining.startsWith("data: ")) {
|
|
78
|
+
try {
|
|
79
|
+
const data = JSON.parse(remaining.slice(6));
|
|
80
|
+
yield { event: currentEvent, data };
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} finally {
|
|
86
|
+
reader.releaseLock();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
var RNEventSource = class {
|
|
90
|
+
constructor(url, headers = {}) {
|
|
91
|
+
this.abortController = null;
|
|
92
|
+
this.onmessage = null;
|
|
93
|
+
this.onerror = null;
|
|
94
|
+
this.onopen = null;
|
|
95
|
+
this.url = url;
|
|
96
|
+
this.headers = headers;
|
|
97
|
+
}
|
|
98
|
+
async connect(body) {
|
|
99
|
+
this.abortController = new AbortController();
|
|
100
|
+
try {
|
|
101
|
+
const response = await fetch(this.url, {
|
|
102
|
+
method: body ? "POST" : "GET",
|
|
103
|
+
headers: {
|
|
104
|
+
...this.headers,
|
|
105
|
+
Accept: "text/event-stream",
|
|
106
|
+
...body ? { "Content-Type": "application/json" } : {}
|
|
107
|
+
},
|
|
108
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
109
|
+
signal: this.abortController.signal
|
|
110
|
+
});
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
throw new Error(`EventSource connection failed: ${response.status}`);
|
|
113
|
+
}
|
|
114
|
+
this.onopen?.();
|
|
115
|
+
for await (const event of parseSSEFromFetch(response)) {
|
|
116
|
+
if (this.abortController?.signal.aborted) break;
|
|
117
|
+
this.onmessage?.(event);
|
|
118
|
+
}
|
|
119
|
+
} catch (err) {
|
|
120
|
+
if (!(err instanceof DOMException && err.name === "AbortError")) {
|
|
121
|
+
this.onerror?.(err instanceof Error ? err : new Error(String(err)));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
close() {
|
|
126
|
+
this.abortController?.abort();
|
|
127
|
+
this.abortController = null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/client.ts
|
|
132
|
+
var JourneyHiveRNClient = class {
|
|
133
|
+
constructor(config) {
|
|
134
|
+
this.offlineQueue = [];
|
|
135
|
+
this.isConnected = true;
|
|
136
|
+
this.connectionListeners = [];
|
|
137
|
+
this.appStateListeners = [];
|
|
138
|
+
this.appState = "active";
|
|
139
|
+
this.apiKey = config.apiKey;
|
|
140
|
+
this.baseUrl = config.baseUrl || "https://journey-hive.replit.app";
|
|
141
|
+
this.timeout = config.timeout || 3e4;
|
|
142
|
+
this.defaultAgentId = config.defaultAgentId;
|
|
143
|
+
this.debug = config.debug || false;
|
|
144
|
+
}
|
|
145
|
+
resolveAgentId(agentId) {
|
|
146
|
+
return agentId || this.defaultAgentId;
|
|
147
|
+
}
|
|
148
|
+
get headers() {
|
|
149
|
+
return {
|
|
150
|
+
"Content-Type": "application/json",
|
|
151
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
log(message, data) {
|
|
155
|
+
if (this.debug) {
|
|
156
|
+
console.log(`[JourneyHive] ${message}`, data !== void 0 ? data : "");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async request(method, path, body) {
|
|
160
|
+
if (!this.isConnected && method === "POST") {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
if (body?.input) {
|
|
163
|
+
this.offlineQueue.push({
|
|
164
|
+
id: `queue_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
165
|
+
params: body,
|
|
166
|
+
resolve,
|
|
167
|
+
reject
|
|
168
|
+
});
|
|
169
|
+
this.log("Queued offline message", { path });
|
|
170
|
+
} else {
|
|
171
|
+
reject(new Error("No network connection"));
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
this.log(`${method} ${path}`, body);
|
|
176
|
+
const controller = new AbortController();
|
|
177
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
178
|
+
try {
|
|
179
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
180
|
+
method,
|
|
181
|
+
headers: this.headers,
|
|
182
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
183
|
+
signal: controller.signal
|
|
184
|
+
});
|
|
185
|
+
clearTimeout(timeoutId);
|
|
186
|
+
if (!res.ok) {
|
|
187
|
+
const err = await res.json().catch(() => ({}));
|
|
188
|
+
const error = new Error(err?.error?.message || `Request failed with status ${res.status}`);
|
|
189
|
+
this.log(`${method} ${path} failed`, { status: res.status, error: err });
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
const result = await res.json();
|
|
193
|
+
this.log(`${method} ${path} response`, { status: res.status });
|
|
194
|
+
return result;
|
|
195
|
+
} catch (err) {
|
|
196
|
+
clearTimeout(timeoutId);
|
|
197
|
+
throw err;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async createResponse(params) {
|
|
201
|
+
const resolved = { ...params, agent_id: this.resolveAgentId(params.agent_id) };
|
|
202
|
+
if (params.stream) {
|
|
203
|
+
return this.createStreamingResponse(resolved);
|
|
204
|
+
}
|
|
205
|
+
return this.request("POST", "/v1/responses", resolved);
|
|
206
|
+
}
|
|
207
|
+
async *createStreamingResponse(params) {
|
|
208
|
+
const resolved = { ...params, agent_id: this.resolveAgentId(params.agent_id) };
|
|
209
|
+
const controller = new AbortController();
|
|
210
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout * 3);
|
|
211
|
+
try {
|
|
212
|
+
this.log("POST /v1/responses (streaming)", resolved);
|
|
213
|
+
const response = await fetch(`${this.baseUrl}/v1/responses`, {
|
|
214
|
+
method: "POST",
|
|
215
|
+
headers: this.headers,
|
|
216
|
+
body: JSON.stringify(resolved),
|
|
217
|
+
signal: controller.signal
|
|
218
|
+
});
|
|
219
|
+
clearTimeout(timeoutId);
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
const err = await response.json().catch(() => ({}));
|
|
222
|
+
throw new Error(err?.error?.message || `Request failed with status ${response.status}`);
|
|
223
|
+
}
|
|
224
|
+
yield* parseSSEFromFetch(response);
|
|
225
|
+
} catch (err) {
|
|
226
|
+
clearTimeout(timeoutId);
|
|
227
|
+
throw err;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async getAgent(agentId) {
|
|
231
|
+
return this.request("GET", `/v1/agents/${agentId}`);
|
|
232
|
+
}
|
|
233
|
+
async listAgents() {
|
|
234
|
+
return this.request("GET", "/v1/agents");
|
|
235
|
+
}
|
|
236
|
+
async updateAgent(agentId, params) {
|
|
237
|
+
return this.request("PATCH", `/v1/agents/${agentId}`, params);
|
|
238
|
+
}
|
|
239
|
+
async createConversation(params) {
|
|
240
|
+
const resolved = { ...params, agent_id: this.resolveAgentId(params.agent_id) };
|
|
241
|
+
return this.request("POST", "/v1/conversations", resolved);
|
|
242
|
+
}
|
|
243
|
+
async getConversation(conversationId) {
|
|
244
|
+
return this.request("GET", `/v1/conversations/${conversationId}`);
|
|
245
|
+
}
|
|
246
|
+
async getMessages(conversationId) {
|
|
247
|
+
return this.request("GET", `/v1/conversations/${conversationId}/messages`);
|
|
248
|
+
}
|
|
249
|
+
setConnectionStatus(connected) {
|
|
250
|
+
const changed = this.isConnected !== connected;
|
|
251
|
+
this.isConnected = connected;
|
|
252
|
+
if (changed) {
|
|
253
|
+
this.connectionListeners.forEach((listener) => listener(connected));
|
|
254
|
+
if (connected) {
|
|
255
|
+
this.flushOfflineQueue();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
getConnectionStatus() {
|
|
260
|
+
return this.isConnected;
|
|
261
|
+
}
|
|
262
|
+
onConnectionChange(listener) {
|
|
263
|
+
this.connectionListeners.push(listener);
|
|
264
|
+
return () => {
|
|
265
|
+
this.connectionListeners = this.connectionListeners.filter((l) => l !== listener);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
setAppState(state) {
|
|
269
|
+
const prev = this.appState;
|
|
270
|
+
this.appState = state;
|
|
271
|
+
if (prev !== state) {
|
|
272
|
+
this.appStateListeners.forEach((listener) => listener(state));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
onAppStateChange(listener) {
|
|
276
|
+
this.appStateListeners.push(listener);
|
|
277
|
+
return () => {
|
|
278
|
+
this.appStateListeners = this.appStateListeners.filter((l) => l !== listener);
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
getQueuedMessages() {
|
|
282
|
+
return [...this.offlineQueue];
|
|
283
|
+
}
|
|
284
|
+
clearQueue() {
|
|
285
|
+
this.offlineQueue.forEach((msg) => msg.reject(new Error("Queue cleared")));
|
|
286
|
+
this.offlineQueue = [];
|
|
287
|
+
}
|
|
288
|
+
async flushOfflineQueue() {
|
|
289
|
+
const queue = [...this.offlineQueue];
|
|
290
|
+
this.offlineQueue = [];
|
|
291
|
+
for (const item of queue) {
|
|
292
|
+
try {
|
|
293
|
+
const result = await this.request("POST", "/v1/responses", item.params);
|
|
294
|
+
item.resolve(result);
|
|
295
|
+
} catch (err) {
|
|
296
|
+
item.reject(err);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/hooks.ts
|
|
303
|
+
var import_react = require("react");
|
|
304
|
+
var JourneyHiveContext = (0, import_react.createContext)(null);
|
|
305
|
+
function JourneyHiveProvider({ apiKey, baseUrl, children }) {
|
|
306
|
+
const clientRef = (0, import_react.useRef)(null);
|
|
307
|
+
if (!clientRef.current) {
|
|
308
|
+
clientRef.current = new JourneyHiveRNClient({ apiKey, baseUrl });
|
|
309
|
+
}
|
|
310
|
+
return (0, import_react.createElement)(JourneyHiveContext.Provider, { value: clientRef.current }, children);
|
|
311
|
+
}
|
|
312
|
+
function useJourneyHive() {
|
|
313
|
+
const client = (0, import_react.useContext)(JourneyHiveContext);
|
|
314
|
+
if (!client) {
|
|
315
|
+
throw new Error("useJourneyHive must be used within a JourneyHiveProvider");
|
|
316
|
+
}
|
|
317
|
+
return client;
|
|
318
|
+
}
|
|
319
|
+
function useResponse(params) {
|
|
320
|
+
const client = useJourneyHive();
|
|
321
|
+
const [data, setData] = (0, import_react.useState)(null);
|
|
322
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(false);
|
|
323
|
+
const [isStreaming, setIsStreaming] = (0, import_react.useState)(false);
|
|
324
|
+
const [streamedText, setStreamedText] = (0, import_react.useState)("");
|
|
325
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
326
|
+
const send = (0, import_react.useCallback)(
|
|
327
|
+
async (input) => {
|
|
328
|
+
setIsLoading(true);
|
|
329
|
+
setIsStreaming(false);
|
|
330
|
+
setStreamedText("");
|
|
331
|
+
setError(null);
|
|
332
|
+
setData(null);
|
|
333
|
+
try {
|
|
334
|
+
const stream = client.createStreamingResponse({
|
|
335
|
+
agent_id: params?.agent_id || "",
|
|
336
|
+
input,
|
|
337
|
+
stream: true,
|
|
338
|
+
conversation_id: params?.conversation_id,
|
|
339
|
+
instructions: params?.instructions
|
|
340
|
+
});
|
|
341
|
+
setIsStreaming(true);
|
|
342
|
+
let accumulated = "";
|
|
343
|
+
for await (const { event, data: eventData } of stream) {
|
|
344
|
+
if (event === "response.output_text.delta") {
|
|
345
|
+
accumulated += eventData.delta;
|
|
346
|
+
setStreamedText(accumulated);
|
|
347
|
+
} else if (event === "response.completed") {
|
|
348
|
+
setData(eventData);
|
|
349
|
+
} else if (event === "response.failed") {
|
|
350
|
+
throw new Error(eventData.error?.message || "Response failed");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
setIsStreaming(false);
|
|
354
|
+
} catch (err) {
|
|
355
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
356
|
+
} finally {
|
|
357
|
+
setIsLoading(false);
|
|
358
|
+
setIsStreaming(false);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
[client, params]
|
|
362
|
+
);
|
|
363
|
+
return { data, isLoading, isStreaming, streamedText, error, send };
|
|
364
|
+
}
|
|
365
|
+
function useConversation(conversationId) {
|
|
366
|
+
const client = useJourneyHive();
|
|
367
|
+
const [conversation, setConversation] = (0, import_react.useState)(null);
|
|
368
|
+
const [messages, setMessages] = (0, import_react.useState)([]);
|
|
369
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
370
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
371
|
+
(0, import_react.useEffect)(() => {
|
|
372
|
+
if (!conversationId) return;
|
|
373
|
+
setIsLoading(true);
|
|
374
|
+
Promise.all([
|
|
375
|
+
client.getConversation(conversationId),
|
|
376
|
+
client.getMessages(conversationId)
|
|
377
|
+
]).then(([conv, msgResult]) => {
|
|
378
|
+
setConversation(conv);
|
|
379
|
+
setMessages(msgResult.data || []);
|
|
380
|
+
}).catch((err) => setError(err instanceof Error ? err : new Error(String(err)))).finally(() => setIsLoading(false));
|
|
381
|
+
}, [conversationId, client]);
|
|
382
|
+
const sendMessage = (0, import_react.useCallback)(
|
|
383
|
+
async (input) => {
|
|
384
|
+
if (!conversation) return;
|
|
385
|
+
const optimisticMsg = {
|
|
386
|
+
id: `temp_${Date.now()}`,
|
|
387
|
+
object: "message",
|
|
388
|
+
role: "user",
|
|
389
|
+
content: [{ type: "output_text", text: input }],
|
|
390
|
+
created_at: Math.floor(Date.now() / 1e3)
|
|
391
|
+
};
|
|
392
|
+
setMessages((prev) => [...prev, optimisticMsg]);
|
|
393
|
+
try {
|
|
394
|
+
const result = await client.createResponse({
|
|
395
|
+
agent_id: conversation.agent_id,
|
|
396
|
+
input,
|
|
397
|
+
conversation_id: conversationId
|
|
398
|
+
});
|
|
399
|
+
if (result?.output) {
|
|
400
|
+
const assistantMsg = {
|
|
401
|
+
id: result.output[0]?.id || `msg_${Date.now()}`,
|
|
402
|
+
object: "message",
|
|
403
|
+
role: "assistant",
|
|
404
|
+
content: result.output[0]?.content || [],
|
|
405
|
+
created_at: result.created_at
|
|
406
|
+
};
|
|
407
|
+
setMessages((prev) => [...prev, assistantMsg]);
|
|
408
|
+
}
|
|
409
|
+
} catch (err) {
|
|
410
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
411
|
+
setMessages((prev) => prev.filter((m) => m.id !== optimisticMsg.id));
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
[client, conversation, conversationId]
|
|
415
|
+
);
|
|
416
|
+
return { conversation, messages, isLoading, error, sendMessage };
|
|
417
|
+
}
|
|
418
|
+
function useAgent(agentId) {
|
|
419
|
+
const client = useJourneyHive();
|
|
420
|
+
const [agent, setAgent] = (0, import_react.useState)(null);
|
|
421
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
422
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
423
|
+
(0, import_react.useEffect)(() => {
|
|
424
|
+
if (!agentId) return;
|
|
425
|
+
setIsLoading(true);
|
|
426
|
+
client.getAgent(agentId).then((a) => setAgent(a)).catch((err) => setError(err instanceof Error ? err : new Error(String(err)))).finally(() => setIsLoading(false));
|
|
427
|
+
}, [agentId, client]);
|
|
428
|
+
const update = (0, import_react.useCallback)(
|
|
429
|
+
async (params) => {
|
|
430
|
+
try {
|
|
431
|
+
const updated = await client.updateAgent(agentId, params);
|
|
432
|
+
setAgent(updated);
|
|
433
|
+
} catch (err) {
|
|
434
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
[client, agentId]
|
|
438
|
+
);
|
|
439
|
+
return { agent, isLoading, error, update };
|
|
440
|
+
}
|
|
441
|
+
function useAgents() {
|
|
442
|
+
const client = useJourneyHive();
|
|
443
|
+
const [agents, setAgents] = (0, import_react.useState)([]);
|
|
444
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
445
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
446
|
+
(0, import_react.useEffect)(() => {
|
|
447
|
+
setIsLoading(true);
|
|
448
|
+
client.listAgents().then((result) => setAgents(result.data || [])).catch((err) => setError(err instanceof Error ? err : new Error(String(err)))).finally(() => setIsLoading(false));
|
|
449
|
+
}, [client]);
|
|
450
|
+
return { agents, isLoading, error };
|
|
451
|
+
}
|
|
452
|
+
function useConnectionStatus() {
|
|
453
|
+
const client = useJourneyHive();
|
|
454
|
+
const [isConnected, setIsConnected] = (0, import_react.useState)(client.getConnectionStatus());
|
|
455
|
+
(0, import_react.useEffect)(() => {
|
|
456
|
+
const unsubscribe = client.onConnectionChange((connected) => {
|
|
457
|
+
setIsConnected(connected);
|
|
458
|
+
});
|
|
459
|
+
return unsubscribe;
|
|
460
|
+
}, [client]);
|
|
461
|
+
return { isConnected };
|
|
462
|
+
}
|
|
463
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
464
|
+
0 && (module.exports = {
|
|
465
|
+
JourneyHiveProvider,
|
|
466
|
+
JourneyHiveRNClient,
|
|
467
|
+
RNEventSource,
|
|
468
|
+
parseSSEFromFetch,
|
|
469
|
+
useAgent,
|
|
470
|
+
useAgents,
|
|
471
|
+
useConnectionStatus,
|
|
472
|
+
useConversation,
|
|
473
|
+
useJourneyHive,
|
|
474
|
+
useResponse
|
|
475
|
+
});
|