@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.
package/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ var SagepilotChatError = class extends Error {
18
18
 
19
19
  // src/core/config/constants.ts
20
20
  var SDK_NAME = "@sagepilot-ai/react-native-sdk";
21
- var SDK_VERSION = "0.3.1";
21
+ var SDK_VERSION = "0.3.3";
22
22
  var DEFAULT_HOST = "https://app.sagepilot.ai";
23
23
  var DEFAULT_WIDGET_HOST = "https://app.sagepilot.ai";
24
24
  var CUSTOMER_API_PREFIX = "/customer-api/v1";
@@ -441,6 +441,7 @@ function fetchUnreadCount(http, host, channelId, sessionId, authorizationHeader)
441
441
  var PRESENTATION_CACHE_NAMESPACE = "sagepilot_rn_presentation";
442
442
  var PRESENTATION_CACHE_KEY = "state";
443
443
  var PRESENTATION_RESTORE_MAX_AGE_MS = 15 * 60 * 1e3;
444
+ var IDENTIFY_PENDING_COMPOSER_TIMEOUT_MS = 60 * 1e3;
444
445
  var DEFAULT_MOBILE_LAUNCHER_CONFIG = {
445
446
  label: "Chat",
446
447
  buttonColor: "#173c2d",
@@ -759,7 +760,16 @@ var SagepilotReactNativeChat = class {
759
760
  return this.showHostedChat();
760
761
  }
761
762
  presentMessageComposer(message, options) {
762
- this.requireConfigured();
763
+ const session = this.requireSession();
764
+ const shouldWaitForIdentify = this.runtimeOptions?.behavior?.waitForIdentifyBeforeComposer === true;
765
+ if (!shouldWaitForIdentify || !this.identifyPending) return this.openMessageComposer(message, options);
766
+ return this.waitForIdentifyOrTimeout().then(() => {
767
+ if (!this.session || this.session.session_id !== session.session_id) return false;
768
+ return this.openMessageComposer(message, options);
769
+ });
770
+ }
771
+ /** Opens the hosted composer with the latest session identity state. */
772
+ openMessageComposer(message, options) {
763
773
  const chatId = normalizeOptionalString(options?.chatId);
764
774
  this.hostedChatView = {
765
775
  screen: "composer",
@@ -771,6 +781,24 @@ var SagepilotReactNativeChat = class {
771
781
  };
772
782
  return this.showHostedChat();
773
783
  }
784
+ /** Waits for a successful identify response before falling back to the timeout. */
785
+ waitForIdentifyOrTimeout(timeoutMs = IDENTIFY_PENDING_COMPOSER_TIMEOUT_MS) {
786
+ if (!this.identifyPending) return Promise.resolve();
787
+ return new Promise((resolve) => {
788
+ let completed = false;
789
+ let timeout = null;
790
+ const finish = () => {
791
+ if (completed) return;
792
+ completed = true;
793
+ if (timeout) clearTimeout(timeout);
794
+ this.identifyCallbacks.delete(handleIdentify);
795
+ resolve();
796
+ };
797
+ const handleIdentify = () => finish();
798
+ timeout = setTimeout(finish, timeoutMs);
799
+ this.identifyCallbacks.add(handleIdentify);
800
+ });
801
+ }
774
802
  dismiss() {
775
803
  this.requireConfigured();
776
804
  if (!this.presented) return true;
@@ -1593,7 +1621,6 @@ function createSagepilotFilePicker(options) {
1593
1621
 
1594
1622
  // src/ui/SagepilotChatProvider.ts
1595
1623
  import { createElement, useCallback, useEffect, useRef, useState } from "react";
1596
- import { Camera, FileText, Images, X } from "lucide-react-native";
1597
1624
  import {
1598
1625
  ActivityIndicator,
1599
1626
  AppState,
@@ -1784,8 +1811,10 @@ function readPresentationState() {
1784
1811
  };
1785
1812
  }
1786
1813
  function getBridgeCapabilities() {
1814
+ const filePicker = internalSagepilotChat.getConfig()?.filePicker;
1787
1815
  return {
1788
- nativeFilePicker: Boolean(internalSagepilotChat.getConfig()?.filePicker)
1816
+ nativeFilePicker: Boolean(filePicker),
1817
+ nativeFilePickerSources: filePicker?.sources ?? []
1789
1818
  };
1790
1819
  }
1791
1820
  function getInjectedWebViewScript() {
@@ -1801,21 +1830,13 @@ var FILE_PICKER_SOURCE_LABELS = {
1801
1830
  library: "Choose from gallery",
1802
1831
  documents: "Browse files"
1803
1832
  };
1804
- var FILE_PICKER_SOURCE_DESCRIPTIONS = {
1805
- camera: "Use the in-app camera",
1806
- library: "Photos and videos on this device",
1807
- documents: "PDFs, documents, and Drive files"
1808
- };
1809
- var FILE_PICKER_SOURCE_ICONS = {
1810
- camera: Camera,
1811
- library: Images,
1812
- documents: FileText
1813
- };
1814
- var FILE_PICKER_SOURCE_ICON_COLORS = {
1815
- camera: "#0284c7",
1816
- library: "#16a34a",
1817
- documents: "#7c3aed"
1818
- };
1833
+ var RN_FILE_PICKER_LOG_PREFIX = "[SagepilotRNFilePicker]";
1834
+ function logNativeFilePicker(event, details) {
1835
+ console.info(`${RN_FILE_PICKER_LOG_PREFIX} ${event}`, details ?? {});
1836
+ }
1837
+ function warnNativeFilePicker(event, details) {
1838
+ console.warn(`${RN_FILE_PICKER_LOG_PREFIX} ${event}`, details ?? {});
1839
+ }
1819
1840
  var DELIVERY_RETRY_MS = 1500;
1820
1841
  var DELIVERY_LEGACY_FALLBACK_ATTEMPTS = 2;
1821
1842
  var DELIVERY_MAX_ATTEMPTS = 8;
@@ -1839,29 +1860,6 @@ function totalBase64Bytes(files) {
1839
1860
  function storageKeyFor(batchId, index) {
1840
1861
  return `${batchId}_${index}.bin`;
1841
1862
  }
1842
- function renderFilePickerSourceIcon(source) {
1843
- const Icon = FILE_PICKER_SOURCE_ICONS[source];
1844
- return createElement(
1845
- View,
1846
- { style: getFilePickerSourceIconStyle(source) },
1847
- createElement(Icon, {
1848
- color: FILE_PICKER_SOURCE_ICON_COLORS[source],
1849
- size: 23,
1850
- strokeWidth: 2.35
1851
- })
1852
- );
1853
- }
1854
- function getFilePickerSourceIconStyle(source) {
1855
- if (source === "camera") return [styles.sheetOptionIcon, styles.cameraOptionIcon];
1856
- if (source === "library") return [styles.sheetOptionIcon, styles.libraryOptionIcon];
1857
- return [styles.sheetOptionIcon, styles.documentsOptionIcon];
1858
- }
1859
- function getSheetOptionStyle(pressed) {
1860
- return [styles.sheetOption, pressed && styles.sheetOptionPressed];
1861
- }
1862
- function getSheetCancelStyle(pressed) {
1863
- return [styles.sheetCancelButton, pressed && styles.sheetCancelButtonPressed];
1864
- }
1865
1863
  function buildDispatchScript(messageLiteral) {
1866
1864
  return [
1867
1865
  "(function(){",
@@ -2112,35 +2110,70 @@ function SagepilotChatProvider({
2112
2110
  }, []);
2113
2111
  const runNativeFilePicker = useCallback((source, multiple) => {
2114
2112
  const filePicker = internalSagepilotChat.getConfig()?.filePicker;
2113
+ logNativeFilePicker("run_requested", {
2114
+ source,
2115
+ multiple,
2116
+ availableSources: filePicker?.sources ?? []
2117
+ });
2115
2118
  if (!filePicker) {
2119
+ warnNativeFilePicker("run_without_file_picker", { source });
2116
2120
  return;
2117
2121
  }
2118
2122
  if (pickerInFlightRef.current) {
2123
+ warnNativeFilePicker("run_ignored_picker_in_flight", { source });
2119
2124
  return;
2120
2125
  }
2121
- pauseLivenessAfterPicker(6e4);
2122
2126
  pickerInFlightRef.current = true;
2123
- filePicker.pickFiles({ source, multiple }).then((files) => {
2124
- if (files.length === 0) {
2125
- nativeWebViewRef.current?.injectJavaScript(buildFilePickerCancelledScript());
2126
- return;
2127
+ pauseLivenessAfterPicker(6e4);
2128
+ void (async () => {
2129
+ try {
2130
+ const files = await filePicker.pickFiles({ source, multiple });
2131
+ logNativeFilePicker("native_pick_resolved", { source, fileCount: files.length });
2132
+ if (files.length === 0) {
2133
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerCancelledScript());
2134
+ return;
2135
+ }
2136
+ queuePickedFiles(files);
2137
+ } catch (error) {
2138
+ const { message, code } = readFilePickerError(error);
2139
+ warnNativeFilePicker("native_pick_failed", { source, code, message });
2140
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(message, code));
2141
+ } finally {
2142
+ pickerInFlightRef.current = false;
2143
+ pauseLivenessAfterPicker(LIVENESS_PICKER_GRACE_MS);
2127
2144
  }
2128
- queuePickedFiles(files);
2129
- }).catch((error) => {
2130
- const { message, code } = readFilePickerError(error);
2131
- nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(message, code));
2132
- }).finally(() => {
2133
- pickerInFlightRef.current = false;
2134
- pauseLivenessAfterPicker(LIVENESS_PICKER_GRACE_MS);
2135
- });
2145
+ })();
2136
2146
  }, [pauseLivenessAfterPicker, queuePickedFiles]);
2137
- const openNativeFilePicker = useCallback((multiple) => {
2147
+ const openNativeFilePicker = useCallback((multiple, source) => {
2138
2148
  const filePicker = internalSagepilotChat.getConfig()?.filePicker;
2149
+ logNativeFilePicker("open_requested", {
2150
+ source: source ?? "source_chooser",
2151
+ multiple,
2152
+ hasFilePicker: Boolean(filePicker),
2153
+ availableSources: filePicker?.sources ?? []
2154
+ });
2139
2155
  if (!filePicker || filePicker.sources.length === 0) {
2156
+ warnNativeFilePicker("open_unavailable", { source: source ?? "source_chooser" });
2157
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(
2158
+ 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.",
2159
+ "camera_unavailable"
2160
+ ));
2161
+ return;
2162
+ }
2163
+ if (source) {
2164
+ if (filePicker.sources.includes(source)) {
2165
+ runNativeFilePicker(source, multiple);
2166
+ } else {
2167
+ warnNativeFilePicker("source_not_available", { source, availableSources: filePicker.sources });
2168
+ nativeWebViewRef.current?.injectJavaScript(buildFilePickerErrorScript(
2169
+ source === "camera" ? "CameraX is not available in this build." : `Native ${source} picker is not available in this build.`,
2170
+ "camera_unavailable"
2171
+ ));
2172
+ }
2140
2173
  return;
2141
2174
  }
2142
2175
  const [onlySource] = filePicker.sources;
2143
- if (filePicker.sources.length === 1 && onlySource && onlySource !== "camera") {
2176
+ if (filePicker.sources.length === 1 && onlySource) {
2144
2177
  runNativeFilePicker(onlySource, multiple);
2145
2178
  return;
2146
2179
  }
@@ -2320,7 +2353,11 @@ function SagepilotChatProvider({
2320
2353
  const handleWebViewMessage = (event) => {
2321
2354
  const message = parseHostedBridgeMessage(event.nativeEvent?.data);
2322
2355
  if (message?.type === "sagepilot:open_file_picker") {
2323
- openNativeFilePicker(message.multiple ?? true);
2356
+ logNativeFilePicker("bridge_message_open_file_picker", {
2357
+ source: message.source ?? "source_chooser",
2358
+ multiple: message.multiple ?? true
2359
+ });
2360
+ openNativeFilePicker(message.multiple ?? true, message.source);
2324
2361
  return;
2325
2362
  }
2326
2363
  if (message?.type === "sagepilot:widget_listener_ready") {
@@ -2538,7 +2575,6 @@ function SagepilotChatProvider({
2538
2575
  createElement(
2539
2576
  View,
2540
2577
  { style: styles.sheetCard },
2541
- createElement(View, { style: styles.sheetHandle }),
2542
2578
  createElement(Text, { style: styles.sheetTitle }, "Add attachment"),
2543
2579
  ...(internalSagepilotChat.getConfig()?.filePicker?.sources ?? []).map(
2544
2580
  (source) => createElement(
@@ -2546,29 +2582,19 @@ function SagepilotChatProvider({
2546
2582
  {
2547
2583
  key: source,
2548
2584
  accessibilityRole: "button",
2549
- android_ripple: { color: "rgba(15, 23, 42, 0.06)" },
2550
- hitSlop: 4,
2551
- style: ({ pressed }) => getSheetOptionStyle(pressed),
2585
+ style: styles.sheetButton,
2552
2586
  onPress: () => handleSourceChoice(source)
2553
2587
  },
2554
- renderFilePickerSourceIcon(source),
2555
- createElement(
2556
- View,
2557
- { style: styles.sheetOptionText },
2558
- createElement(Text, { style: styles.sheetButtonText }, FILE_PICKER_SOURCE_LABELS[source]),
2559
- createElement(Text, { style: styles.sheetButtonDescription }, FILE_PICKER_SOURCE_DESCRIPTIONS[source])
2560
- )
2588
+ createElement(Text, { style: styles.sheetButtonText }, FILE_PICKER_SOURCE_LABELS[source])
2561
2589
  )
2562
2590
  ),
2563
2591
  createElement(
2564
2592
  Pressable,
2565
2593
  {
2566
2594
  accessibilityRole: "button",
2567
- android_ripple: { color: "rgba(15, 23, 42, 0.06)" },
2568
- style: ({ pressed }) => getSheetCancelStyle(pressed),
2595
+ style: [styles.sheetButton, styles.sheetCancelButton],
2569
2596
  onPress: () => setSourceChooser(null)
2570
2597
  },
2571
- createElement(X, { color: "#334155", size: 18, strokeWidth: 2.5, style: styles.sheetCancelIcon }),
2572
2598
  createElement(Text, { style: styles.sheetCancelText }, "Cancel")
2573
2599
  )
2574
2600
  )
@@ -2674,109 +2700,43 @@ var styles = StyleSheet.create({
2674
2700
  },
2675
2701
  sheetBackdrop: {
2676
2702
  flex: 1,
2677
- alignItems: "center",
2678
2703
  justifyContent: "flex-end",
2679
- backgroundColor: "rgba(15, 23, 42, 0.48)"
2704
+ backgroundColor: "rgba(17, 24, 39, 0.36)"
2680
2705
  },
2681
2706
  sheetCard: {
2682
- width: "100%",
2683
- maxWidth: 540,
2684
2707
  backgroundColor: "#ffffff",
2685
- borderTopLeftRadius: 26,
2686
- borderTopRightRadius: 26,
2687
- paddingTop: 10,
2688
- paddingBottom: 18,
2689
- paddingHorizontal: 14,
2690
- shadowColor: "#0f172a",
2691
- shadowOpacity: 0.22,
2692
- shadowRadius: 28,
2693
- shadowOffset: { width: 0, height: -10 },
2694
- elevation: 18
2695
- },
2696
- sheetHandle: {
2697
- alignSelf: "center",
2698
- width: 42,
2699
- height: 5,
2700
- borderRadius: 999,
2701
- backgroundColor: "#d1d5db",
2702
- marginBottom: 14
2708
+ borderTopLeftRadius: 16,
2709
+ borderTopRightRadius: 16,
2710
+ paddingTop: 8,
2711
+ paddingBottom: 24,
2712
+ paddingHorizontal: 8
2703
2713
  },
2704
2714
  sheetTitle: {
2705
- color: "#111827",
2706
- fontSize: 17,
2707
- fontWeight: "700",
2708
- paddingBottom: 12,
2709
- paddingHorizontal: 4
2710
- },
2711
- sheetOption: {
2712
- minHeight: 70,
2713
- flexDirection: "row",
2714
- alignItems: "center",
2715
- borderRadius: 18,
2716
- paddingHorizontal: 12,
2717
- marginBottom: 6,
2718
- backgroundColor: "#ffffff"
2719
- },
2720
- sheetOptionPressed: {
2721
- backgroundColor: "#f8fafc",
2722
- transform: [{ scale: 0.985 }]
2715
+ textAlign: "center",
2716
+ color: "#6b7280",
2717
+ fontSize: 13,
2718
+ fontWeight: "600",
2719
+ paddingVertical: 10
2723
2720
  },
2724
- sheetOptionIcon: {
2725
- width: 46,
2726
- height: 46,
2727
- borderRadius: 16,
2728
- marginRight: 14,
2721
+ sheetButton: {
2722
+ minHeight: 52,
2729
2723
  alignItems: "center",
2730
2724
  justifyContent: "center",
2731
- position: "relative",
2732
- overflow: "hidden"
2733
- },
2734
- sheetOptionText: {
2735
- flex: 1,
2736
- justifyContent: "center"
2725
+ borderRadius: 12
2737
2726
  },
2738
2727
  sheetButtonText: {
2739
- color: "#0f172a",
2728
+ color: "#111827",
2740
2729
  fontSize: 16,
2741
- fontWeight: "700"
2742
- },
2743
- sheetButtonDescription: {
2744
- color: "#64748b",
2745
- fontSize: 13,
2746
- fontWeight: "500",
2747
- marginTop: 3
2748
- },
2749
- cameraOptionIcon: {
2750
- backgroundColor: "#e0f2fe"
2751
- },
2752
- libraryOptionIcon: {
2753
- backgroundColor: "#ecfdf5"
2754
- },
2755
- documentsOptionIcon: {
2756
- backgroundColor: "#f5f3ff"
2730
+ fontWeight: "500"
2757
2731
  },
2758
2732
  sheetCancelButton: {
2759
- minHeight: 56,
2760
- flexDirection: "row",
2761
- alignItems: "center",
2762
- justifyContent: "center",
2763
- borderRadius: 18,
2764
- marginTop: 8,
2765
- backgroundColor: "#f1f5f9"
2766
- },
2767
- sheetCancelButtonPressed: {
2768
- backgroundColor: "#e2e8f0",
2769
- transform: [{ scale: 0.985 }]
2770
- },
2771
- sheetCancelIcon: {
2772
- width: 18,
2773
- height: 18,
2774
- marginRight: 8
2733
+ marginTop: 6,
2734
+ backgroundColor: "#f3f4f6"
2775
2735
  },
2776
2736
  sheetCancelText: {
2777
- color: "#0f172a",
2737
+ color: "#111827",
2778
2738
  fontSize: 16,
2779
- fontWeight: "700"
2739
+ fontWeight: "600"
2780
2740
  }
2781
2741
  });
2782
2742
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagepilot-ai/react-native-sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Sagepilot AI React Native chat SDK",
5
5
  "keywords": [
6
6
  "sagepilot",
@@ -46,9 +46,6 @@
46
46
  "typecheck": "tsc --noEmit",
47
47
  "prepublishOnly": "npm run typecheck && npm run build"
48
48
  },
49
- "dependencies": {
50
- "lucide-react-native": "^1.21.0"
51
- },
52
49
  "peerDependencies": {
53
50
  "@react-native-async-storage/async-storage": ">=1.23",
54
51
  "@react-native-documents/picker": ">=10",