@gr33n-ai/jade-sdk-rn-client 0.1.0 → 0.1.2
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 +13 -13
- package/dist/index.d.mts +339 -6
- package/dist/index.d.ts +339 -6
- package/dist/index.js +30 -55
- package/dist/index.mjs +27 -36
- package/package.json +17 -23
- package/dist/react-native/index.d.mts +0 -339
- package/dist/react-native/index.d.ts +0 -339
- package/dist/react-native/index.js +0 -2795
- package/dist/react-native/index.mjs +0 -2784
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useState, useEffect, useMemo, useContext, useRef, useCallback } from 'react';
|
|
2
|
-
import { AppState } from 'react-native';
|
|
3
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { AppState } from 'react-native';
|
|
4
4
|
|
|
5
5
|
var __create = Object.create;
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
@@ -320,8 +320,6 @@ var require_react_native_sse = __commonJS({
|
|
|
320
320
|
module.exports = EventSource3;
|
|
321
321
|
}
|
|
322
322
|
});
|
|
323
|
-
|
|
324
|
-
// ../ts-client/dist/index.js
|
|
325
323
|
async function getBytes(stream, onChunk) {
|
|
326
324
|
const reader = stream.getReader();
|
|
327
325
|
let result;
|
|
@@ -1571,14 +1569,6 @@ var TOOL_REGISTRY = {
|
|
|
1571
1569
|
function getToolDefinition(toolName) {
|
|
1572
1570
|
return TOOL_REGISTRY[toolName];
|
|
1573
1571
|
}
|
|
1574
|
-
function getToolIconName(toolName, toolInput) {
|
|
1575
|
-
const def = getToolDefinition(toolName);
|
|
1576
|
-
if (!def) return "Wrench";
|
|
1577
|
-
if (def.iconVariant && toolInput) {
|
|
1578
|
-
return def.iconVariant(toolInput);
|
|
1579
|
-
}
|
|
1580
|
-
return def.iconName;
|
|
1581
|
-
}
|
|
1582
1572
|
var SUGGESTION_REGEX = /<gr3\.suggestion>([\s\S]*?)<\/gr3\.suggestion>/g;
|
|
1583
1573
|
function parseSuggestions(text) {
|
|
1584
1574
|
const suggestions = [];
|
|
@@ -1978,6 +1968,7 @@ function extractMedia(conversation) {
|
|
|
1978
1968
|
mediaArray.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
1979
1969
|
return mediaArray;
|
|
1980
1970
|
}
|
|
1971
|
+
createContext(null);
|
|
1981
1972
|
|
|
1982
1973
|
// src/react-native/sse-adapter.ts
|
|
1983
1974
|
var import_react_native_sse = __toESM(require_react_native_sse());
|
|
@@ -2045,7 +2036,7 @@ async function createRNSSEStream(options) {
|
|
|
2045
2036
|
];
|
|
2046
2037
|
for (const eventType of eventTypes) {
|
|
2047
2038
|
es.addEventListener(eventType, (event) => {
|
|
2048
|
-
console.log(`[
|
|
2039
|
+
console.log(`[Jade-SSE] Received ${eventType} event:`, event.data?.substring?.(0, 100) || event.data);
|
|
2049
2040
|
const eventData = {
|
|
2050
2041
|
data: event.data,
|
|
2051
2042
|
lastEventId: event.lastEventId ?? void 0
|
|
@@ -2054,7 +2045,7 @@ async function createRNSSEStream(options) {
|
|
|
2054
2045
|
});
|
|
2055
2046
|
}
|
|
2056
2047
|
es.addEventListener("message", (event) => {
|
|
2057
|
-
console.log("[
|
|
2048
|
+
console.log("[Jade-SSE] Received message event:", event.data?.substring?.(0, 100) || event.data);
|
|
2058
2049
|
const eventData = {
|
|
2059
2050
|
data: event.data,
|
|
2060
2051
|
lastEventId: event.lastEventId ?? void 0
|
|
@@ -2062,7 +2053,7 @@ async function createRNSSEStream(options) {
|
|
|
2062
2053
|
handleSSEEvent("message", eventData, emitter, processedIds);
|
|
2063
2054
|
});
|
|
2064
2055
|
es.addEventListener("error", (event) => {
|
|
2065
|
-
console.log("[
|
|
2056
|
+
console.log("[Jade-SSE] Error event:", JSON.stringify(event));
|
|
2066
2057
|
if (signal?.aborted || isClosed) {
|
|
2067
2058
|
cleanup();
|
|
2068
2059
|
return;
|
|
@@ -2071,7 +2062,7 @@ async function createRNSSEStream(options) {
|
|
|
2071
2062
|
const status = event.xhrStatus;
|
|
2072
2063
|
if (status === 401 || status === 403 || errorMessage.includes("401") || errorMessage.includes("403") || errorMessage.includes("Authentication")) {
|
|
2073
2064
|
const authError = `Authentication failed (${status || "unknown"}): ${errorMessage}`;
|
|
2074
|
-
console.log("[
|
|
2065
|
+
console.log("[Jade-SSE] Auth error detected:", authError);
|
|
2075
2066
|
emitter.emit("error", { error: authError });
|
|
2076
2067
|
cleanup();
|
|
2077
2068
|
reject(new Error(authError));
|
|
@@ -2101,7 +2092,7 @@ async function createRNSSEStream(options) {
|
|
|
2101
2092
|
INITIAL_RETRY_DELAY2 * Math.pow(2, retryCount - 1),
|
|
2102
2093
|
MAX_RETRY_DELAY2
|
|
2103
2094
|
);
|
|
2104
|
-
console.log(`[
|
|
2095
|
+
console.log(`[Jade-SSE] Retry ${retryCount}/${MAX_RETRIES2} in ${delay}ms`);
|
|
2105
2096
|
es?.close();
|
|
2106
2097
|
setTimeout(connect, delay);
|
|
2107
2098
|
});
|
|
@@ -2162,7 +2153,7 @@ function handleSSEEvent(eventType, event, emitter, processedIds) {
|
|
|
2162
2153
|
break;
|
|
2163
2154
|
}
|
|
2164
2155
|
} catch (e) {
|
|
2165
|
-
console.error("[
|
|
2156
|
+
console.error("[Jade-SSE] Failed to parse event:", event.data, e);
|
|
2166
2157
|
}
|
|
2167
2158
|
}
|
|
2168
2159
|
function handleStreamEvent2(data, emitter) {
|
|
@@ -2182,7 +2173,7 @@ function handleStreamEvent2(data, emitter) {
|
|
|
2182
2173
|
}
|
|
2183
2174
|
|
|
2184
2175
|
// src/react-native/client.ts
|
|
2185
|
-
var
|
|
2176
|
+
var JadeClient = class {
|
|
2186
2177
|
config;
|
|
2187
2178
|
baseClient;
|
|
2188
2179
|
activeStreams = /* @__PURE__ */ new Map();
|
|
@@ -2397,8 +2388,8 @@ var RNAgentClient = class {
|
|
|
2397
2388
|
return this.baseClient.getPluginBundle(skills);
|
|
2398
2389
|
}
|
|
2399
2390
|
};
|
|
2400
|
-
var
|
|
2401
|
-
function
|
|
2391
|
+
var JadeContext = createContext(null);
|
|
2392
|
+
function JadeProvider({
|
|
2402
2393
|
children,
|
|
2403
2394
|
config,
|
|
2404
2395
|
storage,
|
|
@@ -2413,7 +2404,7 @@ function RNAgentProvider({
|
|
|
2413
2404
|
return () => subscription.remove();
|
|
2414
2405
|
}, [pauseOnBackground]);
|
|
2415
2406
|
const client = useMemo(
|
|
2416
|
-
() => new
|
|
2407
|
+
() => new JadeClient(config),
|
|
2417
2408
|
// Only recreate client if endpoint changes
|
|
2418
2409
|
[config.endpoint, config.apiVersion, config.timeout]
|
|
2419
2410
|
);
|
|
@@ -2421,31 +2412,31 @@ function RNAgentProvider({
|
|
|
2421
2412
|
() => ({ client, storage, appState }),
|
|
2422
2413
|
[client, storage, appState]
|
|
2423
2414
|
);
|
|
2424
|
-
return /* @__PURE__ */ jsx(
|
|
2415
|
+
return /* @__PURE__ */ jsx(JadeContext.Provider, { value, children });
|
|
2425
2416
|
}
|
|
2426
|
-
function
|
|
2427
|
-
const context = useContext(
|
|
2417
|
+
function useJadeClient() {
|
|
2418
|
+
const context = useContext(JadeContext);
|
|
2428
2419
|
if (!context) {
|
|
2429
|
-
throw new Error("
|
|
2420
|
+
throw new Error("useJadeClient must be used within a JadeProvider");
|
|
2430
2421
|
}
|
|
2431
2422
|
return context.client;
|
|
2432
2423
|
}
|
|
2433
2424
|
function useStorage() {
|
|
2434
|
-
const context = useContext(
|
|
2425
|
+
const context = useContext(JadeContext);
|
|
2435
2426
|
if (!context) {
|
|
2436
|
-
throw new Error("useStorage must be used within
|
|
2427
|
+
throw new Error("useStorage must be used within a JadeProvider");
|
|
2437
2428
|
}
|
|
2438
2429
|
return context.storage;
|
|
2439
2430
|
}
|
|
2440
2431
|
function useAppState() {
|
|
2441
|
-
const context = useContext(
|
|
2432
|
+
const context = useContext(JadeContext);
|
|
2442
2433
|
if (!context) {
|
|
2443
|
-
throw new Error("useAppState must be used within
|
|
2434
|
+
throw new Error("useAppState must be used within a JadeProvider");
|
|
2444
2435
|
}
|
|
2445
2436
|
return context.appState;
|
|
2446
2437
|
}
|
|
2447
|
-
function
|
|
2448
|
-
const client =
|
|
2438
|
+
function useJadeSessionCore(options = {}) {
|
|
2439
|
+
const client = useJadeClient();
|
|
2449
2440
|
const appState = useAppState();
|
|
2450
2441
|
const {
|
|
2451
2442
|
initialSessionId,
|
|
@@ -2463,7 +2454,7 @@ function useRNAgentSession(options = {}) {
|
|
|
2463
2454
|
const accumulatedTextRef = useRef({});
|
|
2464
2455
|
useEffect(() => {
|
|
2465
2456
|
if (pauseOnBackground && appState !== "active" && session.isStreaming) {
|
|
2466
|
-
console.log("[
|
|
2457
|
+
console.log("[JadeSession] App went to background while streaming");
|
|
2467
2458
|
}
|
|
2468
2459
|
}, [appState, pauseOnBackground, session.isStreaming]);
|
|
2469
2460
|
const setupEventHandlers = useCallback(
|
|
@@ -2608,10 +2599,10 @@ function useRNAgentSession(options = {}) {
|
|
|
2608
2599
|
try {
|
|
2609
2600
|
await client.cancelSession(session.sessionId);
|
|
2610
2601
|
} catch (error) {
|
|
2611
|
-
console.error("[
|
|
2602
|
+
console.error("[JadeSession] Server-side cancel failed:", error);
|
|
2612
2603
|
}
|
|
2613
2604
|
} else {
|
|
2614
|
-
console.warn("[
|
|
2605
|
+
console.warn("[JadeSession] No sessionId available for server-side cancel");
|
|
2615
2606
|
}
|
|
2616
2607
|
if (abortRef.current) {
|
|
2617
2608
|
abortRef.current();
|
|
@@ -2735,7 +2726,7 @@ function useJadeSession(options = {}) {
|
|
|
2735
2726
|
processingOptions,
|
|
2736
2727
|
...agentOptions
|
|
2737
2728
|
} = options;
|
|
2738
|
-
const session =
|
|
2729
|
+
const session = useJadeSessionCore(agentOptions);
|
|
2739
2730
|
const processedConversation = useMemo(() => {
|
|
2740
2731
|
return processConversation(session.conversation, {
|
|
2741
2732
|
skipSkillContext,
|
|
@@ -2789,4 +2780,4 @@ var STORAGE_KEYS = {
|
|
|
2789
2780
|
USER_PREFERENCES: "@gr33n-ai/user-preferences"
|
|
2790
2781
|
};
|
|
2791
2782
|
|
|
2792
|
-
export {
|
|
2783
|
+
export { JadeClient, JadeProvider, STORAGE_KEYS, TOOL_REGISTRY, createAsyncStorageAdapter, createMMKVAdapter, createMemoryStorageAdapter, extractMedia, getToolDefinition, processConversation, useAppState, useJadeClient, useJadeSession, useJadeSessionCore, useStorage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gr33n-ai/jade-sdk-rn-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "React Native client for Jade AI - generate images, videos, and audio on mobile",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "gr33n.ai",
|
|
@@ -34,32 +34,14 @@
|
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
35
|
"import": "./dist/index.mjs",
|
|
36
36
|
"require": "./dist/index.js"
|
|
37
|
-
},
|
|
38
|
-
"./react-native": {
|
|
39
|
-
"react-native": "./dist/react-native/index.mjs",
|
|
40
|
-
"types": "./dist/react-native/index.d.ts",
|
|
41
|
-
"import": "./dist/react-native/index.mjs",
|
|
42
|
-
"require": "./dist/react-native/index.js"
|
|
43
37
|
}
|
|
44
38
|
},
|
|
45
39
|
"files": [
|
|
46
40
|
"dist"
|
|
47
41
|
],
|
|
48
|
-
"scripts": {
|
|
49
|
-
"build": "tsup",
|
|
50
|
-
"build:deps": "pnpm --filter @gr33n-ai/agent-sdk-client build && pnpm --filter @gr33n-ai/jade-sdk-client build",
|
|
51
|
-
"build:all": "pnpm run build:deps && pnpm run build",
|
|
52
|
-
"dev": "tsup --watch",
|
|
53
|
-
"typecheck": "tsc --noEmit",
|
|
54
|
-
"lint": "eslint src/",
|
|
55
|
-
"test": "jest",
|
|
56
|
-
"playground": "cd playground && npx expo start",
|
|
57
|
-
"playground:ios": "cd playground && npx expo start --ios",
|
|
58
|
-
"playground:android": "cd playground && npx expo start --android"
|
|
59
|
-
},
|
|
60
42
|
"dependencies": {
|
|
61
|
-
"
|
|
62
|
-
"
|
|
43
|
+
"react-native-sse": "^1.2.1",
|
|
44
|
+
"@gr33n-ai/jade-sdk-client": "0.1.2"
|
|
63
45
|
},
|
|
64
46
|
"peerDependencies": {
|
|
65
47
|
"react": ">=18.0.0",
|
|
@@ -76,5 +58,17 @@
|
|
|
76
58
|
"tsup": "^8.0.0",
|
|
77
59
|
"typescript": "^5"
|
|
78
60
|
},
|
|
79
|
-
"sideEffects": false
|
|
80
|
-
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"build:deps": "pnpm --filter @gr33n-ai/agent-sdk-client build && pnpm --filter @gr33n-ai/jade-sdk-client build",
|
|
65
|
+
"build:all": "pnpm run build:deps && pnpm run build",
|
|
66
|
+
"dev": "tsup --watch",
|
|
67
|
+
"typecheck": "tsc --noEmit",
|
|
68
|
+
"lint": "eslint src/",
|
|
69
|
+
"test": "jest",
|
|
70
|
+
"playground": "cd playground && npx expo start",
|
|
71
|
+
"playground:ios": "cd playground && npx expo start --ios",
|
|
72
|
+
"playground:android": "cd playground && npx expo start --android"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
import { AgentClientConfig, MessagesRequest, AgentEventEmitter, SessionListResponse, SessionConversationResponse, SessionContentResponse, SessionStatusResponse, UpdateSessionRequest, SuccessResponse, CancelResponse, SkillListResponse, SaveSkillRequest, PluginManifestResponse, PluginBundleResponse, ConversationEntry, StreamingToolCall, ProcessingOptions, ProcessedEntry, MediaInfo } from '@gr33n-ai/jade-sdk-client';
|
|
2
|
-
export { ConversationEntry, MediaInfo, ProcessedEntry, ProcessingOptions, SessionMetadata, SkillMetadata, StreamingToolCall } from '@gr33n-ai/jade-sdk-client';
|
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { AppStateStatus } from 'react-native';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* RNAgentClient - React Native client for the Agent SDK API.
|
|
9
|
-
* Uses react-native-sse for streaming instead of @microsoft/fetch-event-source.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
declare class RNAgentClient {
|
|
13
|
-
private config;
|
|
14
|
-
private baseClient;
|
|
15
|
-
private activeStreams;
|
|
16
|
-
constructor(config: AgentClientConfig);
|
|
17
|
-
/** Whether org context is configured (orgId is set) */
|
|
18
|
-
get hasOrgContext(): boolean;
|
|
19
|
-
private get baseUrl();
|
|
20
|
-
private getHeaders;
|
|
21
|
-
/**
|
|
22
|
-
* Send a message and stream responses using React Native SSE.
|
|
23
|
-
* @returns Object with event emitter and abort function
|
|
24
|
-
*/
|
|
25
|
-
stream(request: MessagesRequest): {
|
|
26
|
-
emitter: AgentEventEmitter;
|
|
27
|
-
abort: () => void;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Reconnect to an active streaming session using React Native SSE.
|
|
31
|
-
* @returns Object with event emitter and abort function
|
|
32
|
-
*/
|
|
33
|
-
reconnect(sessionId: string, lastEventId?: number): {
|
|
34
|
-
emitter: AgentEventEmitter;
|
|
35
|
-
abort: () => void;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* List all sessions for the authenticated user.
|
|
39
|
-
*/
|
|
40
|
-
listSessions(): Promise<SessionListResponse>;
|
|
41
|
-
/**
|
|
42
|
-
* Get session content in display format.
|
|
43
|
-
*/
|
|
44
|
-
getSession(sessionId: string): Promise<SessionConversationResponse>;
|
|
45
|
-
/**
|
|
46
|
-
* Get session content as raw JSONL.
|
|
47
|
-
*/
|
|
48
|
-
getSessionRaw(sessionId: string): Promise<SessionContentResponse>;
|
|
49
|
-
/**
|
|
50
|
-
* Check if a session is actively streaming.
|
|
51
|
-
*/
|
|
52
|
-
getSessionStatus(sessionId: string): Promise<SessionStatusResponse>;
|
|
53
|
-
/**
|
|
54
|
-
* Update session metadata (name).
|
|
55
|
-
*/
|
|
56
|
-
updateSession(sessionId: string, updates: UpdateSessionRequest): Promise<SuccessResponse>;
|
|
57
|
-
/**
|
|
58
|
-
* Delete a session.
|
|
59
|
-
*/
|
|
60
|
-
deleteSession(sessionId: string): Promise<SuccessResponse>;
|
|
61
|
-
/**
|
|
62
|
-
* Cancel an active session query.
|
|
63
|
-
*/
|
|
64
|
-
cancelSession(sessionId: string): Promise<CancelResponse>;
|
|
65
|
-
/**
|
|
66
|
-
* List personal skills.
|
|
67
|
-
*/
|
|
68
|
-
listSkills(): Promise<SkillListResponse>;
|
|
69
|
-
/**
|
|
70
|
-
* Get personal skill content.
|
|
71
|
-
*/
|
|
72
|
-
getSkill(name: string): Promise<Uint8Array>;
|
|
73
|
-
/**
|
|
74
|
-
* Create or update a personal skill.
|
|
75
|
-
*/
|
|
76
|
-
saveSkill(skill: SaveSkillRequest): Promise<SuccessResponse>;
|
|
77
|
-
/**
|
|
78
|
-
* Delete a personal skill.
|
|
79
|
-
*/
|
|
80
|
-
deleteSkill(name: string): Promise<SuccessResponse>;
|
|
81
|
-
/**
|
|
82
|
-
* List organization skills.
|
|
83
|
-
*/
|
|
84
|
-
listOrgSkills(): Promise<SkillListResponse>;
|
|
85
|
-
/**
|
|
86
|
-
* Get organization skill content.
|
|
87
|
-
*/
|
|
88
|
-
getOrgSkill(name: string): Promise<Uint8Array>;
|
|
89
|
-
/**
|
|
90
|
-
* Create or update an organization skill.
|
|
91
|
-
*/
|
|
92
|
-
saveOrgSkill(skill: SaveSkillRequest): Promise<SuccessResponse>;
|
|
93
|
-
/**
|
|
94
|
-
* Delete an organization skill.
|
|
95
|
-
*/
|
|
96
|
-
deleteOrgSkill(name: string): Promise<SuccessResponse>;
|
|
97
|
-
/**
|
|
98
|
-
* Get plugin manifest for client sync.
|
|
99
|
-
*/
|
|
100
|
-
getPluginManifest(): Promise<PluginManifestResponse>;
|
|
101
|
-
/**
|
|
102
|
-
* Download plugin bundle.
|
|
103
|
-
*/
|
|
104
|
-
getPluginBundle(skills?: string[]): Promise<PluginBundleResponse>;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Storage adapter for React Native.
|
|
109
|
-
* Provides AsyncStorage and MMKV implementations.
|
|
110
|
-
*/
|
|
111
|
-
interface StorageAdapter {
|
|
112
|
-
getItem(key: string): Promise<string | null>;
|
|
113
|
-
setItem(key: string, value: string): Promise<void>;
|
|
114
|
-
removeItem(key: string): Promise<void>;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Create a storage adapter using @react-native-async-storage/async-storage.
|
|
118
|
-
* AsyncStorage must be passed in to avoid requiring it as a direct dependency.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```typescript
|
|
122
|
-
* import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
123
|
-
* const storage = createAsyncStorageAdapter(AsyncStorage);
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
declare function createAsyncStorageAdapter(asyncStorage: {
|
|
127
|
-
getItem: (key: string) => Promise<string | null>;
|
|
128
|
-
setItem: (key: string, value: string) => Promise<void>;
|
|
129
|
-
removeItem: (key: string) => Promise<void>;
|
|
130
|
-
}): StorageAdapter;
|
|
131
|
-
/**
|
|
132
|
-
* Create a storage adapter using react-native-mmkv.
|
|
133
|
-
* MMKV instance must be passed in to avoid requiring it as a direct dependency.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```typescript
|
|
137
|
-
* import { MMKV } from 'react-native-mmkv';
|
|
138
|
-
* const mmkv = new MMKV();
|
|
139
|
-
* const storage = createMMKVAdapter(mmkv);
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
declare function createMMKVAdapter(mmkv: {
|
|
143
|
-
getString: (key: string) => string | undefined;
|
|
144
|
-
set: (key: string, value: string) => void;
|
|
145
|
-
delete: (key: string) => void;
|
|
146
|
-
}): StorageAdapter;
|
|
147
|
-
/**
|
|
148
|
-
* Create an in-memory storage adapter for testing.
|
|
149
|
-
*/
|
|
150
|
-
declare function createMemoryStorageAdapter(): StorageAdapter;
|
|
151
|
-
/**
|
|
152
|
-
* Standard storage keys used by the Jade SDK.
|
|
153
|
-
*/
|
|
154
|
-
declare const STORAGE_KEYS: {
|
|
155
|
-
readonly AUTH_TOKEN: "@gr33n-ai/auth-token";
|
|
156
|
-
readonly ENDPOINT: "@gr33n-ai/endpoint";
|
|
157
|
-
readonly ORG_ID: "@gr33n-ai/org-id";
|
|
158
|
-
readonly LAST_SESSION_ID: "@gr33n-ai/last-session-id";
|
|
159
|
-
readonly USER_PREFERENCES: "@gr33n-ai/user-preferences";
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
interface RNAgentProviderProps {
|
|
163
|
-
children: React.ReactNode;
|
|
164
|
-
/** Client configuration */
|
|
165
|
-
config: AgentClientConfig;
|
|
166
|
-
/** Optional storage adapter for persisting auth tokens, etc. */
|
|
167
|
-
storage?: StorageAdapter;
|
|
168
|
-
/** Pause streaming when app goes to background (default: true) */
|
|
169
|
-
pauseOnBackground?: boolean;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Provider component for the React Native Jade SDK client.
|
|
173
|
-
* Wrap your app with this to use the agent hooks.
|
|
174
|
-
*
|
|
175
|
-
* Features:
|
|
176
|
-
* - AppState-aware (tracks foreground/background)
|
|
177
|
-
* - Optional storage adapter for persistence
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```tsx
|
|
181
|
-
* import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
182
|
-
* import { createAsyncStorageAdapter } from '@gr33n-ai/jade-sdk-rn-client/react-native';
|
|
183
|
-
*
|
|
184
|
-
* const storage = createAsyncStorageAdapter(AsyncStorage);
|
|
185
|
-
*
|
|
186
|
-
* <RNAgentProvider
|
|
187
|
-
* config={{
|
|
188
|
-
* endpoint: 'https://api.example.com',
|
|
189
|
-
* getAuthToken: async () => storage.getItem('@gr33n-ai/auth-token'),
|
|
190
|
-
* }}
|
|
191
|
-
* storage={storage}
|
|
192
|
-
* >
|
|
193
|
-
* <App />
|
|
194
|
-
* </RNAgentProvider>
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
declare function RNAgentProvider({ children, config, storage, pauseOnBackground, }: RNAgentProviderProps): react_jsx_runtime.JSX.Element;
|
|
198
|
-
/**
|
|
199
|
-
* Get the React Native Agent SDK client instance.
|
|
200
|
-
* Must be used within an RNAgentProvider.
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```tsx
|
|
204
|
-
* const client = useRNAgentClient();
|
|
205
|
-
* const sessions = await client.listSessions();
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
declare function useRNAgentClient(): RNAgentClient;
|
|
209
|
-
/**
|
|
210
|
-
* Get the storage adapter instance.
|
|
211
|
-
* Must be used within an RNAgentProvider.
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* ```tsx
|
|
215
|
-
* const storage = useStorage();
|
|
216
|
-
* if (storage) {
|
|
217
|
-
* await storage.setItem('@gr33n-ai/last-session', sessionId);
|
|
218
|
-
* }
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
declare function useStorage(): StorageAdapter | undefined;
|
|
222
|
-
/**
|
|
223
|
-
* Get the current app state (active, background, inactive).
|
|
224
|
-
* Useful for pausing/resuming operations based on app visibility.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```tsx
|
|
228
|
-
* const appState = useAppState();
|
|
229
|
-
* useEffect(() => {
|
|
230
|
-
* if (appState === 'active') {
|
|
231
|
-
* // Resume operations
|
|
232
|
-
* }
|
|
233
|
-
* }, [appState]);
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
declare function useAppState(): AppStateStatus;
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* useRNAgentSession hook for React Native.
|
|
240
|
-
* Manages agent sessions with streaming support using the RNAgentClient.
|
|
241
|
-
*/
|
|
242
|
-
|
|
243
|
-
interface UseRNAgentSessionOptions {
|
|
244
|
-
/** Initial session ID */
|
|
245
|
-
initialSessionId?: string;
|
|
246
|
-
/** Initial conversation entries */
|
|
247
|
-
initialConversation?: ConversationEntry[];
|
|
248
|
-
/** Callback when media is generated (image/video/audio) */
|
|
249
|
-
onMediaGenerated?: (urls: string[], type: 'image' | 'video' | 'audio') => void;
|
|
250
|
-
/** Pause streaming when app goes to background (default: true) */
|
|
251
|
-
pauseOnBackground?: boolean;
|
|
252
|
-
}
|
|
253
|
-
interface UseRNAgentSessionReturn {
|
|
254
|
-
sessionId: string | undefined;
|
|
255
|
-
conversation: ConversationEntry[];
|
|
256
|
-
isStreaming: boolean;
|
|
257
|
-
streamingText: string | undefined;
|
|
258
|
-
streamingToolCall: StreamingToolCall | undefined;
|
|
259
|
-
showTinkering: boolean;
|
|
260
|
-
sendMessage: (prompt: string, skills?: string[]) => Promise<void>;
|
|
261
|
-
cancel: () => Promise<void>;
|
|
262
|
-
clear: () => void;
|
|
263
|
-
reconnect: (sessionId: string, freshConversation?: ConversationEntry[], streamingPrompt?: string) => Promise<void>;
|
|
264
|
-
setSessionId: (id: string | undefined) => void;
|
|
265
|
-
setConversation: (entries: ConversationEntry[], sessionId?: string) => void;
|
|
266
|
-
loadSession: (sessionId: string) => Promise<ConversationEntry[]>;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Hook for managing agent sessions with streaming support in React Native.
|
|
270
|
-
*
|
|
271
|
-
* Features:
|
|
272
|
-
* - Streaming with RN-specific SSE implementation
|
|
273
|
-
* - AppState-aware (can pause on background)
|
|
274
|
-
* - Same API as useAgentSession from agent-sdk-client
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* ```tsx
|
|
278
|
-
* const {
|
|
279
|
-
* conversation,
|
|
280
|
-
* isStreaming,
|
|
281
|
-
* streamingText,
|
|
282
|
-
* sendMessage,
|
|
283
|
-
* cancel,
|
|
284
|
-
* } = useRNAgentSession();
|
|
285
|
-
*
|
|
286
|
-
* await sendMessage('Hello!');
|
|
287
|
-
* ```
|
|
288
|
-
*/
|
|
289
|
-
declare function useRNAgentSession(options?: UseRNAgentSessionOptions): UseRNAgentSessionReturn;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* useJadeSession hook for React Native.
|
|
293
|
-
* Extends useRNAgentSession with processed conversation and media extraction.
|
|
294
|
-
*/
|
|
295
|
-
|
|
296
|
-
interface UseJadeSessionOptions extends UseRNAgentSessionOptions {
|
|
297
|
-
/** Skip Skill context injection entries (default: true) */
|
|
298
|
-
skipSkillContext?: boolean;
|
|
299
|
-
/** Processing options */
|
|
300
|
-
processingOptions?: ProcessingOptions;
|
|
301
|
-
}
|
|
302
|
-
interface UseJadeSessionReturn extends UseRNAgentSessionReturn {
|
|
303
|
-
/** Processed conversation entries with tool pairing and parsing */
|
|
304
|
-
processedConversation: ProcessedEntry[];
|
|
305
|
-
/** All media extracted from conversation (deduplicated, sorted by timestamp) */
|
|
306
|
-
media: MediaInfo[];
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Hook for managing Jade agent sessions with enhanced conversation processing.
|
|
310
|
-
* React Native version using RNAgentClient for streaming.
|
|
311
|
-
*
|
|
312
|
-
* Extends useRNAgentSession with:
|
|
313
|
-
* - Processed conversation (tool call/result pairing, parsed inputs/results)
|
|
314
|
-
* - Media extraction from generated content
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* ```tsx
|
|
318
|
-
* const {
|
|
319
|
-
* conversation,
|
|
320
|
-
* processedConversation,
|
|
321
|
-
* media,
|
|
322
|
-
* isStreaming,
|
|
323
|
-
* sendMessage,
|
|
324
|
-
* } = useJadeSession();
|
|
325
|
-
*
|
|
326
|
-
* // Render processed entries
|
|
327
|
-
* {processedConversation.map((entry, i) => (
|
|
328
|
-
* <MessageRenderer key={i} entry={entry} />
|
|
329
|
-
* ))}
|
|
330
|
-
*
|
|
331
|
-
* // Show media gallery
|
|
332
|
-
* {media.map((item) => (
|
|
333
|
-
* <MediaThumbnail key={item.url} {...item} />
|
|
334
|
-
* ))}
|
|
335
|
-
* ```
|
|
336
|
-
*/
|
|
337
|
-
declare function useJadeSession(options?: UseJadeSessionOptions): UseJadeSessionReturn;
|
|
338
|
-
|
|
339
|
-
export { RNAgentClient as R, RNAgentProvider, type RNAgentProviderProps, STORAGE_KEYS, type StorageAdapter, type UseJadeSessionOptions, type UseJadeSessionReturn, type UseRNAgentSessionOptions, type UseRNAgentSessionReturn, createAsyncStorageAdapter, createMMKVAdapter, createMemoryStorageAdapter, useAppState, useJadeSession, useRNAgentClient, useRNAgentSession, useStorage };
|