@sagepilot-ai/react-native-sdk 0.2.4 → 0.3.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/LICENSE.md +21 -0
- package/README.md +197 -4
- package/android/build.gradle +13 -4
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotReactNativeSdkPackage.java +2 -0
- package/dist/index.d.mts +215 -1
- package/dist/index.d.ts +215 -1
- package/dist/index.js +1322 -43
- package/dist/index.mjs +1301 -28
- package/package.json +18 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,203 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Wire shape delivered to the hosted widget. Matches the Customer API
|
|
5
|
+
* attachment input (`data_base64`) so the widget can reuse its existing
|
|
6
|
+
* validation and send path without backend changes.
|
|
7
|
+
*/
|
|
8
|
+
type SagepilotPickedFile = {
|
|
9
|
+
file_name: string;
|
|
10
|
+
mime_type: string;
|
|
11
|
+
size: number;
|
|
12
|
+
data_base64: string;
|
|
13
|
+
};
|
|
14
|
+
type SagepilotFilePickerErrorCode = "permission_denied" | "camera_unavailable" | "encode_failed" | "file_too_large" | "read_failed" | "unknown";
|
|
15
|
+
/**
|
|
16
|
+
* Structured picker failure. The provider maps `.code` to a user-facing message
|
|
17
|
+
* and surfaces it via sagepilot:file_picker_error so a failed capture is never
|
|
18
|
+
* silently swallowed.
|
|
19
|
+
*/
|
|
20
|
+
declare class SagepilotFilePickerError extends Error {
|
|
21
|
+
readonly code: SagepilotFilePickerErrorCode;
|
|
22
|
+
/** Creates a typed picker error that can be surfaced over the widget bridge. */
|
|
23
|
+
constructor(code: SagepilotFilePickerErrorCode, message: string);
|
|
24
|
+
}
|
|
25
|
+
declare const SAGEPILOT_DEFAULT_IMAGE_MAX_DIMENSION = 1920;
|
|
26
|
+
declare const SAGEPILOT_DEFAULT_IMAGE_QUALITY = 0.8;
|
|
27
|
+
declare const SAGEPILOT_DEFAULT_IMAGE_MAX_FILE_SIZE_BYTES: number;
|
|
28
|
+
|
|
29
|
+
type SagepilotFilePickerSource = "camera" | "library" | "documents";
|
|
30
|
+
type SagepilotFilePickerRequest = {
|
|
31
|
+
source: SagepilotFilePickerSource;
|
|
32
|
+
multiple: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Host-app-provided native file picker. When configured, the hosted widget's
|
|
36
|
+
* attach button routes through native pickers instead of the WebView's
|
|
37
|
+
* `<input type="file">`. This is required for reliable camera capture on
|
|
38
|
+
* low-RAM Android devices: the OS can kill the WebView render process while
|
|
39
|
+
* the camera activity is foregrounded, which destroys any in-WebView file
|
|
40
|
+
* chooser state. Natively captured files survive that kill and are
|
|
41
|
+
* re-delivered after the WebView reloads.
|
|
42
|
+
*/
|
|
43
|
+
type SagepilotFilePickerAdapter = {
|
|
44
|
+
/** Sources offered to the customer in the attachment chooser. */
|
|
45
|
+
sources: SagepilotFilePickerSource[];
|
|
46
|
+
/** Resolves picked files, or an empty array when the customer cancels. */
|
|
47
|
+
pickFiles: (request: SagepilotFilePickerRequest) => Promise<SagepilotPickedFile[]>;
|
|
48
|
+
};
|
|
49
|
+
/** Structural subset of `react-native-image-picker` used by the SDK. */
|
|
50
|
+
type SagepilotImagePickerModule = {
|
|
51
|
+
launchCamera: (options: Record<string, unknown>) => Promise<SagepilotImagePickerResult>;
|
|
52
|
+
launchImageLibrary: (options: Record<string, unknown>) => Promise<SagepilotImagePickerResult>;
|
|
53
|
+
};
|
|
54
|
+
type SagepilotImagePickerResult = {
|
|
55
|
+
didCancel?: boolean;
|
|
56
|
+
errorCode?: string;
|
|
57
|
+
errorMessage?: string;
|
|
58
|
+
assets?: Array<{
|
|
59
|
+
fileName?: string | null;
|
|
60
|
+
type?: string | null;
|
|
61
|
+
fileSize?: number | null;
|
|
62
|
+
base64?: string | null;
|
|
63
|
+
uri?: string | null;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
/** Structural subset of `@react-native-documents/picker` used by the SDK. */
|
|
67
|
+
type SagepilotDocumentsPickerModule = {
|
|
68
|
+
pick: (options?: Record<string, unknown>) => Promise<Array<{
|
|
69
|
+
uri: string;
|
|
70
|
+
name: string | null;
|
|
71
|
+
size: number | null;
|
|
72
|
+
type: string | null;
|
|
73
|
+
}>>;
|
|
74
|
+
keepLocalCopy?: (options: {
|
|
75
|
+
files: Array<{
|
|
76
|
+
uri: string;
|
|
77
|
+
fileName: string;
|
|
78
|
+
}>;
|
|
79
|
+
destination: "cachesDirectory" | "documentDirectory";
|
|
80
|
+
}) => Promise<Array<{
|
|
81
|
+
status: string;
|
|
82
|
+
sourceUri: string;
|
|
83
|
+
localUri?: string;
|
|
84
|
+
copyError?: string;
|
|
85
|
+
}>>;
|
|
86
|
+
};
|
|
87
|
+
/** Structural subset of `react-native-blob-util` used for document reads. */
|
|
88
|
+
type SagepilotFileReaderModule = {
|
|
89
|
+
fs: {
|
|
90
|
+
readFile: (path: string, encoding: string) => Promise<unknown>;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
type SagepilotCreateFilePickerOptions = {
|
|
94
|
+
imagePicker?: SagepilotImagePickerModule;
|
|
95
|
+
documentsPicker?: SagepilotDocumentsPickerModule;
|
|
96
|
+
/** Optional `react-native-blob-util` for reliable document reads. */
|
|
97
|
+
fileReader?: SagepilotFileReaderModule;
|
|
98
|
+
/**
|
|
99
|
+
* Longest image edge in pixels for camera/library picks. Downscaling
|
|
100
|
+
* natively keeps memory and upload size low on low-RAM devices.
|
|
101
|
+
*/
|
|
102
|
+
imageMaxDimension?: number;
|
|
103
|
+
/** JPEG quality (0-1) applied to camera/library picks. */
|
|
104
|
+
imageQuality?: number;
|
|
105
|
+
/**
|
|
106
|
+
* Max images per gallery selection. Defaults to 5. Set 0 for unlimited
|
|
107
|
+
* (not recommended: a large batch produces a multi-megabyte bridge payload).
|
|
108
|
+
*/
|
|
109
|
+
imageSelectionLimit?: number;
|
|
110
|
+
/** Reject documents larger than this (bytes) before reading them. */
|
|
111
|
+
documentMaxFileSizeBytes?: number;
|
|
112
|
+
/** Reject camera/library images larger than this (bytes). */
|
|
113
|
+
imageMaxFileSizeBytes?: number;
|
|
114
|
+
};
|
|
115
|
+
/** Shows an actionable Android settings prompt after permanent camera denial. */
|
|
116
|
+
declare function promptOpenSagepilotCameraSettings(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Android apps that declare the CAMERA permission must also hold it at runtime
|
|
119
|
+
* before the SDK-owned camera screen can open. Request it defensively; apps
|
|
120
|
+
* that never declared it are unaffected and native launch can surface the real
|
|
121
|
+
* failure.
|
|
122
|
+
*/
|
|
123
|
+
declare function ensureSagepilotAndroidCameraPermission(): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Builds the SDK file picker adapter from host-app-installed native modules.
|
|
126
|
+
* Modules are passed in (rather than required by the SDK) so Metro never
|
|
127
|
+
* tries to resolve packages the host app has not installed.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* import * as imagePicker from "react-native-image-picker";
|
|
131
|
+
* import * as documentsPicker from "@react-native-documents/picker";
|
|
132
|
+
*
|
|
133
|
+
* SagepilotChat.configure({
|
|
134
|
+
* key: "...",
|
|
135
|
+
* filePicker: createSagepilotFilePicker({ imagePicker, documentsPicker })
|
|
136
|
+
* });
|
|
137
|
+
*/
|
|
138
|
+
declare function createSagepilotFilePicker(options: SagepilotCreateFilePickerOptions): SagepilotFilePickerAdapter | undefined;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Durable file outbox for natively-picked attachments.
|
|
142
|
+
*
|
|
143
|
+
* Persisting attachment BYTES in `cacheStorage` (AsyncStorage) does not scale:
|
|
144
|
+
* Android's SQLite-backed store caps a single row at ~2MB (CursorWindow), so a
|
|
145
|
+
* multi-megabyte capture cannot be stored there at all. Instead we write the
|
|
146
|
+
* bytes to a stable app-private file and persist only a tiny manifest of file
|
|
147
|
+
* keys + metadata in `cacheStorage`. This makes durability size-independent and
|
|
148
|
+
* lets a capture survive a full app-process death during the camera round-trip.
|
|
149
|
+
*
|
|
150
|
+
* The store is built from the host app's `react-native-blob-util` so the SDK
|
|
151
|
+
* itself depends on no filesystem package (same injection pattern as the
|
|
152
|
+
* native file picker).
|
|
153
|
+
*/
|
|
154
|
+
/** Structural subset of `react-native-blob-util` used by the file store. */
|
|
155
|
+
type SagepilotBlobUtilLike = {
|
|
156
|
+
fs: {
|
|
157
|
+
dirs: {
|
|
158
|
+
DocumentDir: string;
|
|
159
|
+
};
|
|
160
|
+
writeFile: (path: string, data: string, encoding: string) => Promise<unknown>;
|
|
161
|
+
readFile: (path: string, encoding: string) => Promise<unknown>;
|
|
162
|
+
unlink: (path: string) => Promise<unknown>;
|
|
163
|
+
exists: (path: string) => Promise<boolean>;
|
|
164
|
+
ls: (path: string) => Promise<string[]>;
|
|
165
|
+
mkdir: (path: string) => Promise<unknown>;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Persists attachment bytes to disk under stable, app-private keys. Keys (not
|
|
170
|
+
* absolute paths) are stored in the manifest so persistence survives the
|
|
171
|
+
* platform relocating the app container between launches (notably iOS).
|
|
172
|
+
*/
|
|
173
|
+
type SagepilotPersistedFileStore = {
|
|
174
|
+
/** Writes base64 content under `key`; resolves once durably on disk. */
|
|
175
|
+
write: (key: string, base64: string) => Promise<void>;
|
|
176
|
+
/** Reads previously-written content back as base64. */
|
|
177
|
+
read: (key: string) => Promise<string>;
|
|
178
|
+
/** Best-effort delete of a single key. */
|
|
179
|
+
remove: (key: string) => Promise<void>;
|
|
180
|
+
/** Best-effort delete of every stored file whose key is not in `keepKeys`. */
|
|
181
|
+
prune: (keepKeys: string[]) => Promise<void>;
|
|
182
|
+
};
|
|
183
|
+
type SagepilotCreateFileStoreOptions = {
|
|
184
|
+
/** Sub-directory under DocumentDir. Defaults to "sagepilot-attachments". */
|
|
185
|
+
directoryName?: string;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Builds a {@link SagepilotPersistedFileStore} backed by react-native-blob-util.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* import ReactNativeBlobUtil from "react-native-blob-util";
|
|
192
|
+
* SagepilotChat.configure({
|
|
193
|
+
* key: "...",
|
|
194
|
+
* cacheStorage: createAsyncStorageCacheStorage(AsyncStorage),
|
|
195
|
+
* fileStore: createSagepilotFileStore(ReactNativeBlobUtil),
|
|
196
|
+
* filePicker: createSagepilotFilePicker({ imagePicker, documentsPicker, fileReader: ReactNativeBlobUtil })
|
|
197
|
+
* });
|
|
198
|
+
*/
|
|
199
|
+
declare function createSagepilotFileStore(blobUtil: SagepilotBlobUtilLike, options?: SagepilotCreateFileStoreOptions): SagepilotPersistedFileStore;
|
|
200
|
+
|
|
3
201
|
type SagepilotMobilePresentationStyle = "sheet" | "fullScreen" | "push";
|
|
4
202
|
type SagepilotMobileColorScheme = "system" | "light" | "dark";
|
|
5
203
|
type SagepilotChatErrorCode = "invalid_config" | "not_initialized" | "already_initialized" | "network_error" | "invalid_response" | "invalid_request" | "unauthorized" | "forbidden" | "session_not_found" | "session_expired" | "channel_not_found" | "conversation_not_found" | "message_not_found" | "contact_required" | "otp_required" | "otp_invalid" | "otp_expired" | "identity_verification_failed" | "rate_limited" | "idempotency_conflict" | "not_implemented" | "internal_error";
|
|
@@ -110,6 +308,22 @@ type SagepilotMobileConfig = {
|
|
|
110
308
|
cacheStorage?: SagepilotCacheStorage;
|
|
111
309
|
deviceInfo?: SagepilotDeviceInfoAdapter;
|
|
112
310
|
biometrics?: SagepilotBiometricsAdapter;
|
|
311
|
+
/**
|
|
312
|
+
* Native file picker used by the hosted chat widget's attach button.
|
|
313
|
+
* Strongly recommended: in-WebView camera capture is unreliable on
|
|
314
|
+
* low-RAM Android devices (the OS can kill the WebView render process
|
|
315
|
+
* while the camera is open). Build with createSagepilotFilePicker() or
|
|
316
|
+
* the optional @sagepilot-ai/react-native-camera-addon package.
|
|
317
|
+
*/
|
|
318
|
+
filePicker?: SagepilotFilePickerAdapter;
|
|
319
|
+
/**
|
|
320
|
+
* Durable on-disk store for picked attachments. When provided, a captured
|
|
321
|
+
* photo/document survives a full app-process death during the camera
|
|
322
|
+
* round-trip (the SDK rehydrates and re-delivers it on relaunch), with no
|
|
323
|
+
* size limit. Without it, durability falls back to small batches stored in
|
|
324
|
+
* cacheStorage. Build with createSagepilotFileStore(ReactNativeBlobUtil).
|
|
325
|
+
*/
|
|
326
|
+
fileStore?: SagepilotPersistedFileStore;
|
|
113
327
|
presentation?: SagepilotMobilePresentationConfig;
|
|
114
328
|
theme?: SagepilotMobileThemeConfig;
|
|
115
329
|
behavior?: SagepilotMobileBehaviorConfig;
|
|
@@ -342,4 +556,4 @@ declare function SagepilotChatProvider({ children, closeLabel, loadingLabel }: S
|
|
|
342
556
|
|
|
343
557
|
declare function useSagepilotChat(): SagepilotChatHookState;
|
|
344
558
|
|
|
345
|
-
export { type SagepilotBiometricsAdapter, type SagepilotBootstrapChannelResponse, type SagepilotCacheStorage, SagepilotChat, SagepilotChatError, type SagepilotChatErrorCode, type SagepilotChatHookState, SagepilotChatProvider, type SagepilotChatProviderProps, type SagepilotConversationCreatedEvent, type SagepilotDeviceInfo, type SagepilotDeviceInfoAdapter, type SagepilotIdentifyResult, type SagepilotIdentity, type SagepilotIdentityState, type SagepilotLifecycleState, type SagepilotLogoutResponse, type SagepilotMessageComposerOptions, type SagepilotMobileBehaviorConfig, type SagepilotMobileColorScheme, type SagepilotMobileConfig, type SagepilotMobileConfigureResult, type SagepilotMobileLauncherConfig, type SagepilotMobilePresentationConfig, type SagepilotMobilePresentationStyle, type SagepilotMobileResolvedLauncherConfig, type SagepilotMobileState, type SagepilotMobileSubscription, type SagepilotMobileThemeConfig, type SagepilotMobileThemeState, type SagepilotSessionState, type SagepilotTokenStorage, type SagepilotUnreadState, createAsyncStorageCacheStorage, createKeychainTokenStorage, useSagepilotChat };
|
|
559
|
+
export { SAGEPILOT_DEFAULT_IMAGE_MAX_DIMENSION, SAGEPILOT_DEFAULT_IMAGE_MAX_FILE_SIZE_BYTES, SAGEPILOT_DEFAULT_IMAGE_QUALITY, type SagepilotBiometricsAdapter, type SagepilotBlobUtilLike, type SagepilotBootstrapChannelResponse, type SagepilotCacheStorage, SagepilotChat, SagepilotChatError, type SagepilotChatErrorCode, type SagepilotChatHookState, SagepilotChatProvider, type SagepilotChatProviderProps, type SagepilotConversationCreatedEvent, type SagepilotCreateFilePickerOptions, type SagepilotCreateFileStoreOptions, type SagepilotDeviceInfo, type SagepilotDeviceInfoAdapter, type SagepilotDocumentsPickerModule, type SagepilotFilePickerAdapter, SagepilotFilePickerError, type SagepilotFilePickerErrorCode, type SagepilotFilePickerRequest, type SagepilotFilePickerSource, type SagepilotFileReaderModule, type SagepilotIdentifyResult, type SagepilotIdentity, type SagepilotIdentityState, type SagepilotImagePickerModule, type SagepilotImagePickerResult, type SagepilotLifecycleState, type SagepilotLogoutResponse, type SagepilotMessageComposerOptions, type SagepilotMobileBehaviorConfig, type SagepilotMobileColorScheme, type SagepilotMobileConfig, type SagepilotMobileConfigureResult, type SagepilotMobileLauncherConfig, type SagepilotMobilePresentationConfig, type SagepilotMobilePresentationStyle, type SagepilotMobileResolvedLauncherConfig, type SagepilotMobileState, type SagepilotMobileSubscription, type SagepilotMobileThemeConfig, type SagepilotMobileThemeState, type SagepilotPersistedFileStore, type SagepilotPickedFile, type SagepilotSessionState, type SagepilotTokenStorage, type SagepilotUnreadState, createAsyncStorageCacheStorage, createKeychainTokenStorage, createSagepilotFilePicker, createSagepilotFileStore, ensureSagepilotAndroidCameraPermission, promptOpenSagepilotCameraSettings, useSagepilotChat };
|