@sagepilot-ai/react-native-sdk 0.4.2 → 0.4.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 CHANGED
@@ -16,7 +16,7 @@ For full integration docs, see [React Native SDK docs](https://docs.sagepilot.ai
16
16
 
17
17
  ## Install
18
18
 
19
- The base SDK, camera add-on and push add-on share release **0.4.2**. Install matching versions of the add-ons your app uses; chat-only apps do not need either add-on.
19
+ Base SDK **0.4.3** adds the optional native URL handler. Camera and push add-ons remain at **0.4.2** and retain their existing peer compatibility; chat-only apps do not need either add-on.
20
20
 
21
21
  ```bash
22
22
  npm install @sagepilot-ai/react-native-sdk@latest react-native-webview
@@ -91,6 +91,8 @@ export function SagepilotProvider({ children }: { children: ReactNode }) {
91
91
  }
92
92
  ```
93
93
 
94
+ For native product navigation, pass `onOpenURL` to `SagepilotChatProvider`. It receives external top-level destinations; return `true` (or a promise resolving to `true`) when your native router handles the URL. Returning `false`, omitting the callback, or throwing preserves the existing `Linking.openURL` fallback. Same-origin widget pages, including `/cta` click tracking, load normally before their final destination is offered to the callback. A handled destination resets the hosted WebView so reopening chat does not leave it on a tracking page.
95
+
94
96
  ```tsx
95
97
  export function App() {
96
98
  return (
package/dist/index.d.mts CHANGED
@@ -487,6 +487,8 @@ type SagepilotChatProviderProps = {
487
487
  children?: ReactNode;
488
488
  closeLabel?: string;
489
489
  loadingLabel?: string;
490
+ /** Handle an external destination natively. Return true when handled; false or an error uses Linking.openURL. Same-origin widget and tracking pages remain in the WebView. */
491
+ onOpenURL?: (url: string) => boolean | Promise<boolean>;
490
492
  };
491
493
 
492
494
  type SagepilotPushPermission = "authorized" | "provisional" | "denied" | "not_determined";
@@ -725,7 +727,7 @@ type SagepilotAsyncStorageLike = {
725
727
  };
726
728
  declare function createAsyncStorageCacheStorage(asyncStorage: SagepilotAsyncStorageLike): SagepilotCacheStorage;
727
729
 
728
- declare function SagepilotChatProvider({ children, closeLabel, loadingLabel }: SagepilotChatProviderProps): ReactNode;
730
+ declare function SagepilotChatProvider({ children, closeLabel, loadingLabel, onOpenURL }: SagepilotChatProviderProps): ReactNode;
729
731
 
730
732
  declare function useSagepilotChat(): SagepilotChatHookState;
731
733
 
package/dist/index.d.ts CHANGED
@@ -487,6 +487,8 @@ type SagepilotChatProviderProps = {
487
487
  children?: ReactNode;
488
488
  closeLabel?: string;
489
489
  loadingLabel?: string;
490
+ /** Handle an external destination natively. Return true when handled; false or an error uses Linking.openURL. Same-origin widget and tracking pages remain in the WebView. */
491
+ onOpenURL?: (url: string) => boolean | Promise<boolean>;
490
492
  };
491
493
 
492
494
  type SagepilotPushPermission = "authorized" | "provisional" | "denied" | "not_determined";
@@ -725,7 +727,7 @@ type SagepilotAsyncStorageLike = {
725
727
  };
726
728
  declare function createAsyncStorageCacheStorage(asyncStorage: SagepilotAsyncStorageLike): SagepilotCacheStorage;
727
729
 
728
- declare function SagepilotChatProvider({ children, closeLabel, loadingLabel }: SagepilotChatProviderProps): ReactNode;
730
+ declare function SagepilotChatProvider({ children, closeLabel, loadingLabel, onOpenURL }: SagepilotChatProviderProps): ReactNode;
729
731
 
730
732
  declare function useSagepilotChat(): SagepilotChatHookState;
731
733
 
package/dist/index.js CHANGED
@@ -54,7 +54,7 @@ var import_react_native2 = require("react-native");
54
54
 
55
55
  // package.json
56
56
  var name = "@sagepilot-ai/react-native-sdk";
57
- var version = "0.4.2";
57
+ var version = "0.4.3";
58
58
 
59
59
  // src/core/config/constants.ts
60
60
  var SDK_NAME = name;
@@ -2238,6 +2238,19 @@ var import_react = require("react");
2238
2238
  var import_react_native4 = require("react-native");
2239
2239
  var import_react_native_webview = require("react-native-webview");
2240
2240
 
2241
+ // src/core/webview/openUrl.ts
2242
+ async function openHostedChatURL(url, openSystemURL, onOpenURL) {
2243
+ try {
2244
+ if (await onOpenURL?.(url) === true) return true;
2245
+ } catch {
2246
+ }
2247
+ try {
2248
+ await openSystemURL(url);
2249
+ } catch {
2250
+ }
2251
+ return false;
2252
+ }
2253
+
2241
2254
  // src/core/webview/mobileBridge.ts
2242
2255
  var FILE_PICKER_PROTOCOL_VERSION = 2;
2243
2256
  function buildBridgeCapabilitiesPayload(capabilities) {
@@ -2549,7 +2562,8 @@ var emptyAndroidInsets = { top: 0, bottom: 0 };
2549
2562
  function SagepilotChatProvider({
2550
2563
  children,
2551
2564
  closeLabel = "Close",
2552
- loadingLabel = "Loading chat"
2565
+ loadingLabel = "Loading chat",
2566
+ onOpenURL
2553
2567
  }) {
2554
2568
  const [state, setState] = (0, import_react.useState)(readPresentationState);
2555
2569
  const [androidModalInsets, setAndroidModalInsets] = (0, import_react.useState)(emptyAndroidInsets);
@@ -3032,16 +3046,18 @@ function SagepilotChatProvider({
3032
3046
  };
3033
3047
  const handleShouldStartLoadWithRequest = (0, import_react.useCallback)((request) => {
3034
3048
  const url = request?.url ?? "";
3035
- if (!url || request?.isTopFrame === false || isInternalWebViewScheme(url)) {
3049
+ if (!url || request?.isTopFrame === false && request?.hasTargetFrame !== false || isInternalWebViewScheme(url)) {
3036
3050
  return true;
3037
3051
  }
3038
3052
  const widgetOrigin = readUrlOrigin(state.conversationUrl ?? state.preloadUrl);
3039
3053
  if (widgetOrigin && readUrlOrigin(url) === widgetOrigin) {
3040
3054
  return true;
3041
3055
  }
3042
- import_react_native4.Linking.openURL(url).catch(() => void 0);
3056
+ void openHostedChatURL(url, import_react_native4.Linking.openURL, onOpenURL).then((handled) => {
3057
+ if (handled) setNativeWebViewKey((key) => key + 1);
3058
+ });
3043
3059
  return false;
3044
- }, [state.conversationUrl, state.preloadUrl]);
3060
+ }, [state.conversationUrl, state.preloadUrl, onOpenURL]);
3045
3061
  (0, import_react.useEffect)(() => {
3046
3062
  if (import_react_native4.Platform.OS !== "web" || typeof window === "undefined") return;
3047
3063
  const trustedWidgetOrigin = readUrlOrigin(state.conversationUrl);
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { AppState as AppState2, Platform } from "react-native";
3
3
 
4
4
  // package.json
5
5
  var name = "@sagepilot-ai/react-native-sdk";
6
- var version = "0.4.2";
6
+ var version = "0.4.3";
7
7
 
8
8
  // src/core/config/constants.ts
9
9
  var SDK_NAME = name;
@@ -2199,6 +2199,19 @@ import {
2199
2199
  } from "react-native";
2200
2200
  import { WebView } from "react-native-webview";
2201
2201
 
2202
+ // src/core/webview/openUrl.ts
2203
+ async function openHostedChatURL(url, openSystemURL, onOpenURL) {
2204
+ try {
2205
+ if (await onOpenURL?.(url) === true) return true;
2206
+ } catch {
2207
+ }
2208
+ try {
2209
+ await openSystemURL(url);
2210
+ } catch {
2211
+ }
2212
+ return false;
2213
+ }
2214
+
2202
2215
  // src/core/webview/mobileBridge.ts
2203
2216
  var FILE_PICKER_PROTOCOL_VERSION = 2;
2204
2217
  function buildBridgeCapabilitiesPayload(capabilities) {
@@ -2510,7 +2523,8 @@ var emptyAndroidInsets = { top: 0, bottom: 0 };
2510
2523
  function SagepilotChatProvider({
2511
2524
  children,
2512
2525
  closeLabel = "Close",
2513
- loadingLabel = "Loading chat"
2526
+ loadingLabel = "Loading chat",
2527
+ onOpenURL
2514
2528
  }) {
2515
2529
  const [state, setState] = useState(readPresentationState);
2516
2530
  const [androidModalInsets, setAndroidModalInsets] = useState(emptyAndroidInsets);
@@ -2993,16 +3007,18 @@ function SagepilotChatProvider({
2993
3007
  };
2994
3008
  const handleShouldStartLoadWithRequest = useCallback((request) => {
2995
3009
  const url = request?.url ?? "";
2996
- if (!url || request?.isTopFrame === false || isInternalWebViewScheme(url)) {
3010
+ if (!url || request?.isTopFrame === false && request?.hasTargetFrame !== false || isInternalWebViewScheme(url)) {
2997
3011
  return true;
2998
3012
  }
2999
3013
  const widgetOrigin = readUrlOrigin(state.conversationUrl ?? state.preloadUrl);
3000
3014
  if (widgetOrigin && readUrlOrigin(url) === widgetOrigin) {
3001
3015
  return true;
3002
3016
  }
3003
- Linking2.openURL(url).catch(() => void 0);
3017
+ void openHostedChatURL(url, Linking2.openURL, onOpenURL).then((handled) => {
3018
+ if (handled) setNativeWebViewKey((key) => key + 1);
3019
+ });
3004
3020
  return false;
3005
- }, [state.conversationUrl, state.preloadUrl]);
3021
+ }, [state.conversationUrl, state.preloadUrl, onOpenURL]);
3006
3022
  useEffect(() => {
3007
3023
  if (Platform3.OS !== "web" || typeof window === "undefined") return;
3008
3024
  const trustedWidgetOrigin = readUrlOrigin(state.conversationUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagepilot-ai/react-native-sdk",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Sagepilot AI React Native chat SDK",
5
5
  "keywords": [
6
6
  "sagepilot",