@hashbrownai/react
Version:
React components for Hashbrown AI
1,466 lines (1,220 loc) • 108 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import React, { createContext, useRef, useCallback, useSyncExternalStore, useMemo, useContext, useEffect, useState } from 'react';
import { ɵdeepEqual as _deepEqual, fryHashbrown, ɵcomponents as _components, s, ɵcreateRuntimeFunctionImpl as _createRuntimeFunctionImpl, ɵcreateRuntimeImpl as _createRuntimeImpl } from '@hashbrownai/core';
const HashbrownContext = /*#__PURE__*/createContext(undefined);
/**
* The context for the Hashbrown provider. This is used to store the URL and middleware for contacting the Hashbrown endpoint.
*
* @example
* ```ts
* <HashbrownProvider url="https://your.api.local/chat">
* <App />
* </HashbrownProvider>
* ```
*/
const HashbrownProvider = (
/**
* The options for the Hashbrown provider.
*/
props) => {
const {
url,
middleware,
children
} = props;
return jsx(HashbrownContext.Provider, {
value: {
url,
middleware
},
children: children
});
};
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
var check = function (it) {
return it && it.Math === Math && it;
};
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var globalThis_1 =
// eslint-disable-next-line es/no-global-this -- safe
check(typeof globalThis == 'object' && globalThis) ||
check(typeof window == 'object' && window) ||
// eslint-disable-next-line no-restricted-globals -- safe
check(typeof self == 'object' && self) ||
check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
// eslint-disable-next-line no-new-func -- fallback
(function () { return this; })() || Function('return this')();
var objectGetOwnPropertyDescriptor = {};
var fails$d = function (exec) {
try {
return !!exec();
} catch (error) {
return true;
}
};
var fails$c = fails$d;
// Detect IE8's incomplete defineProperty implementation
var descriptors = !fails$c(function () {
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] !== 7;
});
var fails$b = fails$d;
var functionBindNative = !fails$b(function () {
// eslint-disable-next-line es/no-function-prototype-bind -- safe
var test = (function () { /* empty */ }).bind();
// eslint-disable-next-line no-prototype-builtins -- safe
return typeof test != 'function' || test.hasOwnProperty('prototype');
});
var NATIVE_BIND$3 = functionBindNative;
var call$c = Function.prototype.call;
// eslint-disable-next-line es/no-function-prototype-bind -- safe
var functionCall = NATIVE_BIND$3 ? call$c.bind(call$c) : function () {
return call$c.apply(call$c, arguments);
};
var objectPropertyIsEnumerable = {};
var $propertyIsEnumerable = {}.propertyIsEnumerable;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
// Nashorn ~ JDK8 bug
var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
// `Object.prototype.propertyIsEnumerable` method implementation
// https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
var descriptor = getOwnPropertyDescriptor$1(this, V);
return !!descriptor && descriptor.enumerable;
} : $propertyIsEnumerable;
var createPropertyDescriptor$5 = function (bitmap, value) {
return {
enumerable: !(bitmap & 1),
configurable: !(bitmap & 2),
writable: !(bitmap & 4),
value: value
};
};
var NATIVE_BIND$2 = functionBindNative;
var FunctionPrototype$2 = Function.prototype;
var call$b = FunctionPrototype$2.call;
// eslint-disable-next-line es/no-function-prototype-bind -- safe
var uncurryThisWithBind = NATIVE_BIND$2 && FunctionPrototype$2.bind.bind(call$b, call$b);
var functionUncurryThis = NATIVE_BIND$2 ? uncurryThisWithBind : function (fn) {
return function () {
return call$b.apply(fn, arguments);
};
};
var uncurryThis$e = functionUncurryThis;
var toString$4 = uncurryThis$e({}.toString);
var stringSlice$2 = uncurryThis$e(''.slice);
var classofRaw$2 = function (it) {
return stringSlice$2(toString$4(it), 8, -1);
};
var uncurryThis$d = functionUncurryThis;
var fails$a = fails$d;
var classof$3 = classofRaw$2;
var $Object$4 = Object;
var split = uncurryThis$d(''.split);
// fallback for non-array-like ES3 and non-enumerable old V8 strings
var indexedObject = fails$a(function () {
// throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
// eslint-disable-next-line no-prototype-builtins -- safe
return !$Object$4('z').propertyIsEnumerable(0);
}) ? function (it) {
return classof$3(it) === 'String' ? split(it, '') : $Object$4(it);
} : $Object$4;
// we can't use just `it == null` since of `document.all` special case
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-aec
var isNullOrUndefined$3 = function (it) {
return it === null || it === undefined;
};
var isNullOrUndefined$2 = isNullOrUndefined$3;
var $TypeError$a = TypeError;
// `RequireObjectCoercible` abstract operation
// https://tc39.es/ecma262/#sec-requireobjectcoercible
var requireObjectCoercible$3 = function (it) {
if (isNullOrUndefined$2(it)) throw new $TypeError$a("Can't call method on " + it);
return it;
};
// toObject with fallback for non-array-like ES3 strings
var IndexedObject$2 = indexedObject;
var requireObjectCoercible$2 = requireObjectCoercible$3;
var toIndexedObject$5 = function (it) {
return IndexedObject$2(requireObjectCoercible$2(it));
};
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
var documentAll = typeof document == 'object' && document.all;
// `IsCallable` abstract operation
// https://tc39.es/ecma262/#sec-iscallable
// eslint-disable-next-line unicorn/no-typeof-undefined -- required for testing
var isCallable$h = typeof documentAll == 'undefined' && documentAll !== undefined ? function (argument) {
return typeof argument == 'function' || argument === documentAll;
} : function (argument) {
return typeof argument == 'function';
};
var isCallable$g = isCallable$h;
var isObject$a = function (it) {
return typeof it == 'object' ? it !== null : isCallable$g(it);
};
var globalThis$f = globalThis_1;
var isCallable$f = isCallable$h;
var aFunction = function (argument) {
return isCallable$f(argument) ? argument : undefined;
};
var getBuiltIn$4 = function (namespace, method) {
return arguments.length < 2 ? aFunction(globalThis$f[namespace]) : globalThis$f[namespace] && globalThis$f[namespace][method];
};
var uncurryThis$c = functionUncurryThis;
var objectIsPrototypeOf = uncurryThis$c({}.isPrototypeOf);
var globalThis$e = globalThis_1;
var navigator = globalThis$e.navigator;
var userAgent$1 = navigator && navigator.userAgent;
var environmentUserAgent = userAgent$1 ? String(userAgent$1) : '';
var globalThis$d = globalThis_1;
var userAgent = environmentUserAgent;
var process = globalThis$d.process;
var Deno = globalThis$d.Deno;
var versions = process && process.versions || Deno && Deno.version;
var v8 = versions && versions.v8;
var match, version;
if (v8) {
match = v8.split('.');
// in old Chrome, versions of V8 isn't V8 = Chrome / 10
// but their correct versions are not interesting for us
version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]);
}
// BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0`
// so check `userAgent` even if `.v8` exists, but 0
if (!version && userAgent) {
match = userAgent.match(/Edge\/(\d+)/);
if (!match || match[1] >= 74) {
match = userAgent.match(/Chrome\/(\d+)/);
if (match) version = +match[1];
}
}
var environmentV8Version = version;
/* eslint-disable es/no-symbol -- required for testing */
var V8_VERSION = environmentV8Version;
var fails$9 = fails$d;
var globalThis$c = globalThis_1;
var $String$5 = globalThis$c.String;
// eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
var symbolConstructorDetection = !!Object.getOwnPropertySymbols && !fails$9(function () {
var symbol = Symbol('symbol detection');
// Chrome 38 Symbol has incorrect toString conversion
// `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
// nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will,
// of course, fail.
return !$String$5(symbol) || !(Object(symbol) instanceof Symbol) ||
// Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
!Symbol.sham && V8_VERSION && V8_VERSION < 41;
});
/* eslint-disable es/no-symbol -- required for testing */
var NATIVE_SYMBOL$2 = symbolConstructorDetection;
var useSymbolAsUid = NATIVE_SYMBOL$2 &&
!Symbol.sham &&
typeof Symbol.iterator == 'symbol';
var getBuiltIn$3 = getBuiltIn$4;
var isCallable$e = isCallable$h;
var isPrototypeOf$4 = objectIsPrototypeOf;
var USE_SYMBOL_AS_UID$1 = useSymbolAsUid;
var $Object$3 = Object;
var isSymbol$2 = USE_SYMBOL_AS_UID$1 ? function (it) {
return typeof it == 'symbol';
} : function (it) {
var $Symbol = getBuiltIn$3('Symbol');
return isCallable$e($Symbol) && isPrototypeOf$4($Symbol.prototype, $Object$3(it));
};
var $String$4 = String;
var tryToString$3 = function (argument) {
try {
return $String$4(argument);
} catch (error) {
return 'Object';
}
};
var isCallable$d = isCallable$h;
var tryToString$2 = tryToString$3;
var $TypeError$9 = TypeError;
// `Assert: IsCallable(argument) is true`
var aCallable$6 = function (argument) {
if (isCallable$d(argument)) return argument;
throw new $TypeError$9(tryToString$2(argument) + ' is not a function');
};
var aCallable$5 = aCallable$6;
var isNullOrUndefined$1 = isNullOrUndefined$3;
// `GetMethod` abstract operation
// https://tc39.es/ecma262/#sec-getmethod
var getMethod$4 = function (V, P) {
var func = V[P];
return isNullOrUndefined$1(func) ? undefined : aCallable$5(func);
};
var call$a = functionCall;
var isCallable$c = isCallable$h;
var isObject$9 = isObject$a;
var $TypeError$8 = TypeError;
// `OrdinaryToPrimitive` abstract operation
// https://tc39.es/ecma262/#sec-ordinarytoprimitive
var ordinaryToPrimitive$1 = function (input, pref) {
var fn, val;
if (pref === 'string' && isCallable$c(fn = input.toString) && !isObject$9(val = call$a(fn, input))) return val;
if (isCallable$c(fn = input.valueOf) && !isObject$9(val = call$a(fn, input))) return val;
if (pref !== 'string' && isCallable$c(fn = input.toString) && !isObject$9(val = call$a(fn, input))) return val;
throw new $TypeError$8("Can't convert object to primitive value");
};
var sharedStore = {exports: {}};
var isPure = false;
var globalThis$b = globalThis_1;
// eslint-disable-next-line es/no-object-defineproperty -- safe
var defineProperty$7 = Object.defineProperty;
var defineGlobalProperty$3 = function (key, value) {
try {
defineProperty$7(globalThis$b, key, { value: value, configurable: true, writable: true });
} catch (error) {
globalThis$b[key] = value;
} return value;
};
var globalThis$a = globalThis_1;
var defineGlobalProperty$2 = defineGlobalProperty$3;
var SHARED = '__core-js_shared__';
var store$3 = sharedStore.exports = globalThis$a[SHARED] || defineGlobalProperty$2(SHARED, {});
(store$3.versions || (store$3.versions = [])).push({
version: '3.40.0',
mode: 'global',
copyright: '© 2014-2025 Denis Pushkarev (zloirock.ru)',
license: 'https://github.com/zloirock/core-js/blob/v3.40.0/LICENSE',
source: 'https://github.com/zloirock/core-js'
});
var sharedStoreExports = sharedStore.exports;
var store$2 = sharedStoreExports;
var shared$3 = function (key, value) {
return store$2[key] || (store$2[key] = value || {});
};
var requireObjectCoercible$1 = requireObjectCoercible$3;
var $Object$2 = Object;
// `ToObject` abstract operation
// https://tc39.es/ecma262/#sec-toobject
var toObject$4 = function (argument) {
return $Object$2(requireObjectCoercible$1(argument));
};
var uncurryThis$b = functionUncurryThis;
var toObject$3 = toObject$4;
var hasOwnProperty = uncurryThis$b({}.hasOwnProperty);
// `HasOwnProperty` abstract operation
// https://tc39.es/ecma262/#sec-hasownproperty
// eslint-disable-next-line es/no-object-hasown -- safe
var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
return hasOwnProperty(toObject$3(it), key);
};
var uncurryThis$a = functionUncurryThis;
var id = 0;
var postfix = Math.random();
var toString$3 = uncurryThis$a(1.0.toString);
var uid$2 = function (key) {
return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$3(++id + postfix, 36);
};
var globalThis$9 = globalThis_1;
var shared$2 = shared$3;
var hasOwn$b = hasOwnProperty_1;
var uid$1 = uid$2;
var NATIVE_SYMBOL$1 = symbolConstructorDetection;
var USE_SYMBOL_AS_UID = useSymbolAsUid;
var Symbol$1 = globalThis$9.Symbol;
var WellKnownSymbolsStore = shared$2('wks');
var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$1['for'] || Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1;
var wellKnownSymbol$c = function (name) {
if (!hasOwn$b(WellKnownSymbolsStore, name)) {
WellKnownSymbolsStore[name] = NATIVE_SYMBOL$1 && hasOwn$b(Symbol$1, name)
? Symbol$1[name]
: createWellKnownSymbol('Symbol.' + name);
} return WellKnownSymbolsStore[name];
};
var call$9 = functionCall;
var isObject$8 = isObject$a;
var isSymbol$1 = isSymbol$2;
var getMethod$3 = getMethod$4;
var ordinaryToPrimitive = ordinaryToPrimitive$1;
var wellKnownSymbol$b = wellKnownSymbol$c;
var $TypeError$7 = TypeError;
var TO_PRIMITIVE = wellKnownSymbol$b('toPrimitive');
// `ToPrimitive` abstract operation
// https://tc39.es/ecma262/#sec-toprimitive
var toPrimitive$1 = function (input, pref) {
if (!isObject$8(input) || isSymbol$1(input)) return input;
var exoticToPrim = getMethod$3(input, TO_PRIMITIVE);
var result;
if (exoticToPrim) {
if (pref === undefined) pref = 'default';
result = call$9(exoticToPrim, input, pref);
if (!isObject$8(result) || isSymbol$1(result)) return result;
throw new $TypeError$7("Can't convert object to primitive value");
}
if (pref === undefined) pref = 'number';
return ordinaryToPrimitive(input, pref);
};
var toPrimitive = toPrimitive$1;
var isSymbol = isSymbol$2;
// `ToPropertyKey` abstract operation
// https://tc39.es/ecma262/#sec-topropertykey
var toPropertyKey$2 = function (argument) {
var key = toPrimitive(argument, 'string');
return isSymbol(key) ? key : key + '';
};
var globalThis$8 = globalThis_1;
var isObject$7 = isObject$a;
var document$1 = globalThis$8.document;
// typeof document.createElement is 'object' in old IE
var EXISTS$1 = isObject$7(document$1) && isObject$7(document$1.createElement);
var documentCreateElement$2 = function (it) {
return EXISTS$1 ? document$1.createElement(it) : {};
};
var DESCRIPTORS$d = descriptors;
var fails$8 = fails$d;
var createElement = documentCreateElement$2;
// Thanks to IE8 for its funny defineProperty
var ie8DomDefine = !DESCRIPTORS$d && !fails$8(function () {
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
return Object.defineProperty(createElement('div'), 'a', {
get: function () { return 7; }
}).a !== 7;
});
var DESCRIPTORS$c = descriptors;
var call$8 = functionCall;
var propertyIsEnumerableModule$1 = objectPropertyIsEnumerable;
var createPropertyDescriptor$4 = createPropertyDescriptor$5;
var toIndexedObject$4 = toIndexedObject$5;
var toPropertyKey$1 = toPropertyKey$2;
var hasOwn$a = hasOwnProperty_1;
var IE8_DOM_DEFINE$1 = ie8DomDefine;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
// `Object.getOwnPropertyDescriptor` method
// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
objectGetOwnPropertyDescriptor.f = DESCRIPTORS$c ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) {
O = toIndexedObject$4(O);
P = toPropertyKey$1(P);
if (IE8_DOM_DEFINE$1) try {
return $getOwnPropertyDescriptor$1(O, P);
} catch (error) { /* empty */ }
if (hasOwn$a(O, P)) return createPropertyDescriptor$4(!call$8(propertyIsEnumerableModule$1.f, O, P), O[P]);
};
var objectDefineProperty = {};
var DESCRIPTORS$b = descriptors;
var fails$7 = fails$d;
// V8 ~ Chrome 36-
// https://bugs.chromium.org/p/v8/issues/detail?id=3334
var v8PrototypeDefineBug = DESCRIPTORS$b && fails$7(function () {
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
return Object.defineProperty(function () { /* empty */ }, 'prototype', {
value: 42,
writable: false
}).prototype !== 42;
});
var isObject$6 = isObject$a;
var $String$3 = String;
var $TypeError$6 = TypeError;
// `Assert: Type(argument) is Object`
var anObject$b = function (argument) {
if (isObject$6(argument)) return argument;
throw new $TypeError$6($String$3(argument) + ' is not an object');
};
var DESCRIPTORS$a = descriptors;
var IE8_DOM_DEFINE = ie8DomDefine;
var V8_PROTOTYPE_DEFINE_BUG$1 = v8PrototypeDefineBug;
var anObject$a = anObject$b;
var toPropertyKey = toPropertyKey$2;
var $TypeError$5 = TypeError;
// eslint-disable-next-line es/no-object-defineproperty -- safe
var $defineProperty = Object.defineProperty;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
var ENUMERABLE = 'enumerable';
var CONFIGURABLE$1 = 'configurable';
var WRITABLE = 'writable';
// `Object.defineProperty` method
// https://tc39.es/ecma262/#sec-object.defineproperty
objectDefineProperty.f = DESCRIPTORS$a ? V8_PROTOTYPE_DEFINE_BUG$1 ? function defineProperty(O, P, Attributes) {
anObject$a(O);
P = toPropertyKey(P);
anObject$a(Attributes);
if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) {
var current = $getOwnPropertyDescriptor(O, P);
if (current && current[WRITABLE]) {
O[P] = Attributes.value;
Attributes = {
configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1],
enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE],
writable: false
};
}
} return $defineProperty(O, P, Attributes);
} : $defineProperty : function defineProperty(O, P, Attributes) {
anObject$a(O);
P = toPropertyKey(P);
anObject$a(Attributes);
if (IE8_DOM_DEFINE) try {
return $defineProperty(O, P, Attributes);
} catch (error) { /* empty */ }
if ('get' in Attributes || 'set' in Attributes) throw new $TypeError$5('Accessors not supported');
if ('value' in Attributes) O[P] = Attributes.value;
return O;
};
var DESCRIPTORS$9 = descriptors;
var definePropertyModule$4 = objectDefineProperty;
var createPropertyDescriptor$3 = createPropertyDescriptor$5;
var createNonEnumerableProperty$8 = DESCRIPTORS$9 ? function (object, key, value) {
return definePropertyModule$4.f(object, key, createPropertyDescriptor$3(1, value));
} : function (object, key, value) {
object[key] = value;
return object;
};
var makeBuiltIn$3 = {exports: {}};
var DESCRIPTORS$8 = descriptors;
var hasOwn$9 = hasOwnProperty_1;
var FunctionPrototype$1 = Function.prototype;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var getDescriptor = DESCRIPTORS$8 && Object.getOwnPropertyDescriptor;
var EXISTS = hasOwn$9(FunctionPrototype$1, 'name');
// additional protection from minified / mangled / dropped function names
var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something';
var CONFIGURABLE = EXISTS && (!DESCRIPTORS$8 || (DESCRIPTORS$8 && getDescriptor(FunctionPrototype$1, 'name').configurable));
var functionName = {
EXISTS: EXISTS,
PROPER: PROPER,
CONFIGURABLE: CONFIGURABLE
};
var uncurryThis$9 = functionUncurryThis;
var isCallable$b = isCallable$h;
var store$1 = sharedStoreExports;
var functionToString = uncurryThis$9(Function.toString);
// this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
if (!isCallable$b(store$1.inspectSource)) {
store$1.inspectSource = function (it) {
return functionToString(it);
};
}
var inspectSource$1 = store$1.inspectSource;
var globalThis$7 = globalThis_1;
var isCallable$a = isCallable$h;
var WeakMap$1 = globalThis$7.WeakMap;
var weakMapBasicDetection = isCallable$a(WeakMap$1) && /native code/.test(String(WeakMap$1));
var shared$1 = shared$3;
var uid = uid$2;
var keys = shared$1('keys');
var sharedKey$3 = function (key) {
return keys[key] || (keys[key] = uid(key));
};
var hiddenKeys$4 = {};
var NATIVE_WEAK_MAP = weakMapBasicDetection;
var globalThis$6 = globalThis_1;
var isObject$5 = isObject$a;
var createNonEnumerableProperty$7 = createNonEnumerableProperty$8;
var hasOwn$8 = hasOwnProperty_1;
var shared = sharedStoreExports;
var sharedKey$2 = sharedKey$3;
var hiddenKeys$3 = hiddenKeys$4;
var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
var TypeError$1 = globalThis$6.TypeError;
var WeakMap = globalThis$6.WeakMap;
var set, get, has;
var enforce = function (it) {
return has(it) ? get(it) : set(it, {});
};
var getterFor = function (TYPE) {
return function (it) {
var state;
if (!isObject$5(it) || (state = get(it)).type !== TYPE) {
throw new TypeError$1('Incompatible receiver, ' + TYPE + ' required');
} return state;
};
};
if (NATIVE_WEAK_MAP || shared.state) {
var store = shared.state || (shared.state = new WeakMap());
/* eslint-disable no-self-assign -- prototype methods protection */
store.get = store.get;
store.has = store.has;
store.set = store.set;
/* eslint-enable no-self-assign -- prototype methods protection */
set = function (it, metadata) {
if (store.has(it)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
metadata.facade = it;
store.set(it, metadata);
return metadata;
};
get = function (it) {
return store.get(it) || {};
};
has = function (it) {
return store.has(it);
};
} else {
var STATE = sharedKey$2('state');
hiddenKeys$3[STATE] = true;
set = function (it, metadata) {
if (hasOwn$8(it, STATE)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
metadata.facade = it;
createNonEnumerableProperty$7(it, STATE, metadata);
return metadata;
};
get = function (it) {
return hasOwn$8(it, STATE) ? it[STATE] : {};
};
has = function (it) {
return hasOwn$8(it, STATE);
};
}
var internalState = {
set: set,
get: get,
has: has,
enforce: enforce,
getterFor: getterFor
};
var uncurryThis$8 = functionUncurryThis;
var fails$6 = fails$d;
var isCallable$9 = isCallable$h;
var hasOwn$7 = hasOwnProperty_1;
var DESCRIPTORS$7 = descriptors;
var CONFIGURABLE_FUNCTION_NAME$1 = functionName.CONFIGURABLE;
var inspectSource = inspectSource$1;
var InternalStateModule$2 = internalState;
var enforceInternalState = InternalStateModule$2.enforce;
var getInternalState$1 = InternalStateModule$2.get;
var $String$2 = String;
// eslint-disable-next-line es/no-object-defineproperty -- safe
var defineProperty$6 = Object.defineProperty;
var stringSlice$1 = uncurryThis$8(''.slice);
var replace$2 = uncurryThis$8(''.replace);
var join = uncurryThis$8([].join);
var CONFIGURABLE_LENGTH = DESCRIPTORS$7 && !fails$6(function () {
return defineProperty$6(function () { /* empty */ }, 'length', { value: 8 }).length !== 8;
});
var TEMPLATE = String(String).split('String');
var makeBuiltIn$2 = makeBuiltIn$3.exports = function (value, name, options) {
if (stringSlice$1($String$2(name), 0, 7) === 'Symbol(') {
name = '[' + replace$2($String$2(name), /^Symbol\(([^)]*)\).*$/, '$1') + ']';
}
if (options && options.getter) name = 'get ' + name;
if (options && options.setter) name = 'set ' + name;
if (!hasOwn$7(value, 'name') || (CONFIGURABLE_FUNCTION_NAME$1 && value.name !== name)) {
if (DESCRIPTORS$7) defineProperty$6(value, 'name', { value: name, configurable: true });
else value.name = name;
}
if (CONFIGURABLE_LENGTH && options && hasOwn$7(options, 'arity') && value.length !== options.arity) {
defineProperty$6(value, 'length', { value: options.arity });
}
try {
if (options && hasOwn$7(options, 'constructor') && options.constructor) {
if (DESCRIPTORS$7) defineProperty$6(value, 'prototype', { writable: false });
// in V8 ~ Chrome 53, prototypes of some methods, like `Array.prototype.values`, are non-writable
} else if (value.prototype) value.prototype = undefined;
} catch (error) { /* empty */ }
var state = enforceInternalState(value);
if (!hasOwn$7(state, 'source')) {
state.source = join(TEMPLATE, typeof name == 'string' ? name : '');
} return value;
};
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
// eslint-disable-next-line no-extend-native -- required
Function.prototype.toString = makeBuiltIn$2(function toString() {
return isCallable$9(this) && getInternalState$1(this).source || inspectSource(this);
}, 'toString');
var makeBuiltInExports = makeBuiltIn$3.exports;
var isCallable$8 = isCallable$h;
var definePropertyModule$3 = objectDefineProperty;
var makeBuiltIn$1 = makeBuiltInExports;
var defineGlobalProperty$1 = defineGlobalProperty$3;
var defineBuiltIn$4 = function (O, key, value, options) {
if (!options) options = {};
var simple = options.enumerable;
var name = options.name !== undefined ? options.name : key;
if (isCallable$8(value)) makeBuiltIn$1(value, name, options);
if (options.global) {
if (simple) O[key] = value;
else defineGlobalProperty$1(key, value);
} else {
try {
if (!options.unsafe) delete O[key];
else if (O[key]) simple = true;
} catch (error) { /* empty */ }
if (simple) O[key] = value;
else definePropertyModule$3.f(O, key, {
value: value,
enumerable: false,
configurable: !options.nonConfigurable,
writable: !options.nonWritable
});
} return O;
};
var objectGetOwnPropertyNames = {};
var ceil = Math.ceil;
var floor = Math.floor;
// `Math.trunc` method
// https://tc39.es/ecma262/#sec-math.trunc
// eslint-disable-next-line es/no-math-trunc -- safe
var mathTrunc = Math.trunc || function trunc(x) {
var n = +x;
return (n > 0 ? floor : ceil)(n);
};
var trunc = mathTrunc;
// `ToIntegerOrInfinity` abstract operation
// https://tc39.es/ecma262/#sec-tointegerorinfinity
var toIntegerOrInfinity$2 = function (argument) {
var number = +argument;
// eslint-disable-next-line no-self-compare -- NaN check
return number !== number || number === 0 ? 0 : trunc(number);
};
var toIntegerOrInfinity$1 = toIntegerOrInfinity$2;
var max = Math.max;
var min$1 = Math.min;
// Helper for a popular repeating case of the spec:
// Let integer be ? ToInteger(index).
// If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
var toAbsoluteIndex$1 = function (index, length) {
var integer = toIntegerOrInfinity$1(index);
return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
};
var toIntegerOrInfinity = toIntegerOrInfinity$2;
var min = Math.min;
// `ToLength` abstract operation
// https://tc39.es/ecma262/#sec-tolength
var toLength$1 = function (argument) {
var len = toIntegerOrInfinity(argument);
return len > 0 ? min(len, 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
};
var toLength = toLength$1;
// `LengthOfArrayLike` abstract operation
// https://tc39.es/ecma262/#sec-lengthofarraylike
var lengthOfArrayLike$3 = function (obj) {
return toLength(obj.length);
};
var toIndexedObject$3 = toIndexedObject$5;
var toAbsoluteIndex = toAbsoluteIndex$1;
var lengthOfArrayLike$2 = lengthOfArrayLike$3;
// `Array.prototype.{ indexOf, includes }` methods implementation
var createMethod$1 = function (IS_INCLUDES) {
return function ($this, el, fromIndex) {
var O = toIndexedObject$3($this);
var length = lengthOfArrayLike$2(O);
if (length === 0) return !IS_INCLUDES && -1;
var index = toAbsoluteIndex(fromIndex, length);
var value;
// Array#includes uses SameValueZero equality algorithm
// eslint-disable-next-line no-self-compare -- NaN check
if (IS_INCLUDES && el !== el) while (length > index) {
value = O[index++];
// eslint-disable-next-line no-self-compare -- NaN check
if (value !== value) return true;
// Array#indexOf ignores holes, Array#includes - not
} else for (;length > index; index++) {
if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
} return !IS_INCLUDES && -1;
};
};
var arrayIncludes = {
// `Array.prototype.includes` method
// https://tc39.es/ecma262/#sec-array.prototype.includes
includes: createMethod$1(true),
// `Array.prototype.indexOf` method
// https://tc39.es/ecma262/#sec-array.prototype.indexof
indexOf: createMethod$1(false)
};
var uncurryThis$7 = functionUncurryThis;
var hasOwn$6 = hasOwnProperty_1;
var toIndexedObject$2 = toIndexedObject$5;
var indexOf = arrayIncludes.indexOf;
var hiddenKeys$2 = hiddenKeys$4;
var push = uncurryThis$7([].push);
var objectKeysInternal = function (object, names) {
var O = toIndexedObject$2(object);
var i = 0;
var result = [];
var key;
for (key in O) !hasOwn$6(hiddenKeys$2, key) && hasOwn$6(O, key) && push(result, key);
// Don't enum bug & hidden keys
while (names.length > i) if (hasOwn$6(O, key = names[i++])) {
~indexOf(result, key) || push(result, key);
}
return result;
};
// IE8- don't enum bug keys
var enumBugKeys$3 = [
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf'
];
var internalObjectKeys$1 = objectKeysInternal;
var enumBugKeys$2 = enumBugKeys$3;
var hiddenKeys$1 = enumBugKeys$2.concat('length', 'prototype');
// `Object.getOwnPropertyNames` method
// https://tc39.es/ecma262/#sec-object.getownpropertynames
// eslint-disable-next-line es/no-object-getownpropertynames -- safe
objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
return internalObjectKeys$1(O, hiddenKeys$1);
};
var objectGetOwnPropertySymbols = {};
// eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols;
var getBuiltIn$2 = getBuiltIn$4;
var uncurryThis$6 = functionUncurryThis;
var getOwnPropertyNamesModule = objectGetOwnPropertyNames;
var getOwnPropertySymbolsModule$1 = objectGetOwnPropertySymbols;
var anObject$9 = anObject$b;
var concat$1 = uncurryThis$6([].concat);
// all object keys, includes non-enumerable and symbols
var ownKeys$1 = getBuiltIn$2('Reflect', 'ownKeys') || function ownKeys(it) {
var keys = getOwnPropertyNamesModule.f(anObject$9(it));
var getOwnPropertySymbols = getOwnPropertySymbolsModule$1.f;
return getOwnPropertySymbols ? concat$1(keys, getOwnPropertySymbols(it)) : keys;
};
var hasOwn$5 = hasOwnProperty_1;
var ownKeys = ownKeys$1;
var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor;
var definePropertyModule$2 = objectDefineProperty;
var copyConstructorProperties$3 = function (target, source, exceptions) {
var keys = ownKeys(source);
var defineProperty = definePropertyModule$2.f;
var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!hasOwn$5(target, key) && !(exceptions && hasOwn$5(exceptions, key))) {
defineProperty(target, key, getOwnPropertyDescriptor(source, key));
}
}
};
var fails$5 = fails$d;
var isCallable$7 = isCallable$h;
var replacement = /#|\.prototype\./;
var isForced$1 = function (feature, detection) {
var value = data[normalize(feature)];
return value === POLYFILL ? true
: value === NATIVE ? false
: isCallable$7(detection) ? fails$5(detection)
: !!detection;
};
var normalize = isForced$1.normalize = function (string) {
return String(string).replace(replacement, '.').toLowerCase();
};
var data = isForced$1.data = {};
var NATIVE = isForced$1.NATIVE = 'N';
var POLYFILL = isForced$1.POLYFILL = 'P';
var isForced_1 = isForced$1;
var globalThis$5 = globalThis_1;
var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
var createNonEnumerableProperty$6 = createNonEnumerableProperty$8;
var defineBuiltIn$3 = defineBuiltIn$4;
var defineGlobalProperty = defineGlobalProperty$3;
var copyConstructorProperties$2 = copyConstructorProperties$3;
var isForced = isForced_1;
/*
options.target - name of the target object
options.global - target is the global object
options.stat - export as static methods of target
options.proto - export as prototype methods of target
options.real - real prototype method for the `pure` version
options.forced - export even if the native feature is available
options.bind - bind methods to the target, required for the `pure` version
options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
options.unsafe - use the simple assignment of property instead of delete + defineProperty
options.sham - add a flag to not completely full polyfills
options.enumerable - export as enumerable property
options.dontCallGetSet - prevent calling a getter on target
options.name - the .name of the function if it does not match the key
*/
var _export = function (options, source) {
var TARGET = options.target;
var GLOBAL = options.global;
var STATIC = options.stat;
var FORCED, target, key, targetProperty, sourceProperty, descriptor;
if (GLOBAL) {
target = globalThis$5;
} else if (STATIC) {
target = globalThis$5[TARGET] || defineGlobalProperty(TARGET, {});
} else {
target = globalThis$5[TARGET] && globalThis$5[TARGET].prototype;
}
if (target) for (key in source) {
sourceProperty = source[key];
if (options.dontCallGetSet) {
descriptor = getOwnPropertyDescriptor(target, key);
targetProperty = descriptor && descriptor.value;
} else targetProperty = target[key];
FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
// contained in target
if (!FORCED && targetProperty !== undefined) {
if (typeof sourceProperty == typeof targetProperty) continue;
copyConstructorProperties$2(sourceProperty, targetProperty);
}
// add a flag to not completely full polyfills
if (options.sham || (targetProperty && targetProperty.sham)) {
createNonEnumerableProperty$6(sourceProperty, 'sham', true);
}
defineBuiltIn$3(target, key, sourceProperty, options);
}
};
var NATIVE_BIND$1 = functionBindNative;
var FunctionPrototype = Function.prototype;
var apply$1 = FunctionPrototype.apply;
var call$7 = FunctionPrototype.call;
// eslint-disable-next-line es/no-function-prototype-bind, es/no-reflect -- safe
var functionApply = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND$1 ? call$7.bind(apply$1) : function () {
return call$7.apply(apply$1, arguments);
});
var uncurryThis$5 = functionUncurryThis;
var aCallable$4 = aCallable$6;
var functionUncurryThisAccessor = function (object, key, method) {
try {
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
return uncurryThis$5(aCallable$4(Object.getOwnPropertyDescriptor(object, key)[method]));
} catch (error) { /* empty */ }
};
var isObject$4 = isObject$a;
var isPossiblePrototype$1 = function (argument) {
return isObject$4(argument) || argument === null;
};
var isPossiblePrototype = isPossiblePrototype$1;
var $String$1 = String;
var $TypeError$4 = TypeError;
var aPossiblePrototype$1 = function (argument) {
if (isPossiblePrototype(argument)) return argument;
throw new $TypeError$4("Can't set " + $String$1(argument) + ' as a prototype');
};
/* eslint-disable no-proto -- safe */
var uncurryThisAccessor = functionUncurryThisAccessor;
var isObject$3 = isObject$a;
var requireObjectCoercible = requireObjectCoercible$3;
var aPossiblePrototype = aPossiblePrototype$1;
// `Object.setPrototypeOf` method
// https://tc39.es/ecma262/#sec-object.setprototypeof
// Works with __proto__ only. Old v8 can't work with null proto objects.
// eslint-disable-next-line es/no-object-setprototypeof -- safe
var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () {
var CORRECT_SETTER = false;
var test = {};
var setter;
try {
setter = uncurryThisAccessor(Object.prototype, '__proto__', 'set');
setter(test, []);
CORRECT_SETTER = test instanceof Array;
} catch (error) { /* empty */ }
return function setPrototypeOf(O, proto) {
requireObjectCoercible(O);
aPossiblePrototype(proto);
if (!isObject$3(O)) return O;
if (CORRECT_SETTER) setter(O, proto);
else O.__proto__ = proto;
return O;
};
}() : undefined);
var defineProperty$5 = objectDefineProperty.f;
var proxyAccessor$1 = function (Target, Source, key) {
key in Target || defineProperty$5(Target, key, {
configurable: true,
get: function () { return Source[key]; },
set: function (it) { Source[key] = it; }
});
};
var isCallable$6 = isCallable$h;
var isObject$2 = isObject$a;
var setPrototypeOf$2 = objectSetPrototypeOf;
// makes subclassing work correct for wrapped built-ins
var inheritIfRequired$1 = function ($this, dummy, Wrapper) {
var NewTarget, NewTargetPrototype;
if (
// it can work only with native `setPrototypeOf`
setPrototypeOf$2 &&
// we haven't completely correct pre-ES6 way for getting `new.target`, so use this
isCallable$6(NewTarget = dummy.constructor) &&
NewTarget !== Wrapper &&
isObject$2(NewTargetPrototype = NewTarget.prototype) &&
NewTargetPrototype !== Wrapper.prototype
) setPrototypeOf$2($this, NewTargetPrototype);
return $this;
};
var wellKnownSymbol$a = wellKnownSymbol$c;
var TO_STRING_TAG$4 = wellKnownSymbol$a('toStringTag');
var test = {};
test[TO_STRING_TAG$4] = 'z';
var toStringTagSupport = String(test) === '[object z]';
var TO_STRING_TAG_SUPPORT = toStringTagSupport;
var isCallable$5 = isCallable$h;
var classofRaw$1 = classofRaw$2;
var wellKnownSymbol$9 = wellKnownSymbol$c;
var TO_STRING_TAG$3 = wellKnownSymbol$9('toStringTag');
var $Object$1 = Object;
// ES3 wrong here
var CORRECT_ARGUMENTS = classofRaw$1(function () { return arguments; }()) === 'Arguments';
// fallback for IE11 Script Access Denied error
var tryGet = function (it, key) {
try {
return it[key];
} catch (error) { /* empty */ }
};
// getting tag from ES6+ `Object.prototype.toString`
var classof$2 = TO_STRING_TAG_SUPPORT ? classofRaw$1 : function (it) {
var O, tag, result;
return it === undefined ? 'Undefined' : it === null ? 'Null'
// @@toStringTag case
: typeof (tag = tryGet(O = $Object$1(it), TO_STRING_TAG$3)) == 'string' ? tag
// builtinTag case
: CORRECT_ARGUMENTS ? classofRaw$1(O)
// ES3 arguments fallback
: (result = classofRaw$1(O)) === 'Object' && isCallable$5(O.callee) ? 'Arguments' : result;
};
var classof$1 = classof$2;
var $String = String;
var toString$2 = function (argument) {
if (classof$1(argument) === 'Symbol') throw new TypeError('Cannot convert a Symbol value to a string');
return $String(argument);
};
var toString$1 = toString$2;
var normalizeStringArgument$1 = function (argument, $default) {
return argument === undefined ? arguments.length < 2 ? '' : $default : toString$1(argument);
};
var isObject$1 = isObject$a;
var createNonEnumerableProperty$5 = createNonEnumerableProperty$8;
// `InstallErrorCause` abstract operation
// https://tc39.es/proposal-error-cause/#sec-errorobjects-install-error-cause
var installErrorCause$1 = function (O, options) {
if (isObject$1(options) && 'cause' in options) {
createNonEnumerableProperty$5(O, 'cause', options.cause);
}
};
var uncurryThis$4 = functionUncurryThis;
var $Error = Error;
var replace$1 = uncurryThis$4(''.replace);
var TEST = (function (arg) { return String(new $Error(arg).stack); })('zxcasd');
// eslint-disable-next-line redos/no-vulnerable, sonarjs/slow-regex -- safe
var V8_OR_CHAKRA_STACK_ENTRY = /\n\s*at [^:]*:[^\n]*/;
var IS_V8_OR_CHAKRA_STACK = V8_OR_CHAKRA_STACK_ENTRY.test(TEST);
var errorStackClear = function (stack, dropEntries) {
if (IS_V8_OR_CHAKRA_STACK && typeof stack == 'string' && !$Error.prepareStackTrace) {
while (dropEntries--) stack = replace$1(stack, V8_OR_CHAKRA_STACK_ENTRY, '');
} return stack;
};
var fails$4 = fails$d;
var createPropertyDescriptor$2 = createPropertyDescriptor$5;
var errorStackInstallable = !fails$4(function () {
var error = new Error('a');
if (!('stack' in error)) return true;
// eslint-disable-next-line es/no-object-defineproperty -- safe
Object.defineProperty(error, 'stack', createPropertyDescriptor$2(1, 7));
return error.stack !== 7;
});
var createNonEnumerableProperty$4 = createNonEnumerableProperty$8;
var clearErrorStack = errorStackClear;
var ERROR_STACK_INSTALLABLE = errorStackInstallable;
// non-standard V8
var captureStackTrace = Error.captureStackTrace;
var errorStackInstall = function (error, C, stack, dropEntries) {
if (ERROR_STACK_INSTALLABLE) {
if (captureStackTrace) captureStackTrace(error, C);
else createNonEnumerableProperty$4(error, 'stack', clearErrorStack(stack, dropEntries));
}
};
var getBuiltIn$1 = getBuiltIn$4;
var hasOwn$4 = hasOwnProperty_1;
var createNonEnumerableProperty$3 = createNonEnumerableProperty$8;
var isPrototypeOf$3 = objectIsPrototypeOf;
var setPrototypeOf$1 = objectSetPrototypeOf;
var copyConstructorProperties$1 = copyConstructorProperties$3;
var proxyAccessor = proxyAccessor$1;
var inheritIfRequired = inheritIfRequired$1;
var normalizeStringArgument = normalizeStringArgument$1;
var installErrorCause = installErrorCause$1;
var installErrorStack = errorStackInstall;
var DESCRIPTORS$6 = descriptors;
var wrapErrorConstructorWithCause$1 = function (FULL_NAME, wrapper, FORCED, IS_AGGREGATE_ERROR) {
var STACK_TRACE_LIMIT = 'stackTraceLimit';
var OPTIONS_POSITION = IS_AGGREGATE_ERROR ? 2 : 1;
var path = FULL_NAME.split('.');
var ERROR_NAME = path[path.length - 1];
var OriginalError = getBuiltIn$1.apply(null, path);
if (!OriginalError) return;
var OriginalErrorPrototype = OriginalError.prototype;
// V8 9.3- bug https://bugs.chromium.org/p/v8/issues/detail?id=12006
if (hasOwn$4(OriginalErrorPrototype, 'cause')) delete OriginalErrorPrototype.cause;
if (!FORCED) return OriginalError;
var BaseError = getBuiltIn$1('Error');
var WrappedError = wrapper(function (a, b) {
var message = normalizeStringArgument(IS_AGGREGATE_ERROR ? b : a, undefined);
var result = IS_AGGREGATE_ERROR ? new OriginalError(a) : new OriginalError();
if (message !== undefined) createNonEnumerableProperty$3(result, 'message', message);
installErrorStack(result, WrappedError, result.stack, 2);
if (this && isPrototypeOf$3(OriginalErrorPrototype, this)) inheritIfRequired(result, this, WrappedError);
if (arguments.length > OPTIONS_POSITION) installErrorCause(result, arguments[OPTIONS_POSITION]);
return result;
});
WrappedError.prototype = OriginalErrorPrototype;
if (ERROR_NAME !== 'Error') {
if (setPrototypeOf$1) setPrototypeOf$1(WrappedError, BaseError);
else copyConstructorProperties$1(WrappedError, BaseError, { name: true });
} else if (DESCRIPTORS$6 && STACK_TRACE_LIMIT in OriginalError) {
proxyAccessor(WrappedError, OriginalError, STACK_TRACE_LIMIT);
proxyAccessor(WrappedError, OriginalError, 'prepareStackTrace');
}
copyConstructorProperties$1(WrappedError, OriginalError);
try {
// Safari 13- bug: WebAssembly errors does not have a proper `.name`
if (OriginalErrorPrototype.name !== ERROR_NAME) {
createNonEnumerableProperty$3(OriginalErrorPrototype, 'name', ERROR_NAME);
}
OriginalErrorPrototype.constructor = WrappedError;
} catch (error) { /* empty */ }
return WrappedError;
};
/* eslint-disable no-unused-vars -- required for functions `.length` */
var $$7 = _export;
var globalThis$4 = globalThis_1;
var apply = functionApply;
var wrapErrorConstructorWithCause = wrapErrorConstructorWithCause$1;
var WEB_ASSEMBLY = 'WebAssembly';
var WebAssembly = globalThis$4[WEB_ASSEMBLY];
// eslint-disable-next-line es/no-error-cause -- feature detection
var FORCED$1 = new Error('e', { cause: 7 }).cause !== 7;
var exportGlobalErrorCauseWrapper = function (ERROR_NAME, wrapper) {
var O = {};
O[ERROR_NAME] = wrapErrorConstructorWithCause(ERROR_NAME, wrapper, FORCED$1);
$$7({ global: true, constructor: true, arity: 1, forced: FORCED$1 }, O);
};
var exportWebAssemblyErrorCauseWrapper = function (ERROR_NAME, wrapper) {
if (WebAssembly && WebAssembly[ERROR_NAME]) {
var O = {};
O[ERROR_NAME] = wrapErrorConstructorWithCause(WEB_ASSEMBLY + '.' + ERROR_NAME, wrapper, FORCED$1);
$$7({ target: WEB_ASSEMBLY, stat: true, constructor: true, arity: 1, forced: FORCED$1 }, O);
}
};
// https://tc39.es/ecma262/#sec-nativeerror
exportGlobalErrorCauseWrapper('Error', function (init) {
return function Error(message) { return apply(init, this, arguments); };
});
exportGlobalErrorCauseWrapper('EvalError', function (init) {
return function EvalError(message) { return apply(init, this, arguments); };
});
exportGlobalErrorCauseWrapper('RangeError', function (init) {
return function RangeError(message) { return apply(init, this, arguments); };
});
exportGlobalErrorCauseWrapper('ReferenceError', function (init) {
return function ReferenceError(message) { return apply(init, this, arguments); };
});
exportGlobalErrorCauseWrapper('SyntaxError', function (init) {
return function SyntaxError(message) { return apply(init, this, arguments); };
});
exportGlobalErrorCauseWrapper('TypeError', function (init) {
return function TypeError(message) { return apply(init, this, arguments); };
});
exportGlobalErrorCauseWrapper('URIError', function (init) {
return function URIError(message) { return apply(init, this, arguments); };
});
exportWebAssemblyErrorCauseWrapper('CompileError', function (init) {
return function CompileError(message) { return apply(init, this, arguments); };
});
exportWebAssemblyErrorCauseWrapper('LinkError', function (init) {
return function LinkError(message) { return apply(init, this, arguments); };
});
exportWebAssemblyErrorCauseWrapper('RuntimeError', function (init) {
return function RuntimeError(message) { return apply(init, this, arguments); };
});
/**
* Connects a Hashbrown Signal to React's reactivity system
*
* @param signal The signal to connect to React
* @returns The value contained in the signal
*/
function useHashbrownSignal(signal) {
const lastValue = useRef(signal());
const hasSkippedFirstCall = useRef(false);
const equality = useCallback((a, b) => _deepEqual(a, b), []);
const read = useCallback(() => {
const value = signal();
if (!equality(value, lastValue.current)) {
lastValue.current = value;
}
return lastValue.current;
}, [signal, equality]);
const subscribe = useCallback(onStoreChange => {
let lastRead;
const cleanup = signal.subscribe(value => {
if (!hasSkippedFirstCall.current) {
hasSkippedFirstCall.current = true;
return;
}
const currentValue = read();
if (currentValue !== lastRead) {
lastRead = currentValue;
onStoreChange();
}
});
return () => {
cleanup();
hasSkippedFirstCall.current = false;
};
}, [signal, read]);
return useSyncExternalStore(subscribe, read);
}
/**
* This React hook creates a chat instance used to interact with the LLM.
* The result object contains functions and state enabling you to send and recieve messages and monitor the state of the chat.
*
* @description
* The `useChat` hook provides the most basic functionality for un-structured chats. Unstructured chats include things like general chats and natural language controls.
*
* @returns {UseChatResult} An object containing chat state and functions to interact with the chat.
*
* @example
* This example demonstrates how to use the `useChat` hook to create a simple chat component.
*
* ```tsx
* const MyChatComponent = () => {
* const { messages, sendMessage, status } = useChat({
* model: 'gpt-4o',
* system: 'You are a helpful assistant.',
* tools: [],
* });
*
* const handleSendMessage = () => {
* sendMessage({ role: 'user', content: 'Hello, how are you?' });
* };
*
* return (
* <div>
* <button onClick={handleSendMessage}>Send Message</button>
* <div>Status: {status}</div>
* <ul>
* {messages.map((msg, index) => (
* <li key={index}>{msg.content}</li>
* ))}
* </ul>
* </div>
* );
* };
* ```
*/
function useChat(
/**
* The options for the chat.
*/
options) {
var _a;
const tools = useMemo(() => {
var _a;
return (_a = options.tools) !== null && _a !== void 0 ? _a : [];
},
// eslint-disable-next-line react-hooks/exhaustive-deps
(_a = options.tools) !== null && _a !== void 0 ? _a : []);
const config = useContext(HashbrownContext);
if (!config) {
throw new Error('HashbrownContext not found');
}
const hashbrownRef = useRef(null);
if (!hashbrownRef.current) {
hashbrownRef.current = fryHashbrown({
apiUrl: config.url,
middleware: config.middleware,
debugName: options.debugName,
model: options.model,
system: options.system,
tools,
debounce: options.debounceTime,