@kontextso/sdk-react-native 0.0.5-rc.5 → 0.0.5-rc.7

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.
Files changed (3) hide show
  1. package/dist/index.js +130 -80
  2. package/dist/index.mjs +102 -52
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39,14 +39,14 @@ __export(src_exports, {
39
39
  module.exports = __toCommonJS(src_exports);
40
40
 
41
41
  // src/formats/InlineAd.tsx
42
- var import_react11 = require("react");
42
+ var import_react12 = require("react");
43
43
  var import_react_native5 = require("react-native");
44
44
 
45
45
  // src/hooks/useAdViewed.tsx
46
- var import_react5 = require("react");
46
+ var import_react6 = require("react");
47
47
 
48
48
  // src/context/AdsProvider.tsx
49
- var import_react4 = __toESM(require("react"));
49
+ var import_react5 = __toESM(require("react"));
50
50
 
51
51
  // src/hooks/useInitializeAds.tsx
52
52
  var import_react = require("react");
@@ -201,7 +201,7 @@ var parseMessageText = (text) => {
201
201
  var import_loglevel = __toESM(require("loglevel"));
202
202
 
203
203
  // package.json
204
- var version = "0.0.5-rc.4";
204
+ var version = "0.0.5-rc.6";
205
205
 
206
206
  // src/hooks/useInitializeAds.tsx
207
207
  async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
@@ -301,7 +301,7 @@ function useInitializeAds({
301
301
  }
302
302
  }
303
303
  ).catch((e) => {
304
- import_loglevel.default.error("[BRAIN] Error initializing ads", e);
304
+ import_loglevel.default.warn("[BRAIN] Error initializing ads", e);
305
305
  setError(e.message);
306
306
  });
307
307
  } else {
@@ -382,8 +382,7 @@ function usePreloadAds({
382
382
  setPreloadDone(true);
383
383
  import_loglevel2.default.log("[BRAIN] preload ads finished");
384
384
  } catch (e) {
385
- import_loglevel2.default.error("[BRAIN] Error preloading ads", e);
386
- setPreloadDone(true);
385
+ import_loglevel2.default.warn("[BRAIN] Error preloading ads", e);
387
386
  }
388
387
  }
389
388
  preload();
@@ -624,7 +623,11 @@ if (import_react_native.Platform.OS !== "web") {
624
623
  patchFetch = require("react-native-fetch-api").fetch;
625
624
  }
626
625
  ErrorUtils.setGlobalHandler((error, isFatal) => {
627
- import_loglevel3.default.error(error);
626
+ if (!isFatal) {
627
+ import_loglevel3.default.warn(error);
628
+ } else {
629
+ import_loglevel3.default.error(error);
630
+ }
628
631
  });
629
632
  function useStreamAds({
630
633
  userId,
@@ -729,7 +732,7 @@ function useStreamAds({
729
732
  );
730
733
  import_loglevel3.default.log(`[BRAIN] streaming ${code} ad done`);
731
734
  } catch (e) {
732
- import_loglevel3.default.error("[BRAIN] Error streaming ad", e);
735
+ import_loglevel3.default.warn("[BRAIN] Error streaming ad", e);
733
736
  setAds((oldAds) => [...oldAds, { isError: true, code }]);
734
737
  }
735
738
  };
@@ -746,9 +749,54 @@ function useStreamAds({
746
749
  }
747
750
 
748
751
  // src/context/AdsProvider.tsx
752
+ var import_loglevel5 = __toESM(require("loglevel"));
753
+
754
+ // src/components/ErrorBoundary.tsx
755
+ var import_react4 = __toESM(require("react"));
749
756
  var import_loglevel4 = __toESM(require("loglevel"));
757
+ var captureErrorFn = (adServerUrl, error, componentStack, context) => {
758
+ fetch(`${adServerUrl}/error`, {
759
+ method: "POST",
760
+ body: JSON.stringify({
761
+ error: error?.message,
762
+ stack: componentStack,
763
+ context
764
+ })
765
+ }).catch((e) => {
766
+ import_loglevel4.default.warn("Error reporting client error", e);
767
+ }).finally(() => {
768
+ import_loglevel4.default.warn(error, componentStack);
769
+ });
770
+ };
771
+ var ErrorBoundary = class extends import_react4.default.Component {
772
+ constructor(props) {
773
+ super(props);
774
+ this.state = {
775
+ hasError: false
776
+ };
777
+ }
778
+ static getDerivedStateFromError() {
779
+ return {
780
+ hasError: true
781
+ };
782
+ }
783
+ componentDidCatch(error, info) {
784
+ const adServerUrl = this.props.adserverUrl;
785
+ if (adServerUrl) {
786
+ captureErrorFn(adServerUrl, error, info?.componentStack, this.props.reqBodyParams);
787
+ }
788
+ }
789
+ render() {
790
+ if (this.state.hasError) {
791
+ return this.props.fallback || null;
792
+ }
793
+ return this.props.children;
794
+ }
795
+ };
796
+
797
+ // src/context/AdsProvider.tsx
750
798
  var import_jsx_runtime = require("react/jsx-runtime");
751
- var AdsContext = import_react4.default.createContext(null);
799
+ var AdsContext = import_react5.default.createContext(null);
752
800
  AdsContext.displayName = "AdsContext";
753
801
  var VISITOR_ID_KEY = "brain-visitor-id";
754
802
  var AdsProviderWithoutBoundary = ({
@@ -766,9 +814,9 @@ var AdsProviderWithoutBoundary = ({
766
814
  onAdClick,
767
815
  ...props
768
816
  }) => {
769
- const [viewedAds, setViewedAds] = (0, import_react4.useState)([]);
817
+ const [viewedAds, setViewedAds] = (0, import_react5.useState)([]);
770
818
  const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
771
- import_loglevel4.default.setLevel(logLevel || "ERROR");
819
+ import_loglevel5.default.setLevel(logLevel || "ERROR");
772
820
  const {
773
821
  ads: initAds,
774
822
  sessionId,
@@ -816,7 +864,7 @@ var AdsProviderWithoutBoundary = ({
816
864
  throw new Error("Test error");
817
865
  }
818
866
  const markAdAsViewed = (ad) => {
819
- import_loglevel4.default.debug("[Brain] Calling onAdView");
867
+ import_loglevel5.default.debug("[Brain] Calling onAdView");
820
868
  onAdView && onAdView({
821
869
  id: ad.id,
822
870
  code: ad.code,
@@ -828,7 +876,7 @@ var AdsProviderWithoutBoundary = ({
828
876
  setViewedAds((old) => [...old, ad.id]);
829
877
  };
830
878
  const onAdClickInternal = (ad) => {
831
- import_loglevel4.default.debug("[Brain] Calling onAdClick");
879
+ import_loglevel5.default.debug("[Brain] Calling onAdClick");
832
880
  onAdClick && onAdClick({
833
881
  id: ad.id,
834
882
  code: ad.code,
@@ -876,47 +924,49 @@ var AdsProvider = ({
876
924
  onAdClick,
877
925
  ...props
878
926
  }) => {
879
- return (
880
- // <ErrorBoundary
881
- // fallback={children}
882
- // adserverUrl={adserverUrl}
883
- // reqBodyParams={{
884
- // publisherToken,
885
- // adserverUrl,
886
- // conversationId,
887
- // character,
888
- // userId,
889
- // isLoading,
890
- // messages
891
- // }}
892
- // >
893
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
894
- AdsProviderWithoutBoundary,
895
- {
896
- children,
897
- messages,
927
+ const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
928
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
929
+ ErrorBoundary,
930
+ {
931
+ fallback: children,
932
+ adserverUrl: adServerUrlOrDefault,
933
+ reqBodyParams: {
898
934
  publisherToken,
899
- isLoading,
900
935
  adserverUrl,
901
- isDisabled,
902
- character,
903
936
  conversationId,
937
+ character,
904
938
  userId,
905
- logLevel,
906
- onAdView,
907
- onAdClick,
908
- throwError: props.throwError
909
- }
910
- )
939
+ isLoading,
940
+ messages
941
+ },
942
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
943
+ AdsProviderWithoutBoundary,
944
+ {
945
+ children,
946
+ messages,
947
+ publisherToken,
948
+ isLoading,
949
+ adserverUrl,
950
+ isDisabled,
951
+ character,
952
+ conversationId,
953
+ userId,
954
+ logLevel,
955
+ onAdView,
956
+ onAdClick,
957
+ throwError: props.throwError
958
+ }
959
+ )
960
+ }
911
961
  );
912
962
  };
913
963
 
914
964
  // src/hooks/useAdViewed.tsx
915
- var import_react6 = require("react");
916
- var import_loglevel5 = __toESM(require("loglevel"));
965
+ var import_react7 = require("react");
966
+ var import_loglevel6 = __toESM(require("loglevel"));
917
967
  function useAdViewed(ad) {
918
- const context = (0, import_react6.useContext)(AdsContext);
919
- const [stillMounted, setStillMounted] = (0, import_react5.useState)(false);
968
+ const context = (0, import_react7.useContext)(AdsContext);
969
+ const [stillMounted, setStillMounted] = (0, import_react6.useState)(false);
920
970
  const sendRequest = async () => {
921
971
  if (!context?.adserverUrl || !ad?.id) {
922
972
  return;
@@ -933,48 +983,48 @@ function useAdViewed(ad) {
933
983
  if (!response.ok) {
934
984
  throw new Error("Error sending view request");
935
985
  }
936
- import_loglevel5.default.log("[BRAIN] ad marked as viewed", ad.id, ad.code);
986
+ import_loglevel6.default.log("[BRAIN] ad marked as viewed", ad.id, ad.code);
937
987
  } catch (e) {
938
- import_loglevel5.default.error("[BRAIN] Error sending view request", e);
988
+ import_loglevel6.default.warn("[BRAIN] Error sending view request", e);
939
989
  }
940
990
  };
941
- (0, import_react5.useEffect)(() => {
991
+ (0, import_react6.useEffect)(() => {
942
992
  if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
943
993
  return;
944
994
  }
945
- import_loglevel5.default.log("[BRAIN] setting timeout", ad.id, ad.code);
995
+ import_loglevel6.default.log("[BRAIN] setting timeout", ad.id, ad.code);
946
996
  setTimeout(() => {
947
- import_loglevel5.default.log("[BRAIN] setting setStillMounted", ad.id, ad.code);
997
+ import_loglevel6.default.log("[BRAIN] setting setStillMounted", ad.id, ad.code);
948
998
  setStillMounted(true);
949
999
  }, 1e3);
950
1000
  }, [ad]);
951
- (0, import_react5.useEffect)(() => {
1001
+ (0, import_react6.useEffect)(() => {
952
1002
  if (stillMounted) {
953
- import_loglevel5.default.log("[BRAIN] sending request");
1003
+ import_loglevel6.default.log("[BRAIN] sending request");
954
1004
  sendRequest();
955
1005
  }
956
1006
  }, [stillMounted]);
957
1007
  }
958
1008
 
959
1009
  // src/formats/InlineAd.tsx
960
- var import_loglevel8 = __toESM(require("loglevel"));
1010
+ var import_loglevel9 = __toESM(require("loglevel"));
961
1011
 
962
1012
  // src/components/MarkdownText.tsx
963
- var import_loglevel6 = __toESM(require("loglevel"));
964
- var import_react7 = require("react");
1013
+ var import_loglevel7 = __toESM(require("loglevel"));
1014
+ var import_react8 = require("react");
965
1015
  var import_react_native2 = require("react-native");
966
1016
  var import_jsx_runtime2 = require("react/jsx-runtime");
967
1017
  function MarkdownText({
968
1018
  content,
969
1019
  onLinkClick
970
1020
  }) {
971
- const context = (0, import_react7.useContext)(AdsContext);
1021
+ const context = (0, import_react8.useContext)(AdsContext);
972
1022
  const textParts = parseMessageText(content);
973
1023
  const styles = context?.styles?.markdownText;
974
1024
  const linkClickHandler = (href) => {
975
1025
  onLinkClick();
976
1026
  import_react_native2.Linking.openURL(href).catch(
977
- (err) => import_loglevel6.default.error("Failed to open URL:", err)
1027
+ (err) => import_loglevel7.default.warn("Failed to open URL:", err)
978
1028
  );
979
1029
  return false;
980
1030
  };
@@ -1001,18 +1051,18 @@ function MarkdownText({
1001
1051
 
1002
1052
  // src/components/VideoPlayer.tsx
1003
1053
  var import_expo_av = require("expo-av");
1004
- var import_loglevel7 = __toESM(require("loglevel"));
1005
- var import_react9 = require("react");
1054
+ var import_loglevel8 = __toESM(require("loglevel"));
1055
+ var import_react10 = require("react");
1006
1056
  var import_react_native4 = require("react-native");
1007
1057
 
1008
1058
  // src/components/VideoProgressBar.tsx
1009
- var import_react8 = require("react");
1059
+ var import_react9 = require("react");
1010
1060
  var import_react_native3 = require("react-native");
1011
1061
  var import_jsx_runtime3 = require("react/jsx-runtime");
1012
1062
  function VideoProgressBar({ videoRef }) {
1013
- const [progress, setProgress] = (0, import_react8.useState)(0);
1014
- const styles = (0, import_react8.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
1015
- (0, import_react8.useEffect)(() => {
1063
+ const [progress, setProgress] = (0, import_react9.useState)(0);
1064
+ const styles = (0, import_react9.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
1065
+ (0, import_react9.useEffect)(() => {
1016
1066
  const interval = setInterval(() => {
1017
1067
  if (!videoRef.current) {
1018
1068
  return;
@@ -1045,14 +1095,14 @@ var VideoPlayer = ({
1045
1095
  mediaPlacement,
1046
1096
  onLinkClick
1047
1097
  }) => {
1048
- const videoRef = (0, import_react9.useRef)(null);
1049
- const [isPlaying, setIsPlaying] = (0, import_react9.useState)(false);
1050
- const [isPaused, setIsPaused] = (0, import_react9.useState)(true);
1051
- const [isEnded, setIsEnded] = (0, import_react9.useState)(false);
1052
- const [showDownloadBadge, setShowDownloadBadge] = (0, import_react9.useState)(false);
1053
- const lastCallbackTimeRef = (0, import_react9.useRef)(0);
1054
- const styles = (0, import_react9.useContext)(AdsContext)?.styles?.videoPlayer;
1055
- (0, import_react9.useEffect)(() => {
1098
+ const videoRef = (0, import_react10.useRef)(null);
1099
+ const [isPlaying, setIsPlaying] = (0, import_react10.useState)(false);
1100
+ const [isPaused, setIsPaused] = (0, import_react10.useState)(true);
1101
+ const [isEnded, setIsEnded] = (0, import_react10.useState)(false);
1102
+ const [showDownloadBadge, setShowDownloadBadge] = (0, import_react10.useState)(false);
1103
+ const lastCallbackTimeRef = (0, import_react10.useRef)(0);
1104
+ const styles = (0, import_react10.useContext)(AdsContext)?.styles?.videoPlayer;
1105
+ (0, import_react10.useEffect)(() => {
1056
1106
  const interval = setInterval(() => {
1057
1107
  if (videoRef.current) {
1058
1108
  videoRef.current.getStatusAsync().then((status) => {
@@ -1096,7 +1146,7 @@ var VideoPlayer = ({
1096
1146
  };
1097
1147
  const handleLinkClick = (url) => {
1098
1148
  if (url) {
1099
- import_react_native4.Linking.openURL(url).catch((err) => import_loglevel7.default.error("Failed to open URL:", err));
1149
+ import_react_native4.Linking.openURL(url).catch((err) => import_loglevel8.default.warn("Failed to open URL:", err));
1100
1150
  onLinkClick();
1101
1151
  }
1102
1152
  };
@@ -1135,9 +1185,9 @@ var VideoPlayer = ({
1135
1185
  };
1136
1186
 
1137
1187
  // src/hooks/useAd.tsx
1138
- var import_react10 = require("react");
1188
+ var import_react11 = require("react");
1139
1189
  function useAd({ code, messageId }) {
1140
- const context = (0, import_react10.useContext)(AdsContext);
1190
+ const context = (0, import_react11.useContext)(AdsContext);
1141
1191
  if (!context) {
1142
1192
  return null;
1143
1193
  }
@@ -1185,11 +1235,11 @@ function useAd({ code, messageId }) {
1185
1235
  var import_jsx_runtime5 = require("react/jsx-runtime");
1186
1236
  var InlineAd = ({ code, messageId, wrapper }) => {
1187
1237
  const ad = useAd({ code, messageId });
1188
- const [linkIncluded, setLinkIncluded] = (0, import_react11.useState)(false);
1189
- const context = (0, import_react11.useContext)(AdsContext);
1238
+ const [linkIncluded, setLinkIncluded] = (0, import_react12.useState)(false);
1239
+ const context = (0, import_react12.useContext)(AdsContext);
1190
1240
  const styles = context?.styles?.inlineAd;
1191
1241
  useAdViewed(ad);
1192
- (0, import_react11.useEffect)(() => {
1242
+ (0, import_react12.useEffect)(() => {
1193
1243
  if (ad?.content && !ad.isStreaming && !ad.content.match(/\[.*?\]\(.*?\)/) && !linkIncluded) {
1194
1244
  setLinkIncluded(true);
1195
1245
  }
@@ -1198,7 +1248,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
1198
1248
  if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
1199
1249
  return null;
1200
1250
  const onProgress = (progress) => {
1201
- import_loglevel8.default.log(`Progress: ${progress}`);
1251
+ import_loglevel9.default.log(`Progress: ${progress}`);
1202
1252
  };
1203
1253
  const handleImageClick = (url) => {
1204
1254
  if (url) {
@@ -1207,7 +1257,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
1207
1257
  window.open(url, "_blank");
1208
1258
  } else {
1209
1259
  import_react_native5.Linking.openURL(url).catch(
1210
- (err) => import_loglevel8.default.error("Failed to open URL:", err)
1260
+ (err) => import_loglevel9.default.warn("Failed to open URL:", err)
1211
1261
  );
1212
1262
  }
1213
1263
  }
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  import { useEffect as useEffect5, useState as useState5 } from "react";
21
21
 
22
22
  // src/context/AdsProvider.tsx
23
- import React, { useState as useState4 } from "react";
23
+ import React2, { useState as useState4 } from "react";
24
24
 
25
25
  // src/hooks/useInitializeAds.tsx
26
26
  import { useEffect, useState } from "react";
@@ -175,7 +175,7 @@ var parseMessageText = (text) => {
175
175
  import log from "loglevel";
176
176
 
177
177
  // package.json
178
- var version = "0.0.5-rc.4";
178
+ var version = "0.0.5-rc.6";
179
179
 
180
180
  // src/hooks/useInitializeAds.tsx
181
181
  async function initialize(adServerUrl, publisherToken, userId, conversationId, legacyVisitorId, character) {
@@ -275,7 +275,7 @@ function useInitializeAds({
275
275
  }
276
276
  }
277
277
  ).catch((e) => {
278
- log.error("[BRAIN] Error initializing ads", e);
278
+ log.warn("[BRAIN] Error initializing ads", e);
279
279
  setError(e.message);
280
280
  });
281
281
  } else {
@@ -356,8 +356,7 @@ function usePreloadAds({
356
356
  setPreloadDone(true);
357
357
  log2.log("[BRAIN] preload ads finished");
358
358
  } catch (e) {
359
- log2.error("[BRAIN] Error preloading ads", e);
360
- setPreloadDone(true);
359
+ log2.warn("[BRAIN] Error preloading ads", e);
361
360
  }
362
361
  }
363
362
  preload();
@@ -598,7 +597,11 @@ if (Platform.OS !== "web") {
598
597
  patchFetch = __require("react-native-fetch-api").fetch;
599
598
  }
600
599
  ErrorUtils.setGlobalHandler((error, isFatal) => {
601
- log3.error(error);
600
+ if (!isFatal) {
601
+ log3.warn(error);
602
+ } else {
603
+ log3.error(error);
604
+ }
602
605
  });
603
606
  function useStreamAds({
604
607
  userId,
@@ -703,7 +706,7 @@ function useStreamAds({
703
706
  );
704
707
  log3.log(`[BRAIN] streaming ${code} ad done`);
705
708
  } catch (e) {
706
- log3.error("[BRAIN] Error streaming ad", e);
709
+ log3.warn("[BRAIN] Error streaming ad", e);
707
710
  setAds((oldAds) => [...oldAds, { isError: true, code }]);
708
711
  }
709
712
  };
@@ -720,9 +723,54 @@ function useStreamAds({
720
723
  }
721
724
 
722
725
  // src/context/AdsProvider.tsx
726
+ import log5 from "loglevel";
727
+
728
+ // src/components/ErrorBoundary.tsx
729
+ import React from "react";
723
730
  import log4 from "loglevel";
731
+ var captureErrorFn = (adServerUrl, error, componentStack, context) => {
732
+ fetch(`${adServerUrl}/error`, {
733
+ method: "POST",
734
+ body: JSON.stringify({
735
+ error: error?.message,
736
+ stack: componentStack,
737
+ context
738
+ })
739
+ }).catch((e) => {
740
+ log4.warn("Error reporting client error", e);
741
+ }).finally(() => {
742
+ log4.warn(error, componentStack);
743
+ });
744
+ };
745
+ var ErrorBoundary = class extends React.Component {
746
+ constructor(props) {
747
+ super(props);
748
+ this.state = {
749
+ hasError: false
750
+ };
751
+ }
752
+ static getDerivedStateFromError() {
753
+ return {
754
+ hasError: true
755
+ };
756
+ }
757
+ componentDidCatch(error, info) {
758
+ const adServerUrl = this.props.adserverUrl;
759
+ if (adServerUrl) {
760
+ captureErrorFn(adServerUrl, error, info?.componentStack, this.props.reqBodyParams);
761
+ }
762
+ }
763
+ render() {
764
+ if (this.state.hasError) {
765
+ return this.props.fallback || null;
766
+ }
767
+ return this.props.children;
768
+ }
769
+ };
770
+
771
+ // src/context/AdsProvider.tsx
724
772
  import { jsx } from "react/jsx-runtime";
725
- var AdsContext = React.createContext(null);
773
+ var AdsContext = React2.createContext(null);
726
774
  AdsContext.displayName = "AdsContext";
727
775
  var VISITOR_ID_KEY = "brain-visitor-id";
728
776
  var AdsProviderWithoutBoundary = ({
@@ -742,7 +790,7 @@ var AdsProviderWithoutBoundary = ({
742
790
  }) => {
743
791
  const [viewedAds, setViewedAds] = useState4([]);
744
792
  const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
745
- log4.setLevel(logLevel || "ERROR");
793
+ log5.setLevel(logLevel || "ERROR");
746
794
  const {
747
795
  ads: initAds,
748
796
  sessionId,
@@ -790,7 +838,7 @@ var AdsProviderWithoutBoundary = ({
790
838
  throw new Error("Test error");
791
839
  }
792
840
  const markAdAsViewed = (ad) => {
793
- log4.debug("[Brain] Calling onAdView");
841
+ log5.debug("[Brain] Calling onAdView");
794
842
  onAdView && onAdView({
795
843
  id: ad.id,
796
844
  code: ad.code,
@@ -802,7 +850,7 @@ var AdsProviderWithoutBoundary = ({
802
850
  setViewedAds((old) => [...old, ad.id]);
803
851
  };
804
852
  const onAdClickInternal = (ad) => {
805
- log4.debug("[Brain] Calling onAdClick");
853
+ log5.debug("[Brain] Calling onAdClick");
806
854
  onAdClick && onAdClick({
807
855
  id: ad.id,
808
856
  code: ad.code,
@@ -850,44 +898,46 @@ var AdsProvider = ({
850
898
  onAdClick,
851
899
  ...props
852
900
  }) => {
853
- return (
854
- // <ErrorBoundary
855
- // fallback={children}
856
- // adserverUrl={adserverUrl}
857
- // reqBodyParams={{
858
- // publisherToken,
859
- // adserverUrl,
860
- // conversationId,
861
- // character,
862
- // userId,
863
- // isLoading,
864
- // messages
865
- // }}
866
- // >
867
- /* @__PURE__ */ jsx(
868
- AdsProviderWithoutBoundary,
869
- {
870
- children,
871
- messages,
901
+ const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
902
+ return /* @__PURE__ */ jsx(
903
+ ErrorBoundary,
904
+ {
905
+ fallback: children,
906
+ adserverUrl: adServerUrlOrDefault,
907
+ reqBodyParams: {
872
908
  publisherToken,
873
- isLoading,
874
909
  adserverUrl,
875
- isDisabled,
876
- character,
877
910
  conversationId,
911
+ character,
878
912
  userId,
879
- logLevel,
880
- onAdView,
881
- onAdClick,
882
- throwError: props.throwError
883
- }
884
- )
913
+ isLoading,
914
+ messages
915
+ },
916
+ children: /* @__PURE__ */ jsx(
917
+ AdsProviderWithoutBoundary,
918
+ {
919
+ children,
920
+ messages,
921
+ publisherToken,
922
+ isLoading,
923
+ adserverUrl,
924
+ isDisabled,
925
+ character,
926
+ conversationId,
927
+ userId,
928
+ logLevel,
929
+ onAdView,
930
+ onAdClick,
931
+ throwError: props.throwError
932
+ }
933
+ )
934
+ }
885
935
  );
886
936
  };
887
937
 
888
938
  // src/hooks/useAdViewed.tsx
889
939
  import { useContext } from "react";
890
- import log5 from "loglevel";
940
+ import log6 from "loglevel";
891
941
  function useAdViewed(ad) {
892
942
  const context = useContext(AdsContext);
893
943
  const [stillMounted, setStillMounted] = useState5(false);
@@ -907,34 +957,34 @@ function useAdViewed(ad) {
907
957
  if (!response.ok) {
908
958
  throw new Error("Error sending view request");
909
959
  }
910
- log5.log("[BRAIN] ad marked as viewed", ad.id, ad.code);
960
+ log6.log("[BRAIN] ad marked as viewed", ad.id, ad.code);
911
961
  } catch (e) {
912
- log5.error("[BRAIN] Error sending view request", e);
962
+ log6.warn("[BRAIN] Error sending view request", e);
913
963
  }
914
964
  };
915
965
  useEffect5(() => {
916
966
  if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
917
967
  return;
918
968
  }
919
- log5.log("[BRAIN] setting timeout", ad.id, ad.code);
969
+ log6.log("[BRAIN] setting timeout", ad.id, ad.code);
920
970
  setTimeout(() => {
921
- log5.log("[BRAIN] setting setStillMounted", ad.id, ad.code);
971
+ log6.log("[BRAIN] setting setStillMounted", ad.id, ad.code);
922
972
  setStillMounted(true);
923
973
  }, 1e3);
924
974
  }, [ad]);
925
975
  useEffect5(() => {
926
976
  if (stillMounted) {
927
- log5.log("[BRAIN] sending request");
977
+ log6.log("[BRAIN] sending request");
928
978
  sendRequest();
929
979
  }
930
980
  }, [stillMounted]);
931
981
  }
932
982
 
933
983
  // src/formats/InlineAd.tsx
934
- import log8 from "loglevel";
984
+ import log9 from "loglevel";
935
985
 
936
986
  // src/components/MarkdownText.tsx
937
- import log6 from "loglevel";
987
+ import log7 from "loglevel";
938
988
  import { useContext as useContext2 } from "react";
939
989
  import {
940
990
  Linking,
@@ -951,7 +1001,7 @@ function MarkdownText({
951
1001
  const linkClickHandler = (href) => {
952
1002
  onLinkClick();
953
1003
  Linking.openURL(href).catch(
954
- (err) => log6.error("Failed to open URL:", err)
1004
+ (err) => log7.warn("Failed to open URL:", err)
955
1005
  );
956
1006
  return false;
957
1007
  };
@@ -978,7 +1028,7 @@ function MarkdownText({
978
1028
 
979
1029
  // src/components/VideoPlayer.tsx
980
1030
  import { ResizeMode, Video } from "expo-av";
981
- import log7 from "loglevel";
1031
+ import log8 from "loglevel";
982
1032
  import { useContext as useContext4, useEffect as useEffect7, useRef, useState as useState7 } from "react";
983
1033
  import { Linking as Linking2, Text as Text2, TouchableOpacity, View as View2 } from "react-native";
984
1034
 
@@ -1073,7 +1123,7 @@ var VideoPlayer = ({
1073
1123
  };
1074
1124
  const handleLinkClick = (url) => {
1075
1125
  if (url) {
1076
- Linking2.openURL(url).catch((err) => log7.error("Failed to open URL:", err));
1126
+ Linking2.openURL(url).catch((err) => log8.warn("Failed to open URL:", err));
1077
1127
  onLinkClick();
1078
1128
  }
1079
1129
  };
@@ -1175,7 +1225,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
1175
1225
  if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
1176
1226
  return null;
1177
1227
  const onProgress = (progress) => {
1178
- log8.log(`Progress: ${progress}`);
1228
+ log9.log(`Progress: ${progress}`);
1179
1229
  };
1180
1230
  const handleImageClick = (url) => {
1181
1231
  if (url) {
@@ -1184,7 +1234,7 @@ var InlineAd = ({ code, messageId, wrapper }) => {
1184
1234
  window.open(url, "_blank");
1185
1235
  } else {
1186
1236
  Linking3.openURL(url).catch(
1187
- (err) => log8.error("Failed to open URL:", err)
1237
+ (err) => log9.warn("Failed to open URL:", err)
1188
1238
  );
1189
1239
  }
1190
1240
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "0.0.5-rc.5",
3
+ "version": "0.0.5-rc.7",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",