react-instantsearch 7.34.0 → 7.35.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.
package/dist/cjs/widgets/Chat.js
CHANGED
|
@@ -167,13 +167,14 @@ function ChatInner(_0, _1) {
|
|
|
167
167
|
maximizeIconComponent: headerMaximizeIconComponent,
|
|
168
168
|
translations: headerTranslations
|
|
169
169
|
}, headerProps),
|
|
170
|
-
messagesProps: _object_spread._({
|
|
170
|
+
messagesProps: _object_spread_props._(_object_spread._({
|
|
171
171
|
status: status,
|
|
172
172
|
onReload: function onReload(messageId) {
|
|
173
173
|
return regenerate({
|
|
174
174
|
messageId: messageId
|
|
175
175
|
});
|
|
176
176
|
},
|
|
177
|
+
onNewConversation: clearMessages,
|
|
177
178
|
onClose: function onClose() {
|
|
178
179
|
return setOpen(false);
|
|
179
180
|
},
|
|
@@ -205,7 +206,9 @@ function ChatInner(_0, _1) {
|
|
|
205
206
|
}, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.userMessageProps),
|
|
206
207
|
translations: messagesTranslations,
|
|
207
208
|
messageTranslations: messageTranslations
|
|
208
|
-
}, messagesProps),
|
|
209
|
+
}, messagesProps), {
|
|
210
|
+
error: error
|
|
211
|
+
}),
|
|
209
212
|
promptProps: _object_spread._({
|
|
210
213
|
promptRef: promptRef,
|
|
211
214
|
status: status,
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -131,13 +131,14 @@ function ChatInner(_0, _1) {
|
|
|
131
131
|
maximizeIconComponent: headerMaximizeIconComponent,
|
|
132
132
|
translations: headerTranslations
|
|
133
133
|
}, headerProps),
|
|
134
|
-
messagesProps: _$4({
|
|
134
|
+
messagesProps: _$5(_$4({
|
|
135
135
|
status: status,
|
|
136
136
|
onReload: function onReload(messageId) {
|
|
137
137
|
return regenerate({
|
|
138
138
|
messageId: messageId
|
|
139
139
|
});
|
|
140
140
|
},
|
|
141
|
+
onNewConversation: clearMessages,
|
|
141
142
|
onClose: function onClose() {
|
|
142
143
|
return setOpen(false);
|
|
143
144
|
},
|
|
@@ -169,7 +170,9 @@ function ChatInner(_0, _1) {
|
|
|
169
170
|
}, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.userMessageProps),
|
|
170
171
|
translations: messagesTranslations,
|
|
171
172
|
messageTranslations: messageTranslations
|
|
172
|
-
}, messagesProps),
|
|
173
|
+
}, messagesProps), {
|
|
174
|
+
error: error
|
|
175
|
+
}),
|
|
173
176
|
promptProps: _$4({
|
|
174
177
|
promptRef: promptRef,
|
|
175
178
|
status: status,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! React InstantSearch 7.
|
|
1
|
+
/*! React InstantSearch 7.35.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.
|
|
27
|
+
var version$2 = '7.35.0';
|
|
28
28
|
|
|
29
29
|
function _define_property(obj, key, value) {
|
|
30
30
|
if (key in obj) {
|
|
@@ -10821,7 +10821,7 @@
|
|
|
10821
10821
|
};
|
|
10822
10822
|
}
|
|
10823
10823
|
|
|
10824
|
-
var version = '4.
|
|
10824
|
+
var version = '4.101.0';
|
|
10825
10825
|
|
|
10826
10826
|
var withUsage$r = createDocumentationMessageGenerator({
|
|
10827
10827
|
name: 'instantsearch'
|
|
@@ -12211,16 +12211,21 @@
|
|
|
12211
12211
|
onDone();
|
|
12212
12212
|
return;
|
|
12213
12213
|
}
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
result.then
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
|
|
12220
|
-
|
|
12221
|
-
|
|
12222
|
-
|
|
12223
|
-
|
|
12214
|
+
try {
|
|
12215
|
+
var result = onChunk(value);
|
|
12216
|
+
if (result && typeof result.then === 'function') {
|
|
12217
|
+
result.then(function() {
|
|
12218
|
+
return read();
|
|
12219
|
+
}, function(error) {
|
|
12220
|
+
reader.releaseLock();
|
|
12221
|
+
onError(error);
|
|
12222
|
+
});
|
|
12223
|
+
} else {
|
|
12224
|
+
read();
|
|
12225
|
+
}
|
|
12226
|
+
} catch (error) {
|
|
12227
|
+
reader.releaseLock();
|
|
12228
|
+
onError(error);
|
|
12224
12229
|
}
|
|
12225
12230
|
}, function(error) {
|
|
12226
12231
|
reader.releaseLock();
|
|
@@ -12230,6 +12235,49 @@
|
|
|
12230
12235
|
read();
|
|
12231
12236
|
}
|
|
12232
12237
|
|
|
12238
|
+
function _construct(Parent, args, Class) {
|
|
12239
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
12240
|
+
else {
|
|
12241
|
+
_construct = function construct(Parent, args, Class) {
|
|
12242
|
+
var a = [null];
|
|
12243
|
+
a.push.apply(a, args);
|
|
12244
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
12245
|
+
var instance = new Constructor();
|
|
12246
|
+
|
|
12247
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
12248
|
+
|
|
12249
|
+
return instance;
|
|
12250
|
+
};
|
|
12251
|
+
}
|
|
12252
|
+
|
|
12253
|
+
return _construct.apply(null, arguments);
|
|
12254
|
+
}
|
|
12255
|
+
|
|
12256
|
+
function _is_native_function(fn) {
|
|
12257
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
12258
|
+
}
|
|
12259
|
+
|
|
12260
|
+
function _wrap_native_super(Class) {
|
|
12261
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
12262
|
+
_wrap_native_super = function(Class) {
|
|
12263
|
+
if (Class === null || !_is_native_function(Class)) return Class;
|
|
12264
|
+
if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
|
|
12265
|
+
if (typeof _cache !== "undefined") {
|
|
12266
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
12267
|
+
_cache.set(Class, Wrapper);
|
|
12268
|
+
}
|
|
12269
|
+
|
|
12270
|
+
function Wrapper() {
|
|
12271
|
+
return _construct(Class, arguments, _get_prototype_of(this).constructor);
|
|
12272
|
+
}
|
|
12273
|
+
Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } });
|
|
12274
|
+
|
|
12275
|
+
return _set_prototype_of(Wrapper, Class);
|
|
12276
|
+
};
|
|
12277
|
+
|
|
12278
|
+
return _wrap_native_super(Class);
|
|
12279
|
+
}
|
|
12280
|
+
|
|
12233
12281
|
function generateId() {
|
|
12234
12282
|
return Math.random().toString(36).substring(2, 9);
|
|
12235
12283
|
}
|
|
@@ -12302,6 +12350,49 @@
|
|
|
12302
12350
|
}
|
|
12303
12351
|
return Promise.resolve(value);
|
|
12304
12352
|
}
|
|
12353
|
+
/**
|
|
12354
|
+
* Error raised when the upstream stream emits a `data-guardrail-violation`
|
|
12355
|
+
* chunk. The `message` carries the service-provided `fallbackResponse`, which
|
|
12356
|
+
* is intentionally surfaced verbatim through the chat error UI (unlike
|
|
12357
|
+
* generic cost-control / 4xx errors, where the raw API message is hidden
|
|
12358
|
+
* behind a friendly default).
|
|
12359
|
+
*
|
|
12360
|
+
* Detection across package boundaries should rely on `error.name` rather than
|
|
12361
|
+
* `instanceof` to avoid issues with mixed module copies in bundled apps.
|
|
12362
|
+
*/ var GuardrailViolationError = /*#__PURE__*/ function(Error1) {
|
|
12363
|
+
_inherits(GuardrailViolationError, Error1);
|
|
12364
|
+
function GuardrailViolationError(message) {
|
|
12365
|
+
_class_call_check(this, GuardrailViolationError);
|
|
12366
|
+
var _this;
|
|
12367
|
+
_this = _call_super(this, GuardrailViolationError, [
|
|
12368
|
+
message
|
|
12369
|
+
]);
|
|
12370
|
+
_this.name = 'GuardrailViolationError';
|
|
12371
|
+
return _this;
|
|
12372
|
+
}
|
|
12373
|
+
return GuardrailViolationError;
|
|
12374
|
+
}(_wrap_native_super(Error));
|
|
12375
|
+
/**
|
|
12376
|
+
* Reads a non-empty `message` field off a JSON-serialized error envelope.
|
|
12377
|
+
*
|
|
12378
|
+
* Both transports backing `AbstractChat` (stream `error` chunks and HTTP error
|
|
12379
|
+
* responses) serialize errors as `{"message": "...", ...}` — the same shape as
|
|
12380
|
+
* the shared `ErrorResponse` on the API side. Returns the trimmed message if
|
|
12381
|
+
* the input is such a JSON object, otherwise `undefined`.
|
|
12382
|
+
*/ function tryParseErrorMessage(text) {
|
|
12383
|
+
try {
|
|
12384
|
+
var parsed = JSON.parse(text);
|
|
12385
|
+
if (parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && !Array.isArray(parsed) && typeof parsed.message === 'string') {
|
|
12386
|
+
var message = parsed.message.trim();
|
|
12387
|
+
if (message) {
|
|
12388
|
+
return message;
|
|
12389
|
+
}
|
|
12390
|
+
}
|
|
12391
|
+
} catch (unused) {
|
|
12392
|
+
// Not JSON — caller falls back to its own default.
|
|
12393
|
+
}
|
|
12394
|
+
return undefined;
|
|
12395
|
+
}
|
|
12305
12396
|
|
|
12306
12397
|
var tryParseJson = function tryParseJson(value) {
|
|
12307
12398
|
try {
|
|
@@ -12380,7 +12471,7 @@
|
|
|
12380
12471
|
var _param_generateId = param.generateId, generateId$1 = _param_generateId === void 0 ? generateId : _param_generateId, _param_id = param.id, id = _param_id === void 0 ? generateId$1() : _param_id, transport = param.transport, state = param.state, onError = param.onError, onToolCall = param.onToolCall, onFinish = param.onFinish, onData = param.onData, sendAutomaticallyWhen = param.sendAutomaticallyWhen, shouldRepairToolInput = param.shouldRepairToolInput;
|
|
12381
12472
|
var _this1 = this;
|
|
12382
12473
|
_class_call_check(this, AbstractChat);
|
|
12383
|
-
_define_property(this, "
|
|
12474
|
+
_define_property(this, "conversationId", void 0);
|
|
12384
12475
|
_define_property(this, "generateId", void 0);
|
|
12385
12476
|
_define_property(this, "state", void 0);
|
|
12386
12477
|
_define_property(this, "transport", void 0);
|
|
@@ -12536,12 +12627,6 @@
|
|
|
12536
12627
|
}
|
|
12537
12628
|
});
|
|
12538
12629
|
/**
|
|
12539
|
-
* Regenerate the chat id. Use this to start a fresh conversation on the
|
|
12540
|
-
* server while keeping the same Chat instance and its registered listeners.
|
|
12541
|
-
*/ _define_property(this, "regenerateId", function() {
|
|
12542
|
-
_this.id = _this.generateId();
|
|
12543
|
-
});
|
|
12544
|
-
/**
|
|
12545
12630
|
* Add a tool result for a tool call.
|
|
12546
12631
|
*/ _define_property(this, "addToolResult", function(param) {
|
|
12547
12632
|
var tool = param.tool, toolCallId = param.toolCallId, output = param.output;
|
|
@@ -12596,7 +12681,7 @@
|
|
|
12596
12681
|
});
|
|
12597
12682
|
return Promise.resolve();
|
|
12598
12683
|
});
|
|
12599
|
-
this.
|
|
12684
|
+
this.conversationId = id;
|
|
12600
12685
|
this.generateId = generateId$1;
|
|
12601
12686
|
this.state = state;
|
|
12602
12687
|
this.transport = transport;
|
|
@@ -12608,6 +12693,12 @@
|
|
|
12608
12693
|
this.shouldRepairToolInput = shouldRepairToolInput;
|
|
12609
12694
|
}
|
|
12610
12695
|
_create_class(AbstractChat, [
|
|
12696
|
+
{
|
|
12697
|
+
key: "id",
|
|
12698
|
+
get: function get() {
|
|
12699
|
+
return this.conversationId;
|
|
12700
|
+
}
|
|
12701
|
+
},
|
|
12611
12702
|
{
|
|
12612
12703
|
key: "status",
|
|
12613
12704
|
get: /**
|
|
@@ -12637,6 +12728,17 @@
|
|
|
12637
12728
|
return this.state.error;
|
|
12638
12729
|
}
|
|
12639
12730
|
},
|
|
12731
|
+
{
|
|
12732
|
+
/**
|
|
12733
|
+
* Starts a new server-side conversation thread by rotating the id sent as
|
|
12734
|
+
* `chatId` / `id` on the next request. The InstantSearch connector calls this
|
|
12735
|
+
* after the user clears the transcript so completions are not tied to prior
|
|
12736
|
+
* context.
|
|
12737
|
+
*/ key: "resetConversationId",
|
|
12738
|
+
value: function resetConversationId() {
|
|
12739
|
+
this.conversationId = this.generateId();
|
|
12740
|
+
}
|
|
12741
|
+
},
|
|
12640
12742
|
{
|
|
12641
12743
|
key: "messages",
|
|
12642
12744
|
get: function get() {
|
|
@@ -13005,8 +13107,7 @@
|
|
|
13005
13107
|
var updatedParts7 = _to_consumable_array(currentMessage.parts);
|
|
13006
13108
|
var existingPart2 = updatedParts7[toolIndex2];
|
|
13007
13109
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13008
|
-
existingPart2.rawOutput
|
|
13009
|
-
var rest = _object_without_properties(existingPart2, [
|
|
13110
|
+
var _ignored = existingPart2.rawOutput, rest = _object_without_properties(existingPart2, [
|
|
13010
13111
|
"rawOutput"
|
|
13011
13112
|
]);
|
|
13012
13113
|
updatedParts7[toolIndex2] = _object_spread_props(_object_spread({}, rest), {
|
|
@@ -13034,10 +13135,7 @@
|
|
|
13034
13135
|
delete toolRawOutputByCallId[chunk.toolCallId];
|
|
13035
13136
|
var updatedParts8 = _to_consumable_array(currentMessage.parts);
|
|
13036
13137
|
var existingPart3 = updatedParts8[toolIndex3];
|
|
13037
|
-
|
|
13038
|
-
existingPart3.rawOutput; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13039
|
-
existingPart3.preliminary;
|
|
13040
|
-
var rest1 = _object_without_properties(existingPart3, [
|
|
13138
|
+
var _ignoredRawOutput = existingPart3.rawOutput, _ignoredPreliminary = existingPart3.preliminary, rest1 = _object_without_properties(existingPart3, [
|
|
13041
13139
|
"rawOutput",
|
|
13042
13140
|
"preliminary"
|
|
13043
13141
|
]);
|
|
@@ -13132,7 +13230,8 @@
|
|
|
13132
13230
|
case 'error':
|
|
13133
13231
|
{
|
|
13134
13232
|
isError = true;
|
|
13135
|
-
|
|
13233
|
+
var text = chunk.errorText.trim();
|
|
13234
|
+
throw new Error(tryParseErrorMessage(text) || text || 'Unknown error');
|
|
13136
13235
|
}
|
|
13137
13236
|
case 'abort':
|
|
13138
13237
|
{
|
|
@@ -13149,9 +13248,32 @@
|
|
|
13149
13248
|
}
|
|
13150
13249
|
break;
|
|
13151
13250
|
}
|
|
13251
|
+
// Surface guardrail violations through the error state, but
|
|
13252
|
+
// distinct from generic cost-control / 4xx errors: throw a
|
|
13253
|
+
// `GuardrailViolationError` so the UI can render the
|
|
13254
|
+
// service-provided `fallbackResponse` verbatim (it's authored for
|
|
13255
|
+
// end-user display) instead of the friendly default used for
|
|
13256
|
+
// opaque transport errors. Also discard any in-progress assistant
|
|
13257
|
+
// message so no partial text lingers above the fallback, and
|
|
13258
|
+
// clear the local cursor so the `onFinish` callback doesn't
|
|
13259
|
+
// receive a `currentMessage` that no longer exists in state.
|
|
13260
|
+
case 'data-guardrail-violation':
|
|
13261
|
+
{
|
|
13262
|
+
isError = true;
|
|
13263
|
+
if (currentMessageIndex >= 0) {
|
|
13264
|
+
_this.state.messages = _this.state.messages.slice(0, currentMessageIndex);
|
|
13265
|
+
currentMessage = undefined;
|
|
13266
|
+
currentMessageIndex = -1;
|
|
13267
|
+
}
|
|
13268
|
+
// `chunk.data` widens to `unknown` here: the chunk union also
|
|
13269
|
+
// carries a generic `data-${string}` member, and the literal
|
|
13270
|
+
// matches both, so narrowing can't pick the specific shape.
|
|
13271
|
+
var fallbackResponse = chunk.data.fallbackResponse;
|
|
13272
|
+
throw new GuardrailViolationError(fallbackResponse || 'Sorry, we are not able to generate a response at the moment.');
|
|
13273
|
+
}
|
|
13152
13274
|
default:
|
|
13153
13275
|
{
|
|
13154
|
-
// Handle data parts (data-*)
|
|
13276
|
+
// Handle generic data parts (data-*)
|
|
13155
13277
|
var chunkType = chunk.type;
|
|
13156
13278
|
if ((chunkType === null || chunkType === void 0 ? void 0 : chunkType.startsWith('data-')) && currentMessage) {
|
|
13157
13279
|
var dataPart = {
|
|
@@ -13466,6 +13588,20 @@
|
|
|
13466
13588
|
}, []);
|
|
13467
13589
|
}
|
|
13468
13590
|
|
|
13591
|
+
/**
|
|
13592
|
+
* Reads a human-readable message from a failed HTTP response body when the
|
|
13593
|
+
* server returns JSON such as `{ "message": "..." }` (the shared
|
|
13594
|
+
* `ErrorResponse` shape used by every status code), falling back to the HTTP
|
|
13595
|
+
* status line when the body is empty or not parseable.
|
|
13596
|
+
*/ function getHttpErrorMessage(response) {
|
|
13597
|
+
var fallback = "HTTP error: ".concat(response.status, " ").concat(response.statusText);
|
|
13598
|
+
return response.text().then(function(text) {
|
|
13599
|
+
var _tryParseErrorMessage;
|
|
13600
|
+
return (_tryParseErrorMessage = tryParseErrorMessage(text)) !== null && _tryParseErrorMessage !== void 0 ? _tryParseErrorMessage : fallback;
|
|
13601
|
+
}).catch(function() {
|
|
13602
|
+
return fallback;
|
|
13603
|
+
});
|
|
13604
|
+
}
|
|
13469
13605
|
/**
|
|
13470
13606
|
* Abstract base class for HTTP-based chat transports.
|
|
13471
13607
|
*/ var HttpChatTransport = /*#__PURE__*/ function() {
|
|
@@ -13544,7 +13680,9 @@
|
|
|
13544
13680
|
credentials: credentials
|
|
13545
13681
|
}).then(function(response) {
|
|
13546
13682
|
if (!response.ok) {
|
|
13547
|
-
|
|
13683
|
+
return getHttpErrorMessage(response).then(function(message) {
|
|
13684
|
+
throw new Error(message);
|
|
13685
|
+
});
|
|
13548
13686
|
}
|
|
13549
13687
|
if (!response.body) {
|
|
13550
13688
|
throw new Error('Response body is empty');
|
|
@@ -13602,7 +13740,9 @@
|
|
|
13602
13740
|
if (response.status === 404) {
|
|
13603
13741
|
return null;
|
|
13604
13742
|
}
|
|
13605
|
-
|
|
13743
|
+
return getHttpErrorMessage(response).then(function(message) {
|
|
13744
|
+
throw new Error(message);
|
|
13745
|
+
});
|
|
13606
13746
|
}
|
|
13607
13747
|
if (!response.body) {
|
|
13608
13748
|
return null;
|
|
@@ -13750,7 +13890,7 @@
|
|
|
13750
13890
|
var onClearTransitionEnd = function onClearTransitionEnd() {
|
|
13751
13891
|
setMessages([]);
|
|
13752
13892
|
_chatInstance.clearError();
|
|
13753
|
-
_chatInstance.
|
|
13893
|
+
_chatInstance.resetConversationId();
|
|
13754
13894
|
feedbackState = {};
|
|
13755
13895
|
setIsClearing(false);
|
|
13756
13896
|
};
|
|
@@ -19908,15 +20048,32 @@
|
|
|
19908
20048
|
createElement: createElement
|
|
19909
20049
|
});
|
|
19910
20050
|
return function ChatMessageError(userProps) {
|
|
19911
|
-
var
|
|
20051
|
+
var _ref, _ref1;
|
|
20052
|
+
var errorMessage = userProps.errorMessage, onReload = userProps.onReload, onNewConversation = userProps.onNewConversation, actions = userProps.actions, userTranslations = userProps.translations, props = _object_without_properties(userProps, [
|
|
20053
|
+
"errorMessage",
|
|
19912
20054
|
"onReload",
|
|
20055
|
+
"onNewConversation",
|
|
19913
20056
|
"actions",
|
|
19914
20057
|
"translations"
|
|
19915
20058
|
]);
|
|
19916
|
-
var
|
|
19917
|
-
|
|
19918
|
-
|
|
19919
|
-
|
|
20059
|
+
var defaultErrorMessage = 'Sorry, we are not able to generate a response at the moment. Please contact support.';
|
|
20060
|
+
var defaultNewConversationText = 'Start a new conversation';
|
|
20061
|
+
var defaultRetryText = 'Retry';
|
|
20062
|
+
var errorMessageTranslation = userTranslations === null || userTranslations === void 0 ? void 0 : userTranslations.errorMessage;
|
|
20063
|
+
var resolvedErrorMessage = typeof errorMessageTranslation === 'function' ? errorMessageTranslation({
|
|
20064
|
+
errorMessage: errorMessage
|
|
20065
|
+
}) : errorMessageTranslation !== null && errorMessageTranslation !== void 0 ? errorMessageTranslation : defaultErrorMessage;
|
|
20066
|
+
var newConversationText = (_ref = userTranslations === null || userTranslations === void 0 ? void 0 : userTranslations.newConversationText) !== null && _ref !== void 0 ? _ref : defaultNewConversationText;
|
|
20067
|
+
var retryText = (_ref1 = userTranslations === null || userTranslations === void 0 ? void 0 : userTranslations.retryText) !== null && _ref1 !== void 0 ? _ref1 : defaultRetryText;
|
|
20068
|
+
// Action precedence:
|
|
20069
|
+
// 1. `actions` (full custom)
|
|
20070
|
+
// 2. `onNewConversation` (recommended for permanent / guardrail errors)
|
|
20071
|
+
// 3. `onReload` (legacy retry, suitable for transient failures)
|
|
20072
|
+
// 4. nothing
|
|
20073
|
+
var hasCustomActions = Boolean(actions);
|
|
20074
|
+
var showNewConversation = !hasCustomActions && Boolean(onNewConversation);
|
|
20075
|
+
var showRetry = !hasCustomActions && !showNewConversation && Boolean(onReload);
|
|
20076
|
+
var hasActions = hasCustomActions || showNewConversation || showRetry;
|
|
19920
20077
|
return /*#__PURE__*/ createElement("article", _object_spread({
|
|
19921
20078
|
className: "ais-ChatMessageError ais-ChatMessage ais-ChatMessage--left ais-ChatMessage--subtle"
|
|
19922
20079
|
}, props), /*#__PURE__*/ createElement("div", {
|
|
@@ -19925,15 +20082,22 @@
|
|
|
19925
20082
|
className: "ais-ChatMessage-content"
|
|
19926
20083
|
}, /*#__PURE__*/ createElement("div", {
|
|
19927
20084
|
className: "ais-ChatMessage-message"
|
|
19928
|
-
},
|
|
20085
|
+
}, resolvedErrorMessage), hasActions && /*#__PURE__*/ createElement("div", {
|
|
19929
20086
|
className: "ais-ChatMessage-actions"
|
|
19930
|
-
},
|
|
20087
|
+
}, hasCustomActions ? actions.map(function(action, index) {
|
|
19931
20088
|
return /*#__PURE__*/ createElement(Button, _object_spread({
|
|
19932
20089
|
key: index,
|
|
19933
20090
|
variant: "ghost",
|
|
19934
20091
|
className: "ais-ChatMessage-action"
|
|
19935
20092
|
}, action), action.children);
|
|
19936
|
-
}) : /*#__PURE__*/ createElement(Button, {
|
|
20093
|
+
}) : showNewConversation ? /*#__PURE__*/ createElement(Button, {
|
|
20094
|
+
variant: "primary",
|
|
20095
|
+
size: "md",
|
|
20096
|
+
className: "ais-ChatMessage-errorAction",
|
|
20097
|
+
onClick: function onClick() {
|
|
20098
|
+
return onNewConversation === null || onNewConversation === void 0 ? void 0 : onNewConversation();
|
|
20099
|
+
}
|
|
20100
|
+
}, newConversationText) : /*#__PURE__*/ createElement(Button, {
|
|
19937
20101
|
variant: "primary",
|
|
19938
20102
|
size: "md",
|
|
19939
20103
|
className: "ais-ChatMessage-errorAction",
|
|
@@ -19942,7 +20106,7 @@
|
|
|
19942
20106
|
}
|
|
19943
20107
|
}, /*#__PURE__*/ createElement(ReloadIcon, {
|
|
19944
20108
|
createElement: createElement
|
|
19945
|
-
}),
|
|
20109
|
+
}), retryText)))));
|
|
19946
20110
|
};
|
|
19947
20111
|
}
|
|
19948
20112
|
|
|
@@ -20106,7 +20270,7 @@
|
|
|
20106
20270
|
});
|
|
20107
20271
|
return function ChatMessages(userProps) {
|
|
20108
20272
|
var _lastMessage_parts;
|
|
20109
|
-
var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, _userProps_messageClassNames = userProps.messageClassNames, messageClassNames = _userProps_messageClassNames === void 0 ? {} : _userProps_messageClassNames, messageTranslations = userProps.messageTranslations, _userProps_messages = userProps.messages, messages = _userProps_messages === void 0 ? [] : _userProps_messages, MessageComponent = userProps.messageComponent, LoaderComponent = userProps.loaderComponent, ErrorComponent = userProps.errorComponent, EmptyComponent = userProps.emptyComponent, ActionsComponent = userProps.actionsComponent, tools = userProps.tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, _userProps_status = userProps.status, status = _userProps_status === void 0 ? 'ready' : _userProps_status, _userProps_hideScrollToBottom = userProps.hideScrollToBottom, hideScrollToBottom = _userProps_hideScrollToBottom === void 0 ? false : _userProps_hideScrollToBottom, onReload = userProps.onReload, onClose = userProps.onClose, sendMessage = userProps.sendMessage, setInput = userProps.setInput, userTranslations = userProps.translations, userMessageProps = userProps.userMessageProps, assistantMessageProps = userProps.assistantMessageProps, _userProps_isClearing = userProps.isClearing, isClearing = _userProps_isClearing === void 0 ? false : _userProps_isClearing, onClearTransitionEnd = userProps.onClearTransitionEnd, isScrollAtBottom = userProps.isScrollAtBottom, scrollRef = userProps.scrollRef, contentRef = userProps.contentRef, onScrollToBottom = userProps.onScrollToBottom, suggestionsElement = userProps.suggestionsElement, onFeedback = userProps.onFeedback, feedbackState = userProps.feedbackState, props = _object_without_properties(userProps, [
|
|
20273
|
+
var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, _userProps_messageClassNames = userProps.messageClassNames, messageClassNames = _userProps_messageClassNames === void 0 ? {} : _userProps_messageClassNames, messageTranslations = userProps.messageTranslations, _userProps_messages = userProps.messages, messages = _userProps_messages === void 0 ? [] : _userProps_messages, MessageComponent = userProps.messageComponent, LoaderComponent = userProps.loaderComponent, ErrorComponent = userProps.errorComponent, EmptyComponent = userProps.emptyComponent, ActionsComponent = userProps.actionsComponent, tools = userProps.tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, _userProps_status = userProps.status, status = _userProps_status === void 0 ? 'ready' : _userProps_status, error = userProps.error, _userProps_hideScrollToBottom = userProps.hideScrollToBottom, hideScrollToBottom = _userProps_hideScrollToBottom === void 0 ? false : _userProps_hideScrollToBottom, onReload = userProps.onReload, onNewConversation = userProps.onNewConversation, onClose = userProps.onClose, sendMessage = userProps.sendMessage, setInput = userProps.setInput, userTranslations = userProps.translations, userMessageProps = userProps.userMessageProps, assistantMessageProps = userProps.assistantMessageProps, _userProps_isClearing = userProps.isClearing, isClearing = _userProps_isClearing === void 0 ? false : _userProps_isClearing, onClearTransitionEnd = userProps.onClearTransitionEnd, isScrollAtBottom = userProps.isScrollAtBottom, scrollRef = userProps.scrollRef, contentRef = userProps.contentRef, onScrollToBottom = userProps.onScrollToBottom, suggestionsElement = userProps.suggestionsElement, onFeedback = userProps.onFeedback, feedbackState = userProps.feedbackState, props = _object_without_properties(userProps, [
|
|
20110
20274
|
"classNames",
|
|
20111
20275
|
"messageClassNames",
|
|
20112
20276
|
"messageTranslations",
|
|
@@ -20120,8 +20284,10 @@
|
|
|
20120
20284
|
"indexUiState",
|
|
20121
20285
|
"setIndexUiState",
|
|
20122
20286
|
"status",
|
|
20287
|
+
"error",
|
|
20123
20288
|
"hideScrollToBottom",
|
|
20124
20289
|
"onReload",
|
|
20290
|
+
"onNewConversation",
|
|
20125
20291
|
"onClose",
|
|
20126
20292
|
"sendMessage",
|
|
20127
20293
|
"setInput",
|
|
@@ -20206,7 +20372,18 @@
|
|
|
20206
20372
|
loaderText: translations.loaderText
|
|
20207
20373
|
}
|
|
20208
20374
|
}), status === 'error' && /*#__PURE__*/ createElement(DefaultError, {
|
|
20209
|
-
|
|
20375
|
+
onNewConversation: onNewConversation,
|
|
20376
|
+
errorMessage: error === null || error === void 0 ? void 0 : error.message,
|
|
20377
|
+
translations: // `fallbackResponse` that's safe to display verbatim; for
|
|
20378
|
+
// every other error we keep hiding the raw `error.message`
|
|
20379
|
+
// behind the friendly default. Detection is by `error.name`
|
|
20380
|
+
// to avoid coupling this package to `instantsearch.js`.
|
|
20381
|
+
(error === null || error === void 0 ? void 0 : error.name) === 'GuardrailViolationError' ? {
|
|
20382
|
+
errorMessage: function errorMessage(param) {
|
|
20383
|
+
var rawMessage = param.errorMessage;
|
|
20384
|
+
return rawMessage !== null && rawMessage !== void 0 ? rawMessage : '';
|
|
20385
|
+
}
|
|
20386
|
+
} : undefined
|
|
20210
20387
|
}))), /*#__PURE__*/ createElement(Button, {
|
|
20211
20388
|
variant: "outline",
|
|
20212
20389
|
size: "sm",
|
|
@@ -20506,6 +20683,7 @@
|
|
|
20506
20683
|
maximized: maximized
|
|
20507
20684
|
}));
|
|
20508
20685
|
var messagesComponent = /*#__PURE__*/ createElement(ChatMessages, _object_spread_props(_object_spread({}, messagesProps), {
|
|
20686
|
+
error: error,
|
|
20509
20687
|
classNames: classNames.messages,
|
|
20510
20688
|
messageClassNames: classNames.message,
|
|
20511
20689
|
suggestionsElement: createElement(SuggestionsComponent || ChatPromptSuggestions, _object_spread_props(_object_spread({}, suggestionsProps), {
|
|
@@ -22932,13 +23110,14 @@
|
|
|
22932
23110
|
maximizeIconComponent: headerMaximizeIconComponent,
|
|
22933
23111
|
translations: headerTranslations
|
|
22934
23112
|
}, headerProps),
|
|
22935
|
-
messagesProps: _object_spread({
|
|
23113
|
+
messagesProps: _object_spread_props(_object_spread({
|
|
22936
23114
|
status: status,
|
|
22937
23115
|
onReload: function onReload(messageId) {
|
|
22938
23116
|
return regenerate({
|
|
22939
23117
|
messageId: messageId
|
|
22940
23118
|
});
|
|
22941
23119
|
},
|
|
23120
|
+
onNewConversation: clearMessages,
|
|
22942
23121
|
onClose: function onClose() {
|
|
22943
23122
|
return setOpen(false);
|
|
22944
23123
|
},
|
|
@@ -22970,7 +23149,9 @@
|
|
|
22970
23149
|
}, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.userMessageProps),
|
|
22971
23150
|
translations: messagesTranslations,
|
|
22972
23151
|
messageTranslations: messageTranslations
|
|
22973
|
-
}, messagesProps),
|
|
23152
|
+
}, messagesProps), {
|
|
23153
|
+
error: error
|
|
23154
|
+
}),
|
|
22974
23155
|
promptProps: _object_spread({
|
|
22975
23156
|
promptRef: promptRef,
|
|
22976
23157
|
status: status,
|