@sagepilot-ai/react-native-sdk 0.2.2 → 0.2.3
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 +11 -6
- package/android/build.gradle +53 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotInsetsChangeEvent.java +26 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotInsetsView.java +78 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotInsetsViewManager.java +59 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotReactNativeSdkPackage.java +20 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SagepilotInsetsViewManagerDelegate.java +25 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SagepilotInsetsViewManagerInterface.java +10 -0
- package/dist/{index.d.cts → index.d.mts} +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +202 -94
- package/dist/{index.cjs → index.mjs} +170 -117
- package/package.json +18 -8
- package/react-native.config.js +5 -1
- package/src/specs/SagepilotInsetsViewNativeComponent.ts +17 -0
- package/android/.gitkeep +0 -1
|
@@ -1,34 +1,3 @@
|
|
|
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
|
-
SagepilotChat: () => SagepilotChat,
|
|
24
|
-
SagepilotChatError: () => SagepilotChatError,
|
|
25
|
-
SagepilotChatProvider: () => SagepilotChatProvider,
|
|
26
|
-
createAsyncStorageCacheStorage: () => createAsyncStorageCacheStorage,
|
|
27
|
-
createKeychainTokenStorage: () => createKeychainTokenStorage,
|
|
28
|
-
useSagepilotChat: () => useSagepilotChat
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(index_exports);
|
|
31
|
-
|
|
32
1
|
// src/core/errors/SagepilotChatError.ts
|
|
33
2
|
var SagepilotChatError = class extends Error {
|
|
34
3
|
constructor(code, message, options = {}) {
|
|
@@ -46,7 +15,7 @@ var SagepilotChatError = class extends Error {
|
|
|
46
15
|
|
|
47
16
|
// src/core/config/constants.ts
|
|
48
17
|
var SDK_NAME = "@sagepilot-ai/react-native-sdk";
|
|
49
|
-
var SDK_VERSION = "0.2.
|
|
18
|
+
var SDK_VERSION = "0.2.3";
|
|
50
19
|
var DEFAULT_HOST = "https://app.sagepilot.ai";
|
|
51
20
|
var DEFAULT_WIDGET_HOST = "https://app.sagepilot.ai";
|
|
52
21
|
var CUSTOMER_API_PREFIX = "/customer-api/v1";
|
|
@@ -732,9 +701,9 @@ var SagepilotReactNativeChat = class {
|
|
|
732
701
|
this.hostedChatView = { screen: "messages" };
|
|
733
702
|
return this.showHostedChat();
|
|
734
703
|
}
|
|
735
|
-
presentMessageComposer(message) {
|
|
704
|
+
presentMessageComposer(message, options) {
|
|
736
705
|
this.requireConfigured();
|
|
737
|
-
this.hostedChatView = { screen: "composer", message };
|
|
706
|
+
this.hostedChatView = { screen: "composer", message, mode: options?.mode ?? "auto" };
|
|
738
707
|
return this.showHostedChat();
|
|
739
708
|
}
|
|
740
709
|
dismiss() {
|
|
@@ -834,7 +803,9 @@ var SagepilotReactNativeChat = class {
|
|
|
834
803
|
url.searchParams.set("jwt", this.legacyWidgetJwt);
|
|
835
804
|
}
|
|
836
805
|
if (this.hostedChatView.screen === "composer") {
|
|
837
|
-
|
|
806
|
+
if (this.hostedChatView.mode === "new") {
|
|
807
|
+
url.searchParams.set("new", "true");
|
|
808
|
+
}
|
|
838
809
|
if (this.hostedChatView.message) {
|
|
839
810
|
url.searchParams.set("topic", this.hostedChatView.message);
|
|
840
811
|
}
|
|
@@ -1064,7 +1035,9 @@ var SagepilotChat = {
|
|
|
1064
1035
|
stopUnreadPolling: () => internalSagepilotChat.stopUnreadPolling(),
|
|
1065
1036
|
present: () => internalSagepilotChat.present(),
|
|
1066
1037
|
presentMessages: () => internalSagepilotChat.presentMessages(),
|
|
1067
|
-
presentMessageComposer: (message) =>
|
|
1038
|
+
presentMessageComposer: (message, options) => {
|
|
1039
|
+
return internalSagepilotChat.presentMessageComposer(message, options);
|
|
1040
|
+
},
|
|
1068
1041
|
dismiss: () => internalSagepilotChat.dismiss(),
|
|
1069
1042
|
hide: () => internalSagepilotChat.hide(),
|
|
1070
1043
|
toggle: () => internalSagepilotChat.toggle(),
|
|
@@ -1090,9 +1063,19 @@ function createAsyncStorageCacheStorage(asyncStorage) {
|
|
|
1090
1063
|
}
|
|
1091
1064
|
|
|
1092
1065
|
// src/ui/SagepilotChatProvider.ts
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1066
|
+
import { createElement, useCallback, useEffect, useRef, useState } from "react";
|
|
1067
|
+
import {
|
|
1068
|
+
ActivityIndicator,
|
|
1069
|
+
KeyboardAvoidingView,
|
|
1070
|
+
Modal,
|
|
1071
|
+
Platform,
|
|
1072
|
+
Pressable,
|
|
1073
|
+
SafeAreaView,
|
|
1074
|
+
StyleSheet,
|
|
1075
|
+
Text,
|
|
1076
|
+
View
|
|
1077
|
+
} from "react-native";
|
|
1078
|
+
import { WebView } from "react-native-webview";
|
|
1096
1079
|
|
|
1097
1080
|
// src/core/webview/mobileBridge.ts
|
|
1098
1081
|
function isHostedBridgeMessage(value) {
|
|
@@ -1173,6 +1156,28 @@ var mobileWebViewBridgeScript = `
|
|
|
1173
1156
|
} catch (error) {}
|
|
1174
1157
|
}, true);
|
|
1175
1158
|
|
|
1159
|
+
document.addEventListener("focusin", function (event) {
|
|
1160
|
+
try {
|
|
1161
|
+
var target = event.target && event.target.closest
|
|
1162
|
+
? event.target
|
|
1163
|
+
: event.target && event.target.parentElement;
|
|
1164
|
+
if (target && target.closest && target.closest("input, textarea, [contenteditable='true']")) {
|
|
1165
|
+
sendToReactNative({ type: "sagepilot:keyboard_focus" });
|
|
1166
|
+
}
|
|
1167
|
+
} catch (error) {}
|
|
1168
|
+
}, true);
|
|
1169
|
+
|
|
1170
|
+
document.addEventListener("focusout", function (event) {
|
|
1171
|
+
try {
|
|
1172
|
+
var target = event.target && event.target.closest
|
|
1173
|
+
? event.target
|
|
1174
|
+
: event.target && event.target.parentElement;
|
|
1175
|
+
if (target && target.closest && target.closest("input, textarea, [contenteditable='true']")) {
|
|
1176
|
+
sendToReactNative({ type: "sagepilot:keyboard_blur" });
|
|
1177
|
+
}
|
|
1178
|
+
} catch (error) {}
|
|
1179
|
+
}, true);
|
|
1180
|
+
|
|
1176
1181
|
ensureViewport();
|
|
1177
1182
|
injectMobileStyles();
|
|
1178
1183
|
sendToReactNative({ type: "sagepilot:ready" });
|
|
@@ -1180,6 +1185,10 @@ var mobileWebViewBridgeScript = `
|
|
|
1180
1185
|
})();
|
|
1181
1186
|
`;
|
|
1182
1187
|
|
|
1188
|
+
// src/specs/SagepilotInsetsViewNativeComponent.ts
|
|
1189
|
+
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
1190
|
+
var SagepilotInsetsViewNativeComponent_default = codegenNativeComponent("SagepilotInsetsView");
|
|
1191
|
+
|
|
1183
1192
|
// src/ui/SagepilotChatProvider.ts
|
|
1184
1193
|
function readPresentationState() {
|
|
1185
1194
|
return {
|
|
@@ -1222,30 +1231,62 @@ function readUrlOrigin(url) {
|
|
|
1222
1231
|
var hostedChatWebViewProps = {
|
|
1223
1232
|
allowFileAccess: true,
|
|
1224
1233
|
allowFileAccessFromFileURLs: true,
|
|
1234
|
+
bounces: false,
|
|
1225
1235
|
domStorageEnabled: true,
|
|
1226
1236
|
javaScriptEnabled: true,
|
|
1237
|
+
overScrollMode: "never",
|
|
1238
|
+
scrollEnabled: Platform.OS !== "android",
|
|
1227
1239
|
setSupportMultipleWindows: false,
|
|
1228
1240
|
sharedCookiesEnabled: true,
|
|
1229
1241
|
thirdPartyCookiesEnabled: true
|
|
1230
1242
|
};
|
|
1243
|
+
var AndroidInsetsView = Platform.OS === "android" ? SagepilotInsetsViewNativeComponent_default : View;
|
|
1244
|
+
var emptyAndroidInsets = { top: 0, bottom: 0 };
|
|
1231
1245
|
function SagepilotChatProvider({
|
|
1232
1246
|
children,
|
|
1233
1247
|
closeLabel = "Close",
|
|
1234
1248
|
loadingLabel = "Loading chat"
|
|
1235
1249
|
}) {
|
|
1236
|
-
const [state, setState] =
|
|
1237
|
-
const
|
|
1238
|
-
const
|
|
1239
|
-
|
|
1250
|
+
const [state, setState] = useState(readPresentationState);
|
|
1251
|
+
const [androidModalInsets, setAndroidModalInsets] = useState(emptyAndroidInsets);
|
|
1252
|
+
const webFrameRef = useRef(null);
|
|
1253
|
+
const nativeWebViewRef = useRef(null);
|
|
1254
|
+
useEffect(() => {
|
|
1240
1255
|
return internalSagepilotChat.onStateChange(() => {
|
|
1241
1256
|
setState(readPresentationState());
|
|
1242
1257
|
});
|
|
1243
1258
|
}, []);
|
|
1259
|
+
const handleAndroidInsetsChange = useCallback((event) => {
|
|
1260
|
+
const nextBottomInset = event.nativeEvent?.bottom;
|
|
1261
|
+
const nextTopInset = event.nativeEvent?.top;
|
|
1262
|
+
if (typeof nextBottomInset !== "number" || typeof nextTopInset !== "number" || !Number.isFinite(nextBottomInset) || !Number.isFinite(nextTopInset)) return;
|
|
1263
|
+
setAndroidModalInsets({
|
|
1264
|
+
top: Math.max(0, nextTopInset),
|
|
1265
|
+
bottom: Math.max(0, nextBottomInset)
|
|
1266
|
+
});
|
|
1267
|
+
}, []);
|
|
1244
1268
|
const showCloseButton = state.presentation?.showCloseButton ?? false;
|
|
1245
1269
|
const presentationStyle = state.presentation?.style ?? "sheet";
|
|
1246
1270
|
const isFullScreenModal = presentationStyle === "fullScreen";
|
|
1247
1271
|
const animationType = presentationStyle === "fullScreen" || presentationStyle === "push" ? "slide" : "fade";
|
|
1248
|
-
const ModalContainer =
|
|
1272
|
+
const ModalContainer = Platform.OS === "ios" && isFullScreenModal ? SafeAreaView : View;
|
|
1273
|
+
const NativeModalContainer = Platform.OS === "android" ? AndroidInsetsView : ModalContainer;
|
|
1274
|
+
const ChatContentContainer = Platform.OS === "ios" ? KeyboardAvoidingView : View;
|
|
1275
|
+
const nativeModalContainerProps = Platform.OS === "android" ? { style: styles.container, onInsetsChange: handleAndroidInsetsChange } : { style: styles.container };
|
|
1276
|
+
const chatContentContainerProps = Platform.OS === "ios" ? {
|
|
1277
|
+
behavior: "padding",
|
|
1278
|
+
enabled: true,
|
|
1279
|
+
keyboardVerticalOffset: 0,
|
|
1280
|
+
style: styles.modalContent
|
|
1281
|
+
} : {
|
|
1282
|
+
style: [
|
|
1283
|
+
styles.modalContent,
|
|
1284
|
+
Platform.OS === "android" ? {
|
|
1285
|
+
paddingTop: androidModalInsets.top,
|
|
1286
|
+
paddingBottom: androidModalInsets.bottom
|
|
1287
|
+
} : null
|
|
1288
|
+
].filter(Boolean)
|
|
1289
|
+
};
|
|
1249
1290
|
const handleWebViewMessage = (event) => {
|
|
1250
1291
|
internalSagepilotChat.handleHostedBridgeMessage(parseHostedBridgeMessage(event.nativeEvent?.data));
|
|
1251
1292
|
};
|
|
@@ -1260,8 +1301,8 @@ function SagepilotChatProvider({
|
|
|
1260
1301
|
if (!script || !nativeWebViewRef.current) return;
|
|
1261
1302
|
nativeWebViewRef.current.injectJavaScript(script);
|
|
1262
1303
|
};
|
|
1263
|
-
|
|
1264
|
-
if (
|
|
1304
|
+
useEffect(() => {
|
|
1305
|
+
if (Platform.OS !== "web" || typeof window === "undefined") return;
|
|
1265
1306
|
const trustedWidgetOrigin = readUrlOrigin(state.conversationUrl);
|
|
1266
1307
|
if (!trustedWidgetOrigin) return;
|
|
1267
1308
|
const handleWindowMessage = (event) => {
|
|
@@ -1271,41 +1312,41 @@ function SagepilotChatProvider({
|
|
|
1271
1312
|
window.addEventListener("message", handleWindowMessage);
|
|
1272
1313
|
return () => window.removeEventListener("message", handleWindowMessage);
|
|
1273
1314
|
}, [state.conversationUrl]);
|
|
1274
|
-
|
|
1275
|
-
if (
|
|
1315
|
+
useEffect(() => {
|
|
1316
|
+
if (Platform.OS !== "web" || !state.isPresented) return;
|
|
1276
1317
|
postIdentityToWebFrame();
|
|
1277
1318
|
}, [state.isPresented, state.conversationUrl, state.configured]);
|
|
1278
|
-
|
|
1279
|
-
if (
|
|
1319
|
+
useEffect(() => {
|
|
1320
|
+
if (Platform.OS === "web" || !state.isPresented) return;
|
|
1280
1321
|
postIdentityToNativeWebView();
|
|
1281
1322
|
}, [state.isPresented, state.conversationUrl, state.configured]);
|
|
1282
|
-
if (
|
|
1283
|
-
return
|
|
1284
|
-
|
|
1323
|
+
if (Platform.OS === "web") {
|
|
1324
|
+
return createElement(
|
|
1325
|
+
View,
|
|
1285
1326
|
{ style: styles.root },
|
|
1286
1327
|
children,
|
|
1287
|
-
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ?
|
|
1328
|
+
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ? createElement("iframe", {
|
|
1288
1329
|
src: state.preloadUrl,
|
|
1289
1330
|
style: styles.webPreloadFrame,
|
|
1290
1331
|
title: "Sagepilot chat preload"
|
|
1291
1332
|
}) : null,
|
|
1292
|
-
state.configured && state.isPresented && state.conversationUrl ?
|
|
1293
|
-
|
|
1333
|
+
state.configured && state.isPresented && state.conversationUrl ? createElement(
|
|
1334
|
+
View,
|
|
1294
1335
|
{ style: styles.webOverlay },
|
|
1295
|
-
|
|
1296
|
-
|
|
1336
|
+
createElement(
|
|
1337
|
+
View,
|
|
1297
1338
|
{ style: styles.webPanel },
|
|
1298
|
-
showCloseButton ?
|
|
1299
|
-
|
|
1339
|
+
showCloseButton ? createElement(
|
|
1340
|
+
Pressable,
|
|
1300
1341
|
{
|
|
1301
1342
|
accessibilityRole: "button",
|
|
1302
1343
|
accessibilityLabel: closeLabel,
|
|
1303
1344
|
onPress: () => internalSagepilotChat.dismiss(),
|
|
1304
1345
|
style: styles.webCloseButton
|
|
1305
1346
|
},
|
|
1306
|
-
|
|
1347
|
+
createElement(Text, { style: styles.closeText }, closeLabel)
|
|
1307
1348
|
) : null,
|
|
1308
|
-
|
|
1349
|
+
createElement("iframe", {
|
|
1309
1350
|
ref: webFrameRef,
|
|
1310
1351
|
src: state.conversationUrl,
|
|
1311
1352
|
style: styles.webFrame,
|
|
@@ -1316,63 +1357,69 @@ function SagepilotChatProvider({
|
|
|
1316
1357
|
) : null
|
|
1317
1358
|
);
|
|
1318
1359
|
}
|
|
1319
|
-
return
|
|
1320
|
-
|
|
1360
|
+
return createElement(
|
|
1361
|
+
View,
|
|
1321
1362
|
{ style: styles.root },
|
|
1322
1363
|
children,
|
|
1323
|
-
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ?
|
|
1364
|
+
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ? createElement(WebView, {
|
|
1324
1365
|
...hostedChatWebViewProps,
|
|
1325
1366
|
source: { uri: state.preloadUrl },
|
|
1326
1367
|
style: styles.preloadWebview,
|
|
1327
1368
|
injectedJavaScriptBeforeContentLoaded: getInjectedWebViewScript(),
|
|
1328
1369
|
onMessage: handleWebViewMessage
|
|
1329
1370
|
}) : null,
|
|
1330
|
-
|
|
1331
|
-
|
|
1371
|
+
createElement(
|
|
1372
|
+
Modal,
|
|
1332
1373
|
{
|
|
1333
1374
|
visible: state.configured && state.isPresented,
|
|
1334
1375
|
animationType,
|
|
1335
1376
|
presentationStyle: isFullScreenModal ? "fullScreen" : "pageSheet",
|
|
1377
|
+
statusBarTranslucent: Platform.OS === "android",
|
|
1378
|
+
navigationBarTranslucent: Platform.OS === "android",
|
|
1336
1379
|
onRequestClose: () => internalSagepilotChat.dismiss()
|
|
1337
1380
|
},
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
{
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
(
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1381
|
+
createElement(
|
|
1382
|
+
NativeModalContainer,
|
|
1383
|
+
nativeModalContainerProps,
|
|
1384
|
+
createElement(
|
|
1385
|
+
ChatContentContainer,
|
|
1386
|
+
chatContentContainerProps,
|
|
1387
|
+
showCloseButton ? createElement(
|
|
1388
|
+
View,
|
|
1389
|
+
{ style: styles.header },
|
|
1390
|
+
createElement(
|
|
1391
|
+
Pressable,
|
|
1392
|
+
{
|
|
1393
|
+
accessibilityRole: "button",
|
|
1394
|
+
accessibilityLabel: closeLabel,
|
|
1395
|
+
onPress: () => internalSagepilotChat.dismiss(),
|
|
1396
|
+
style: styles.closeButton
|
|
1397
|
+
},
|
|
1398
|
+
createElement(Text, { style: styles.closeText }, closeLabel)
|
|
1399
|
+
)
|
|
1400
|
+
) : null,
|
|
1401
|
+
state.conversationUrl ? createElement(WebView, {
|
|
1402
|
+
...hostedChatWebViewProps,
|
|
1403
|
+
ref: nativeWebViewRef,
|
|
1404
|
+
source: { uri: state.conversationUrl },
|
|
1405
|
+
style: styles.webview,
|
|
1406
|
+
startInLoadingState: true,
|
|
1407
|
+
injectedJavaScriptBeforeContentLoaded: getInjectedWebViewScript(),
|
|
1408
|
+
onMessage: handleWebViewMessage,
|
|
1409
|
+
onLoadEnd: postIdentityToNativeWebView,
|
|
1410
|
+
renderLoading: () => createElement(
|
|
1411
|
+
View,
|
|
1412
|
+
{ style: styles.loading },
|
|
1413
|
+
createElement(ActivityIndicator, null),
|
|
1414
|
+
createElement(Text, { style: styles.loadingText }, loadingLabel)
|
|
1415
|
+
)
|
|
1416
|
+
}) : null
|
|
1417
|
+
)
|
|
1371
1418
|
)
|
|
1372
1419
|
)
|
|
1373
1420
|
);
|
|
1374
1421
|
}
|
|
1375
|
-
var styles =
|
|
1422
|
+
var styles = StyleSheet.create({
|
|
1376
1423
|
root: {
|
|
1377
1424
|
flex: 1
|
|
1378
1425
|
},
|
|
@@ -1380,6 +1427,11 @@ var styles = import_react_native.StyleSheet.create({
|
|
|
1380
1427
|
flex: 1,
|
|
1381
1428
|
backgroundColor: "#ffffff"
|
|
1382
1429
|
},
|
|
1430
|
+
modalContent: {
|
|
1431
|
+
flex: 1,
|
|
1432
|
+
width: "100%",
|
|
1433
|
+
backgroundColor: "#ffffff"
|
|
1434
|
+
},
|
|
1383
1435
|
header: {
|
|
1384
1436
|
minHeight: 48,
|
|
1385
1437
|
alignItems: "flex-end",
|
|
@@ -1453,7 +1505,7 @@ var styles = import_react_native.StyleSheet.create({
|
|
|
1453
1505
|
borderStyle: "none"
|
|
1454
1506
|
},
|
|
1455
1507
|
loading: {
|
|
1456
|
-
...
|
|
1508
|
+
...StyleSheet.absoluteFillObject,
|
|
1457
1509
|
alignItems: "center",
|
|
1458
1510
|
justifyContent: "center",
|
|
1459
1511
|
backgroundColor: "#ffffff"
|
|
@@ -1466,7 +1518,7 @@ var styles = import_react_native.StyleSheet.create({
|
|
|
1466
1518
|
});
|
|
1467
1519
|
|
|
1468
1520
|
// src/hooks/useSagepilotChat.ts
|
|
1469
|
-
|
|
1521
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
1470
1522
|
function readState() {
|
|
1471
1523
|
const state = SagepilotChat.getState();
|
|
1472
1524
|
return {
|
|
@@ -1478,23 +1530,25 @@ function readState() {
|
|
|
1478
1530
|
};
|
|
1479
1531
|
}
|
|
1480
1532
|
function useSagepilotChat() {
|
|
1481
|
-
const [state, setState] = (
|
|
1482
|
-
(
|
|
1533
|
+
const [state, setState] = useState2(readState);
|
|
1534
|
+
useEffect2(() => {
|
|
1483
1535
|
return SagepilotChat.onStateChange(() => {
|
|
1484
1536
|
setState(readState());
|
|
1485
1537
|
});
|
|
1486
1538
|
}, []);
|
|
1487
|
-
const present = (
|
|
1488
|
-
const presentMessages = (
|
|
1489
|
-
const presentMessageComposer = (
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
const
|
|
1493
|
-
const
|
|
1539
|
+
const present = useCallback2(() => SagepilotChat.present(), []);
|
|
1540
|
+
const presentMessages = useCallback2(() => SagepilotChat.presentMessages(), []);
|
|
1541
|
+
const presentMessageComposer = useCallback2((message, options) => {
|
|
1542
|
+
return SagepilotChat.presentMessageComposer(message, options);
|
|
1543
|
+
}, []);
|
|
1544
|
+
const dismiss = useCallback2(() => SagepilotChat.dismiss(), []);
|
|
1545
|
+
const hide = useCallback2(() => SagepilotChat.hide(), []);
|
|
1546
|
+
const toggle = useCallback2(() => SagepilotChat.toggle(), []);
|
|
1547
|
+
const identify = useCallback2((identity) => {
|
|
1494
1548
|
return SagepilotChat.identify(identity);
|
|
1495
1549
|
}, []);
|
|
1496
|
-
const logout = (
|
|
1497
|
-
const getUnreadCount = (
|
|
1550
|
+
const logout = useCallback2(() => SagepilotChat.logout(), []);
|
|
1551
|
+
const getUnreadCount = useCallback2(() => SagepilotChat.getUnreadCount(), []);
|
|
1498
1552
|
return {
|
|
1499
1553
|
...state,
|
|
1500
1554
|
present,
|
|
@@ -1508,12 +1562,11 @@ function useSagepilotChat() {
|
|
|
1508
1562
|
getUnreadCount
|
|
1509
1563
|
};
|
|
1510
1564
|
}
|
|
1511
|
-
|
|
1512
|
-
0 && (module.exports = {
|
|
1565
|
+
export {
|
|
1513
1566
|
SagepilotChat,
|
|
1514
1567
|
SagepilotChatError,
|
|
1515
1568
|
SagepilotChatProvider,
|
|
1516
1569
|
createAsyncStorageCacheStorage,
|
|
1517
1570
|
createKeychainTokenStorage,
|
|
1518
1571
|
useSagepilotChat
|
|
1519
|
-
}
|
|
1572
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sagepilot-ai/react-native-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Sagepilot AI React Native chat SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sagepilot",
|
|
@@ -11,28 +11,38 @@
|
|
|
11
11
|
"sdk"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"react-native": "./dist/index.js",
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/index.
|
|
22
|
-
"require": "./dist/index.
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"LICENSE.md",
|
|
27
|
-
"android",
|
|
27
|
+
"android/build.gradle",
|
|
28
|
+
"android/src",
|
|
28
29
|
"dist",
|
|
29
30
|
"ios",
|
|
30
31
|
"react-native.config.js",
|
|
32
|
+
"src/specs",
|
|
31
33
|
"README.md"
|
|
32
34
|
],
|
|
35
|
+
"codegenConfig": {
|
|
36
|
+
"name": "SagepilotReactNativeSdkSpec",
|
|
37
|
+
"type": "components",
|
|
38
|
+
"jsSrcsDir": "./src/specs",
|
|
39
|
+
"android": {
|
|
40
|
+
"javaPackageName": "ai.sagepilot.reactnativesdk"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
33
43
|
"sideEffects": false,
|
|
34
44
|
"scripts": {
|
|
35
|
-
"build": "tsup
|
|
45
|
+
"build": "tsup",
|
|
36
46
|
"typecheck": "tsc --noEmit",
|
|
37
47
|
"prepublishOnly": "npm run typecheck && npm run build"
|
|
38
48
|
},
|
package/react-native.config.js
CHANGED
|
@@ -2,7 +2,11 @@ module.exports = {
|
|
|
2
2
|
dependency: {
|
|
3
3
|
platforms: {
|
|
4
4
|
ios: {},
|
|
5
|
-
android: {
|
|
5
|
+
android: {
|
|
6
|
+
sourceDir: "./android",
|
|
7
|
+
packageImportPath: "import ai.sagepilot.reactnativesdk.SagepilotReactNativeSdkPackage;",
|
|
8
|
+
packageInstance: "new SagepilotReactNativeSdkPackage()"
|
|
9
|
+
}
|
|
6
10
|
}
|
|
7
11
|
}
|
|
8
12
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HostComponent, ViewProps } from "react-native";
|
|
2
|
+
import type { DirectEventHandler, Double } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
|
+
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
4
|
+
|
|
5
|
+
export type SagepilotInsetsChangeEvent = Readonly<{
|
|
6
|
+
top: Double;
|
|
7
|
+
bottom: Double;
|
|
8
|
+
imeBottom: Double;
|
|
9
|
+
systemBarsBottom: Double;
|
|
10
|
+
keyboardVisible: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
export interface NativeProps extends ViewProps {
|
|
14
|
+
onInsetsChange?: DirectEventHandler<SagepilotInsetsChangeEvent>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default codegenNativeComponent<NativeProps>("SagepilotInsetsView") as HostComponent<NativeProps>;
|
package/android/.gitkeep
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|