@kontextso/sdk-react-native 0.0.7-rc.1 → 0.0.7-rc.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.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.2";
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
  }
@@ -1058,10 +1075,10 @@ var AdsProvider = ({
1058
1075
  };
1059
1076
 
1060
1077
  // src/hooks/useAdViewed.tsx
1061
- var import_react7 = require("react");
1078
+ var import_react8 = require("react");
1062
1079
  function useAdViewed(ad) {
1063
- const context = (0, import_react7.useContext)(AdsContext);
1064
- const [stillMounted, setStillMounted] = (0, import_react6.useState)(false);
1080
+ const context = (0, import_react8.useContext)(AdsContext);
1081
+ const [stillMounted, setStillMounted] = (0, import_react7.useState)(false);
1065
1082
  const sendRequest = async () => {
1066
1083
  if (!context?.adserverUrl || !ad?.id) {
1067
1084
  return;
@@ -1083,7 +1100,7 @@ function useAdViewed(ad) {
1083
1100
  log_default.warn("[BRAIN] Error sending view request", e);
1084
1101
  }
1085
1102
  };
1086
- (0, import_react6.useEffect)(() => {
1103
+ (0, import_react7.useEffect)(() => {
1087
1104
  if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
1088
1105
  return;
1089
1106
  }
@@ -1093,7 +1110,7 @@ function useAdViewed(ad) {
1093
1110
  setStillMounted(true);
1094
1111
  }, 1e3);
1095
1112
  }, [ad]);
1096
- (0, import_react6.useEffect)(() => {
1113
+ (0, import_react7.useEffect)(() => {
1097
1114
  if (stillMounted) {
1098
1115
  log_default.log("[BRAIN] sending request");
1099
1116
  sendRequest();
@@ -1102,16 +1119,17 @@ function useAdViewed(ad) {
1102
1119
  }
1103
1120
 
1104
1121
  // src/components/MarkdownText.tsx
1105
- var import_react8 = require("react");
1122
+ var import_react9 = require("react");
1106
1123
  var import_react_native2 = require("react-native");
1107
1124
  var import_jsx_runtime2 = require("react/jsx-runtime");
1108
1125
  function MarkdownText({
1109
1126
  content,
1110
1127
  onLinkClick
1111
1128
  }) {
1112
- const context = (0, import_react8.useContext)(AdsContext);
1129
+ const context = (0, import_react9.useContext)(AdsContext);
1113
1130
  const textParts = parseMessageText(content);
1114
1131
  const styles = context?.styles?.markdownText;
1132
+ useTestError(context?.experimentErrorBoundary, "markdowntext", true, 2e3);
1115
1133
  const linkClickHandler = (href) => {
1116
1134
  onLinkClick();
1117
1135
  import_react_native2.Linking.openURL(href).catch(
@@ -1142,17 +1160,17 @@ function MarkdownText({
1142
1160
 
1143
1161
  // src/components/VideoPlayer.tsx
1144
1162
  var import_expo_av = require("expo-av");
1145
- var import_react10 = require("react");
1163
+ var import_react11 = require("react");
1146
1164
  var import_react_native4 = require("react-native");
1147
1165
 
1148
1166
  // src/components/VideoProgressBar.tsx
1149
- var import_react9 = require("react");
1167
+ var import_react10 = require("react");
1150
1168
  var import_react_native3 = require("react-native");
1151
1169
  var import_jsx_runtime3 = require("react/jsx-runtime");
1152
1170
  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)(() => {
1171
+ const [progress, setProgress] = (0, import_react10.useState)(0);
1172
+ const styles = (0, import_react10.useContext)(AdsContext)?.styles?.videoPlayer?.videoProgress;
1173
+ (0, import_react10.useEffect)(() => {
1156
1174
  const interval = setInterval(() => {
1157
1175
  if (!videoRef.current) {
1158
1176
  return;
@@ -1185,14 +1203,14 @@ var VideoPlayer = ({
1185
1203
  mediaPlacement,
1186
1204
  onLinkClick
1187
1205
  }) => {
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)(() => {
1206
+ const videoRef = (0, import_react11.useRef)(null);
1207
+ const [isPlaying, setIsPlaying] = (0, import_react11.useState)(false);
1208
+ const [isPaused, setIsPaused] = (0, import_react11.useState)(true);
1209
+ const [isEnded, setIsEnded] = (0, import_react11.useState)(false);
1210
+ const [showDownloadBadge, setShowDownloadBadge] = (0, import_react11.useState)(false);
1211
+ const lastCallbackTimeRef = (0, import_react11.useRef)(0);
1212
+ const styles = (0, import_react11.useContext)(AdsContext)?.styles?.videoPlayer;
1213
+ (0, import_react11.useEffect)(() => {
1196
1214
  const interval = setInterval(() => {
1197
1215
  if (videoRef.current) {
1198
1216
  videoRef.current.getStatusAsync().then((status) => {
@@ -1275,9 +1293,9 @@ var VideoPlayer = ({
1275
1293
  };
1276
1294
 
1277
1295
  // src/hooks/useAd.tsx
1278
- var import_react11 = require("react");
1296
+ var import_react12 = require("react");
1279
1297
  function useAd({ code, messageId }) {
1280
- const context = (0, import_react11.useContext)(AdsContext);
1298
+ const context = (0, import_react12.useContext)(AdsContext);
1281
1299
  if (!context) {
1282
1300
  return null;
1283
1301
  }
@@ -1325,15 +1343,17 @@ function useAd({ code, messageId }) {
1325
1343
  var import_jsx_runtime5 = require("react/jsx-runtime");
1326
1344
  var InlineAd = ({ code, messageId, wrapper }) => {
1327
1345
  const ad = useAd({ code, messageId });
1328
- const [linkIncluded, setLinkIncluded] = (0, import_react12.useState)(false);
1329
- const context = (0, import_react12.useContext)(AdsContext);
1346
+ const [linkIncluded, setLinkIncluded] = (0, import_react13.useState)(false);
1347
+ const context = (0, import_react13.useContext)(AdsContext);
1330
1348
  const styles = context?.styles?.inlineAd;
1331
1349
  useAdViewed(ad);
1332
- (0, import_react12.useEffect)(() => {
1350
+ useTestError(context?.experimentErrorBoundary, "inlinead-top", true, 2e3);
1351
+ (0, import_react13.useEffect)(() => {
1333
1352
  if (ad?.content && !ad.isStreaming && !ad.content.match(/\[.*?\]\(.*?\)/) && !linkIncluded) {
1334
1353
  setLinkIncluded(true);
1335
1354
  }
1336
1355
  }, [ad]);
1356
+ useTestError(context?.experimentErrorBoundary, "inlinead-content", !!ad, 2e3);
1337
1357
  if (!ad || !ad.content || context?.isDisabled) return null;
1338
1358
  if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
1339
1359
  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.2";
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
  }
@@ -1035,7 +1052,7 @@ var AdsProvider = ({
1035
1052
  import { useContext } from "react";
1036
1053
  function useAdViewed(ad) {
1037
1054
  const context = useContext(AdsContext);
1038
- const [stillMounted, setStillMounted] = useState5(false);
1055
+ const [stillMounted, setStillMounted] = useState6(false);
1039
1056
  const sendRequest = async () => {
1040
1057
  if (!context?.adserverUrl || !ad?.id) {
1041
1058
  return;
@@ -1057,7 +1074,7 @@ function useAdViewed(ad) {
1057
1074
  log_default.warn("[BRAIN] Error sending view request", e);
1058
1075
  }
1059
1076
  };
1060
- useEffect5(() => {
1077
+ useEffect6(() => {
1061
1078
  if (!ad || ad.isError || ad.isLoading || ad.isStreaming || ad.viewed || stillMounted) {
1062
1079
  return;
1063
1080
  }
@@ -1067,7 +1084,7 @@ function useAdViewed(ad) {
1067
1084
  setStillMounted(true);
1068
1085
  }, 1e3);
1069
1086
  }, [ad]);
1070
- useEffect5(() => {
1087
+ useEffect6(() => {
1071
1088
  if (stillMounted) {
1072
1089
  log_default.log("[BRAIN] sending request");
1073
1090
  sendRequest();
@@ -1089,6 +1106,7 @@ function MarkdownText({
1089
1106
  const context = useContext2(AdsContext);
1090
1107
  const textParts = parseMessageText(content);
1091
1108
  const styles = context?.styles?.markdownText;
1109
+ useTestError(context?.experimentErrorBoundary, "markdowntext", true, 2e3);
1092
1110
  const linkClickHandler = (href) => {
1093
1111
  onLinkClick();
1094
1112
  Linking.openURL(href).catch(
@@ -1119,17 +1137,17 @@ function MarkdownText({
1119
1137
 
1120
1138
  // src/components/VideoPlayer.tsx
1121
1139
  import { ResizeMode, Video } from "expo-av";
1122
- import { useContext as useContext4, useEffect as useEffect7, useRef, useState as useState7 } from "react";
1140
+ import { useContext as useContext4, useEffect as useEffect8, useRef, useState as useState8 } from "react";
1123
1141
  import { Linking as Linking2, Text as Text2, TouchableOpacity, View as View2 } from "react-native";
1124
1142
 
1125
1143
  // src/components/VideoProgressBar.tsx
1126
- import { useState as useState6, useEffect as useEffect6, useContext as useContext3 } from "react";
1144
+ import { useState as useState7, useEffect as useEffect7, useContext as useContext3 } from "react";
1127
1145
  import { View } from "react-native";
1128
1146
  import { jsx as jsx3 } from "react/jsx-runtime";
1129
1147
  function VideoProgressBar({ videoRef }) {
1130
- const [progress, setProgress] = useState6(0);
1148
+ const [progress, setProgress] = useState7(0);
1131
1149
  const styles = useContext3(AdsContext)?.styles?.videoPlayer?.videoProgress;
1132
- useEffect6(() => {
1150
+ useEffect7(() => {
1133
1151
  const interval = setInterval(() => {
1134
1152
  if (!videoRef.current) {
1135
1153
  return;
@@ -1163,13 +1181,13 @@ var VideoPlayer = ({
1163
1181
  onLinkClick
1164
1182
  }) => {
1165
1183
  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);
1184
+ const [isPlaying, setIsPlaying] = useState8(false);
1185
+ const [isPaused, setIsPaused] = useState8(true);
1186
+ const [isEnded, setIsEnded] = useState8(false);
1187
+ const [showDownloadBadge, setShowDownloadBadge] = useState8(false);
1170
1188
  const lastCallbackTimeRef = useRef(0);
1171
1189
  const styles = useContext4(AdsContext)?.styles?.videoPlayer;
1172
- useEffect7(() => {
1190
+ useEffect8(() => {
1173
1191
  const interval = setInterval(() => {
1174
1192
  if (videoRef.current) {
1175
1193
  videoRef.current.getStatusAsync().then((status) => {
@@ -1302,15 +1320,17 @@ function useAd({ code, messageId }) {
1302
1320
  import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1303
1321
  var InlineAd = ({ code, messageId, wrapper }) => {
1304
1322
  const ad = useAd({ code, messageId });
1305
- const [linkIncluded, setLinkIncluded] = useState8(false);
1323
+ const [linkIncluded, setLinkIncluded] = useState9(false);
1306
1324
  const context = useContext6(AdsContext);
1307
1325
  const styles = context?.styles?.inlineAd;
1308
1326
  useAdViewed(ad);
1309
- useEffect8(() => {
1327
+ useTestError(context?.experimentErrorBoundary, "inlinead-top", true, 2e3);
1328
+ useEffect9(() => {
1310
1329
  if (ad?.content && !ad.isStreaming && !ad.content.match(/\[.*?\]\(.*?\)/) && !linkIncluded) {
1311
1330
  setLinkIncluded(true);
1312
1331
  }
1313
1332
  }, [ad]);
1333
+ useTestError(context?.experimentErrorBoundary, "inlinead-content", !!ad, 2e3);
1314
1334
  if (!ad || !ad.content || context?.isDisabled) return null;
1315
1335
  if (ad.isLoading || ad.content?.trim().toLowerCase().includes("none"))
1316
1336
  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.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",