@lorikeetai/react-native-sdk 2.0.0 → 2.2.0-beta.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/conversation-metadata.ts","../src/customisations.ts","../src/events.ts","../src/types.ts","../src/widget.tsx","../src/client.ts","../src/errors.ts","../src/lifecycle.ts"],"mappings":";;;KAEY,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;UCuBzB;;EAER;EACA;;EAEA;;EAEA;EACA;;UAGe;;EAEf;EACA;EACA,UAAU;;;;;;;;;;;;;;;EAeV;;EAEA;EACA;EACA;;IAEE;;;;;;IAMA;;;;;;;IAOA;;EAEF,SAAS;EACT;;;;;;;EAOA;IACE;IACA;IACA;IACA;IACA;;IAEA;;;EAGF;EACA,QAAQ;EACR;;EAEA;;UAGe;;;;;;EAMf;EACA;;EAEA;EACA;;EAEA;EACA;;;;;;;;;EASA;;;;;EAKA;;EAEA;;EAEA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;;KCxHU;;;EAEN;;;;;;;;EAMA;EAAwB;;;;EAExB;;;;;;;;;;;;EAUA;EAAuB;;;;;;;;;;;;;;;;;EAevB;EAAe;;;;;;;;;;;;EAUf;;;;;;;EAKA;;;;;;;EAKA;EAA2B;;;;;;;EAK3B;EAAyB;;;;;;;;;;;;;;;;EAczB;;;;;;;;;;;;EAUA;;;;EAEA;EAAe;;;;;;;;;;;;;EAYf;EACA;EACA;;;KAIM;;;UCjHK;;;;EAIf;;;;EAIA,iBAAiB;;;;;EAKjB,WAAW;;;;EAIX;;KAGU;;;;EAIV;;;;EAIA;;;;EAIA,eAAe;;;;;;;;;;;;;;;EAef,WAAW,OAAO;;KAGR;;;;EAIV;;;;EAIA,QAAQ,UAAU;;;;EAIlB,OAAO,MAAM;;;;EAIb;;;;;;;KAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCV;IACE;IACA;IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BF;;;;;;;;;;;;;EAaA;;KAGU;;;;EAIV;;;;EAIA;;;;EAIA;;;;;;;;;;;;;EAaA,oBAAoB,OAAO;;;;;EAK3B,WAAW,OAAO;;;;EAIlB,iBAAiB;;;;EAIjB;IACE,SAAS,UAAU;;;;;;;;;EASrB;;;;;;;EAOA;;;;;;EAMA,WAAW;;;;;;;EAOX,eAAe;;;;cC5IJ,uCAAqB,0BAAA,6CAAA,cAAA;cA2HrB,yBAAwB,OAAA,OAAA,MAAA,eAKlC,8CAAyB,IAAA;cAYf,oCAAkB,0BAAA,0CAAA,cAAA;;;cCjOlB;EACX;EACA,gBAAgB;EAChB,UAAU;EACV;EAEY,cACV,gBACA,UACA,UACA,cACC;EAeH,kBAAiB,gBAAA,eAAA,OAAA,WAAA;IAOf;IACA;IACA;IACA;IACA;;;;;;;;;;;;EAmDF;;;;;;;;;;;;;;cCnFW;KAgBD,4BAA4B;;iBAexB,2BAA2B;iBAK3B,uBAAuB;;;;;;;;;;;;;;cCtB1B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/conversation-metadata.ts","../src/customisations.ts","../src/events.ts","../src/types.ts","../src/widget.tsx","../src/client.ts","../src/errors.ts","../src/lifecycle.ts"],"mappings":";;KAEY,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;UCuBzB;;EAER;EACA;;EAEA;;EAEA;EACA;;UAGe;;EAEf;EACA;EACA,UAAU;;;;;;;;;;;;;;;EAeV;;EAEA;EACA;EACA;;IAEE;;;;;;IAMA;;;;;;;IAOA;;EAEF,SAAS;EACT;;;;;;;EAOA;IACE;IACA;IACA;IACA;IACA;;IAEA;;;EAGF;EACA,QAAQ;EACR;;EAEA;;UAGe;;;;;;EAMf;EACA;;EAEA;EACA;;EAEA;EACA;;;;;;;;;EASA;;;;;EAKA;;EAEA;;EAEA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;;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cCtB1B"}
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
2
- import { AppState, Linking, StyleSheet, Text, TouchableOpacity, View } from "react-native";
2
+ import { AppState, KeyboardAvoidingView, Linking, StyleSheet, Text, TouchableOpacity, View } from "react-native";
3
3
  import { SafeAreaView } from "react-native-safe-area-context";
4
4
  import { WebView } from "react-native-webview";
5
5
  import Svg, { Line, Path } from "react-native-svg";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
7
 
8
- //#region src/bridge.ts
8
+ // src/bridge.ts
9
9
  /**
10
10
  * The public key, base URL and token are one unit, and a conversation belongs to
11
11
  * the credentials that created it. Stamping an observation with them is what
@@ -25,8 +25,7 @@ const resumableConversation = (observed, identity, intendedTicketId) => {
25
25
  };
26
26
  };
27
27
 
28
- //#endregion
29
- //#region src/encode.ts
28
+ // src/encode.ts
30
29
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
31
30
  /**
32
31
  * Base64 of a string's UTF-8 bytes.
@@ -53,8 +52,7 @@ function base64EncodeUtf8(value) {
53
52
  return encoded;
54
53
  }
55
54
 
56
- //#endregion
57
- //#region \0@oxc-project+runtime@0.147.0/helpers/esm/typeof.js
55
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
58
56
  function _typeof(o) {
59
57
  "@babel/helpers - typeof";
60
58
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -64,8 +62,7 @@ function _typeof(o) {
64
62
  }, _typeof(o);
65
63
  }
66
64
 
67
- //#endregion
68
- //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPrimitive.js
65
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
69
66
  function toPrimitive(t, r) {
70
67
  if ("object" != _typeof(t) || !t) return t;
71
68
  var e = t[Symbol.toPrimitive];
@@ -77,15 +74,13 @@ function toPrimitive(t, r) {
77
74
  return ("string" === r ? String : Number)(t);
78
75
  }
79
76
 
80
- //#endregion
81
- //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPropertyKey.js
77
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
82
78
  function toPropertyKey(t) {
83
79
  var i = toPrimitive(t, "string");
84
80
  return "symbol" == _typeof(i) ? i : i + "";
85
81
  }
86
82
 
87
- //#endregion
88
- //#region \0@oxc-project+runtime@0.147.0/helpers/esm/defineProperty.js
83
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
89
84
  function _defineProperty(e, r, t) {
90
85
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
91
86
  value: t,
@@ -95,8 +90,7 @@ function _defineProperty(e, r, t) {
95
90
  }) : e[r] = t, e;
96
91
  }
97
92
 
98
- //#endregion
99
- //#region src/client.ts
93
+ // src/client.ts
100
94
  var LorikeetClient = class {
101
95
  constructor({ customisations, api_base, metadata, public_key }) {
102
96
  _defineProperty(this, "baseUrl", "https://chat.lorikeetcx.ai");
@@ -142,8 +136,7 @@ var LorikeetClient = class {
142
136
  }
143
137
  };
144
138
 
145
- //#endregion
146
- //#region src/errors.ts
139
+ // src/errors.ts
147
140
  /**
148
141
  * The chat page's error vocabulary, as it reaches a host in
149
142
  * `{ type: 'error', error: CODE }`. Mirrored here because the page publishes it
@@ -190,8 +183,7 @@ function isUnusableConversation(message) {
190
183
  return type === "error" && typeof error === "string" ? isUnusableConversationCode(error) : false;
191
184
  }
192
185
 
193
- //#endregion
194
- //#region src/events.ts
186
+ // src/events.ts
195
187
  const asRecord = (message) => typeof message === "object" && message !== null && !Array.isArray(message) ? message : null;
196
188
  const asNonEmptyString = (value) => typeof value === "string" && value !== "" ? value : null;
197
189
  /**
@@ -269,8 +261,7 @@ const resumedTicketIdFromUri = (uri) => {
269
261
  return (_segments$ = segments[2]) !== null && _segments$ !== void 0 ? _segments$ : null;
270
262
  };
271
263
 
272
- //#endregion
273
- //#region src/lifecycle.ts
264
+ // src/lifecycle.ts
274
265
  /**
275
266
  * The page gives its message stream ten attempts with exponential backoff
276
267
  * capped at 30s (`message-stream-utils.tsx`), so the budget runs out roughly
@@ -307,8 +298,7 @@ const shouldReloadAfterBackground = (backgroundedAt, now, thresholdMs = BACKGROU
307
298
  return elapsed >= thresholdMs;
308
299
  };
309
300
 
310
- //#endregion
311
- //#region src/links.ts
301
+ // src/links.ts
312
302
  /**
313
303
  * Schemes the WebView resolves for itself. None of them is a page the customer
314
304
  * asked to leave the app for, and the OS cannot open them anyway.
@@ -353,8 +343,7 @@ const isInternalNavigation = (url, baseUrl) => {
353
343
  return target.origin === base.origin;
354
344
  };
355
345
 
356
- //#endregion
357
- //#region src/message-circle-plus-icon.tsx
346
+ // src/message-circle-plus-icon.tsx
358
347
  const MessageCirclePlusIcon = ({ size = 24, color = "currentColor", strokeWidth = 2 }) => {
359
348
  return /* @__PURE__ */ jsxs(Svg, {
360
349
  fill: "none",
@@ -391,13 +380,13 @@ const MessageCirclePlusIcon = ({ size = 24, color = "currentColor", strokeWidth
391
380
  });
392
381
  };
393
382
 
394
- //#endregion
395
- //#region src/widget.tsx
383
+ // src/widget.tsx
396
384
  const stylesheet = StyleSheet.create({
397
385
  root: {
398
386
  flex: 1,
399
387
  backgroundColor: "#fff"
400
388
  },
389
+ keyboardAvoiding: { flex: 1 },
401
390
  container: {
402
391
  flex: 1,
403
392
  borderRadius: 8,
@@ -501,7 +490,7 @@ const LorikeetWidgetHeader = ({ title, style, icon = /* @__PURE__ */ jsx(Message
501
490
  ]
502
491
  });
503
492
  };
504
- const LorikeetWidgetView = forwardRef(function LorikeetWidgetView({ publicKey, baseUrl, authToken, customisations, styles, onEvent, onWebViewMessage, ticketId, session, metadata, webviewProps }, ref) {
493
+ const LorikeetWidgetView = forwardRef(function LorikeetWidgetView({ publicKey, baseUrl, authToken, customisations, styles, onEvent, onWebViewMessage, ticketId, session, metadata, webviewProps, avoidKeyboard = true }, ref) {
505
494
  var _customisations$hideH, _customisations$title;
506
495
  const [lorikeetClient, setLorikeetClient] = useState(null);
507
496
  const [loaded, setLoaded] = useState(null);
@@ -512,6 +501,15 @@ const LorikeetWidgetView = forwardRef(function LorikeetWidgetView({ publicKey, b
512
501
  setGeneration((previous) => previous + 1);
513
502
  }, []);
514
503
  const webViewRef = useRef(null);
504
+ const containerRef = useRef(null);
505
+ const [keyboardOffset, setKeyboardOffset] = useState(0);
506
+ const measureKeyboardOffset = useCallback((event) => {
507
+ var _containerRef$current;
508
+ const { y } = event.nativeEvent.layout;
509
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 || _containerRef$current.measureInWindow((_x, windowY) => {
510
+ setKeyboardOffset(windowY - y);
511
+ });
512
+ }, []);
515
513
  const [refusedTicketId, setRefusedTicketId] = useState(null);
516
514
  const observedRef = useRef(null);
517
515
  const backgroundedAtRef = useRef(null);
@@ -799,67 +797,74 @@ const LorikeetWidgetView = forwardRef(function LorikeetWidgetView({ publicKey, b
799
797
  "right"
800
798
  ],
801
799
  style: stylesheet.root,
802
- children: /* @__PURE__ */ jsxs(View, {
803
- style: stylesheet.container,
804
- children: [
805
- hideHeader && closed !== "minimised" ? /* @__PURE__ */ jsx(LorikeetWidgetHeader, {
806
- onIconPress: startNewChat,
807
- style: styles === null || styles === void 0 ? void 0 : styles.header,
808
- title: (_customisations$title = customisations === null || customisations === void 0 ? void 0 : customisations.title) !== null && _customisations$title !== void 0 ? _customisations$title : "Lorikeet AI Agent"
809
- }) : null,
810
- closed === "minimised" ? /* @__PURE__ */ jsx(TouchableOpacity, {
811
- onPress: reopen,
812
- style: stylesheet.closedControl,
813
- children: /* @__PURE__ */ jsx(Text, {
814
- style: stylesheet.headerText,
815
- children: "Reopen chat"
816
- })
817
- }) : null,
818
- !hideHeader && closed === "ended" ? /* @__PURE__ */ jsx(TouchableOpacity, {
819
- onPress: startNewChat,
820
- style: stylesheet.closedControl,
821
- children: /* @__PURE__ */ jsx(Text, {
822
- style: stylesheet.headerText,
823
- children: "Start new chat"
824
- })
825
- }) : null,
826
- /* @__PURE__ */ jsx(View, {
827
- accessibilityElementsHidden: isClosed,
828
- importantForAccessibility: isClosed ? "no-hide-descendants" : "auto",
829
- pointerEvents: isClosed ? "none" : "auto",
830
- style: isClosed ? stylesheet.closed : stylesheet.webView,
831
- children: /* @__PURE__ */ jsx(LorikeetWidgetWebView, {
832
- baseUrl: lorikeetClient.baseUrl,
833
- onEvent: handleEvent,
834
- ref: webViewRef,
835
- uri: loaded.uri,
836
- webviewProps: {
837
- allowsInlineMediaPlayback: true,
838
- mediaPlaybackRequiresUserAction: false,
839
- scalesPageToFit: true,
840
- startInLoadingState: true,
841
- style: stylesheet.webView,
842
- ...webviewProps,
843
- onMessage: handleMessage,
844
- onRenderProcessGone: (event) => {
845
- var _webviewProps$onRende;
846
- if (generation === generationRef.current) reload();
847
- webviewProps === null || webviewProps === void 0 || (_webviewProps$onRende = webviewProps.onRenderProcessGone) === null || _webviewProps$onRende === void 0 || _webviewProps$onRende.call(webviewProps, event);
848
- },
849
- onContentProcessDidTerminate: (event) => {
850
- var _webviewProps$onConte;
851
- if (generation === generationRef.current) reload();
852
- webviewProps === null || webviewProps === void 0 || (_webviewProps$onConte = webviewProps.onContentProcessDidTerminate) === null || _webviewProps$onConte === void 0 || _webviewProps$onConte.call(webviewProps, event);
800
+ children: /* @__PURE__ */ jsx(KeyboardAvoidingView, {
801
+ behavior: "padding",
802
+ enabled: avoidKeyboard,
803
+ keyboardVerticalOffset: keyboardOffset,
804
+ onLayout: measureKeyboardOffset,
805
+ style: stylesheet.keyboardAvoiding,
806
+ children: /* @__PURE__ */ jsxs(View, {
807
+ ref: containerRef,
808
+ style: stylesheet.container,
809
+ children: [
810
+ hideHeader && closed !== "minimised" ? /* @__PURE__ */ jsx(LorikeetWidgetHeader, {
811
+ onIconPress: startNewChat,
812
+ style: styles === null || styles === void 0 ? void 0 : styles.header,
813
+ title: (_customisations$title = customisations === null || customisations === void 0 ? void 0 : customisations.title) !== null && _customisations$title !== void 0 ? _customisations$title : "Lorikeet AI Agent"
814
+ }) : null,
815
+ closed === "minimised" ? /* @__PURE__ */ jsx(TouchableOpacity, {
816
+ onPress: reopen,
817
+ style: stylesheet.closedControl,
818
+ children: /* @__PURE__ */ jsx(Text, {
819
+ style: stylesheet.headerText,
820
+ children: "Reopen chat"
821
+ })
822
+ }) : null,
823
+ !hideHeader && closed === "ended" ? /* @__PURE__ */ jsx(TouchableOpacity, {
824
+ onPress: startNewChat,
825
+ style: stylesheet.closedControl,
826
+ children: /* @__PURE__ */ jsx(Text, {
827
+ style: stylesheet.headerText,
828
+ children: "Start new chat"
829
+ })
830
+ }) : null,
831
+ /* @__PURE__ */ jsx(View, {
832
+ accessibilityElementsHidden: isClosed,
833
+ importantForAccessibility: isClosed ? "no-hide-descendants" : "auto",
834
+ pointerEvents: isClosed ? "none" : "auto",
835
+ style: isClosed ? stylesheet.closed : stylesheet.webView,
836
+ children: /* @__PURE__ */ jsx(LorikeetWidgetWebView, {
837
+ baseUrl: lorikeetClient.baseUrl,
838
+ onEvent: handleEvent,
839
+ ref: webViewRef,
840
+ uri: loaded.uri,
841
+ webviewProps: {
842
+ allowsInlineMediaPlayback: true,
843
+ mediaPlaybackRequiresUserAction: false,
844
+ scalesPageToFit: true,
845
+ startInLoadingState: true,
846
+ style: stylesheet.webView,
847
+ ...webviewProps,
848
+ onMessage: handleMessage,
849
+ onRenderProcessGone: (event) => {
850
+ var _webviewProps$onRende;
851
+ if (generation === generationRef.current) reload();
852
+ webviewProps === null || webviewProps === void 0 || (_webviewProps$onRende = webviewProps.onRenderProcessGone) === null || _webviewProps$onRende === void 0 || _webviewProps$onRende.call(webviewProps, event);
853
+ },
854
+ onContentProcessDidTerminate: (event) => {
855
+ var _webviewProps$onConte;
856
+ if (generation === generationRef.current) reload();
857
+ webviewProps === null || webviewProps === void 0 || (_webviewProps$onConte = webviewProps.onContentProcessDidTerminate) === null || _webviewProps$onConte === void 0 || _webviewProps$onConte.call(webviewProps, event);
858
+ }
853
859
  }
854
- }
855
- }, `${identity}|${resumingTicketId !== null && resumingTicketId !== void 0 ? resumingTicketId : ""}|${generation}`)
856
- })
857
- ]
860
+ }, `${identity}|${resumingTicketId !== null && resumingTicketId !== void 0 ? resumingTicketId : ""}|${generation}`)
861
+ })
862
+ ]
863
+ })
858
864
  })
859
865
  });
860
866
  });
861
867
  LorikeetWidgetView.displayName = "LorikeetWidgetView";
862
868
 
863
- //#endregion
864
869
  export { LOGOUT_CONFIRMATION_TIMEOUT_MS, LORIKEET_ERROR_CODES, LorikeetClient, LorikeetWidgetHeader, LorikeetWidgetView, LorikeetWidgetWebView, isUnusableConversation, isUnusableConversationCode };
865
870
  //# sourceMappingURL=index.js.map