react-instantsearch-core 7.36.0 → 7.38.0

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.
@@ -9,4 +9,4 @@ Object.defineProperty(exports, "default", {
9
9
  return _default;
10
10
  }
11
11
  });
12
- var _default = '7.36.0';
12
+ var _default = '7.38.0';
@@ -1,2 +1,2 @@
1
- declare const _default: "7.36.0";
1
+ declare const _default: "7.38.0";
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
- var version = '7.36.0';
1
+ var version = '7.38.0';
2
2
 
3
3
  export { version as default };
@@ -1,4 +1,4 @@
1
- /*! React InstantSearch Core 7.36.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch Core 7.38.0 | © 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.36.0';
27
+ var version$2 = '7.38.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -6903,10 +6903,11 @@
6903
6903
 
6904
6904
  var hasAlphanumeric = new RegExp(/\w/i);
6905
6905
  function getHighlightFromSiblings(parts, i) {
6906
+ var _ref, _ref1;
6906
6907
  var _parts_, _parts_1;
6907
6908
  var current = parts[i];
6908
- var isNextHighlighted = ((_parts_ = parts[i + 1]) === null || _parts_ === void 0 ? void 0 : _parts_.isHighlighted) || true;
6909
- var isPreviousHighlighted = ((_parts_1 = parts[i - 1]) === null || _parts_1 === void 0 ? void 0 : _parts_1.isHighlighted) || true;
6909
+ var isNextHighlighted = (_ref = (_parts_ = parts[i + 1]) === null || _parts_ === void 0 ? void 0 : _parts_.isHighlighted) !== null && _ref !== void 0 ? _ref : true;
6910
+ var isPreviousHighlighted = (_ref1 = (_parts_1 = parts[i - 1]) === null || _parts_1 === void 0 ? void 0 : _parts_1.isHighlighted) !== null && _ref1 !== void 0 ? _ref1 : true;
6910
6911
  if (!hasAlphanumeric.test(unescape$1(current.value)) && isPreviousHighlighted === isNextHighlighted) {
6911
6912
  return isPreviousHighlighted;
6912
6913
  }
@@ -10853,7 +10854,7 @@
10853
10854
  };
10854
10855
  }
10855
10856
 
10856
- var version = '4.102.0';
10857
+ var version = '4.104.0';
10857
10858
 
10858
10859
  var withUsage$r = createDocumentationMessageGenerator({
10859
10860
  name: 'instantsearch'
@@ -13174,33 +13175,74 @@
13174
13175
  }
13175
13176
  break;
13176
13177
  }
13177
- case 'tool-error':
13178
+ case 'tool-input-error':
13178
13179
  {
13180
+ var _chunk_input, _chunk_providerExecuted, _chunk_providerMetadata;
13179
13181
  if (!currentMessage) break;
13182
+ delete toolRawInputByCallId[chunk.toolCallId];
13183
+ delete toolRawOutputByCallId[chunk.toolCallId];
13180
13184
  var toolIndex3 = currentMessage.parts.findIndex(function(p) {
13181
13185
  return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
13182
13186
  });
13187
+ var existingPart3 = toolIndex3 >= 0 ? currentMessage.parts[toolIndex3] : null;
13188
+ var _ref5 = existingPart3 !== null && existingPart3 !== void 0 ? existingPart3 : {}, _ignoredOutput = _ref5.output, _ignoredRawOutput = _ref5.rawOutput, _ignoredPreliminary = _ref5.preliminary, carryOver = _object_without_properties(_ref5, [
13189
+ "output",
13190
+ "rawOutput",
13191
+ "preliminary"
13192
+ ]);
13193
+ var nextToolPart2 = _object_spread_props(_object_spread({}, carryOver), {
13194
+ type: "tool-".concat(chunk.toolName),
13195
+ toolCallId: chunk.toolCallId,
13196
+ state: 'output-error',
13197
+ input: undefined,
13198
+ rawInput: (_chunk_input = chunk.input) !== null && _chunk_input !== void 0 ? _chunk_input : carryOver.rawInput,
13199
+ errorText: chunk.errorText,
13200
+ providerExecuted: (_chunk_providerExecuted = chunk.providerExecuted) !== null && _chunk_providerExecuted !== void 0 ? _chunk_providerExecuted : carryOver.providerExecuted,
13201
+ callProviderMetadata: (_chunk_providerMetadata = chunk.providerMetadata) !== null && _chunk_providerMetadata !== void 0 ? _chunk_providerMetadata : carryOver.callProviderMetadata
13202
+ });
13183
13203
  if (toolIndex3 >= 0) {
13184
- var _chunk_input;
13185
- delete toolRawInputByCallId[chunk.toolCallId];
13186
- delete toolRawOutputByCallId[chunk.toolCallId];
13187
13204
  var updatedParts8 = _to_consumable_array(currentMessage.parts);
13188
- var existingPart3 = updatedParts8[toolIndex3];
13189
- var _ignoredRawOutput = existingPart3.rawOutput, _ignoredPreliminary = existingPart3.preliminary, rest1 = _object_without_properties(existingPart3, [
13190
- "rawOutput",
13191
- "preliminary"
13192
- ]);
13193
- updatedParts8[toolIndex3] = _object_spread_props(_object_spread({}, rest1), {
13194
- state: 'output-error',
13195
- errorText: chunk.errorText,
13196
- input: (_chunk_input = chunk.input) !== null && _chunk_input !== void 0 ? _chunk_input : existingPart3.input,
13197
- callProviderMetadata: chunk.callProviderMetadata
13198
- });
13205
+ updatedParts8[toolIndex3] = nextToolPart2;
13199
13206
  currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
13200
13207
  parts: updatedParts8
13201
13208
  });
13202
- _this.state.replaceMessage(currentMessageIndex, currentMessage);
13209
+ } else {
13210
+ currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
13211
+ parts: _to_consumable_array(currentMessage.parts).concat([
13212
+ nextToolPart2
13213
+ ])
13214
+ });
13203
13215
  }
13216
+ _this.state.replaceMessage(currentMessageIndex, currentMessage);
13217
+ break;
13218
+ }
13219
+ case 'tool-output-error':
13220
+ {
13221
+ var _chunk_providerExecuted1, _chunk_providerMetadata1;
13222
+ if (!currentMessage) break;
13223
+ var toolIndex4 = currentMessage.parts.findIndex(function(p) {
13224
+ return 'toolCallId' in p && p.toolCallId === chunk.toolCallId;
13225
+ });
13226
+ if (toolIndex4 < 0) break;
13227
+ delete toolRawInputByCallId[chunk.toolCallId];
13228
+ delete toolRawOutputByCallId[chunk.toolCallId];
13229
+ var updatedParts9 = _to_consumable_array(currentMessage.parts);
13230
+ var existingPart4 = updatedParts9[toolIndex4];
13231
+ var _ignoredRawOutput1 = existingPart4.rawOutput, _ignoredPreliminary1 = existingPart4.preliminary, _ignoredOutput1 = existingPart4.output, rest1 = _object_without_properties(existingPart4, [
13232
+ "rawOutput",
13233
+ "preliminary",
13234
+ "output"
13235
+ ]);
13236
+ updatedParts9[toolIndex4] = _object_spread_props(_object_spread({}, rest1), {
13237
+ state: 'output-error',
13238
+ errorText: chunk.errorText,
13239
+ providerExecuted: (_chunk_providerExecuted1 = chunk.providerExecuted) !== null && _chunk_providerExecuted1 !== void 0 ? _chunk_providerExecuted1 : rest1.providerExecuted,
13240
+ callProviderMetadata: (_chunk_providerMetadata1 = chunk.providerMetadata) !== null && _chunk_providerMetadata1 !== void 0 ? _chunk_providerMetadata1 : rest1.callProviderMetadata
13241
+ });
13242
+ currentMessage = _object_spread_props(_object_spread({}, currentMessage), {
13243
+ parts: updatedParts9
13244
+ });
13245
+ _this.state.replaceMessage(currentMessageIndex, currentMessage);
13204
13246
  break;
13205
13247
  }
13206
13248
  case 'source-url':
@@ -13889,12 +13931,10 @@
13889
13931
  var _chatInstance;
13890
13932
  var input = '';
13891
13933
  var open = false;
13892
- var isClearing = false;
13893
13934
  var sendEvent;
13894
13935
  var setInput;
13895
13936
  var setOpen;
13896
13937
  var focusInput;
13897
- var setIsClearing;
13898
13938
  var setFeedbackState;
13899
13939
  var hasValidatedEntryPoints = false;
13900
13940
  var agentId = 'agentId' in options ? options.agentId : undefined;
@@ -13924,21 +13964,17 @@
13924
13964
  _chatInstance.messages = messagesParam;
13925
13965
  };
13926
13966
  var clearMessages = function clearMessages() {
13927
- if (!_chatInstance.messages || _chatInstance.messages.length === 0) {
13928
- return;
13929
- }
13930
13967
  var status = _chatInstance.status;
13931
13968
  if (status === 'submitted' || status === 'streaming') {
13932
13969
  _chatInstance.stop();
13933
13970
  }
13934
- setIsClearing(true);
13935
- };
13936
- var onClearTransitionEnd = function onClearTransitionEnd() {
13971
+ // Reset the non-reactive state first: `setMessages` and `clearError` emit
13972
+ // ChatState callbacks that synchronously re-render, so they must run last
13973
+ // for that render to see the cleared feedback and rotated conversation id.
13974
+ feedbackState = {};
13975
+ _chatInstance.resetConversationId();
13937
13976
  setMessages([]);
13938
13977
  _chatInstance.clearError();
13939
- _chatInstance.resetConversationId();
13940
- feedbackState = {};
13941
- setIsClearing(false);
13942
13978
  };
13943
13979
  var validateEntryPoints = function validateEntryPoints(instantSearchInstance) {
13944
13980
  if (disableTriggerValidation || hasValidatedEntryPoints) {
@@ -14004,22 +14040,37 @@
14004
14040
  }));
14005
14041
  }
14006
14042
  if ('agentId' in options && options.agentId) {
14043
+ var _options_requestOptions, _options_requestOptions1;
14007
14044
  if (!appId || !apiKey) {
14008
14045
  throw new Error(withUsage$o('Could not extract Algolia credentials from the search client.'));
14009
14046
  }
14010
- var baseApi = "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5");
14047
+ var createApi = function createApi() {
14048
+ var bypassCache = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
14049
+ var _options_requestOptions;
14050
+ var api = new URL("https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions"));
14051
+ var queryParameters = _object_spread(_object_spread_props(_object_spread({}, (_options_requestOptions = options.requestOptions) === null || _options_requestOptions === void 0 ? void 0 : _options_requestOptions.queryParameters), {
14052
+ compatibilityMode: 'ai-sdk-5'
14053
+ }), bypassCache ? {
14054
+ cache: false
14055
+ } : {});
14056
+ api.search = new URLSearchParams(queryParameters).toString();
14057
+ return api.toString();
14058
+ };
14059
+ var baseApi = createApi();
14011
14060
  transport = new DefaultChatTransport({
14012
14061
  api: baseApi,
14013
- headers: {
14062
+ headers: _object_spread_props(_object_spread({}, _instanceof((_options_requestOptions = options.requestOptions) === null || _options_requestOptions === void 0 ? void 0 : _options_requestOptions.headers, Headers) ? Object.fromEntries(options.requestOptions.headers.entries()) : (_options_requestOptions1 = options.requestOptions) === null || _options_requestOptions1 === void 0 ? void 0 : _options_requestOptions1.headers), {
14063
+ // Preserve the required Algolia identity headers and chat agent
14064
+ // marker, even when requestOptions.headers contains the same keys.
14014
14065
  'x-algolia-application-id': appId,
14015
14066
  'x-algolia-api-key': apiKey,
14016
14067
  'x-algolia-agent': "".concat(getAlgoliaAgent(client), "; chat")
14017
- },
14068
+ }),
14018
14069
  prepareSendMessagesRequest: function prepareSendMessagesRequest(param) {
14019
14070
  var id = param.id, messages = param.messages, trigger = param.trigger, messageId = param.messageId;
14020
14071
  return {
14021
14072
  // Bypass cache when regenerating to ensure fresh responses
14022
- api: trigger === 'regenerate-message' ? "".concat(baseApi, "&cache=false") : baseApi,
14073
+ api: trigger === 'regenerate-message' ? createApi(true) : baseApi,
14023
14074
  body: {
14024
14075
  id: id,
14025
14076
  messageId: messageId,
@@ -14104,10 +14155,6 @@
14104
14155
  input = i;
14105
14156
  render();
14106
14157
  };
14107
- setIsClearing = function setIsClearing(value) {
14108
- isClearing = value;
14109
- render();
14110
- };
14111
14158
  setFeedbackState = function setFeedbackState(messageId, state) {
14112
14159
  feedbackState = _object_spread_props(_object_spread({}, feedbackState), _define_property({}, messageId, state));
14113
14160
  render();
@@ -14226,9 +14273,7 @@
14226
14273
  focusInput: focusInput,
14227
14274
  setMessages: setMessages,
14228
14275
  suggestions: getSuggestionsFromMessages(_chatInstance.messages),
14229
- isClearing: isClearing,
14230
14276
  clearMessages: clearMessages,
14231
- onClearTransitionEnd: onClearTransitionEnd,
14232
14277
  tools: toolsWithAddToolResult,
14233
14278
  sendChatMessageFeedback: _sendChatMessageFeedback,
14234
14279
  feedbackState: feedbackState,