react-instantsearch 7.39.0 → 7.39.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,4 +1,4 @@
1
- /*! React InstantSearch 7.39.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch 7.39.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
@@ -24,7 +24,7 @@
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
- var version$2 = '7.39.0';
27
+ var version$2 = '7.39.1';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -9160,7 +9160,7 @@
9160
9160
  });
9161
9161
  }
9162
9162
 
9163
- var version = '4.105.0';
9163
+ var version = '4.106.0';
9164
9164
 
9165
9165
  var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
9166
9166
  function getCookie(name) {
@@ -12557,15 +12557,14 @@
12557
12557
  return Promise.resolve(value);
12558
12558
  }
12559
12559
  /**
12560
- * Error raised when the upstream stream emits a `data-guardrail-violation`
12561
- * chunk. The `message` carries the service-provided `fallbackResponse`, which
12562
- * is intentionally surfaced verbatim through the chat error UI (unlike
12563
- * generic cost-control / 4xx errors, where the raw API message is hidden
12564
- * behind a friendly default).
12560
+ * Error shape for custom chat implementations that still surface a
12561
+ * `data-guardrail-violation` chunk through the error UI. The `message` carries
12562
+ * the service-provided `fallbackResponse`, which is authored for end-user
12563
+ * display.
12565
12564
  *
12566
12565
  * Detection across package boundaries should rely on `error.name` rather than
12567
12566
  * `instanceof` to avoid issues with mixed module copies in bundled apps.
12568
- */ var GuardrailViolationError = /*#__PURE__*/ function(Error1) {
12567
+ */ /*#__PURE__*/ (function(Error1) {
12569
12568
  _inherits(GuardrailViolationError, Error1);
12570
12569
  function GuardrailViolationError(message) {
12571
12570
  _class_call_check(this, GuardrailViolationError);
@@ -12577,7 +12576,7 @@
12577
12576
  return _this;
12578
12577
  }
12579
12578
  return GuardrailViolationError;
12580
- }(_wrap_native_super(Error));
12579
+ })(_wrap_native_super(Error));
12581
12580
  /**
12582
12581
  * Reads a non-empty `message` field off a JSON-serialized error envelope.
12583
12582
  *
@@ -12669,6 +12668,7 @@
12669
12668
  }
12670
12669
  return fallbackInput;
12671
12670
  };
12671
+ var defaultGuardrailFallbackResponse = 'Sorry, we are not able to generate a response at the moment.';
12672
12672
  /**
12673
12673
  * Abstract base class for chat implementations.
12674
12674
  */ var AbstractChat = /*#__PURE__*/ function() {
@@ -13495,28 +13495,37 @@
13495
13495
  }
13496
13496
  break;
13497
13497
  }
13498
- // Surface guardrail violations through the error state, but
13499
- // distinct from generic cost-control / 4xx errors: throw a
13500
- // `GuardrailViolationError` so the UI can render the
13501
- // service-provided `fallbackResponse` verbatim (it's authored for
13502
- // end-user display) instead of the friendly default used for
13503
- // opaque transport errors. Also discard any in-progress assistant
13504
- // message so no partial text lingers above the fallback, and
13505
- // clear the local cursor so the `onFinish` callback doesn't
13506
- // receive a `currentMessage` that no longer exists in state.
13507
13498
  case 'data-guardrail-violation':
13508
13499
  {
13509
- isError = true;
13510
- if (currentMessageIndex >= 0) {
13511
- _this.state.messages = _this.state.messages.slice(0, currentMessageIndex);
13512
- currentMessage = undefined;
13513
- currentMessageIndex = -1;
13514
- }
13515
13500
  // `chunk.data` widens to `unknown` here: the chunk union also
13516
13501
  // carries a generic `data-${string}` member, and the literal
13517
13502
  // matches both, so narrowing can't pick the specific shape.
13518
13503
  var fallbackResponse = chunk.data.fallbackResponse;
13519
- throw new GuardrailViolationError(fallbackResponse || 'Sorry, we are not able to generate a response at the moment.');
13504
+ var fallbackText = fallbackResponse || defaultGuardrailFallbackResponse;
13505
+ // The stream closes after a guardrail violation; keep the
13506
+ // fallback as the current message so the normal finish path runs.
13507
+ currentMessage = {
13508
+ id: (currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.id) || currentMessageId || _this.generateId(),
13509
+ role: 'assistant',
13510
+ metadata: currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.metadata,
13511
+ parts: [
13512
+ {
13513
+ type: 'text',
13514
+ text: fallbackText,
13515
+ state: 'done'
13516
+ }
13517
+ ]
13518
+ };
13519
+ if (currentMessageIndex >= 0) {
13520
+ _this.state.replaceMessage(currentMessageIndex, currentMessage);
13521
+ } else {
13522
+ _this.state.pushMessage(currentMessage);
13523
+ currentMessageIndex = _this.state.messages.length - 1;
13524
+ }
13525
+ currentMessageId = currentMessage.id;
13526
+ currentTextPartId = undefined;
13527
+ currentReasoningPartId = undefined;
13528
+ break;
13520
13529
  }
13521
13530
  default:
13522
13531
  {
@@ -13651,7 +13660,7 @@
13651
13660
  var ChatState = /*#__PURE__*/ function() {
13652
13661
  function ChatState() {
13653
13662
  var _this = this;
13654
- var id = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : undefined, initialMessages = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : getDefaultInitialMessages(id);
13663
+ var id = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : undefined, initialMessages = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : undefined, persistence = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
13655
13664
  _class_call_check(this, ChatState);
13656
13665
  _define_property(this, "_messages", void 0);
13657
13666
  _define_property(this, "_status", 'ready');
@@ -13711,7 +13720,16 @@
13711
13720
  return callback();
13712
13721
  });
13713
13722
  });
13714
- this._messages = initialMessages;
13723
+ if (initialMessages !== undefined) {
13724
+ this._messages = initialMessages;
13725
+ } else if (persistence) {
13726
+ this._messages = getDefaultInitialMessages(id);
13727
+ } else {
13728
+ this._messages = [];
13729
+ }
13730
+ if (!persistence) {
13731
+ return;
13732
+ }
13715
13733
  var saveMessagesInLocalStorage = function saveMessagesInLocalStorage() {
13716
13734
  if (_this.status === 'ready') {
13717
13735
  try {
@@ -13765,11 +13783,12 @@
13765
13783
  function Chat(_0) {
13766
13784
  _class_call_check(this, Chat);
13767
13785
  var _this;
13768
- var messages = _0.messages, agentId = _0.agentId, init = _object_without_properties(_0, [
13786
+ var messages = _0.messages, agentId = _0.agentId, _0_persistence = _0.persistence, persistence = _0_persistence === void 0 ? true : _0_persistence, init = _object_without_properties(_0, [
13769
13787
  "messages",
13770
- "agentId"
13788
+ "agentId",
13789
+ "persistence"
13771
13790
  ]);
13772
- var state = new ChatState(agentId, messages);
13791
+ var state = new ChatState(agentId, messages, persistence);
13773
13792
  _this = _call_super(this, Chat, [
13774
13793
  _object_spread_props(_object_spread({}, init), {
13775
13794
  state: state