@kontextso/sdk-react-native 0.0.7-rc.1 → 0.0.7-rc.4

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.d.mts CHANGED
@@ -142,6 +142,7 @@ interface AdsProviderProps {
142
142
  logLevel?: any;
143
143
  conversationId: string;
144
144
  styles?: AdStyles;
145
+ experimentErrorBoundary?: 'provider' | 'hook' | 'inlinead-top' | 'inlinead-content' | 'markdowntext' | 'log' | 'none';
145
146
  }
146
147
  declare const VISITOR_ID_KEY = "brain-visitor-id";
147
148
  declare const AdsProvider: ({ children, messages, publisherToken, isLoading, adserverUrl, isDisabled, character, conversationId, userId, logLevel, onAdView, onAdClick, ...props }: AdsProviderProps) => react_jsx_runtime.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -142,6 +142,7 @@ interface AdsProviderProps {
142
142
  logLevel?: any;
143
143
  conversationId: string;
144
144
  styles?: AdStyles;
145
+ experimentErrorBoundary?: 'provider' | 'hook' | 'inlinead-top' | 'inlinead-content' | 'markdowntext' | 'log' | 'none';
145
146
  }
146
147
  declare const VISITOR_ID_KEY = "brain-visitor-id";
147
148
  declare const AdsProvider: ({ children, messages, publisherToken, isLoading, adserverUrl, isDisabled, character, conversationId, userId, logLevel, onAdView, onAdClick, ...props }: AdsProviderProps) => react_jsx_runtime.JSX.Element;
package/dist/index.js CHANGED
@@ -39,19 +39,20 @@ __export(src_exports, {
39
39
  module.exports = __toCommonJS(src_exports);
40
40
 
41
41
  // src/formats/InlineAd.tsx
42
- var import_react12 = require("react");
42
+ var import_react13 = require("react");
43
43
  var import_react_native5 = require("react-native");
44
44
 
45
45
  // src/hooks/useAdViewed.tsx
46
- var import_react6 = require("react");
46
+ var import_react7 = require("react");
47
47
 
48
48
  // src/context/AdsProvider.tsx
49
- var import_react5 = __toESM(require("react"));
49
+ var import_react6 = __toESM(require("react"));
50
50
 
51
51
  // src/hooks/useInitializeAds.tsx
52
- var import_react = require("react");
52
+ var import_react2 = require("react");
53
53
 
54
54
  // src/utils.ts
55
+ var import_react = require("react");
55
56
  var UNRETRIABLE_ERRORS = [403, 429];
56
57
  var fetchWithTimeout = async (input, init) => {
57
58
  const { timeout = 16e3 } = init || {};
@@ -158,6 +159,17 @@ function mergeStyles(propStyles, defaultStyles, overridingStyles) {
158
159
  mergedStyles = deepMerge(mergedStyles, overridingStyles || {});
159
160
  return mergedStyles;
160
161
  }
162
+ var useTestError = (boundarySetting, errorPosition, shouldThrow, delay) => {
163
+ const [throwError, setThrowError] = (0, import_react.useState)(false);
164
+ (0, import_react.useEffect)(() => {
165
+ setTimeout(() => {
166
+ setThrowError(true);
167
+ }, delay);
168
+ }, []);
169
+ if (boundarySetting === errorPosition && throwError && shouldThrow) {
170
+ throw new Error("test");
171
+ }
172
+ };
161
173
  var parseMessageText = (text) => {
162
174
  const parts = [];
163
175
  let start = 0;
@@ -277,7 +289,7 @@ var log = new Logger();
277
289
  var log_default = log;
278
290
 
279
291
  // package.json
280
- var version = "0.0.7-rc.1";
292
+ var version = "0.0.7-rc.3";
281
293
 
282
294
  // src/hooks/useInitializeAds.tsx
283
295
  var SINGLE_INIT_TIMEOUT_BUDGET_MS = 3e3;
@@ -336,17 +348,19 @@ function useInitializeAds({
336
348
  conversationId,
337
349
  isDisabled,
338
350
  character,
339
- legacyVisitorId
351
+ legacyVisitorId,
352
+ experimentErrorBoundary
340
353
  }) {
341
- const [enabledPlacements, setEnabledPlacements] = (0, import_react.useState)([]);
342
- const [ads, setAds] = (0, import_react.useState)([]);
343
- const [error, setError] = (0, import_react.useState)();
344
- const [streamAdServerUrl, setStreamAdServerUrl] = (0, import_react.useState)();
345
- const [onlyStream, setOnlyStream] = (0, import_react.useState)(false);
346
- const [sessionId, setSessionId] = (0, import_react.useState)();
347
- const [defaultReactNativeStyles, setDefaultReactNativeStyles] = (0, import_react.useState)();
348
- const [overridingReactNativeStyles, setOverridingReactNativeStyles] = (0, import_react.useState)();
349
- (0, import_react.useEffect)(() => {
354
+ const [enabledPlacements, setEnabledPlacements] = (0, import_react2.useState)([]);
355
+ const [ads, setAds] = (0, import_react2.useState)([]);
356
+ const [error, setError] = (0, import_react2.useState)();
357
+ const [streamAdServerUrl, setStreamAdServerUrl] = (0, import_react2.useState)();
358
+ const [onlyStream, setOnlyStream] = (0, import_react2.useState)(false);
359
+ const [sessionId, setSessionId] = (0, import_react2.useState)();
360
+ const [defaultReactNativeStyles, setDefaultReactNativeStyles] = (0, import_react2.useState)();
361
+ const [overridingReactNativeStyles, setOverridingReactNativeStyles] = (0, import_react2.useState)();
362
+ useTestError(experimentErrorBoundary, "hook", true, 2e3);
363
+ (0, import_react2.useEffect)(() => {
350
364
  log_default.setRemoteLevel("debug");
351
365
  log_default.configureRemote(adServerUrl, {
352
366
  publisherToken,
@@ -426,7 +440,7 @@ function useInitializeAds({
426
440
  }
427
441
 
428
442
  // src/hooks/usePreloadAds.tsx
429
- var import_react2 = require("react");
443
+ var import_react3 = require("react");
430
444
  function usePreloadAds({
431
445
  userId,
432
446
  sessionId,
@@ -437,10 +451,10 @@ function usePreloadAds({
437
451
  character,
438
452
  onlyStream
439
453
  }) {
440
- const [preloadDone, setPreloadDone] = (0, import_react2.useState)(false);
441
- const [ads, setAds] = (0, import_react2.useState)([]);
454
+ const [preloadDone, setPreloadDone] = (0, import_react3.useState)(false);
455
+ const [ads, setAds] = (0, import_react3.useState)([]);
442
456
  const userMessagesContent = messages.filter((m) => m.role === "user").map((m) => m.content).join(" ");
443
- (0, import_react2.useEffect)(() => {
457
+ (0, import_react3.useEffect)(() => {
444
458
  if (onlyStream) {
445
459
  setPreloadDone(true);
446
460
  log_default.log("[BRAIN] skipping preload ads");
@@ -489,7 +503,7 @@ function usePreloadAds({
489
503
  }
490
504
 
491
505
  // src/hooks/useStreamAds.tsx
492
- var import_react3 = require("react");
506
+ var import_react4 = require("react");
493
507
 
494
508
  // src/hooks/data-stream.ts
495
509
  var textStreamPart = {
@@ -738,7 +752,7 @@ function useStreamAds({
738
752
  character,
739
753
  publisherToken
740
754
  }) {
741
- const [ads, setAds] = (0, import_react3.useState)([]);
755
+ const [ads, setAds] = (0, import_react4.useState)([]);
742
756
  const fetchStream = async (messages2, code) => {
743
757
  const lastAssistantMessage = [...messages2].reverse().find((m) => m.role === "assistant");
744
758
  if (!lastAssistantMessage) {
@@ -833,7 +847,7 @@ function useStreamAds({
833
847
  setAds((oldAds) => [...oldAds, { isError: true, code }]);
834
848
  }
835
849
  };
836
- (0, import_react3.useEffect)(() => {
850
+ (0, import_react4.useEffect)(() => {
837
851
  if (!isLoading && sessionId && messages.length > 2 && messages[messages.length - 1]?.role === "assistant" && preloadDone) {
838
852
  enabledPlacements.forEach((placement) => {
839
853
  if (["QUERY_STREAM", "INLINE_AD", "BOX_AD"].includes(placement.format)) {
@@ -846,7 +860,7 @@ function useStreamAds({
846
860
  }
847
861
 
848
862
  // src/components/ErrorBoundary.tsx
849
- var import_react4 = __toESM(require("react"));
863
+ var import_react5 = __toESM(require("react"));
850
864
  var captureErrorFn = (adServerUrl, error, componentStack, context) => {
851
865
  fetch(`${adServerUrl}/error`, {
852
866
  method: "POST",
@@ -859,7 +873,7 @@ var captureErrorFn = (adServerUrl, error, componentStack, context) => {
859
873
  log_default.warn("Error reporting client error", e);
860
874
  });
861
875
  };
862
- var ErrorBoundary = class extends import_react4.default.Component {
876
+ var ErrorBoundary = class extends import_react5.default.Component {
863
877
  constructor(props) {
864
878
  super(props);
865
879
  this.state = {
@@ -887,7 +901,7 @@ var ErrorBoundary = class extends import_react4.default.Component {
887
901
 
888
902
  // src/context/AdsProvider.tsx
889
903
  var import_jsx_runtime = require("react/jsx-runtime");
890
- var AdsContext = import_react5.default.createContext(null);
904
+ var AdsContext = import_react6.default.createContext(null);
891
905
  AdsContext.displayName = "AdsContext";
892
906
  var VISITOR_ID_KEY = "brain-visitor-id";
893
907
  var AdsProviderWithoutBoundary = ({
@@ -905,8 +919,8 @@ var AdsProviderWithoutBoundary = ({
905
919
  onAdClick,
906
920
  ...props
907
921
  }) => {
908
- const [viewedAds, setViewedAds] = (0, import_react5.useState)([]);
909
- const [clickedAds, setClickedAds] = (0, import_react5.useState)([]);
922
+ const [viewedAds, setViewedAds] = (0, import_react6.useState)([]);
923
+ const [clickedAds, setClickedAds] = (0, import_react6.useState)([]);
910
924
  const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
911
925
  log_default.setLocalLevel(logLevel || "silent");
912
926
  const {
@@ -925,7 +939,8 @@ var AdsProviderWithoutBoundary = ({
925
939
  legacyVisitorId: void 0,
926
940
  conversationId,
927
941
  character,
928
- isDisabled: !!isDisabled
942
+ isDisabled: !!isDisabled,
943
+ experimentErrorBoundary: props.experimentErrorBoundary
929
944
  });
930
945
  const styles = mergeStyles(props.styles, defaultReactNativeStyles, overridingReactNativeStyles);
931
946
  const isInitialised = !!isDisabled || !!error || !!sessionId;
@@ -980,6 +995,7 @@ var AdsProviderWithoutBoundary = ({
980
995
  }
981
996
  setClickedAds((old) => [...old, ad.id]);
982
997
  };
998
+ useTestError(props.experimentErrorBoundary, "provider", true, 2e3);
983
999
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
984
1000
  AdsContext.Provider,
985
1001
  {
@@ -1000,7 +1016,8 @@ var AdsProviderWithoutBoundary = ({
1000
1016
  userId,
1001
1017
  markAdAsViewed,
1002
1018
  onlyStream,
1003
- styles
1019
+ styles,
1020
+ experimentErrorBoundary: props.experimentErrorBoundary
1004
1021
  },
1005
1022
  children
1006
1023
  }
@@ -1050,7 +1067,8 @@ var AdsProvider = ({
1050
1067
  userId,
1051
1068
  logLevel,
1052
1069
  onAdView,
1053
- onAdClick
1070
+ onAdClick,
1071
+ ...props
1054
1072
  }
1055
1073
  )
1056
1074
  }
@@ -1058,10 +1076,10 @@ var AdsProvider = ({
1058
1076
  };
1059
1077
 
1060
1078
  // src/hooks/useAdViewed.tsx
1061
- var import_react7 = require("react");
1079
+ var import_react8 = require("react");
1062
1080
  function useAdViewed(ad) {
1063
- const context = (0, import_react7.useContext)(AdsContext);
1064
- const [stillMounted, setStillMounted] = (0, import_react6.useState)(false);
1081
+ const context = (0, import_react8.useContext)(AdsContext);
1082
+ const [stillMounted, setStillMounted] = (0, import_react7.useState)(false);
1065
1083
  const sendRequest = async () => {
1066
1084
  if (!context?.adserverUrl || !ad?.id) {
1067
1085
  return;
@@ -1083,7 +1101,7 @@ function useAdViewed(ad) {
1083
1101
  log_default.warn("[BRAIN] Error sending view request", e);
1084
1102
  }
1085
1103
  };
1086
- (0, import_react6.useEffect)(() => {
1104
+ (0, import_react7.useEffect)(() => {
1087
1105
  if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
1088
1106
  return;
1089
1107
  }
@@ -1093,7 +1111,7 @@ function useAdViewed(ad) {
1093
1111
  setStillMounted(true);
1094
1112
  }, 1e3);
1095
1113
  }, [ad]);
1096
- (0, import_react6.useEffect)(() => {
1114
+ (0, import_react7.useEffect)(() => {
1097
1115
  if (stillMounted) {
1098
1116
  log_default.log("[BRAIN] sending request");
1099
1117
  sendRequest();
@@ -1102,16 +1120,17 @@ function useAdViewed(ad) {
1102
1120
  }
1103
1121
 
1104
1122
  // src/components/MarkdownText.tsx
1105
- var import_react8 = require("react");
1123
+ var import_react9 = require("react");
1106
1124
  var import_react_native2 = require("react-native");
1107
1125
  var import_jsx_runtime2 = require("react/jsx-runtime");
1108
1126
  function MarkdownText({
1109
1127
  content,
1110
1128
  onLinkClick
1111
1129
  }) {
1112
- const context = (0, import_react8.useContext)(AdsContext);
1130
+ const context = (0, import_react9.useContext)(AdsContext);
1113
1131
  const textParts = parseMessageText(content);
1114
1132
  const styles = context?.styles?.markdownText;
1133
+ useTestError(context?.experimentErrorBoundary, "markdowntext", true, 2e3);
1115
1134
  const linkClickHandler = (href) => {
1116
1135
  onLinkClick();
1117
1136
  import_react_native2.Linking.openURL(href).catch(
@@ -1142,17 +1161,17 @@ function MarkdownText({
1142
1161
 
1143
1162
  // src/components/VideoPlayer.tsx
1144
1163
  var import_expo_av = require("expo-av");
1145
- var import_react10 = require("react");
1164
+ var import_react11 = require("react");
1146
1165
  var import_react_native4 = require("react-native");
1147
1166
 
1148
1167
  // src/components/VideoProgressBar.tsx
1149
- var import_react9 = require("react");
1168
+ var import_react10 = require("react");
1150
1169
  var import_react_native3 = require("react-native");
1151
1170
  var import_jsx_runtime3 = require("react/jsx-runtime");
1152
1171
  function VideoProgressBar({ videoRef }) {
1153
- const [progress, setProgress] = (0, import_react9.useState)(0);
1154
- const styles = (0, import_react9.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
1155
- (0, import_react9.useEffect)(() => {
1172
+ const [progress, setProgress] = (0, import_react10.useState)(0);
1173
+ const styles = (0, import_react10.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
1174
+ (0, import_react10.useEffect)(() => {
1156
1175
  const interval = setInterval(() => {
1157
1176
  if (!videoRef.current) {
1158
1177
  return;
@@ -1185,14 +1204,14 @@ var VideoPlayer = ({
1185
1204
  mediaPlacement,
1186
1205
  onLinkClick
1187
1206
  }) => {
1188
- const videoRef = (0, import_react10.useRef)(null);
1189
- const [isPlaying, setIsPlaying] = (0, import_react10.useState)(false);
1190
- const [isPaused, setIsPaused] = (0, import_react10.useState)(true);
1191
- const [isEnded, setIsEnded] = (0, import_react10.useState)(false);
1192
- const [showDownloadBadge, setShowDownloadBadge] = (0, import_react10.useState)(false);
1193
- const lastCallbackTimeRef = (0, import_react10.useRef)(0);
1194
- const styles = (0, import_react10.useContext)(AdsContext)?.styles?.videoPlayer;
1195
- (0, import_react10.useEffect)(() => {
1207
+ const videoRef = (0, import_react11.useRef)(null);
1208
+ const [isPlaying, setIsPlaying] = (0, import_react11.useState)(false);
1209
+ const [isPaused, setIsPaused] = (0, import_react11.useState)(true);
1210
+ const [isEnded, setIsEnded] = (0, import_react11.useState)(false);
1211
+ const [showDownloadBadge, setShowDownloadBadge] = (0, import_react11.useState)(false);
1212
+ const lastCallbackTimeRef = (0, import_react11.useRef)(0);
1213
+ const styles = (0, import_react11.useContext)(AdsContext)?.styles?.videoPlayer;
1214
+ (0, import_react11.useEffect)(() => {
1196
1215
  const interval = setInterval(() => {
1197
1216
  if (videoRef.current) {
1198
1217
  videoRef.current.getStatusAsync().then((status) => {
@@ -1275,9 +1294,9 @@ var VideoPlayer = ({
1275
1294
  };
1276
1295
 
1277
1296
  // src/hooks/useAd.tsx
1278
- var import_react11 = require("react");
1297
+ var import_react12 = require("react");
1279
1298
  function useAd({ code, messageId }) {
1280
- const context = (0, import_react11.useContext)(AdsContext);
1299
+ const context = (0, import_react12.useContext)(AdsContext);
1281
1300
  if (!context) {
1282
1301
  return null;
1283
1302
  }
@@ -1325,15 +1344,17 @@ function useAd({ code, messageId }) {
1325
1344
  var import_jsx_runtime5 = require("react/jsx-runtime");
1326
1345
  var InlineAd = ({ code, messageId, wrapper }) => {
1327
1346
  const ad = useAd({ code, messageId });
1328
- const [linkIncluded, setLinkIncluded] = (0, import_react12.useState)(false);
1329
- const context = (0, import_react12.useContext)(AdsContext);
1347
+ const [linkIncluded, setLinkIncluded] = (0, import_react13.useState)(false);
1348
+ const context = (0, import_react13.useContext)(AdsContext);
1330
1349
  const styles = context?.styles?.inlineAd;
1331
1350
  useAdViewed(ad);
1332
- (0, import_react12.useEffect)(() => {
1351
+ useTestError(context?.experimentErrorBoundary, "inlinead-top", true, 2e3);
1352
+ (0, import_react13.useEffect)(() => {
1333
1353
  if (ad?.content && !ad.isStreaming && !ad.content.match(/\[.*?\]\(.*?\)/) && !linkIncluded) {
1334
1354
  setLinkIncluded(true);
1335
1355
  }
1336
1356
  }, [ad]);
1357
+ useTestError(context?.experimentErrorBoundary, "inlinead-content", !!ad, 2e3);
1337
1358
  if (!ad || !ad.content || context?.isDisabled) return null;
1338
1359
  if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
1339
1360
  return null;
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/formats/InlineAd.tsx
9
- import { useContext as useContext6, useEffect as useEffect8, useState as useState8 } from "react";
9
+ import { useContext as useContext6, useEffect as useEffect9, useState as useState9 } from "react";
10
10
  import {
11
11
  Image,
12
12
  Linking as Linking3,
@@ -17,15 +17,16 @@ import {
17
17
  } from "react-native";
18
18
 
19
19
  // src/hooks/useAdViewed.tsx
20
- import { useEffect as useEffect5, useState as useState5 } from "react";
20
+ import { useEffect as useEffect6, useState as useState6 } from "react";
21
21
 
22
22
  // src/context/AdsProvider.tsx
23
- import React2, { useState as useState4 } from "react";
23
+ import React2, { useState as useState5 } from "react";
24
24
 
25
25
  // src/hooks/useInitializeAds.tsx
26
- import { useEffect, useState } from "react";
26
+ import { useEffect as useEffect2, useState as useState2 } from "react";
27
27
 
28
28
  // src/utils.ts
29
+ import { useEffect, useState } from "react";
29
30
  var UNRETRIABLE_ERRORS = [403, 429];
30
31
  var fetchWithTimeout = async (input, init) => {
31
32
  const { timeout = 16e3 } = init || {};
@@ -132,6 +133,17 @@ function mergeStyles(propStyles, defaultStyles, overridingStyles) {
132
133
  mergedStyles = deepMerge(mergedStyles, overridingStyles || {});
133
134
  return mergedStyles;
134
135
  }
136
+ var useTestError = (boundarySetting, errorPosition, shouldThrow, delay) => {
137
+ const [throwError, setThrowError] = useState(false);
138
+ useEffect(() => {
139
+ setTimeout(() => {
140
+ setThrowError(true);
141
+ }, delay);
142
+ }, []);
143
+ if (boundarySetting === errorPosition && throwError && shouldThrow) {
144
+ throw new Error("test");
145
+ }
146
+ };
135
147
  var parseMessageText = (text) => {
136
148
  const parts = [];
137
149
  let start = 0;
@@ -251,7 +263,7 @@ var log = new Logger();
251
263
  var log_default = log;
252
264
 
253
265
  // package.json
254
- var version = "0.0.7-rc.1";
266
+ var version = "0.0.7-rc.3";
255
267
 
256
268
  // src/hooks/useInitializeAds.tsx
257
269
  var SINGLE_INIT_TIMEOUT_BUDGET_MS = 3e3;
@@ -310,17 +322,19 @@ function useInitializeAds({
310
322
  conversationId,
311
323
  isDisabled,
312
324
  character,
313
- legacyVisitorId
325
+ legacyVisitorId,
326
+ experimentErrorBoundary
314
327
  }) {
315
- const [enabledPlacements, setEnabledPlacements] = useState([]);
316
- const [ads, setAds] = useState([]);
317
- const [error, setError] = useState();
318
- const [streamAdServerUrl, setStreamAdServerUrl] = useState();
319
- const [onlyStream, setOnlyStream] = useState(false);
320
- const [sessionId, setSessionId] = useState();
321
- const [defaultReactNativeStyles, setDefaultReactNativeStyles] = useState();
322
- const [overridingReactNativeStyles, setOverridingReactNativeStyles] = useState();
323
- useEffect(() => {
328
+ const [enabledPlacements, setEnabledPlacements] = useState2([]);
329
+ const [ads, setAds] = useState2([]);
330
+ const [error, setError] = useState2();
331
+ const [streamAdServerUrl, setStreamAdServerUrl] = useState2();
332
+ const [onlyStream, setOnlyStream] = useState2(false);
333
+ const [sessionId, setSessionId] = useState2();
334
+ const [defaultReactNativeStyles, setDefaultReactNativeStyles] = useState2();
335
+ const [overridingReactNativeStyles, setOverridingReactNativeStyles] = useState2();
336
+ useTestError(experimentErrorBoundary, "hook", true, 2e3);
337
+ useEffect2(() => {
324
338
  log_default.setRemoteLevel("debug");
325
339
  log_default.configureRemote(adServerUrl, {
326
340
  publisherToken,
@@ -400,7 +414,7 @@ function useInitializeAds({
400
414
  }
401
415
 
402
416
  // src/hooks/usePreloadAds.tsx
403
- import { useEffect as useEffect2, useState as useState2 } from "react";
417
+ import { useEffect as useEffect3, useState as useState3 } from "react";
404
418
  function usePreloadAds({
405
419
  userId,
406
420
  sessionId,
@@ -411,10 +425,10 @@ function usePreloadAds({
411
425
  character,
412
426
  onlyStream
413
427
  }) {
414
- const [preloadDone, setPreloadDone] = useState2(false);
415
- const [ads, setAds] = useState2([]);
428
+ const [preloadDone, setPreloadDone] = useState3(false);
429
+ const [ads, setAds] = useState3([]);
416
430
  const userMessagesContent = messages.filter((m) => m.role === "user").map((m) => m.content).join(" ");
417
- useEffect2(() => {
431
+ useEffect3(() => {
418
432
  if (onlyStream) {
419
433
  setPreloadDone(true);
420
434
  log_default.log("[BRAIN] skipping preload ads");
@@ -463,7 +477,7 @@ function usePreloadAds({
463
477
  }
464
478
 
465
479
  // src/hooks/useStreamAds.tsx
466
- import { useEffect as useEffect3, useState as useState3 } from "react";
480
+ import { useEffect as useEffect4, useState as useState4 } from "react";
467
481
 
468
482
  // src/hooks/data-stream.ts
469
483
  var textStreamPart = {
@@ -712,7 +726,7 @@ function useStreamAds({
712
726
  character,
713
727
  publisherToken
714
728
  }) {
715
- const [ads, setAds] = useState3([]);
729
+ const [ads, setAds] = useState4([]);
716
730
  const fetchStream = async (messages2, code) => {
717
731
  const lastAssistantMessage = [...messages2].reverse().find((m) => m.role === "assistant");
718
732
  if (!lastAssistantMessage) {
@@ -807,7 +821,7 @@ function useStreamAds({
807
821
  setAds((oldAds) => [...oldAds, { isError: true, code }]);
808
822
  }
809
823
  };
810
- useEffect3(() => {
824
+ useEffect4(() => {
811
825
  if (!isLoading && sessionId && messages.length > 2 && messages[messages.length - 1]?.role === "assistant" && preloadDone) {
812
826
  enabledPlacements.forEach((placement) => {
813
827
  if (["QUERY_STREAM", "INLINE_AD", "BOX_AD"].includes(placement.format)) {
@@ -879,8 +893,8 @@ var AdsProviderWithoutBoundary = ({
879
893
  onAdClick,
880
894
  ...props
881
895
  }) => {
882
- const [viewedAds, setViewedAds] = useState4([]);
883
- const [clickedAds, setClickedAds] = useState4([]);
896
+ const [viewedAds, setViewedAds] = useState5([]);
897
+ const [clickedAds, setClickedAds] = useState5([]);
884
898
  const adServerUrlOrDefault = adserverUrl || "https://server.megabrain.co";
885
899
  log_default.setLocalLevel(logLevel || "silent");
886
900
  const {
@@ -899,7 +913,8 @@ var AdsProviderWithoutBoundary = ({
899
913
  legacyVisitorId: void 0,
900
914
  conversationId,
901
915
  character,
902
- isDisabled: !!isDisabled
916
+ isDisabled: !!isDisabled,
917
+ experimentErrorBoundary: props.experimentErrorBoundary
903
918
  });
904
919
  const styles = mergeStyles(props.styles, defaultReactNativeStyles, overridingReactNativeStyles);
905
920
  const isInitialised = !!isDisabled || !!error || !!sessionId;
@@ -954,6 +969,7 @@ var AdsProviderWithoutBoundary = ({
954
969
  }
955
970
  setClickedAds((old) => [...old, ad.id]);
956
971
  };
972
+ useTestError(props.experimentErrorBoundary, "provider", true, 2e3);
957
973
  return /* @__PURE__ */ jsx(
958
974
  AdsContext.Provider,
959
975
  {
@@ -974,7 +990,8 @@ var AdsProviderWithoutBoundary = ({
974
990
  userId,
975
991
  markAdAsViewed,
976
992
  onlyStream,
977
- styles
993
+ styles,
994
+ experimentErrorBoundary: props.experimentErrorBoundary
978
995
  },
979
996
  children
980
997
  }
@@ -1024,7 +1041,8 @@ var AdsProvider = ({
1024
1041
  userId,
1025
1042
  logLevel,
1026
1043
  onAdView,
1027
- onAdClick
1044
+ onAdClick,
1045
+ ...props
1028
1046
  }
1029
1047
  )
1030
1048
  }
@@ -1035,7 +1053,7 @@ var AdsProvider = ({
1035
1053
  import { useContext } from "react";
1036
1054
  function useAdViewed(ad) {
1037
1055
  const context = useContext(AdsContext);
1038
- const [stillMounted, setStillMounted] = useState5(false);
1056
+ const [stillMounted, setStillMounted] = useState6(false);
1039
1057
  const sendRequest = async () => {
1040
1058
  if (!context?.adserverUrl || !ad?.id) {
1041
1059
  return;
@@ -1057,7 +1075,7 @@ function useAdViewed(ad) {
1057
1075
  log_default.warn("[BRAIN] Error sending view request", e);
1058
1076
  }
1059
1077
  };
1060
- useEffect5(() => {
1078
+ useEffect6(() => {
1061
1079
  if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
1062
1080
  return;
1063
1081
  }
@@ -1067,7 +1085,7 @@ function useAdViewed(ad) {
1067
1085
  setStillMounted(true);
1068
1086
  }, 1e3);
1069
1087
  }, [ad]);
1070
- useEffect5(() => {
1088
+ useEffect6(() => {
1071
1089
  if (stillMounted) {
1072
1090
  log_default.log("[BRAIN] sending request");
1073
1091
  sendRequest();
@@ -1089,6 +1107,7 @@ function MarkdownText({
1089
1107
  const context = useContext2(AdsContext);
1090
1108
  const textParts = parseMessageText(content);
1091
1109
  const styles = context?.styles?.markdownText;
1110
+ useTestError(context?.experimentErrorBoundary, "markdowntext", true, 2e3);
1092
1111
  const linkClickHandler = (href) => {
1093
1112
  onLinkClick();
1094
1113
  Linking.openURL(href).catch(
@@ -1119,17 +1138,17 @@ function MarkdownText({
1119
1138
 
1120
1139
  // src/components/VideoPlayer.tsx
1121
1140
  import { ResizeMode, Video } from "expo-av";
1122
- import { useContext as useContext4, useEffect as useEffect7, useRef, useState as useState7 } from "react";
1141
+ import { useContext as useContext4, useEffect as useEffect8, useRef, useState as useState8 } from "react";
1123
1142
  import { Linking as Linking2, Text as Text2, TouchableOpacity, View as View2 } from "react-native";
1124
1143
 
1125
1144
  // src/components/VideoProgressBar.tsx
1126
- import { useState as useState6, useEffect as useEffect6, useContext as useContext3 } from "react";
1145
+ import { useState as useState7, useEffect as useEffect7, useContext as useContext3 } from "react";
1127
1146
  import { View } from "react-native";
1128
1147
  import { jsx as jsx3 } from "react/jsx-runtime";
1129
1148
  function VideoProgressBar({ videoRef }) {
1130
- const [progress, setProgress] = useState6(0);
1149
+ const [progress, setProgress] = useState7(0);
1131
1150
  const styles = useContext3(AdsContext)?.styles?.videoPlayer?.videoProgress;
1132
- useEffect6(() => {
1151
+ useEffect7(() => {
1133
1152
  const interval = setInterval(() => {
1134
1153
  if (!videoRef.current) {
1135
1154
  return;
@@ -1163,13 +1182,13 @@ var VideoPlayer = ({
1163
1182
  onLinkClick
1164
1183
  }) => {
1165
1184
  const videoRef = useRef(null);
1166
- const [isPlaying, setIsPlaying] = useState7(false);
1167
- const [isPaused, setIsPaused] = useState7(true);
1168
- const [isEnded, setIsEnded] = useState7(false);
1169
- const [showDownloadBadge, setShowDownloadBadge] = useState7(false);
1185
+ const [isPlaying, setIsPlaying] = useState8(false);
1186
+ const [isPaused, setIsPaused] = useState8(true);
1187
+ const [isEnded, setIsEnded] = useState8(false);
1188
+ const [showDownloadBadge, setShowDownloadBadge] = useState8(false);
1170
1189
  const lastCallbackTimeRef = useRef(0);
1171
1190
  const styles = useContext4(AdsContext)?.styles?.videoPlayer;
1172
- useEffect7(() => {
1191
+ useEffect8(() => {
1173
1192
  const interval = setInterval(() => {
1174
1193
  if (videoRef.current) {
1175
1194
  videoRef.current.getStatusAsync().then((status) => {
@@ -1302,15 +1321,17 @@ function useAd({ code, messageId }) {
1302
1321
  import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1303
1322
  var InlineAd = ({ code, messageId, wrapper }) => {
1304
1323
  const ad = useAd({ code, messageId });
1305
- const [linkIncluded, setLinkIncluded] = useState8(false);
1324
+ const [linkIncluded, setLinkIncluded] = useState9(false);
1306
1325
  const context = useContext6(AdsContext);
1307
1326
  const styles = context?.styles?.inlineAd;
1308
1327
  useAdViewed(ad);
1309
- useEffect8(() => {
1328
+ useTestError(context?.experimentErrorBoundary, "inlinead-top", true, 2e3);
1329
+ useEffect9(() => {
1310
1330
  if (ad?.content && !ad.isStreaming && !ad.content.match(/\[.*?\]\(.*?\)/) && !linkIncluded) {
1311
1331
  setLinkIncluded(true);
1312
1332
  }
1313
1333
  }, [ad]);
1334
+ useTestError(context?.experimentErrorBoundary, "inlinead-content", !!ad, 2e3);
1314
1335
  if (!ad || !ad.content || context?.isDisabled) return null;
1315
1336
  if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
1316
1337
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "0.0.7-rc.1",
3
+ "version": "0.0.7-rc.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",