@sagepilot-ai/react-native-sdk 0.3.1 → 0.3.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.
@@ -8,13 +8,11 @@ import java.util.Collections;
8
8
  import java.util.List;
9
9
 
10
10
  public class SagepilotReactNativeSdkPackage implements ReactPackage {
11
- /** Registers SDK-owned native modules exposed to JavaScript. */
12
11
  @Override
13
12
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
14
13
  return Collections.emptyList();
15
14
  }
16
15
 
17
- /** Registers the existing SDK view managers without changing their surface. */
18
16
  @Override
19
17
  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
20
18
  return Collections.singletonList(new SagepilotInsetsViewManager());
package/dist/index.d.mts CHANGED
@@ -246,6 +246,7 @@ type SagepilotMobileBehaviorConfig = {
246
246
  enableUnreadPolling?: boolean;
247
247
  preloadWebView?: boolean;
248
248
  unreadPollIntervalMs?: number;
249
+ waitForIdentifyBeforeComposer?: boolean;
249
250
  };
250
251
  type SagepilotTokenStorage = {
251
252
  getItem: (key: string) => Promise<string | null>;
@@ -471,7 +472,7 @@ type SagepilotChatHookState = {
471
472
  theme: SagepilotMobileThemeState;
472
473
  present: () => boolean;
473
474
  presentMessages: () => boolean;
474
- presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean;
475
+ presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean | Promise<boolean>;
475
476
  dismiss: () => boolean;
476
477
  hide: () => boolean;
477
478
  toggle: () => boolean;
@@ -505,7 +506,7 @@ declare const SagepilotChat: {
505
506
  stopUnreadPolling: () => void;
506
507
  present: () => boolean;
507
508
  presentMessages: () => boolean;
508
- presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean;
509
+ presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean | Promise<boolean>;
509
510
  dismiss: () => boolean;
510
511
  hide: () => boolean;
511
512
  toggle: () => boolean;
package/dist/index.d.ts CHANGED
@@ -246,6 +246,7 @@ type SagepilotMobileBehaviorConfig = {
246
246
  enableUnreadPolling?: boolean;
247
247
  preloadWebView?: boolean;
248
248
  unreadPollIntervalMs?: number;
249
+ waitForIdentifyBeforeComposer?: boolean;
249
250
  };
250
251
  type SagepilotTokenStorage = {
251
252
  getItem: (key: string) => Promise<string | null>;
@@ -471,7 +472,7 @@ type SagepilotChatHookState = {
471
472
  theme: SagepilotMobileThemeState;
472
473
  present: () => boolean;
473
474
  presentMessages: () => boolean;
474
- presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean;
475
+ presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean | Promise<boolean>;
475
476
  dismiss: () => boolean;
476
477
  hide: () => boolean;
477
478
  toggle: () => boolean;
@@ -505,7 +506,7 @@ declare const SagepilotChat: {
505
506
  stopUnreadPolling: () => void;
506
507
  present: () => boolean;
507
508
  presentMessages: () => boolean;
508
- presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean;
509
+ presentMessageComposer: (message?: string, options?: SagepilotMessageComposerOptions) => boolean | Promise<boolean>;
509
510
  dismiss: () => boolean;
510
511
  hide: () => boolean;
511
512
  toggle: () => boolean;
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ var SagepilotChatError = class extends Error {
67
67
 
68
68
  // src/core/config/constants.ts
69
69
  var SDK_NAME = "@sagepilot-ai/react-native-sdk";
70
- var SDK_VERSION = "0.3.1";
70
+ var SDK_VERSION = "0.3.3";
71
71
  var DEFAULT_HOST = "https://app.sagepilot.ai";
72
72
  var DEFAULT_WIDGET_HOST = "https://app.sagepilot.ai";
73
73
  var CUSTOMER_API_PREFIX = "/customer-api/v1";
@@ -490,6 +490,7 @@ function fetchUnreadCount(http, host, channelId, sessionId, authorizationHeader)
490
490
  var PRESENTATION_CACHE_NAMESPACE = "sagepilot_rn_presentation";
491
491
  var PRESENTATION_CACHE_KEY = "state";
492
492
  var PRESENTATION_RESTORE_MAX_AGE_MS = 15 * 60 * 1e3;
493
+ var IDENTIFY_PENDING_COMPOSER_TIMEOUT_MS = 60 * 1e3;
493
494
  var DEFAULT_MOBILE_LAUNCHER_CONFIG = {
494
495
  label: "Chat",
495
496
  buttonColor: "#173c2d",
@@ -808,7 +809,16 @@ var SagepilotReactNativeChat = class {
808
809
  return this.showHostedChat();
809
810
  }
810
811
  presentMessageComposer(message, options) {
811
- this.requireConfigured();
812
+ const session = this.requireSession();
813
+ const shouldWaitForIdentify = this.runtimeOptions?.behavior?.waitForIdentifyBeforeComposer === true;
814
+ if (!shouldWaitForIdentify || !this.identifyPending) return this.openMessageComposer(message, options);
815
+ return this.waitForIdentifyOrTimeout().then(() => {
816
+ if (!this.session || this.session.session_id !== session.session_id) return false;
817
+ return this.openMessageComposer(message, options);
818
+ });
819
+ }
820
+ /** Opens the hosted composer with the latest session identity state. */
821
+ openMessageComposer(message, options) {
812
822
  const chatId = normalizeOptionalString(options?.chatId);
813
823
  this.hostedChatView = {
814
824
  screen: "composer",
@@ -820,6 +830,24 @@ var SagepilotReactNativeChat = class {
820
830
  };
821
831
  return this.showHostedChat();
822
832
  }
833
+ /** Waits for a successful identify response before falling back to the timeout. */
834
+ waitForIdentifyOrTimeout(timeoutMs = IDENTIFY_PENDING_COMPOSER_TIMEOUT_MS) {
835
+ if (!this.identifyPending) return Promise.resolve();
836
+ return new Promise((resolve) => {
837
+ let completed = false;
838
+ let timeout = null;
839
+ const finish = () => {
840
+ if (completed) return;
841
+ completed = true;
842
+ if (timeout) clearTimeout(timeout);
843
+ this.identifyCallbacks.delete(handleIdentify);
844
+ resolve();
845
+ };
846
+ const handleIdentify = () => finish();
847
+ timeout = setTimeout(finish, timeoutMs);
848
+ this.identifyCallbacks.add(handleIdentify);
849
+ });
850
+ }
823
851
  dismiss() {
824
852
  this.requireConfigured();
825
853
  if (!this.presented) return true;
@@ -1642,7 +1670,6 @@ function createSagepilotFilePicker(options) {
1642
1670
 
1643
1671
  // src/ui/SagepilotChatProvider.ts
1644
1672
  var import_react = require("react");
1645
- var import_lucide_react_native = require("lucide-react-native");
1646
1673
  var import_react_native3 = require("react-native");
1647
1674
  var import_react_native_webview = require("react-native-webview");
1648
1675
 
@@ -1821,8 +1848,10 @@ function readPresentationState() {
1821
1848
  };
1822
1849
  }
1823
1850
  function getBridgeCapabilities() {
1851
+ const filePicker = internalSagepilotChat.getConfig()?.filePicker;
1824
1852
  return {
1825
- nativeFilePicker: Boolean(internalSagepilotChat.getConfig()?.filePicker)
1853
+ nativeFilePicker: Boolean(filePicker),
1854
+ nativeFilePickerSources: filePicker?.sources ?? []
1826
1855
  };
1827
1856
  }
1828
1857
  function getInjectedWebViewScript() {
@@ -1838,21 +1867,13 @@ var FILE_PICKER_SOURCE_LABELS = {
1838
1867
  library: "Choose from gallery",
1839
1868
  documents: "Browse files"
1840
1869
  };
1841
- var FILE_PICKER_SOURCE_DESCRIPTIONS = {
1842
- camera: "Use the in-app camera",
1843
- library: "Photos and videos on this device",
1844
- documents: "PDFs, documents, and Drive files"
1845
- };
1846
- var FILE_PICKER_SOURCE_ICONS = {
1847
- camera: import_lucide_react_native.Camera,
1848
- library: import_lucide_react_native.Images,
1849
- documents: import_lucide_react_native.FileText
1850
- };
1851
- var FILE_PICKER_SOURCE_ICON_COLORS = {
1852
- camera: "#0284c7",
1853
- library: "#16a34a",
1854
- documents: "#7c3aed"
1855
- };
1870
+ var RN_FILE_PICKER_LOG_PREFIX = "[SagepilotRNFilePicker]";
1871
+ function logNativeFilePicker(event, details) {
1872
+ console.info(`${RN_FILE_PICKER_LOG_PREFIX} ${event}`, details ?? {});
1873
+ }
1874
+ function warnNativeFilePicker(event, details) {
1875
+ console.warn(`${RN_FILE_PICKER_LOG_PREFIX} ${event}`, details ?? {});
1876
+ }
1856
1877
  var DELIVERY_RETRY_MS = 1500;
1857
1878
  var DELIVERY_LEGACY_FALLBACK_ATTEMPTS = 2;
1858
1879
  var DELIVERY_MAX_ATTEMPTS = 8;
@@ -1876,29 +1897,6 @@ function totalBase64Bytes(files) {
1876
1897
  function storageKeyFor(batchId, index) {
1877
1898
  return `${batchId}_${index}.bin`;
1878
1899
  }
1879
- function renderFilePickerSourceIcon(source) {
1880
- const Icon = FILE_PICKER_SOURCE_ICONS[source];
1881
- return (0, import_react.createElement)(
1882
- import_react_native3.View,
1883
- { style: getFilePickerSourceIconStyle(source) },
1884
- (0, import_react.createElement)(Icon, {
1885
- color: FILE_PICKER_SOURCE_ICON_COLORS[source],
1886
- size: 23,
1887
- strokeWidth: 2.35
1888
- })
1889
- );
1890
- }
1891
- function getFilePickerSourceIconStyle(source) {
1892
- if (source === "camera") return [styles.sheetOptionIcon, styles.cameraOptionIcon];
1893
- if (source === "library") return [styles.sheetOptionIcon, styles.libraryOptionIcon];
1894
- return [styles.sheetOptionIcon, styles.documentsOptionIcon];
1895
- }
1896
- function getSheetOptionStyle(pressed) {
1897
- return [styles.sheetOption, pressed && styles.sheetOptionPressed];
1898
- }
1899
- function getSheetCancelStyle(pressed) {
1900
- return [styles.sheetCancelButton, pressed && styles.sheetCancelButtonPressed];
1901
- }
1902
1900
  function buildDispatchScript(messageLiteral) {
1903
1901
  return [
1904
1902
  "(function(){",
@@ -2149,35 +2147,70 @@ function SagepilotChatProvider({
2149
2147
  }, []);
2150
2148
  const runNativeFilePicker = (0, import_react.useCallback)((source, multiple) => {
2151
2149
  const filePicker = internalSagepilotChat.getConfig()?.filePicker;
2150
+ logNativeFilePicker("run_requested", {
2151
+ source,
2152
+ multiple,
2153
+ availableSources: filePicker?.sources ?? []
2154
+ });
2152
2155
  if (!filePicker) {
2156
+ warnNativeFilePicker("run_without_file_picker", { source });
2153
2157
  return;
2154
2158
  }
2155
2159
  if (pickerInFlightRef.current) {
2160
+ warnNativeFilePicker("run_ignored_picker_in_flight", { source });
2156
2161
  return;
2157
2162
  }
2158
- pauseLivenessAfterPicker(6e4);
2159
2163
  pickerInFlightRef.current = true;
2160
- filePicker.pickFiles({ source, multiple }).then((files) => {
2161
- if (files.length === 0) {
2162
- nativeWebViewRef.current?.injectJavaScript(buildFilePickerCancelledScript());
2163
- return;
2164
+ pauseLivenessAfterPicker(6e4);
2165
+ void (async () => {
2166
+ try {
2167
+ const files = await filePicker.pickFiles({ source, multiple });
2168
+ logNativeFilePicker("native_pick_resolved", { source, fileCount: files.length });
2169
+ if (files.length === 0) {
2170
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerCancelledScript());
2171
+ return;
2172
+ }
2173
+ queuePickedFiles(files);
2174
+ } catch (error) {
2175
+ const { message, code } = readFilePickerError(error);
2176
+ warnNativeFilePicker("native_pick_failed", { source, code, message });
2177
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(message, code));
2178
+ } finally {
2179
+ pickerInFlightRef.current = false;
2180
+ pauseLivenessAfterPicker(LIVENESS_PICKER_GRACE_MS);
2164
2181
  }
2165
- queuePickedFiles(files);
2166
- }).catch((error) => {
2167
- const { message, code } = readFilePickerError(error);
2168
- nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(message, code));
2169
- }).finally(() => {
2170
- pickerInFlightRef.current = false;
2171
- pauseLivenessAfterPicker(LIVENESS_PICKER_GRACE_MS);
2172
- });
2182
+ })();
2173
2183
  }, [pauseLivenessAfterPicker, queuePickedFiles]);
2174
- const openNativeFilePicker = (0, import_react.useCallback)((multiple) => {
2184
+ const openNativeFilePicker = (0, import_react.useCallback)((multiple, source) => {
2175
2185
  const filePicker = internalSagepilotChat.getConfig()?.filePicker;
2186
+ logNativeFilePicker("open_requested", {
2187
+ source: source ?? "source_chooser",
2188
+ multiple,
2189
+ hasFilePicker: Boolean(filePicker),
2190
+ availableSources: filePicker?.sources ?? []
2191
+ });
2176
2192
  if (!filePicker || filePicker.sources.length === 0) {
2193
+ warnNativeFilePicker("open_unavailable", { source: source ?? "source_chooser" });
2194
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(
2195
+ source === "camera" ? "CameraX is not available in this Expo runtime. Use a dev build with the CameraX addon linked." : "Native attachment picker is not available in this build.",
2196
+ "camera_unavailable"
2197
+ ));
2198
+ return;
2199
+ }
2200
+ if (source) {
2201
+ if (filePicker.sources.includes(source)) {
2202
+ runNativeFilePicker(source, multiple);
2203
+ } else {
2204
+ warnNativeFilePicker("source_not_available", { source, availableSources: filePicker.sources });
2205
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(
2206
+ source === "camera" ? "CameraX is not available in this build." : `Native ${source} picker is not available in this build.`,
2207
+ "camera_unavailable"
2208
+ ));
2209
+ }
2177
2210
  return;
2178
2211
  }
2179
2212
  const [onlySource] = filePicker.sources;
2180
- if (filePicker.sources.length === 1 && onlySource && onlySource !== "camera") {
2213
+ if (filePicker.sources.length === 1 && onlySource) {
2181
2214
  runNativeFilePicker(onlySource, multiple);
2182
2215
  return;
2183
2216
  }
@@ -2357,7 +2390,11 @@ function SagepilotChatProvider({
2357
2390
  const handleWebViewMessage = (event) => {
2358
2391
  const message = parseHostedBridgeMessage(event.nativeEvent?.data);
2359
2392
  if (message?.type === "sagepilot:open_file_picker") {
2360
- openNativeFilePicker(message.multiple ?? true);
2393
+ logNativeFilePicker("bridge_message_open_file_picker", {
2394
+ source: message.source ?? "source_chooser",
2395
+ multiple: message.multiple ?? true
2396
+ });
2397
+ openNativeFilePicker(message.multiple ?? true, message.source);
2361
2398
  return;
2362
2399
  }
2363
2400
  if (message?.type === "sagepilot:widget_listener_ready") {
@@ -2575,7 +2612,6 @@ function SagepilotChatProvider({
2575
2612
  (0, import_react.createElement)(
2576
2613
  import_react_native3.View,
2577
2614
  { style: styles.sheetCard },
2578
- (0, import_react.createElement)(import_react_native3.View, { style: styles.sheetHandle }),
2579
2615
  (0, import_react.createElement)(import_react_native3.Text, { style: styles.sheetTitle }, "Add attachment"),
2580
2616
  ...(internalSagepilotChat.getConfig()?.filePicker?.sources ?? []).map(
2581
2617
  (source) => (0, import_react.createElement)(
@@ -2583,29 +2619,19 @@ function SagepilotChatProvider({
2583
2619
  {
2584
2620
  key: source,
2585
2621
  accessibilityRole: "button",
2586
- android_ripple: { color: "rgba(15, 23, 42, 0.06)" },
2587
- hitSlop: 4,
2588
- style: ({ pressed }) => getSheetOptionStyle(pressed),
2622
+ style: styles.sheetButton,
2589
2623
  onPress: () => handleSourceChoice(source)
2590
2624
  },
2591
- renderFilePickerSourceIcon(source),
2592
- (0, import_react.createElement)(
2593
- import_react_native3.View,
2594
- { style: styles.sheetOptionText },
2595
- (0, import_react.createElement)(import_react_native3.Text, { style: styles.sheetButtonText }, FILE_PICKER_SOURCE_LABELS[source]),
2596
- (0, import_react.createElement)(import_react_native3.Text, { style: styles.sheetButtonDescription }, FILE_PICKER_SOURCE_DESCRIPTIONS[source])
2597
- )
2625
+ (0, import_react.createElement)(import_react_native3.Text, { style: styles.sheetButtonText }, FILE_PICKER_SOURCE_LABELS[source])
2598
2626
  )
2599
2627
  ),
2600
2628
  (0, import_react.createElement)(
2601
2629
  import_react_native3.Pressable,
2602
2630
  {
2603
2631
  accessibilityRole: "button",
2604
- android_ripple: { color: "rgba(15, 23, 42, 0.06)" },
2605
- style: ({ pressed }) => getSheetCancelStyle(pressed),
2632
+ style: [styles.sheetButton, styles.sheetCancelButton],
2606
2633
  onPress: () => setSourceChooser(null)
2607
2634
  },
2608
- (0, import_react.createElement)(import_lucide_react_native.X, { color: "#334155", size: 18, strokeWidth: 2.5, style: styles.sheetCancelIcon }),
2609
2635
  (0, import_react.createElement)(import_react_native3.Text, { style: styles.sheetCancelText }, "Cancel")
2610
2636
  )
2611
2637
  )
@@ -2711,109 +2737,43 @@ var styles = import_react_native3.StyleSheet.create({
2711
2737
  },
2712
2738
  sheetBackdrop: {
2713
2739
  flex: 1,
2714
- alignItems: "center",
2715
2740
  justifyContent: "flex-end",
2716
- backgroundColor: "rgba(15, 23, 42, 0.48)"
2741
+ backgroundColor: "rgba(17, 24, 39, 0.36)"
2717
2742
  },
2718
2743
  sheetCard: {
2719
- width: "100%",
2720
- maxWidth: 540,
2721
2744
  backgroundColor: "#ffffff",
2722
- borderTopLeftRadius: 26,
2723
- borderTopRightRadius: 26,
2724
- paddingTop: 10,
2725
- paddingBottom: 18,
2726
- paddingHorizontal: 14,
2727
- shadowColor: "#0f172a",
2728
- shadowOpacity: 0.22,
2729
- shadowRadius: 28,
2730
- shadowOffset: { width: 0, height: -10 },
2731
- elevation: 18
2732
- },
2733
- sheetHandle: {
2734
- alignSelf: "center",
2735
- width: 42,
2736
- height: 5,
2737
- borderRadius: 999,
2738
- backgroundColor: "#d1d5db",
2739
- marginBottom: 14
2745
+ borderTopLeftRadius: 16,
2746
+ borderTopRightRadius: 16,
2747
+ paddingTop: 8,
2748
+ paddingBottom: 24,
2749
+ paddingHorizontal: 8
2740
2750
  },
2741
2751
  sheetTitle: {
2742
- color: "#111827",
2743
- fontSize: 17,
2744
- fontWeight: "700",
2745
- paddingBottom: 12,
2746
- paddingHorizontal: 4
2747
- },
2748
- sheetOption: {
2749
- minHeight: 70,
2750
- flexDirection: "row",
2751
- alignItems: "center",
2752
- borderRadius: 18,
2753
- paddingHorizontal: 12,
2754
- marginBottom: 6,
2755
- backgroundColor: "#ffffff"
2756
- },
2757
- sheetOptionPressed: {
2758
- backgroundColor: "#f8fafc",
2759
- transform: [{ scale: 0.985 }]
2752
+ textAlign: "center",
2753
+ color: "#6b7280",
2754
+ fontSize: 13,
2755
+ fontWeight: "600",
2756
+ paddingVertical: 10
2760
2757
  },
2761
- sheetOptionIcon: {
2762
- width: 46,
2763
- height: 46,
2764
- borderRadius: 16,
2765
- marginRight: 14,
2758
+ sheetButton: {
2759
+ minHeight: 52,
2766
2760
  alignItems: "center",
2767
2761
  justifyContent: "center",
2768
- position: "relative",
2769
- overflow: "hidden"
2770
- },
2771
- sheetOptionText: {
2772
- flex: 1,
2773
- justifyContent: "center"
2762
+ borderRadius: 12
2774
2763
  },
2775
2764
  sheetButtonText: {
2776
- color: "#0f172a",
2765
+ color: "#111827",
2777
2766
  fontSize: 16,
2778
- fontWeight: "700"
2779
- },
2780
- sheetButtonDescription: {
2781
- color: "#64748b",
2782
- fontSize: 13,
2783
- fontWeight: "500",
2784
- marginTop: 3
2785
- },
2786
- cameraOptionIcon: {
2787
- backgroundColor: "#e0f2fe"
2788
- },
2789
- libraryOptionIcon: {
2790
- backgroundColor: "#ecfdf5"
2791
- },
2792
- documentsOptionIcon: {
2793
- backgroundColor: "#f5f3ff"
2767
+ fontWeight: "500"
2794
2768
  },
2795
2769
  sheetCancelButton: {
2796
- minHeight: 56,
2797
- flexDirection: "row",
2798
- alignItems: "center",
2799
- justifyContent: "center",
2800
- borderRadius: 18,
2801
- marginTop: 8,
2802
- backgroundColor: "#f1f5f9"
2803
- },
2804
- sheetCancelButtonPressed: {
2805
- backgroundColor: "#e2e8f0",
2806
- transform: [{ scale: 0.985 }]
2807
- },
2808
- sheetCancelIcon: {
2809
- width: 18,
2810
- height: 18,
2811
- marginRight: 8
2770
+ marginTop: 6,
2771
+ backgroundColor: "#f3f4f6"
2812
2772
  },
2813
2773
  sheetCancelText: {
2814
- color: "#0f172a",
2774
+ color: "#111827",
2815
2775
  fontSize: 16,
2816
- fontWeight: "700"
2776
+ fontWeight: "600"
2817
2777
  }
2818
2778
  });
2819
2779