@buildlayer/ai-react
Version:
React UI components for AI chat assistants
1,470 lines (1,467 loc) • 103 kB
JavaScript
import * as g from "react";
import It, { useRef as Z, useEffect as I, useCallback as B, useState as M, createContext as Ye, useContext as ze } from "react";
import "react-dom";
import { getAvailableProviders as Tr, validateProviderConfig as Or, createProviderAdapter as kr, ChatStore as Dr, weatherTool as Lr, getAvailableModels as Ir } from "@buildlayer/ai-core";
function ha(e) {
const t = Z(null);
I(() => (t.current = e.subscribe(() => {
}), () => {
t.current && t.current();
}), [e]);
const r = B(
async (o, f) => {
await e.send(o, f);
},
[e]
), n = B(
async (o) => {
await e.runTool(o);
},
[e]
), s = B(() => {
e.stop();
}, [e]), c = B(() => {
e.reset();
}, [e]), i = B(
(o) => {
e.importHistory(o);
},
[e]
), d = B(() => e.exportHistory(), [e]), u = B(() => {
e.clearHistory();
}, [e]);
return {
// State
sessionId: (e == null ? void 0 : e.sessionId) || "",
messages: (e == null ? void 0 : e.messages) || [],
status: (e == null ? void 0 : e.status) || "idle",
currentToolCall: (e == null ? void 0 : e.currentToolCall) || null,
error: (e == null ? void 0 : e.error) || null,
// Actions
send: r,
runTool: n,
stop: s,
reset: c,
importHistory: i,
exportHistory: d,
clearHistory: u
};
}
const Re = "ai-react-session";
function va(e) {
const [t, r] = M(null), [n, s] = M(!1), c = Z(0), i = Z(0), d = Z(!1), u = 50;
I(() => {
const p = localStorage.getItem(Re);
if (p)
try {
const h = JSON.parse(p);
r(h);
} catch (h) {
console.error("Failed to parse saved session:", h), r(null);
}
else {
const h = {
id: "single-session",
name: "Chat",
messages: [],
createdAt: Date.now(),
updatedAt: Date.now()
};
r(h), localStorage.setItem(Re, JSON.stringify(h));
}
s(!0);
}, []), I(() => {
n && t && t.messages.length > 0 && (d.current = !0, e.importHistory(t.messages), setTimeout(() => {
d.current = !1;
}, 100));
}, [n, t, e]), I(() => !t || !n ? void 0 : e.subscribe((h) => {
if (d.current)
return;
const x = h.messages.length !== i.current;
if (h.status === "idle" || h.status === "error" || x) {
const R = Date.now(), y = R - c.current;
if (!x && y < u)
return;
const N = h.messages, v = {
...t,
messages: N,
updatedAt: R
};
c.current = R, i.current = N.length, r(v), localStorage.setItem(Re, JSON.stringify(v));
}
}), [e, t, n]);
const o = B(() => {
const p = {
...t,
messages: [],
updatedAt: Date.now()
};
r(p), localStorage.setItem(Re, JSON.stringify(p)), e.clearHistory();
}, [t, e]), f = B(() => t ? {
session: {
id: t.id,
name: t.name,
createdAt: t.createdAt,
updatedAt: t.updatedAt
},
messages: t.messages,
exportedAt: Date.now()
} : null, [t]);
return {
session: t,
isLoaded: n,
clearSession: o,
exportSession: f
};
}
var $e = { exports: {} }, le = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Nt;
function Ar() {
if (Nt) return le;
Nt = 1;
var e = It, t = Symbol.for("react.element"), r = Symbol.for("react.fragment"), n = Object.prototype.hasOwnProperty, s = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, c = { key: !0, ref: !0, __self: !0, __source: !0 };
function i(d, u, o) {
var f, p = {}, h = null, x = null;
o !== void 0 && (h = "" + o), u.key !== void 0 && (h = "" + u.key), u.ref !== void 0 && (x = u.ref);
for (f in u) n.call(u, f) && !c.hasOwnProperty(f) && (p[f] = u[f]);
if (d && d.defaultProps) for (f in u = d.defaultProps, u) p[f] === void 0 && (p[f] = u[f]);
return { $$typeof: t, type: d, key: h, ref: x, props: p, _owner: s.current };
}
return le.Fragment = r, le.jsx = i, le.jsxs = i, le;
}
var ce = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Rt;
function Mr() {
return Rt || (Rt = 1, process.env.NODE_ENV !== "production" && function() {
var e = It, t = Symbol.for("react.element"), r = Symbol.for("react.portal"), n = Symbol.for("react.fragment"), s = Symbol.for("react.strict_mode"), c = Symbol.for("react.profiler"), i = Symbol.for("react.provider"), d = Symbol.for("react.context"), u = Symbol.for("react.forward_ref"), o = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), p = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), x = Symbol.for("react.offscreen"), E = Symbol.iterator, R = "@@iterator";
function y(a) {
if (a === null || typeof a != "object")
return null;
var m = E && a[E] || a[R];
return typeof m == "function" ? m : null;
}
var N = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function v(a) {
{
for (var m = arguments.length, b = new Array(m > 1 ? m - 1 : 0), w = 1; w < m; w++)
b[w - 1] = arguments[w];
C("error", a, b);
}
}
function C(a, m, b) {
{
var w = N.ReactDebugCurrentFrame, P = w.getStackAddendum();
P !== "" && (m += "%s", b = b.concat([P]));
var T = b.map(function(_) {
return String(_);
});
T.unshift("Warning: " + m), Function.prototype.apply.call(console[a], console, T);
}
}
var O = !1, V = !1, ne = !1, xe = !1, ae = !1, ye;
ye = Symbol.for("react.module.reference");
function se(a) {
return !!(typeof a == "string" || typeof a == "function" || a === n || a === c || ae || a === s || a === o || a === f || xe || a === x || O || V || ne || typeof a == "object" && a !== null && (a.$$typeof === h || a.$$typeof === p || a.$$typeof === i || a.$$typeof === d || a.$$typeof === u || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
a.$$typeof === ye || a.getModuleId !== void 0));
}
function Te(a, m, b) {
var w = a.displayName;
if (w)
return w;
var P = m.displayName || m.name || "";
return P !== "" ? b + "(" + P + ")" : b;
}
function Qe(a) {
return a.displayName || "Context";
}
function Y(a) {
if (a == null)
return null;
if (typeof a.tag == "number" && v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof a == "function")
return a.displayName || a.name || null;
if (typeof a == "string")
return a;
switch (a) {
case n:
return "Fragment";
case r:
return "Portal";
case c:
return "Profiler";
case s:
return "StrictMode";
case o:
return "Suspense";
case f:
return "SuspenseList";
}
if (typeof a == "object")
switch (a.$$typeof) {
case d:
var m = a;
return Qe(m) + ".Consumer";
case i:
var b = a;
return Qe(b._context) + ".Provider";
case u:
return Te(a, a.render, "ForwardRef");
case p:
var w = a.displayName || null;
return w !== null ? w : Y(a.type) || "Memo";
case h: {
var P = a, T = P._payload, _ = P._init;
try {
return Y(_(T));
} catch {
return null;
}
}
}
return null;
}
var H = Object.assign, oe = 0, et, tt, rt, nt, at, st, ot;
function it() {
}
it.__reactDisabledLog = !0;
function nr() {
{
if (oe === 0) {
et = console.log, tt = console.info, rt = console.warn, nt = console.error, at = console.group, st = console.groupCollapsed, ot = console.groupEnd;
var a = {
configurable: !0,
enumerable: !0,
value: it,
writable: !0
};
Object.defineProperties(console, {
info: a,
log: a,
warn: a,
error: a,
group: a,
groupCollapsed: a,
groupEnd: a
});
}
oe++;
}
}
function ar() {
{
if (oe--, oe === 0) {
var a = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: H({}, a, {
value: et
}),
info: H({}, a, {
value: tt
}),
warn: H({}, a, {
value: rt
}),
error: H({}, a, {
value: nt
}),
group: H({}, a, {
value: at
}),
groupCollapsed: H({}, a, {
value: st
}),
groupEnd: H({}, a, {
value: ot
})
});
}
oe < 0 && v("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var Oe = N.ReactCurrentDispatcher, ke;
function be(a, m, b) {
{
if (ke === void 0)
try {
throw Error();
} catch (P) {
var w = P.stack.trim().match(/\n( *(at )?)/);
ke = w && w[1] || "";
}
return `
` + ke + a;
}
}
var De = !1, Ee;
{
var sr = typeof WeakMap == "function" ? WeakMap : Map;
Ee = new sr();
}
function lt(a, m) {
if (!a || De)
return "";
{
var b = Ee.get(a);
if (b !== void 0)
return b;
}
var w;
De = !0;
var P = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var T;
T = Oe.current, Oe.current = null, nr();
try {
if (m) {
var _ = function() {
throw Error();
};
if (Object.defineProperty(_.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(_, []);
} catch (A) {
w = A;
}
Reflect.construct(a, [], _);
} else {
try {
_.call();
} catch (A) {
w = A;
}
a.call(_.prototype);
}
} else {
try {
throw Error();
} catch (A) {
w = A;
}
a();
}
} catch (A) {
if (A && w && typeof A.stack == "string") {
for (var S = A.stack.split(`
`), L = w.stack.split(`
`), k = S.length - 1, D = L.length - 1; k >= 1 && D >= 0 && S[k] !== L[D]; )
D--;
for (; k >= 1 && D >= 0; k--, D--)
if (S[k] !== L[D]) {
if (k !== 1 || D !== 1)
do
if (k--, D--, D < 0 || S[k] !== L[D]) {
var F = `
` + S[k].replace(" at new ", " at ");
return a.displayName && F.includes("<anonymous>") && (F = F.replace("<anonymous>", a.displayName)), typeof a == "function" && Ee.set(a, F), F;
}
while (k >= 1 && D >= 0);
break;
}
}
} finally {
De = !1, Oe.current = T, ar(), Error.prepareStackTrace = P;
}
var X = a ? a.displayName || a.name : "", q = X ? be(X) : "";
return typeof a == "function" && Ee.set(a, q), q;
}
function or(a, m, b) {
return lt(a, !1);
}
function ir(a) {
var m = a.prototype;
return !!(m && m.isReactComponent);
}
function we(a, m, b) {
if (a == null)
return "";
if (typeof a == "function")
return lt(a, ir(a));
if (typeof a == "string")
return be(a);
switch (a) {
case o:
return be("Suspense");
case f:
return be("SuspenseList");
}
if (typeof a == "object")
switch (a.$$typeof) {
case u:
return or(a.render);
case p:
return we(a.type, m, b);
case h: {
var w = a, P = w._payload, T = w._init;
try {
return we(T(P), m, b);
} catch {
}
}
}
return "";
}
var ie = Object.prototype.hasOwnProperty, ct = {}, ut = N.ReactDebugCurrentFrame;
function Ne(a) {
if (a) {
var m = a._owner, b = we(a.type, a._source, m ? m.type : null);
ut.setExtraStackFrame(b);
} else
ut.setExtraStackFrame(null);
}
function lr(a, m, b, w, P) {
{
var T = Function.call.bind(ie);
for (var _ in a)
if (T(a, _)) {
var S = void 0;
try {
if (typeof a[_] != "function") {
var L = Error((w || "React class") + ": " + b + " type `" + _ + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof a[_] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw L.name = "Invariant Violation", L;
}
S = a[_](m, _, w, b, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (k) {
S = k;
}
S && !(S instanceof Error) && (Ne(P), v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", w || "React class", b, _, typeof S), Ne(null)), S instanceof Error && !(S.message in ct) && (ct[S.message] = !0, Ne(P), v("Failed %s type: %s", b, S.message), Ne(null));
}
}
}
var cr = Array.isArray;
function Le(a) {
return cr(a);
}
function ur(a) {
{
var m = typeof Symbol == "function" && Symbol.toStringTag, b = m && a[Symbol.toStringTag] || a.constructor.name || "Object";
return b;
}
}
function dr(a) {
try {
return dt(a), !1;
} catch {
return !0;
}
}
function dt(a) {
return "" + a;
}
function ft(a) {
if (dr(a))
return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ur(a)), dt(a);
}
var pt = N.ReactCurrentOwner, fr = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, mt, ht;
function pr(a) {
if (ie.call(a, "ref")) {
var m = Object.getOwnPropertyDescriptor(a, "ref").get;
if (m && m.isReactWarning)
return !1;
}
return a.ref !== void 0;
}
function mr(a) {
if (ie.call(a, "key")) {
var m = Object.getOwnPropertyDescriptor(a, "key").get;
if (m && m.isReactWarning)
return !1;
}
return a.key !== void 0;
}
function hr(a, m) {
typeof a.ref == "string" && pt.current;
}
function vr(a, m) {
{
var b = function() {
mt || (mt = !0, v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", m));
};
b.isReactWarning = !0, Object.defineProperty(a, "key", {
get: b,
configurable: !0
});
}
}
function gr(a, m) {
{
var b = function() {
ht || (ht = !0, v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", m));
};
b.isReactWarning = !0, Object.defineProperty(a, "ref", {
get: b,
configurable: !0
});
}
}
var xr = function(a, m, b, w, P, T, _) {
var S = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: t,
// Built-in properties that belong on the element
type: a,
key: m,
ref: b,
props: _,
// Record the component responsible for creating this element.
_owner: T
};
return S._store = {}, Object.defineProperty(S._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(S, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: w
}), Object.defineProperty(S, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: P
}), Object.freeze && (Object.freeze(S.props), Object.freeze(S)), S;
};
function yr(a, m, b, w, P) {
{
var T, _ = {}, S = null, L = null;
b !== void 0 && (ft(b), S = "" + b), mr(m) && (ft(m.key), S = "" + m.key), pr(m) && (L = m.ref, hr(m, P));
for (T in m)
ie.call(m, T) && !fr.hasOwnProperty(T) && (_[T] = m[T]);
if (a && a.defaultProps) {
var k = a.defaultProps;
for (T in k)
_[T] === void 0 && (_[T] = k[T]);
}
if (S || L) {
var D = typeof a == "function" ? a.displayName || a.name || "Unknown" : a;
S && vr(_, D), L && gr(_, D);
}
return xr(a, S, L, P, w, pt.current, _);
}
}
var Ie = N.ReactCurrentOwner, vt = N.ReactDebugCurrentFrame;
function G(a) {
if (a) {
var m = a._owner, b = we(a.type, a._source, m ? m.type : null);
vt.setExtraStackFrame(b);
} else
vt.setExtraStackFrame(null);
}
var Ae;
Ae = !1;
function Me(a) {
return typeof a == "object" && a !== null && a.$$typeof === t;
}
function gt() {
{
if (Ie.current) {
var a = Y(Ie.current.type);
if (a)
return `
Check the render method of \`` + a + "`.";
}
return "";
}
}
function br(a) {
return "";
}
var xt = {};
function Er(a) {
{
var m = gt();
if (!m) {
var b = typeof a == "string" ? a : a.displayName || a.name;
b && (m = `
Check the top-level render call using <` + b + ">.");
}
return m;
}
}
function yt(a, m) {
{
if (!a._store || a._store.validated || a.key != null)
return;
a._store.validated = !0;
var b = Er(m);
if (xt[b])
return;
xt[b] = !0;
var w = "";
a && a._owner && a._owner !== Ie.current && (w = " It was passed a child from " + Y(a._owner.type) + "."), G(a), v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', b, w), G(null);
}
}
function bt(a, m) {
{
if (typeof a != "object")
return;
if (Le(a))
for (var b = 0; b < a.length; b++) {
var w = a[b];
Me(w) && yt(w, m);
}
else if (Me(a))
a._store && (a._store.validated = !0);
else if (a) {
var P = y(a);
if (typeof P == "function" && P !== a.entries)
for (var T = P.call(a), _; !(_ = T.next()).done; )
Me(_.value) && yt(_.value, m);
}
}
}
function wr(a) {
{
var m = a.type;
if (m == null || typeof m == "string")
return;
var b;
if (typeof m == "function")
b = m.propTypes;
else if (typeof m == "object" && (m.$$typeof === u || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
m.$$typeof === p))
b = m.propTypes;
else
return;
if (b) {
var w = Y(m);
lr(b, a.props, "prop", w, a);
} else if (m.PropTypes !== void 0 && !Ae) {
Ae = !0;
var P = Y(m);
v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", P || "Unknown");
}
typeof m.getDefaultProps == "function" && !m.getDefaultProps.isReactClassApproved && v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function Nr(a) {
{
for (var m = Object.keys(a.props), b = 0; b < m.length; b++) {
var w = m[b];
if (w !== "children" && w !== "key") {
G(a), v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", w), G(null);
break;
}
}
a.ref !== null && (G(a), v("Invalid attribute `ref` supplied to `React.Fragment`."), G(null));
}
}
var Et = {};
function wt(a, m, b, w, P, T) {
{
var _ = se(a);
if (!_) {
var S = "";
(a === void 0 || typeof a == "object" && a !== null && Object.keys(a).length === 0) && (S += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var L = br();
L ? S += L : S += gt();
var k;
a === null ? k = "null" : Le(a) ? k = "array" : a !== void 0 && a.$$typeof === t ? (k = "<" + (Y(a.type) || "Unknown") + " />", S = " Did you accidentally export a JSX literal instead of a component?") : k = typeof a, v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", k, S);
}
var D = yr(a, m, b, P, T);
if (D == null)
return D;
if (_) {
var F = m.children;
if (F !== void 0)
if (w)
if (Le(F)) {
for (var X = 0; X < F.length; X++)
bt(F[X], a);
Object.freeze && Object.freeze(F);
} else
v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
bt(F, a);
}
if (ie.call(m, "key")) {
var q = Y(a), A = Object.keys(m).filter(function(Pr) {
return Pr !== "key";
}), Fe = A.length > 0 ? "{key: someKey, " + A.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!Et[q + Fe]) {
var _r = A.length > 0 ? "{" + A.join(": ..., ") + ": ...}" : "{}";
v(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, Fe, q, _r, q), Et[q + Fe] = !0;
}
}
return a === n ? Nr(D) : wr(D), D;
}
}
function Rr(a, m, b) {
return wt(a, m, b, !0);
}
function jr(a, m, b) {
return wt(a, m, b, !1);
}
var Sr = jr, Cr = Rr;
ce.Fragment = n, ce.jsx = Sr, ce.jsxs = Cr;
}()), ce;
}
process.env.NODE_ENV === "production" ? $e.exports = Ar() : $e.exports = Mr();
var l = $e.exports;
/**
* @remix-run/router v1.23.0
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
function ue() {
return ue = Object.assign ? Object.assign.bind() : function(e) {
for (var t = 1; t < arguments.length; t++) {
var r = arguments[t];
for (var n in r)
Object.prototype.hasOwnProperty.call(r, n) && (e[n] = r[n]);
}
return e;
}, ue.apply(this, arguments);
}
var z;
(function(e) {
e.Pop = "POP", e.Push = "PUSH", e.Replace = "REPLACE";
})(z || (z = {}));
const jt = "popstate";
function Fr(e) {
e === void 0 && (e = {});
function t(n, s) {
let {
pathname: c,
search: i,
hash: d
} = n.location;
return Be(
"",
{
pathname: c,
search: i,
hash: d
},
// state defaults to `null` because `window.history.state` does
s.state && s.state.usr || null,
s.state && s.state.key || "default"
);
}
function r(n, s) {
return typeof s == "string" ? s : de(s);
}
return Vr(t, r, null, e);
}
function j(e, t) {
if (e === !1 || e === null || typeof e > "u")
throw new Error(t);
}
function $(e, t) {
if (!e) {
typeof console < "u" && console.warn(t);
try {
throw new Error(t);
} catch {
}
}
}
function Ur() {
return Math.random().toString(36).substr(2, 8);
}
function St(e, t) {
return {
usr: e.state,
key: e.key,
idx: t
};
}
function Be(e, t, r, n) {
return r === void 0 && (r = null), ue({
pathname: typeof e == "string" ? e : e.pathname,
search: "",
hash: ""
}, typeof t == "string" ? ee(t) : t, {
state: r,
// TODO: This could be cleaned up. push/replace should probably just take
// full Locations now and avoid the need to run through this flow at all
// But that's a pretty big refactor to the current test suite so going to
// keep as is for the time being and just let any incoming keys take precedence
key: t && t.key || n || Ur()
});
}
function de(e) {
let {
pathname: t = "/",
search: r = "",
hash: n = ""
} = e;
return r && r !== "?" && (t += r.charAt(0) === "?" ? r : "?" + r), n && n !== "#" && (t += n.charAt(0) === "#" ? n : "#" + n), t;
}
function ee(e) {
let t = {};
if (e) {
let r = e.indexOf("#");
r >= 0 && (t.hash = e.substr(r), e = e.substr(0, r));
let n = e.indexOf("?");
n >= 0 && (t.search = e.substr(n), e = e.substr(0, n)), e && (t.pathname = e);
}
return t;
}
function Vr(e, t, r, n) {
n === void 0 && (n = {});
let {
window: s = document.defaultView,
v5Compat: c = !1
} = n, i = s.history, d = z.Pop, u = null, o = f();
o == null && (o = 0, i.replaceState(ue({}, i.state, {
idx: o
}), ""));
function f() {
return (i.state || {
idx: null
}).idx;
}
function p() {
d = z.Pop;
let y = f(), N = y == null ? null : y - o;
o = y, u && u({
action: d,
location: R.location,
delta: N
});
}
function h(y, N) {
d = z.Push;
let v = Be(R.location, y, N);
o = f() + 1;
let C = St(v, o), O = R.createHref(v);
try {
i.pushState(C, "", O);
} catch (V) {
if (V instanceof DOMException && V.name === "DataCloneError")
throw V;
s.location.assign(O);
}
c && u && u({
action: d,
location: R.location,
delta: 1
});
}
function x(y, N) {
d = z.Replace;
let v = Be(R.location, y, N);
o = f();
let C = St(v, o), O = R.createHref(v);
i.replaceState(C, "", O), c && u && u({
action: d,
location: R.location,
delta: 0
});
}
function E(y) {
let N = s.location.origin !== "null" ? s.location.origin : s.location.href, v = typeof y == "string" ? y : de(y);
return v = v.replace(/ $/, "%20"), j(N, "No window.location.(origin|href) available to create URL for href: " + v), new URL(v, N);
}
let R = {
get action() {
return d;
},
get location() {
return e(s, i);
},
listen(y) {
if (u)
throw new Error("A history only accepts one active listener");
return s.addEventListener(jt, p), u = y, () => {
s.removeEventListener(jt, p), u = null;
};
},
createHref(y) {
return t(s, y);
},
createURL: E,
encodeLocation(y) {
let N = E(y);
return {
pathname: N.pathname,
search: N.search,
hash: N.hash
};
},
push: h,
replace: x,
go(y) {
return i.go(y);
}
};
return R;
}
var Ct;
(function(e) {
e.data = "data", e.deferred = "deferred", e.redirect = "redirect", e.error = "error";
})(Ct || (Ct = {}));
function $r(e, t, r) {
return r === void 0 && (r = "/"), Br(e, t, r);
}
function Br(e, t, r, n) {
let s = typeof t == "string" ? ee(t) : t, c = J(s.pathname || "/", r);
if (c == null)
return null;
let i = At(e);
Wr(i);
let d = null;
for (let u = 0; d == null && u < i.length; ++u) {
let o = en(c);
d = Zr(i[u], o);
}
return d;
}
function At(e, t, r, n) {
t === void 0 && (t = []), r === void 0 && (r = []), n === void 0 && (n = "");
let s = (c, i, d) => {
let u = {
relativePath: d === void 0 ? c.path || "" : d,
caseSensitive: c.caseSensitive === !0,
childrenIndex: i,
route: c
};
u.relativePath.startsWith("/") && (j(u.relativePath.startsWith(n), 'Absolute route path "' + u.relativePath + '" nested under path ' + ('"' + n + '" is not valid. An absolute child route path ') + "must start with the combined path of all its parent routes."), u.relativePath = u.relativePath.slice(n.length));
let o = W([n, u.relativePath]), f = r.concat(u);
c.children && c.children.length > 0 && (j(
// Our types know better, but runtime JS may not!
// @ts-expect-error
c.index !== !0,
"Index routes must not have child routes. Please remove " + ('all child routes from route path "' + o + '".')
), At(c.children, t, f, o)), !(c.path == null && !c.index) && t.push({
path: o,
score: Gr(o, c.index),
routesMeta: f
});
};
return e.forEach((c, i) => {
var d;
if (c.path === "" || !((d = c.path) != null && d.includes("?")))
s(c, i);
else
for (let u of Mt(c.path))
s(c, i, u);
}), t;
}
function Mt(e) {
let t = e.split("/");
if (t.length === 0) return [];
let [r, ...n] = t, s = r.endsWith("?"), c = r.replace(/\?$/, "");
if (n.length === 0)
return s ? [c, ""] : [c];
let i = Mt(n.join("/")), d = [];
return d.push(...i.map((u) => u === "" ? c : [c, u].join("/"))), s && d.push(...i), d.map((u) => e.startsWith("/") && u === "" ? "/" : u);
}
function Wr(e) {
e.sort((t, r) => t.score !== r.score ? r.score - t.score : Xr(t.routesMeta.map((n) => n.childrenIndex), r.routesMeta.map((n) => n.childrenIndex)));
}
const Kr = /^:[\w-]+$/, Yr = 3, zr = 2, Jr = 1, Hr = 10, qr = -2, _t = (e) => e === "*";
function Gr(e, t) {
let r = e.split("/"), n = r.length;
return r.some(_t) && (n += qr), t && (n += zr), r.filter((s) => !_t(s)).reduce((s, c) => s + (Kr.test(c) ? Yr : c === "" ? Jr : Hr), n);
}
function Xr(e, t) {
return e.length === t.length && e.slice(0, -1).every((n, s) => n === t[s]) ? (
// If two routes are siblings, we should try to match the earlier sibling
// first. This allows people to have fine-grained control over the matching
// behavior by simply putting routes with identical paths in the order they
// want them tried.
e[e.length - 1] - t[t.length - 1]
) : (
// Otherwise, it doesn't really make sense to rank non-siblings by index,
// so they sort equally.
0
);
}
function Zr(e, t, r) {
let {
routesMeta: n
} = e, s = {}, c = "/", i = [];
for (let d = 0; d < n.length; ++d) {
let u = n[d], o = d === n.length - 1, f = c === "/" ? t : t.slice(c.length) || "/", p = We({
path: u.relativePath,
caseSensitive: u.caseSensitive,
end: o
}, f), h = u.route;
if (!p)
return null;
Object.assign(s, p.params), i.push({
// TODO: Can this as be avoided?
params: s,
pathname: W([c, p.pathname]),
pathnameBase: an(W([c, p.pathnameBase])),
route: h
}), p.pathnameBase !== "/" && (c = W([c, p.pathnameBase]));
}
return i;
}
function We(e, t) {
typeof e == "string" && (e = {
path: e,
caseSensitive: !1,
end: !0
});
let [r, n] = Qr(e.path, e.caseSensitive, e.end), s = t.match(r);
if (!s) return null;
let c = s[0], i = c.replace(/(.)\/+$/, "$1"), d = s.slice(1);
return {
params: n.reduce((o, f, p) => {
let {
paramName: h,
isOptional: x
} = f;
if (h === "*") {
let R = d[p] || "";
i = c.slice(0, c.length - R.length).replace(/(.)\/+$/, "$1");
}
const E = d[p];
return x && !E ? o[h] = void 0 : o[h] = (E || "").replace(/%2F/g, "/"), o;
}, {}),
pathname: c,
pathnameBase: i,
pattern: e
};
}
function Qr(e, t, r) {
t === void 0 && (t = !1), r === void 0 && (r = !0), $(e === "*" || !e.endsWith("*") || e.endsWith("/*"), 'Route path "' + e + '" will be treated as if it were ' + ('"' + e.replace(/\*$/, "/*") + '" because the `*` character must ') + "always follow a `/` in the pattern. To get rid of this warning, " + ('please change the route path to "' + e.replace(/\*$/, "/*") + '".'));
let n = [], s = "^" + e.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(/\/:([\w-]+)(\?)?/g, (i, d, u) => (n.push({
paramName: d,
isOptional: u != null
}), u ? "/?([^\\/]+)?" : "/([^\\/]+)"));
return e.endsWith("*") ? (n.push({
paramName: "*"
}), s += e === "*" || e === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$") : r ? s += "\\/*$" : e !== "" && e !== "/" && (s += "(?:(?=\\/|$))"), [new RegExp(s, t ? void 0 : "i"), n];
}
function en(e) {
try {
return e.split("/").map((t) => decodeURIComponent(t).replace(/\//g, "%2F")).join("/");
} catch (t) {
return $(!1, 'The URL path "' + e + '" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent ' + ("encoding (" + t + ").")), e;
}
}
function J(e, t) {
if (t === "/") return e;
if (!e.toLowerCase().startsWith(t.toLowerCase()))
return null;
let r = t.endsWith("/") ? t.length - 1 : t.length, n = e.charAt(r);
return n && n !== "/" ? null : e.slice(r) || "/";
}
function tn(e, t) {
t === void 0 && (t = "/");
let {
pathname: r,
search: n = "",
hash: s = ""
} = typeof e == "string" ? ee(e) : e;
return {
pathname: r ? r.startsWith("/") ? r : rn(r, t) : t,
search: sn(n),
hash: on(s)
};
}
function rn(e, t) {
let r = t.replace(/\/+$/, "").split("/");
return e.split("/").forEach((s) => {
s === ".." ? r.length > 1 && r.pop() : s !== "." && r.push(s);
}), r.length > 1 ? r.join("/") : "/";
}
function Ue(e, t, r, n) {
return "Cannot include a '" + e + "' character in a manually specified " + ("`to." + t + "` field [" + JSON.stringify(n) + "]. Please separate it out to the ") + ("`to." + r + "` field. Alternatively you may provide the full path as ") + 'a string in <Link to="..."> and the router will parse it for you.';
}
function nn(e) {
return e.filter((t, r) => r === 0 || t.route.path && t.route.path.length > 0);
}
function Ft(e, t) {
let r = nn(e);
return t ? r.map((n, s) => s === r.length - 1 ? n.pathname : n.pathnameBase) : r.map((n) => n.pathnameBase);
}
function Ut(e, t, r, n) {
n === void 0 && (n = !1);
let s;
typeof e == "string" ? s = ee(e) : (s = ue({}, e), j(!s.pathname || !s.pathname.includes("?"), Ue("?", "pathname", "search", s)), j(!s.pathname || !s.pathname.includes("#"), Ue("#", "pathname", "hash", s)), j(!s.search || !s.search.includes("#"), Ue("#", "search", "hash", s)));
let c = e === "" || s.pathname === "", i = c ? "/" : s.pathname, d;
if (i == null)
d = r;
else {
let p = t.length - 1;
if (!n && i.startsWith("..")) {
let h = i.split("/");
for (; h[0] === ".."; )
h.shift(), p -= 1;
s.pathname = h.join("/");
}
d = p >= 0 ? t[p] : "/";
}
let u = tn(s, d), o = i && i !== "/" && i.endsWith("/"), f = (c || i === ".") && r.endsWith("/");
return !u.pathname.endsWith("/") && (o || f) && (u.pathname += "/"), u;
}
const W = (e) => e.join("/").replace(/\/\/+/g, "/"), an = (e) => e.replace(/\/+$/, "").replace(/^\/*/, "/"), sn = (e) => !e || e === "?" ? "" : e.startsWith("?") ? e : "?" + e, on = (e) => !e || e === "#" ? "" : e.startsWith("#") ? e : "#" + e;
function ln(e) {
return e != null && typeof e.status == "number" && typeof e.statusText == "string" && typeof e.internal == "boolean" && "data" in e;
}
const Vt = ["post", "put", "patch", "delete"];
new Set(Vt);
const cn = ["get", ...Vt];
new Set(cn);
/**
* React Router v6.30.1
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
function fe() {
return fe = Object.assign ? Object.assign.bind() : function(e) {
for (var t = 1; t < arguments.length; t++) {
var r = arguments[t];
for (var n in r)
Object.prototype.hasOwnProperty.call(r, n) && (e[n] = r[n]);
}
return e;
}, fe.apply(this, arguments);
}
const me = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (me.displayName = "DataRouter");
const Je = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (Je.displayName = "DataRouterState");
const un = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (un.displayName = "Await");
const U = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (U.displayName = "Navigation");
const he = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (he.displayName = "Location");
const K = /* @__PURE__ */ g.createContext({
outlet: null,
matches: [],
isDataRoute: !1
});
process.env.NODE_ENV !== "production" && (K.displayName = "Route");
const He = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (He.displayName = "RouteError");
function dn(e, t) {
let {
relative: r
} = t === void 0 ? {} : t;
ve() || (process.env.NODE_ENV !== "production" ? j(
!1,
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useHref() may be used only in the context of a <Router> component."
) : j(!1));
let {
basename: n,
navigator: s
} = g.useContext(U), {
hash: c,
pathname: i,
search: d
} = ge(e, {
relative: r
}), u = i;
return n !== "/" && (u = i === "/" ? n : W([n, i])), s.createHref({
pathname: u,
search: d,
hash: c
});
}
function ve() {
return g.useContext(he) != null;
}
function te() {
return ve() || (process.env.NODE_ENV !== "production" ? j(
!1,
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useLocation() may be used only in the context of a <Router> component."
) : j(!1)), g.useContext(he).location;
}
const $t = "You should call navigate() in a React.useEffect(), not when your component is first rendered.";
function Bt(e) {
g.useContext(U).static || g.useLayoutEffect(e);
}
function fn() {
let {
isDataRoute: e
} = g.useContext(K);
return e ? Sn() : pn();
}
function pn() {
ve() || (process.env.NODE_ENV !== "production" ? j(
!1,
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useNavigate() may be used only in the context of a <Router> component."
) : j(!1));
let e = g.useContext(me), {
basename: t,
future: r,
navigator: n
} = g.useContext(U), {
matches: s
} = g.useContext(K), {
pathname: c
} = te(), i = JSON.stringify(Ft(s, r.v7_relativeSplatPath)), d = g.useRef(!1);
return Bt(() => {
d.current = !0;
}), g.useCallback(function(o, f) {
if (f === void 0 && (f = {}), process.env.NODE_ENV !== "production" && $(d.current, $t), !d.current) return;
if (typeof o == "number") {
n.go(o);
return;
}
let p = Ut(o, JSON.parse(i), c, f.relative === "path");
e == null && t !== "/" && (p.pathname = p.pathname === "/" ? t : W([t, p.pathname])), (f.replace ? n.replace : n.push)(p, f.state, f);
}, [t, n, i, c, e]);
}
function ge(e, t) {
let {
relative: r
} = t === void 0 ? {} : t, {
future: n
} = g.useContext(U), {
matches: s
} = g.useContext(K), {
pathname: c
} = te(), i = JSON.stringify(Ft(s, n.v7_relativeSplatPath));
return g.useMemo(() => Ut(e, JSON.parse(i), c, r === "path"), [e, i, c, r]);
}
function mn(e, t) {
return hn(e, t);
}
function hn(e, t, r, n) {
ve() || (process.env.NODE_ENV !== "production" ? j(
!1,
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useRoutes() may be used only in the context of a <Router> component."
) : j(!1));
let {
navigator: s
} = g.useContext(U), {
matches: c
} = g.useContext(K), i = c[c.length - 1], d = i ? i.params : {}, u = i ? i.pathname : "/", o = i ? i.pathnameBase : "/", f = i && i.route;
if (process.env.NODE_ENV !== "production") {
let v = f && f.path || "";
Kt(u, !f || v.endsWith("*"), "You rendered descendant <Routes> (or called `useRoutes()`) at " + ('"' + u + '" (under <Route path="' + v + '">) but the ') + `parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
` + ('Please change the parent <Route path="' + v + '"> to <Route ') + ('path="' + (v === "/" ? "*" : v + "/*") + '">.'));
}
let p = te(), h;
if (t) {
var x;
let v = typeof t == "string" ? ee(t) : t;
o === "/" || (x = v.pathname) != null && x.startsWith(o) || (process.env.NODE_ENV !== "production" ? j(!1, "When overriding the location using `<Routes location>` or `useRoutes(routes, location)`, the location pathname must begin with the portion of the URL pathname that was " + ('matched by all parent routes. The current pathname base is "' + o + '" ') + ('but pathname "' + v.pathname + '" was given in the `location` prop.')) : j(!1)), h = v;
} else
h = p;
let E = h.pathname || "/", R = E;
if (o !== "/") {
let v = o.replace(/^\//, "").split("/");
R = "/" + E.replace(/^\//, "").split("/").slice(v.length).join("/");
}
let y = $r(e, {
pathname: R
});
process.env.NODE_ENV !== "production" && (process.env.NODE_ENV !== "production" && $(f || y != null, 'No routes matched location "' + h.pathname + h.search + h.hash + '" '), process.env.NODE_ENV !== "production" && $(y == null || y[y.length - 1].route.element !== void 0 || y[y.length - 1].route.Component !== void 0 || y[y.length - 1].route.lazy !== void 0, 'Matched leaf route at location "' + h.pathname + h.search + h.hash + '" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.'));
let N = bn(y && y.map((v) => Object.assign({}, v, {
params: Object.assign({}, d, v.params),
pathname: W([
o,
// Re-encode pathnames that were decoded inside matchRoutes
s.encodeLocation ? s.encodeLocation(v.pathname).pathname : v.pathname
]),
pathnameBase: v.pathnameBase === "/" ? o : W([
o,
// Re-encode pathnames that were decoded inside matchRoutes
s.encodeLocation ? s.encodeLocation(v.pathnameBase).pathname : v.pathnameBase
])
})), c, r, n);
return t && N ? /* @__PURE__ */ g.createElement(he.Provider, {
value: {
location: fe({
pathname: "/",
search: "",
hash: "",
state: null,
key: "default"
}, h),
navigationType: z.Pop
}
}, N) : N;
}
function vn() {
let e = jn(), t = ln(e) ? e.status + " " + e.statusText : e instanceof Error ? e.message : JSON.stringify(e), r = e instanceof Error ? e.stack : null, n = "rgba(200,200,200, 0.5)", s = {
padding: "0.5rem",
backgroundColor: n
}, c = {
padding: "2px 4px",
backgroundColor: n
}, i = null;
return process.env.NODE_ENV !== "production" && (console.error("Error handled by React Router default ErrorBoundary:", e), i = /* @__PURE__ */ g.createElement(g.Fragment, null, /* @__PURE__ */ g.createElement("p", null, "💿 Hey developer 👋"), /* @__PURE__ */ g.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ g.createElement("code", {
style: c
}, "ErrorBoundary"), " or", " ", /* @__PURE__ */ g.createElement("code", {
style: c
}, "errorElement"), " prop on your route."))), /* @__PURE__ */ g.createElement(g.Fragment, null, /* @__PURE__ */ g.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ g.createElement("h3", {
style: {
fontStyle: "italic"
}
}, t), r ? /* @__PURE__ */ g.createElement("pre", {
style: s
}, r) : null, i);
}
const gn = /* @__PURE__ */ g.createElement(vn, null);
class xn extends g.Component {
constructor(t) {
super(t), this.state = {
location: t.location,
revalidation: t.revalidation,
error: t.error
};
}
static getDerivedStateFromError(t) {
return {
error: t
};
}
static getDerivedStateFromProps(t, r) {
return r.location !== t.location || r.revalidation !== "idle" && t.revalidation === "idle" ? {
error: t.error,
location: t.location,
revalidation: t.revalidation
} : {
error: t.error !== void 0 ? t.error : r.error,
location: r.location,
revalidation: t.revalidation || r.revalidation
};
}
componentDidCatch(t, r) {
console.error("React Router caught the following error during render", t, r);
}
render() {
return this.state.error !== void 0 ? /* @__PURE__ */ g.createElement(K.Provider, {
value: this.props.routeContext
}, /* @__PURE__ */ g.createElement(He.Provider, {
value: this.state.error,
children: this.props.component
})) : this.props.children;
}
}
function yn(e) {
let {
routeContext: t,
match: r,
children: n
} = e, s = g.useContext(me);
return s && s.static && s.staticContext && (r.route.errorElement || r.route.ErrorBoundary) && (s.staticContext._deepestRenderedBoundaryId = r.route.id), /* @__PURE__ */ g.createElement(K.Provider, {
value: t
}, n);
}
function bn(e, t, r, n) {
var s;
if (t === void 0 && (t = []), r === void 0 && (r = null), n === void 0 && (n = null), e == null) {
var c;
if (!r)
return null;
if (r.errors)
e = r.matches;
else if ((c = n) != null && c.v7_partialHydration && t.length === 0 && !r.initialized && r.matches.length > 0)
e = r.matches;
else
return null;
}
let i = e, d = (s = r) == null ? void 0 : s.errors;
if (d != null) {
let f = i.findIndex((p) => p.route.id && (d == null ? void 0 : d[p.route.id]) !== void 0);
f >= 0 || (process.env.NODE_ENV !== "production" ? j(!1, "Could not find a matching route for errors on route IDs: " + Object.keys(d).join(",")) : j(!1)), i = i.slice(0, Math.min(i.length, f + 1));
}
let u = !1, o = -1;
if (r && n && n.v7_partialHydration)
for (let f = 0; f < i.length; f++) {
let p = i[f];
if ((p.route.HydrateFallback || p.route.hydrateFallbackElement) && (o = f), p.route.id) {
let {
loaderData: h,
errors: x
} = r, E = p.route.loader && h[p.route.id] === void 0 && (!x || x[p.route.id] === void 0);
if (p.route.lazy || E) {
u = !0, o >= 0 ? i = i.slice(0, o + 1) : i = [i[0]];
break;
}
}
}
return i.reduceRight((f, p, h) => {
let x, E = !1, R = null, y = null;
r && (x = d && p.route.id ? d[p.route.id] : void 0, R = p.route.errorElement || gn, u && (o < 0 && h === 0 ? (Kt("route-fallback", !1, "No `HydrateFallback` element provided to render during initial hydration"), E = !0, y = null) : o === h && (E = !0, y = p.route.hydrateFallbackElement || null)));
let N = t.concat(i.slice(0, h + 1)), v = () => {
let C;
return x ? C = R : E ? C = y : p.route.Component ? C = /* @__PURE__ */ g.createElement(p.route.Component, null) : p.route.element ? C = p.route.element : C = f, /* @__PURE__ */ g.createElement(yn, {
match: p,
routeContext: {
outlet: f,
matches: N,
isDataRoute: r != null
},
children: C
});
};
return r && (p.route.ErrorBoundary || p.route.errorElement || h === 0) ? /* @__PURE__ */ g.createElement(xn, {
location: r.location,
revalidation: r.revalidation,
component: R,
error: x,
children: v(),
routeContext: {
outlet: null,
matches: N,
isDataRoute: !0
}
}) : v();
}, null);
}
var Wt = /* @__PURE__ */ function(e) {
return e.UseBlocker = "useBlocker", e.UseRevalidator = "useRevalidator", e.UseNavigateStable = "useNavigate", e;
}(Wt || {}), pe = /* @__PURE__ */ function(e) {
return e.UseBlocker = "useBlocker", e.UseLoaderData = "useLoaderData", e.UseActionData = "useActionData", e.UseRouteError = "useRouteError", e.UseNavigation = "useNavigation", e.UseRouteLoaderData = "useRouteLoaderData", e.UseMatches = "useMatches", e.UseRevalidator = "useRevalidator", e.UseNavigateStable = "useNavigate", e.UseRouteId = "useRouteId", e;
}(pe |