react-instantsearch-core 7.44.0 → 7.45.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/version.js
CHANGED
package/dist/es/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "7.
|
|
1
|
+
declare const _default: "7.45.0";
|
|
2
2
|
export default _default;
|
package/dist/es/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! React InstantSearch Core 7.
|
|
1
|
+
/*! React InstantSearch Core 7.45.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.45.0';
|
|
28
28
|
|
|
29
29
|
function _define_property(obj, key, value) {
|
|
30
30
|
if (key in obj) {
|
|
@@ -9249,7 +9249,7 @@
|
|
|
9249
9249
|
});
|
|
9250
9250
|
}
|
|
9251
9251
|
|
|
9252
|
-
var version = '4.
|
|
9252
|
+
var version = '4.112.0';
|
|
9253
9253
|
|
|
9254
9254
|
var ANONYMOUS_TOKEN_COOKIE_KEY = '_ALGOLIA';
|
|
9255
9255
|
function getCookie(name) {
|
|
@@ -12444,6 +12444,68 @@
|
|
|
12444
12444
|
return useConnector(connectBreadcrumb, props, additionalWidgetProperties);
|
|
12445
12445
|
}
|
|
12446
12446
|
|
|
12447
|
+
function startsWith(str, prefix) {
|
|
12448
|
+
return str.slice(0, prefix.length) === prefix;
|
|
12449
|
+
}
|
|
12450
|
+
|
|
12451
|
+
var isPartTool = function isPartTool(part) {
|
|
12452
|
+
return startsWith(part.type, 'tool-');
|
|
12453
|
+
};
|
|
12454
|
+
|
|
12455
|
+
var createRecords = function createRecords() {
|
|
12456
|
+
return Object.create(null);
|
|
12457
|
+
};
|
|
12458
|
+
var hasOwn = function hasOwn(records, objectID) {
|
|
12459
|
+
return Object.prototype.hasOwnProperty.call(records, objectID);
|
|
12460
|
+
};
|
|
12461
|
+
function createChatRecordsStore() {
|
|
12462
|
+
var records = createRecords();
|
|
12463
|
+
return {
|
|
12464
|
+
get: function get(objectID) {
|
|
12465
|
+
return hasOwn(records, objectID) ? records[objectID] : undefined;
|
|
12466
|
+
},
|
|
12467
|
+
has: function has(objectID) {
|
|
12468
|
+
return hasOwn(records, objectID);
|
|
12469
|
+
},
|
|
12470
|
+
getAll: function getAll() {
|
|
12471
|
+
return records;
|
|
12472
|
+
},
|
|
12473
|
+
merge: function merge(contributed) {
|
|
12474
|
+
contributed.forEach(function(record) {
|
|
12475
|
+
if (record && typeof record.objectID === 'string' && record.objectID !== '') {
|
|
12476
|
+
records[record.objectID] = record;
|
|
12477
|
+
}
|
|
12478
|
+
});
|
|
12479
|
+
},
|
|
12480
|
+
clear: function clear() {
|
|
12481
|
+
records = createRecords();
|
|
12482
|
+
}
|
|
12483
|
+
};
|
|
12484
|
+
}
|
|
12485
|
+
/**
|
|
12486
|
+
* Collects into `store` the records of every completed tool call in `messages`
|
|
12487
|
+
* whose output holds `hits`. Matching on the output rather than on a tool name
|
|
12488
|
+
* means any tool that fetches records contributes them by returning them.
|
|
12489
|
+
*
|
|
12490
|
+
* Idempotent, so it can re-run over the whole conversation on every update:
|
|
12491
|
+
* streaming deltas and a conversation restored from storage are one code path.
|
|
12492
|
+
*/ function collectChatRecords(messages) {
|
|
12493
|
+
var store = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : createChatRecordsStore();
|
|
12494
|
+
messages === null || messages === void 0 ? void 0 : messages.forEach(function(message) {
|
|
12495
|
+
message.parts.forEach(function(part) {
|
|
12496
|
+
var _part_output;
|
|
12497
|
+
if (!isPartTool(part) || part.state !== 'output-available') {
|
|
12498
|
+
return;
|
|
12499
|
+
}
|
|
12500
|
+
var hits = ((_part_output = part.output) !== null && _part_output !== void 0 ? _part_output : {}).hits;
|
|
12501
|
+
if (Array.isArray(hits)) {
|
|
12502
|
+
store.merge(hits);
|
|
12503
|
+
}
|
|
12504
|
+
});
|
|
12505
|
+
});
|
|
12506
|
+
return store;
|
|
12507
|
+
}
|
|
12508
|
+
|
|
12447
12509
|
var tryParseJson = function tryParseJson(value) {
|
|
12448
12510
|
try {
|
|
12449
12511
|
return JSON.parse(value);
|
|
@@ -12693,7 +12755,17 @@
|
|
|
12693
12755
|
var lastMessage = messages[messages.length - 1];
|
|
12694
12756
|
if (lastMessage.role !== 'assistant') return false;
|
|
12695
12757
|
if (!lastMessage.parts || lastMessage.parts.length === 0) return false;
|
|
12696
|
-
|
|
12758
|
+
// Only the last step of the message counts: earlier steps were answered
|
|
12759
|
+
// before the model was called again, so their resolved tool calls must not
|
|
12760
|
+
// continue the turn a second time.
|
|
12761
|
+
var lastStepStartIndex = lastMessage.parts.reduce(function(lastIndex, part, index) {
|
|
12762
|
+
return part.type === 'step-start' ? index : lastIndex;
|
|
12763
|
+
}, -1);
|
|
12764
|
+
var toolParts = lastMessage.parts.slice(lastStepStartIndex + 1).filter(isToolOrDynamicToolUIPart) // A provider-executed tool call is the provider's to answer, so a turn
|
|
12765
|
+
// made of them is already complete — continuing would resend it.
|
|
12766
|
+
.filter(function(part) {
|
|
12767
|
+
return !part.providerExecuted;
|
|
12768
|
+
});
|
|
12697
12769
|
if (toolParts.length === 0) return false;
|
|
12698
12770
|
return toolParts.every(function(part) {
|
|
12699
12771
|
return part.state === 'output-available' || part.state === 'output-error';
|
|
@@ -12796,6 +12868,37 @@
|
|
|
12796
12868
|
|
|
12797
12869
|
var _computedKey$1;
|
|
12798
12870
|
var defaultGuardrailFallbackResponse = 'Sorry, we are not able to generate a response at the moment.';
|
|
12871
|
+
var TOOL_CALL_CANCELLED_ERROR_TEXT = 'The tool call was cancelled: the conversation moved on before a result was provided.';
|
|
12872
|
+
function getToolName(part) {
|
|
12873
|
+
if (part.type === 'dynamic-tool') {
|
|
12874
|
+
var _part_toolName;
|
|
12875
|
+
return (_part_toolName = part.toolName) !== null && _part_toolName !== void 0 ? _part_toolName : part.type;
|
|
12876
|
+
}
|
|
12877
|
+
return part.type.slice('tool-'.length);
|
|
12878
|
+
}
|
|
12879
|
+
function warnInvalidGlobalToolResult(toolCallId) {}
|
|
12880
|
+
// A tool call awaiting an output that the client owns. Provider-executed calls
|
|
12881
|
+
// are resolved server-side, so they are left alone.
|
|
12882
|
+
function isPendingToolPart(part) {
|
|
12883
|
+
var candidate = part;
|
|
12884
|
+
return typeof candidate.type === 'string' && typeof candidate.toolCallId === 'string' && (candidate.state === 'input-streaming' || candidate.state === 'input-available') && candidate.providerExecuted !== true;
|
|
12885
|
+
}
|
|
12886
|
+
// Drops the fields that only belong to the state being left behind:
|
|
12887
|
+
// `output-error` forbids `output`, and a committed output is not `preliminary`.
|
|
12888
|
+
function withTerminalToolState(part, terminalState) {
|
|
12889
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
12890
|
+
part.preliminary; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
12891
|
+
part.rawOutput; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
12892
|
+
part.output; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
12893
|
+
part.errorText;
|
|
12894
|
+
var retainedPart = _object_without_properties(part, [
|
|
12895
|
+
"preliminary",
|
|
12896
|
+
"rawOutput",
|
|
12897
|
+
"output",
|
|
12898
|
+
"errorText"
|
|
12899
|
+
]);
|
|
12900
|
+
return _object_spread({}, retainedPart, terminalState);
|
|
12901
|
+
}
|
|
12799
12902
|
_computedKey$1 = /** @internal */ '~addToolResultForMessage';
|
|
12800
12903
|
var _computedKey1$1 = _computedKey$1;
|
|
12801
12904
|
/**
|
|
@@ -12803,7 +12906,7 @@
|
|
|
12803
12906
|
*/ var AbstractChat = /*#__PURE__*/ function() {
|
|
12804
12907
|
function AbstractChat(param) {
|
|
12805
12908
|
var _this = this;
|
|
12806
|
-
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;
|
|
12909
|
+
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, resolveCancelledToolOutput = param.resolveCancelledToolOutput;
|
|
12807
12910
|
var _this1 = this;
|
|
12808
12911
|
_class_call_check(this, AbstractChat);
|
|
12809
12912
|
_define_property(this, "conversationId", void 0);
|
|
@@ -12816,6 +12919,7 @@
|
|
|
12816
12919
|
_define_property(this, "onData", void 0);
|
|
12817
12920
|
_define_property(this, "sendAutomaticallyWhen", void 0);
|
|
12818
12921
|
_define_property(this, "shouldRepairToolInput", void 0);
|
|
12922
|
+
_define_property(this, "resolveCancelledToolOutput", void 0);
|
|
12819
12923
|
_define_property(this, "activeResponse", null);
|
|
12820
12924
|
_define_property(this, "latestResponse", null);
|
|
12821
12925
|
_define_property(this, "responsesByToolCallId", new Map());
|
|
@@ -12958,6 +13062,7 @@
|
|
|
12958
13062
|
* Add a tool result for a tool call.
|
|
12959
13063
|
*/ _define_property(this, "addToolResult", function(options) {
|
|
12960
13064
|
if (!_this.acceptsIdentifierOnlyToolResults) {
|
|
13065
|
+
warnInvalidGlobalToolResult(options.toolCallId);
|
|
12961
13066
|
return Promise.resolve();
|
|
12962
13067
|
}
|
|
12963
13068
|
var owners = _this.responsesByToolCallId.get(options.toolCallId);
|
|
@@ -12972,11 +13077,21 @@
|
|
|
12972
13077
|
});
|
|
12973
13078
|
return matchingMessages.length === 1 ? matchingMessages[0] : undefined;
|
|
12974
13079
|
};
|
|
12975
|
-
if (!findMatchingMessage())
|
|
13080
|
+
if (!findMatchingMessage()) {
|
|
13081
|
+
warnInvalidGlobalToolResult(options.toolCallId);
|
|
13082
|
+
return Promise.resolve();
|
|
13083
|
+
}
|
|
12976
13084
|
return _this.jobExecutor.run(function() {
|
|
12977
|
-
if (!_this.acceptsIdentifierOnlyToolResults)
|
|
13085
|
+
if (!_this.acceptsIdentifierOnlyToolResults) {
|
|
13086
|
+
warnInvalidGlobalToolResult(options.toolCallId);
|
|
13087
|
+
return Promise.resolve();
|
|
13088
|
+
}
|
|
12978
13089
|
var message = findMatchingMessage();
|
|
12979
|
-
if (!message
|
|
13090
|
+
if (!message) {
|
|
13091
|
+
warnInvalidGlobalToolResult(options.toolCallId);
|
|
13092
|
+
return Promise.resolve();
|
|
13093
|
+
}
|
|
13094
|
+
if (!_this.commit(options.toolCallId, options.output, message.id, undefined, message)) {
|
|
12980
13095
|
return Promise.resolve();
|
|
12981
13096
|
}
|
|
12982
13097
|
return _this.continueResponse();
|
|
@@ -13023,6 +13138,7 @@
|
|
|
13023
13138
|
this.onData = onData;
|
|
13024
13139
|
this.sendAutomaticallyWhen = sendAutomaticallyWhen;
|
|
13025
13140
|
this.shouldRepairToolInput = shouldRepairToolInput;
|
|
13141
|
+
this.resolveCancelledToolOutput = resolveCancelledToolOutput;
|
|
13026
13142
|
}
|
|
13027
13143
|
_create_class(AbstractChat, [
|
|
13028
13144
|
{
|
|
@@ -13208,15 +13324,8 @@
|
|
|
13208
13324
|
if (!('state' in part) || part.state === 'output-available' && !part.preliminary || part.state === 'output-error') {
|
|
13209
13325
|
return false;
|
|
13210
13326
|
}
|
|
13211
|
-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13212
|
-
part.preliminary; // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
13213
|
-
part.rawOutput;
|
|
13214
|
-
var committedPart = _object_without_properties(part, [
|
|
13215
|
-
"preliminary",
|
|
13216
|
-
"rawOutput"
|
|
13217
|
-
]);
|
|
13218
13327
|
var updatedParts = _to_consumable_array(message.parts);
|
|
13219
|
-
updatedParts[partIndex] =
|
|
13328
|
+
updatedParts[partIndex] = withTerminalToolState(part, {
|
|
13220
13329
|
state: 'output-available',
|
|
13221
13330
|
output: output
|
|
13222
13331
|
});
|
|
@@ -13227,6 +13336,60 @@
|
|
|
13227
13336
|
return true;
|
|
13228
13337
|
}
|
|
13229
13338
|
},
|
|
13339
|
+
{
|
|
13340
|
+
key: "getOutboundMessages",
|
|
13341
|
+
value: /**
|
|
13342
|
+
* The transcript to send, with every tool call still awaiting an output
|
|
13343
|
+
* reported as cancelled — a provider rejects a turn holding a tool call with
|
|
13344
|
+
* no matching result.
|
|
13345
|
+
*
|
|
13346
|
+
* The repair stays on this copy rather than being committed to `messages`:
|
|
13347
|
+
* the card is still mounted, so a result submitted after the send must still
|
|
13348
|
+
* land, and is sent as the real output from then on.
|
|
13349
|
+
*/ function getOutboundMessages() {
|
|
13350
|
+
var _this = this;
|
|
13351
|
+
var outboundMessages;
|
|
13352
|
+
this.messages.forEach(function(message, messageIndex) {
|
|
13353
|
+
var repairedParts;
|
|
13354
|
+
message.parts.forEach(function(part, partIndex) {
|
|
13355
|
+
if (!isPendingToolPart(part)) return;
|
|
13356
|
+
repairedParts = repairedParts || _to_consumable_array(message.parts);
|
|
13357
|
+
repairedParts[partIndex] = withTerminalToolState(part, _this.resolveToolCallCancellation(part));
|
|
13358
|
+
});
|
|
13359
|
+
if (repairedParts) {
|
|
13360
|
+
outboundMessages = outboundMessages || _to_consumable_array(_this.messages);
|
|
13361
|
+
outboundMessages[messageIndex] = _object_spread_props(_object_spread({}, message), {
|
|
13362
|
+
parts: repairedParts
|
|
13363
|
+
});
|
|
13364
|
+
}
|
|
13365
|
+
});
|
|
13366
|
+
return outboundMessages || this.messages;
|
|
13367
|
+
}
|
|
13368
|
+
},
|
|
13369
|
+
{
|
|
13370
|
+
key: "resolveToolCallCancellation",
|
|
13371
|
+
value: function resolveToolCallCancellation(part) {
|
|
13372
|
+
var cancellation;
|
|
13373
|
+
// Repairing the outbound transcript must never fail the request build.
|
|
13374
|
+
try {
|
|
13375
|
+
var _this_resolveCancelledToolOutput, _this;
|
|
13376
|
+
cancellation = (_this_resolveCancelledToolOutput = (_this = this).resolveCancelledToolOutput) === null || _this_resolveCancelledToolOutput === void 0 ? void 0 : _this_resolveCancelledToolOutput.call(_this, {
|
|
13377
|
+
toolName: getToolName(part),
|
|
13378
|
+
toolCallId: part.toolCallId,
|
|
13379
|
+
input: 'input' in part ? part.input : undefined
|
|
13380
|
+
});
|
|
13381
|
+
} catch (unused) {
|
|
13382
|
+
cancellation = undefined;
|
|
13383
|
+
}
|
|
13384
|
+
return cancellation ? {
|
|
13385
|
+
state: 'output-available',
|
|
13386
|
+
output: cancellation.output
|
|
13387
|
+
} : {
|
|
13388
|
+
state: 'output-error',
|
|
13389
|
+
errorText: TOOL_CALL_CANCELLED_ERROR_TEXT
|
|
13390
|
+
};
|
|
13391
|
+
}
|
|
13392
|
+
},
|
|
13230
13393
|
{
|
|
13231
13394
|
key: "continueResponse",
|
|
13232
13395
|
value: function continueResponse(response) {
|
|
@@ -13335,10 +13498,13 @@
|
|
|
13335
13498
|
if (!this.transport) {
|
|
13336
13499
|
return Promise.reject(new Error('Transport is required for sending messages. Please provide a transport when initializing the chat.'));
|
|
13337
13500
|
}
|
|
13501
|
+
// Resolved as late as possible, so a tool that submits its output in the
|
|
13502
|
+
// meantime is sent as answered.
|
|
13503
|
+
var messages = this.getOutboundMessages();
|
|
13338
13504
|
return this.consume(function(abortSignal) {
|
|
13339
13505
|
return _this.transport.sendMessages({
|
|
13340
13506
|
chatId: _this.id,
|
|
13341
|
-
messages:
|
|
13507
|
+
messages: messages,
|
|
13342
13508
|
abortSignal: abortSignal,
|
|
13343
13509
|
trigger: options.trigger,
|
|
13344
13510
|
messageId: options.messageId,
|
|
@@ -13476,8 +13642,14 @@
|
|
|
13476
13642
|
allowRetired: !wasRetired
|
|
13477
13643
|
});
|
|
13478
13644
|
};
|
|
13645
|
+
// A tool call the server answers itself is server-owned, even when the
|
|
13646
|
+
// stream omits `providerExecuted`: nothing is left for the client to
|
|
13647
|
+
// submit, so the response must stop requiring a result for it. Dropping it
|
|
13648
|
+
// from `requiredToolCallIds` also keeps the turn from auto-continuing on
|
|
13649
|
+
// the server's behalf — a turn made of server-executed tool calls is
|
|
13650
|
+
// already complete, and resending it would repeat the whole answer.
|
|
13479
13651
|
var acceptServerToolResult = function acceptServerToolResult(toolCallId) {
|
|
13480
|
-
if (response.requiredToolCallIds.
|
|
13652
|
+
if (response.requiredToolCallIds.delete(toolCallId)) {
|
|
13481
13653
|
response.resolvedToolCallIds.add(toolCallId);
|
|
13482
13654
|
}
|
|
13483
13655
|
};
|
|
@@ -14563,6 +14735,11 @@
|
|
|
14563
14735
|
"requiresSearch"
|
|
14564
14736
|
]);
|
|
14565
14737
|
var normalizedPersistence = normalizePersistence(persistence, 'chat' in options);
|
|
14738
|
+
// Compatibility shim with Algolia MCP Server search tool, which suffixes
|
|
14739
|
+
// the tool name with the index name (`searchIndex_products`).
|
|
14740
|
+
var resolveTool = function resolveTool(toolName) {
|
|
14741
|
+
return tools[toolName] || (toolName.startsWith("".concat(SearchIndexToolType, "_")) ? tools[SearchIndexToolType] : undefined);
|
|
14742
|
+
};
|
|
14566
14743
|
var _chatInstance;
|
|
14567
14744
|
var input = '';
|
|
14568
14745
|
var open = false;
|
|
@@ -14574,6 +14751,13 @@
|
|
|
14574
14751
|
var setFeedbackState;
|
|
14575
14752
|
var hasValidatedEntryPoints = false;
|
|
14576
14753
|
var agentId = 'agentId' in options ? options.agentId : undefined;
|
|
14754
|
+
// Collected here rather than by the tool that searched: that tool renders
|
|
14755
|
+
// nothing while display-results presents its records, and a record has to
|
|
14756
|
+
// outlive the render that produced it.
|
|
14757
|
+
var records = createChatRecordsStore();
|
|
14758
|
+
var collectRecords = function collectRecords() {
|
|
14759
|
+
return collectChatRecords(_chatInstance.messages, records);
|
|
14760
|
+
};
|
|
14577
14761
|
var feedbackState = {};
|
|
14578
14762
|
var _sendChatMessageFeedback;
|
|
14579
14763
|
var feedbackAbortController;
|
|
@@ -14614,6 +14798,7 @@
|
|
|
14614
14798
|
// ChatState callbacks that synchronously re-render, so they must run last
|
|
14615
14799
|
// for that render to see the cleared feedback and rotated conversation id.
|
|
14616
14800
|
feedbackState = {};
|
|
14801
|
+
records.clear();
|
|
14617
14802
|
_chatInstance.resetConversationId();
|
|
14618
14803
|
setMessages([]);
|
|
14619
14804
|
_chatInstance.clearError();
|
|
@@ -14634,6 +14819,10 @@
|
|
|
14634
14819
|
});
|
|
14635
14820
|
hasValidatedEntryPoints = true;
|
|
14636
14821
|
};
|
|
14822
|
+
// Deferred because entry points can be registered after the chat itself:
|
|
14823
|
+
// React adds widgets in mount order, so a trigger further down the tree
|
|
14824
|
+
// only lands after this widget's `init` has run.
|
|
14825
|
+
var deferredValidateEntryPoints = defer(validateEntryPoints);
|
|
14637
14826
|
var makeChatInstance = function makeChatInstance(instantSearchInstance) {
|
|
14638
14827
|
// A caller supplied `chat` already owns its transport, so it bypasses the
|
|
14639
14828
|
// connector's transport construction and validation below.
|
|
@@ -14735,20 +14924,31 @@
|
|
|
14735
14924
|
sendAutomaticallyWhen: sendAutomaticallyWhen,
|
|
14736
14925
|
transport: transport,
|
|
14737
14926
|
shouldRepairToolInput: function shouldRepairToolInput(toolName) {
|
|
14738
|
-
var tool =
|
|
14739
|
-
if (!tool && toolName.startsWith("".concat(SearchIndexToolType, "_"))) {
|
|
14740
|
-
tool = tools[SearchIndexToolType];
|
|
14741
|
-
}
|
|
14927
|
+
var tool = resolveTool(toolName);
|
|
14742
14928
|
if (!tool) return true;
|
|
14743
14929
|
return Boolean(tool.streamInput);
|
|
14744
14930
|
},
|
|
14931
|
+
resolveCancelledToolOutput: function resolveCancelledToolOutput(param) {
|
|
14932
|
+
var toolName = param.toolName, toolCallId = param.toolCallId, input = param.input;
|
|
14933
|
+
var _resolveTool;
|
|
14934
|
+
var cancelOutput = (_resolveTool = resolveTool(toolName)) === null || _resolveTool === void 0 ? void 0 : _resolveTool.cancelOutput;
|
|
14935
|
+
if (!cancelOutput) return undefined;
|
|
14936
|
+
try {
|
|
14937
|
+
var output = cancelOutput({
|
|
14938
|
+
toolCallId: toolCallId,
|
|
14939
|
+
input: input
|
|
14940
|
+
});
|
|
14941
|
+
// `undefined` means the tool declined to provide an output.
|
|
14942
|
+
return output === undefined ? undefined : {
|
|
14943
|
+
output: output
|
|
14944
|
+
};
|
|
14945
|
+
} catch (unused) {
|
|
14946
|
+
return undefined;
|
|
14947
|
+
}
|
|
14948
|
+
},
|
|
14745
14949
|
onToolCall: function onToolCall(param, submitToolResult) {
|
|
14746
14950
|
var toolCall = param.toolCall;
|
|
14747
|
-
var tool =
|
|
14748
|
-
// Compatibility shim with Algolia MCP Server search tool
|
|
14749
|
-
if (!tool && toolCall.toolName.startsWith("".concat(SearchIndexToolType, "_"))) {
|
|
14750
|
-
tool = tools[SearchIndexToolType];
|
|
14751
|
-
}
|
|
14951
|
+
var tool = resolveTool(toolCall.toolName);
|
|
14752
14952
|
if (!tool) {
|
|
14753
14953
|
return submitToolResult({
|
|
14754
14954
|
output: 'No tool implemented for "'.concat(toolCall.toolName, '".'),
|
|
@@ -14779,8 +14979,9 @@
|
|
|
14779
14979
|
init: function init(initOptions) {
|
|
14780
14980
|
var _this = this;
|
|
14781
14981
|
var instantSearchInstance = initOptions.instantSearchInstance;
|
|
14782
|
-
|
|
14982
|
+
deferredValidateEntryPoints(instantSearchInstance);
|
|
14783
14983
|
open = normalizedPersistence.open ? readPersistedOpen(type) : false;
|
|
14984
|
+
records.clear();
|
|
14784
14985
|
_chatInstance = makeChatInstance(instantSearchInstance);
|
|
14785
14986
|
var render = function render() {
|
|
14786
14987
|
renderFn(_object_spread_props(_object_spread({}, _this.getWidgetRenderState(initOptions)), {
|
|
@@ -14846,11 +15047,28 @@
|
|
|
14846
15047
|
_chatInstance.messages = initialMessages;
|
|
14847
15048
|
}
|
|
14848
15049
|
});
|
|
15050
|
+
// Sibling entry points read `status` through the shared `renderState` to
|
|
15051
|
+
// disable themselves, so a transition has to escape this widget's own
|
|
15052
|
+
// render. Message deltas deliberately don't: they stay local to keep
|
|
15053
|
+
// streaming cheap. The `status` setter notifies on every write, hence
|
|
15054
|
+
// the comparison.
|
|
15055
|
+
var lastStatus = _chatInstance.status;
|
|
15056
|
+
var renderOnStatusChange = function renderOnStatusChange() {
|
|
15057
|
+
var statusChanged = _chatInstance.status !== lastStatus;
|
|
15058
|
+
lastStatus = _chatInstance.status;
|
|
15059
|
+
render();
|
|
15060
|
+
if (statusChanged) {
|
|
15061
|
+
initOptions.instantSearchInstance.scheduleRender();
|
|
15062
|
+
}
|
|
15063
|
+
};
|
|
14849
15064
|
safelyRunOnBrowser(function() {
|
|
14850
15065
|
chatSubscriptionUnsubscribers = [
|
|
14851
15066
|
_chatInstance['~registerErrorCallback'](render),
|
|
15067
|
+
// Before `render`, so a delta's records are collected by the time
|
|
15068
|
+
// the tools of that delta render.
|
|
15069
|
+
_chatInstance['~registerMessagesCallback'](collectRecords),
|
|
14852
15070
|
_chatInstance['~registerMessagesCallback'](render),
|
|
14853
|
-
_chatInstance['~registerStatusCallback'](
|
|
15071
|
+
_chatInstance['~registerStatusCallback'](renderOnStatusChange)
|
|
14854
15072
|
];
|
|
14855
15073
|
});
|
|
14856
15074
|
// Resuming and sending reach the network, which a server render must
|
|
@@ -14901,6 +15119,9 @@
|
|
|
14901
15119
|
function applyFilters(params) {
|
|
14902
15120
|
return updateStateFromSearchToolInput(params, helper);
|
|
14903
15121
|
}
|
|
15122
|
+
// A restored or server-rendered conversation never emitted the messages
|
|
15123
|
+
// callback above; collecting is idempotent, so covering it here is free.
|
|
15124
|
+
collectRecords();
|
|
14904
15125
|
var insightsEventContext = {
|
|
14905
15126
|
agentId: agentId,
|
|
14906
15127
|
instantSearchStatus: instantSearchInstance.status
|
|
@@ -14913,7 +15134,8 @@
|
|
|
14913
15134
|
'~addToolResultForMessage': _chatInstance['~addToolResultForMessage'],
|
|
14914
15135
|
applyFilters: applyFilters,
|
|
14915
15136
|
sendEvent: sendEvent,
|
|
14916
|
-
insightsEventContext: insightsEventContext
|
|
15137
|
+
insightsEventContext: insightsEventContext,
|
|
15138
|
+
records: records
|
|
14917
15139
|
});
|
|
14918
15140
|
toolsWithAddToolResult[key] = toolWithAddToolResult;
|
|
14919
15141
|
});
|
|
@@ -14958,6 +15180,7 @@
|
|
|
14958
15180
|
suggestions: getSuggestionsFromMessages(_chatInstance.messages),
|
|
14959
15181
|
clearMessages: clearMessages,
|
|
14960
15182
|
tools: toolsWithAddToolResult,
|
|
15183
|
+
records: records,
|
|
14961
15184
|
sendChatMessageFeedback: _sendChatMessageFeedback,
|
|
14962
15185
|
feedbackState: feedbackState,
|
|
14963
15186
|
widgetParams: widgetParams,
|
|
@@ -14976,6 +15199,7 @@
|
|
|
14976
15199
|
return renderState;
|
|
14977
15200
|
},
|
|
14978
15201
|
dispose: function dispose() {
|
|
15202
|
+
deferredValidateEntryPoints.cancel();
|
|
14979
15203
|
feedbackAbortController === null || feedbackAbortController === void 0 ? void 0 : feedbackAbortController.abort();
|
|
14980
15204
|
unsubscribeChatCallbacks();
|
|
14981
15205
|
unmountFn();
|
|
@@ -15629,6 +15853,10 @@
|
|
|
15629
15853
|
return function(widgetParams) {
|
|
15630
15854
|
var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
|
|
15631
15855
|
var lastOptions = null;
|
|
15856
|
+
function openChatFromTrigger(options) {
|
|
15857
|
+
if (!lastOptions) return false;
|
|
15858
|
+
return openChat(getChatRenderState(lastOptions), options);
|
|
15859
|
+
}
|
|
15632
15860
|
function toggleOpen() {
|
|
15633
15861
|
if (!lastOptions) return;
|
|
15634
15862
|
var chatState = getChatRenderState(lastOptions);
|
|
@@ -15665,6 +15893,8 @@
|
|
|
15665
15893
|
return {
|
|
15666
15894
|
open: (_ref = chatState === null || chatState === void 0 ? void 0 : chatState.open) !== null && _ref !== void 0 ? _ref : false,
|
|
15667
15895
|
toggleOpen: toggleOpen,
|
|
15896
|
+
openChat: openChatFromTrigger,
|
|
15897
|
+
isChatBusy: chatState ? !chatState.sendMessage || isChatBusy(chatState) : false,
|
|
15668
15898
|
widgetParams: params
|
|
15669
15899
|
};
|
|
15670
15900
|
},
|