// @bun
import"./chunk-dhs2bg35.js";

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client10.js
var R = Object.defineProperty;
var T = (t, r, e) => (r in t) ? R(t, r, { enumerable: true, configurable: true, writable: true, value: e }) : t[r] = e;
var j = (t, r, e) => T(t, typeof r != "symbol" ? r + "" : r, e);
var U = async (t, r) => {
  let e = typeof r == "function" ? await r(t) : r;
  if (e)
    return t.scheme === "bearer" ? `Bearer ${e}` : t.scheme === "basic" ? `Basic ${btoa(e)}` : e;
};
var A = { bodySerializer: (t) => JSON.stringify(t, (r, e) => typeof e == "bigint" ? e.toString() : e) };
var _ = (t) => {
  switch (t) {
    case "label":
      return ".";
    case "matrix":
      return ";";
    case "simple":
      return ",";
    default:
      return "&";
  }
};
var z = (t) => {
  switch (t) {
    case "form":
      return ",";
    case "pipeDelimited":
      return "|";
    case "spaceDelimited":
      return "%20";
    default:
      return ",";
  }
};
var E = (t) => {
  switch (t) {
    case "label":
      return ".";
    case "matrix":
      return ";";
    case "simple":
      return ",";
    default:
      return "&";
  }
};
var x = ({ allowReserved: t, explode: r, name: e, style: l, value: n }) => {
  if (!r) {
    let s = (t ? n : n.map((i) => encodeURIComponent(i))).join(z(l));
    switch (l) {
      case "label":
        return `.${s}`;
      case "matrix":
        return `;${e}=${s}`;
      case "simple":
        return s;
      default:
        return `${e}=${s}`;
    }
  }
  let o = _(l), a = n.map((s) => l === "label" || l === "simple" ? t ? s : encodeURIComponent(s) : b({ allowReserved: t, name: e, value: s })).join(o);
  return l === "label" || l === "matrix" ? o + a : a;
};
var b = ({ allowReserved: t, name: r, value: e }) => {
  if (e == null)
    return "";
  if (typeof e == "object")
    throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");
  return `${r}=${t ? e : encodeURIComponent(e)}`;
};
var $ = ({ allowReserved: t, explode: r, name: e, style: l, value: n }) => {
  if (n instanceof Date)
    return `${e}=${n.toISOString()}`;
  if (l !== "deepObject" && !r) {
    let s = [];
    Object.entries(n).forEach(([d, f]) => {
      s = [...s, d, t ? f : encodeURIComponent(f)];
    });
    let i = s.join(",");
    switch (l) {
      case "form":
        return `${e}=${i}`;
      case "label":
        return `.${i}`;
      case "matrix":
        return `;${e}=${i}`;
      default:
        return i;
    }
  }
  let o = E(l), a = Object.entries(n).map(([s, i]) => b({ allowReserved: t, name: l === "deepObject" ? `${e}[${s}]` : s, value: i })).join(o);
  return l === "label" || l === "matrix" ? o + a : a;
};
var W = /\{[^{}]+\}/g;
var D = ({ path: t, url: r }) => {
  let e = r, l = r.match(W);
  if (l)
    for (let n of l) {
      let o = false, a = n.substring(1, n.length - 1), s = "simple";
      a.endsWith("*") && (o = true, a = a.substring(0, a.length - 1)), a.startsWith(".") ? (a = a.substring(1), s = "label") : a.startsWith(";") && (a = a.substring(1), s = "matrix");
      let i = t[a];
      if (i == null)
        continue;
      if (Array.isArray(i)) {
        e = e.replace(n, x({ explode: o, name: a, style: s, value: i }));
        continue;
      }
      if (typeof i == "object") {
        e = e.replace(n, $({ explode: o, name: a, style: s, value: i }));
        continue;
      }
      if (s === "matrix") {
        e = e.replace(n, `;${b({ name: a, value: i })}`);
        continue;
      }
      let d = encodeURIComponent(s === "label" ? `.${i}` : i);
      e = e.replace(n, d);
    }
  return e;
};
var q = ({ allowReserved: t, array: r, object: e } = {}) => (l) => {
  let n = [];
  if (l && typeof l == "object")
    for (let o in l) {
      let a = l[o];
      if (a != null) {
        if (Array.isArray(a)) {
          n = [...n, x({ allowReserved: t, explode: true, name: o, style: "form", value: a, ...r })];
          continue;
        }
        if (typeof a == "object") {
          n = [...n, $({ allowReserved: t, explode: true, name: o, style: "deepObject", value: a, ...e })];
          continue;
        }
        n = [...n, b({ allowReserved: t, name: o, value: a })];
      }
    }
  return n.join("&");
};
var I = (t) => {
  var e;
  if (!t)
    return "stream";
  let r = (e = t.split(";")[0]) == null ? undefined : e.trim();
  if (r) {
    if (r.startsWith("application/json") || r.endsWith("+json"))
      return "json";
    if (r === "multipart/form-data")
      return "formData";
    if (["application/", "audio/", "image/", "video/"].some((l) => r.startsWith(l)))
      return "blob";
    if (r.startsWith("text/"))
      return "text";
  }
};
var k = async ({ security: t, ...r }) => {
  for (let e of t) {
    let l = await U(e, r.auth);
    if (!l)
      continue;
    let n = e.name ?? "Authorization";
    switch (e.in) {
      case "query":
        r.query || (r.query = {}), r.query[n] = l;
        break;
      case "cookie":
        r.headers.append("Cookie", `${n}=${l}`);
        break;
      case "header":
      default:
        r.headers.set(n, l);
        break;
    }
    return;
  }
};
var v = (t) => N({ baseUrl: t.baseUrl, path: t.path, query: t.query, querySerializer: typeof t.querySerializer == "function" ? t.querySerializer : q(t.querySerializer), url: t.url });
var N = ({ baseUrl: t, path: r, query: e, querySerializer: l, url: n }) => {
  let o = n.startsWith("/") ? n : `/${n}`, a = (t ?? "") + o;
  r && (a = D({ path: r, url: a }));
  let s = e ? l(e) : "";
  return s.startsWith("?") && (s = s.substring(1)), s && (a += `?${s}`), a;
};
var g = (t, r) => {
  var l;
  let e = { ...t, ...r };
  return (l = e.baseUrl) != null && l.endsWith("/") && (e.baseUrl = e.baseUrl.substring(0, e.baseUrl.length - 1)), e.headers = C(t.headers, r.headers), e;
};
var C = (...t) => {
  let r = new Headers;
  for (let e of t) {
    if (!e || typeof e != "object")
      continue;
    let l = e instanceof Headers ? e.entries() : Object.entries(e);
    for (let [n, o] of l)
      if (o === null)
        r.delete(n);
      else if (Array.isArray(o))
        for (let a of o)
          r.append(n, a);
      else
        o !== undefined && r.set(n, typeof o == "object" ? JSON.stringify(o) : o);
  }
  return r;
};
var w = class {
  constructor() {
    j(this, "_fns");
    this._fns = [];
  }
  clear() {
    this._fns = [];
  }
  exists(t) {
    return this._fns.indexOf(t) !== -1;
  }
  eject(t) {
    let r = this._fns.indexOf(t);
    r !== -1 && (this._fns = [...this._fns.slice(0, r), ...this._fns.slice(r + 1)]);
  }
  use(t) {
    this._fns = [...this._fns, t];
  }
};
var P = () => ({ error: new w, request: new w, response: new w });
var H = /* @__PURE__ */ q({ allowReserved: false, array: { explode: true, style: "form" }, object: { explode: true, style: "deepObject" } });
var J = { "Content-Type": "application/json" };
var O = (t = {}) => ({ ...A, headers: J, parseAs: "auto", querySerializer: H, ...t });
var B = (t = {}) => {
  let r = g(O(), t), e = () => ({ ...r }), l = (a) => (r = g(r, a), e()), n = P(), o = async (a) => {
    let s = { ...r, ...a, fetch: a.fetch ?? r.fetch ?? globalThis.fetch, headers: C(r.headers, a.headers) };
    s.security && await k({ ...s, security: s.security }), s.body && s.bodySerializer && (s.body = s.bodySerializer(s.body)), (s.body === undefined || s.body === "") && s.headers.delete("Content-Type");
    let i = v(s), d = { redirect: "follow", ...s }, f = new Request(i, d);
    for (let c of n.request._fns)
      f = await c(f, s);
    let S = s.fetch, u = await S(f);
    for (let c of n.response._fns)
      u = await c(u, f, s);
    let h = { request: f, response: u };
    if (u.ok) {
      if (u.status === 204 || u.headers.get("Content-Length") === "0")
        return { data: {}, ...h };
      let c = (s.parseAs === "auto" ? I(u.headers.get("Content-Type")) : s.parseAs) ?? "json";
      if (c === "stream")
        return { data: u.body, ...h };
      let m = await u[c]();
      return c === "json" && (s.responseValidator && await s.responseValidator(m), s.responseTransformer && (m = await s.responseTransformer(m))), { data: m, ...h };
    }
    let y = await u.text();
    try {
      y = JSON.parse(y);
    } catch {}
    let p = y;
    for (let c of n.error._fns)
      p = await c(y, u, f, s);
    if (p = p || {}, s.throwOnError)
      throw p;
    return { error: p, ...h };
  };
  return { buildUrl: v, connect: (a) => o({ ...a, method: "CONNECT" }), delete: (a) => o({ ...a, method: "DELETE" }), get: (a) => o({ ...a, method: "GET" }), getConfig: e, head: (a) => o({ ...a, method: "HEAD" }), interceptors: n, options: (a) => o({ ...a, method: "OPTIONS" }), patch: (a) => o({ ...a, method: "PATCH" }), post: (a) => o({ ...a, method: "POST" }), put: (a) => o({ ...a, method: "PUT" }), request: o, setConfig: l, trace: (a) => o({ ...a, method: "TRACE" }) };
};
var V = B;
var G = O;

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client8.js
var e = (t) => ({
  ...t,
  withCredentials: true,
  timeout: 60000,
  maxBodyLength: 104857600,
  maxContentLength: 104857600,
  throwOnError: true,
  parseAs: "json"
});

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client4.js
var i = /* @__PURE__ */ V(/* @__PURE__ */ e(/* @__PURE__ */ G({
  baseUrl: "https://webchat.botpress.cloud/"
})));

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client3.js
var t = (e2) => (e2.client ?? i).delete({
  url: "/conversations/{id}",
  ...e2
});
var c = (e2) => (e2.client ?? i).get({
  url: "/conversations/{id}",
  ...e2
});
var l = (e2) => (e2.client ?? i).get({
  url: "/conversations",
  ...e2
});
var n = (e2) => (e2.client ?? i).post({
  url: "/conversations",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var s = (e2) => (e2.client ?? i).get({
  url: "/conversations/{id}/messages",
  ...e2
});
var u = (e2) => (e2.client ?? i).get({
  url: "/conversations/{id}/participants",
  ...e2
});
var d = (e2) => (e2.client ?? i).post({
  url: "/conversations/{id}/participants",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var g2 = (e2) => (e2.client ?? i).delete({
  url: "/conversations/{id}/participants/{userId}",
  ...e2
});
var h = (e2) => (e2.client ?? i).get({
  url: "/conversations/{id}/participants/{userId}",
  ...e2
});
var v2 = (e2) => (e2.client ?? i).delete({
  url: "/messages/{id}",
  ...e2
});
var C2 = (e2) => (e2.client ?? i).get({
  url: "/messages/{id}",
  ...e2
});
var m = (e2) => (e2.client ?? i).put({
  url: "/messages/{id}",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var y = (e2) => (e2.client ?? i).post({
  url: "/messages",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var j2 = (e2) => (e2.client ?? i).delete({
  url: "/messages/{id}/feedback",
  ...e2
});
var T2 = (e2) => (e2.client ?? i).put({
  url: "/messages/{id}/feedback",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var M = (e2) => (e2.client ?? i).delete({
  url: "/users/me",
  ...e2
});
var i2 = (e2) => (e2.client ?? i).get({
  url: "/users/me",
  ...e2
});
var f = (e2) => (e2.client ?? i).put({
  url: "/users/me",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var k2 = (e2) => ((e2 == null ? undefined : e2.client) ?? i).post({
  url: "/users",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var P2 = (e2) => ((e2 == null ? undefined : e2.client) ?? i).post({
  url: "/users/key",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var U2 = (e2) => (e2.client ?? i).get({
  url: "/events/{id}",
  ...e2
});
var b2 = (e2) => (e2.client ?? i).post({
  url: "/events",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var F = (e2) => (e2.client ?? i).post({
  url: "/files",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});
var E2 = (e2) => ((e2 == null ? undefined : e2.client) ?? i).post({
  url: "/p",
  ...e2,
  headers: {
    "Content-Type": "application/json",
    ...e2 == null ? undefined : e2.headers
  }
});

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client9.js
class E3 extends Error {
  constructor(d2, i3) {
    super(d2), this.name = "ParseError", this.type = i3.type, this.field = i3.field, this.value = i3.value, this.line = i3.line;
  }
}
function x2(n2) {}
function w2(n2) {
  if (typeof n2 == "function")
    throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
  const { onEvent: d2 = x2, onError: i3 = x2, onRetry: r = x2, onComment: c2 } = n2;
  let o = "", s2 = true, f2, a = "", p = "";
  function b3(e2) {
    const t2 = s2 ? e2.replace(/^\xEF\xBB\xBF/, "") : e2, [l2, u2] = g3(`${o}${t2}`);
    for (const h2 of l2)
      y2(h2);
    o = u2, s2 = false;
  }
  function y2(e2) {
    if (e2 === "") {
      v3();
      return;
    }
    if (e2.startsWith(":")) {
      c2 && c2(e2.slice(e2.startsWith(": ") ? 2 : 1));
      return;
    }
    const t2 = e2.indexOf(":");
    if (t2 !== -1) {
      const l2 = e2.slice(0, t2), u2 = e2[t2 + 1] === " " ? 2 : 1, h2 = e2.slice(t2 + u2);
      m2(l2, h2, e2);
      return;
    }
    m2(e2, "", e2);
  }
  function m2(e2, t2, l2) {
    switch (e2) {
      case "event":
        p = t2;
        break;
      case "data":
        a = `${a}${t2}
`;
        break;
      case "id":
        f2 = t2.includes("\x00") ? undefined : t2;
        break;
      case "retry":
        /^\d+$/.test(t2) ? r(parseInt(t2, 10)) : i3(new E3(`Invalid \`retry\` value: "${t2}"`, {
          type: "invalid-retry",
          value: t2,
          line: l2
        }));
        break;
      default:
        i3(new E3(`Unknown field "${e2.length > 20 ? `${e2.slice(0, 20)}\u2026` : e2}"`, { type: "unknown-field", field: e2, value: t2, line: l2 }));
        break;
    }
  }
  function v3() {
    a.length > 0 && d2({
      id: f2,
      event: p || undefined,
      data: a.endsWith(`
`) ? a.slice(0, -1) : a
    }), f2 = undefined, a = "", p = "";
  }
  function $2(e2 = {}) {
    o && e2.consume && y2(o), s2 = true, f2 = undefined, a = "", p = "", o = "";
  }
  return { feed: b3, reset: $2 };
}
function g3(n2) {
  const d2 = [];
  let i3 = "", r = 0;
  for (;r < n2.length; ) {
    const c2 = n2.indexOf("\r", r), o = n2.indexOf(`
`, r);
    let s2 = -1;
    if (c2 !== -1 && o !== -1 ? s2 = Math.min(c2, o) : c2 !== -1 ? c2 === n2.length - 1 ? s2 = -1 : s2 = c2 : o !== -1 && (s2 = o), s2 === -1) {
      i3 = n2.slice(r);
      break;
    } else {
      const f2 = n2.slice(r, s2);
      d2.push(f2), r = s2 + 1, n2[r - 1] === "\r" && n2[r] === `
` && r++;
    }
  }
  return [d2, i3];
}

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client5.js
class q2 extends Event {
  constructor(e2, i3) {
    var r, c2;
    super(e2), this.code = (r = i3 == null ? undefined : i3.code) != null ? r : undefined, this.message = (c2 = i3 == null ? undefined : i3.message) != null ? c2 : undefined;
  }
  [Symbol.for("nodejs.util.inspect.custom")](e2, i3, r) {
    return r(B2(this), i3);
  }
  [Symbol.for("Deno.customInspect")](e2, i3) {
    return e2(B2(this), i3);
  }
}
function Y(t2) {
  const e2 = globalThis.DOMException;
  return typeof e2 == "function" ? new e2(t2, "SyntaxError") : new SyntaxError(t2);
}
function T3(t2) {
  return t2 instanceof Error ? "errors" in t2 && Array.isArray(t2.errors) ? t2.errors.map(T3).join(", ") : ("cause" in t2) && t2.cause instanceof Error ? `${t2}: ${T3(t2.cause)}` : t2.message : `${t2}`;
}
function B2(t2) {
  return {
    type: t2.type,
    message: t2.message,
    code: t2.code,
    defaultPrevented: t2.defaultPrevented,
    cancelable: t2.cancelable,
    timeStamp: t2.timeStamp
  };
}
var z2 = (t2) => {
  throw TypeError(t2);
};
var D2 = (t2, e2, i3) => e2.has(t2) || z2("Cannot " + i3);
var s2 = (t2, e2, i3) => (D2(t2, e2, "read from private field"), i3 ? i3.call(t2) : e2.get(t2));
var a = (t2, e2, i3) => e2.has(t2) ? z2("Cannot add the same private member more than once") : e2 instanceof WeakSet ? e2.add(t2) : e2.set(t2, i3);
var n2 = (t2, e2, i3, r) => (D2(t2, e2, "write to private field"), e2.set(t2, i3), i3);
var d2 = (t2, e2, i3) => (D2(t2, e2, "access private method"), i3);
var h2;
var u2;
var E4;
var W2;
var O2;
var M2;
var _2;
var N2;
var p;
var f2;
var g4;
var w3;
var C3;
var l2;
var L;
var b3;
var R2;
var H2;
var x3;
var I2;
var y2;
var U3;
var A2;

class S extends EventTarget {
  constructor(e2, i3) {
    var r, c2;
    super(), a(this, l2), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, a(this, h2), a(this, u2), a(this, E4), a(this, W2), a(this, O2), a(this, M2), a(this, _2), a(this, N2, null), a(this, p), a(this, f2), a(this, g4, null), a(this, w3, null), a(this, C3, null), a(this, b3, async (o) => {
      var m2;
      s2(this, f2).reset();
      const { body: k3, redirected: J2, status: v3, headers: K } = o;
      if (v3 === 204) {
        d2(this, l2, y2).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
        return;
      }
      if (J2 ? n2(this, E4, new URL(o.url)) : n2(this, E4, undefined), v3 !== 200) {
        d2(this, l2, y2).call(this, `Non-200 status code (${v3})`, v3);
        return;
      }
      if (!(K.get("content-type") || "").startsWith("text/event-stream")) {
        d2(this, l2, y2).call(this, 'Invalid content type, expected "text/event-stream"', v3);
        return;
      }
      if (s2(this, h2) === this.CLOSED)
        return;
      n2(this, h2, this.OPEN);
      const G2 = new Event("open");
      if ((m2 = s2(this, C3)) == null || m2.call(this, G2), this.dispatchEvent(G2), typeof k3 != "object" || !k3 || !("getReader" in k3)) {
        d2(this, l2, y2).call(this, "Invalid response body, expected a web ReadableStream", v3), this.close();
        return;
      }
      const Q = new TextDecoder, V2 = k3.getReader();
      let P3 = true;
      do {
        const { done: $2, value: F2 } = await V2.read();
        F2 && s2(this, f2).feed(Q.decode(F2, { stream: !$2 })), $2 && (P3 = false, s2(this, f2).reset(), d2(this, l2, U3).call(this));
      } while (P3);
    }), a(this, R2, (o) => {
      n2(this, p, undefined), !(o.name === "AbortError" || o.type === "aborted") && d2(this, l2, U3).call(this, T3(o));
    }), a(this, x3, (o) => {
      typeof o.id == "string" && n2(this, N2, o.id);
      const m2 = new MessageEvent(o.event || "message", {
        data: o.data,
        origin: s2(this, E4) ? s2(this, E4).origin : s2(this, u2).origin,
        lastEventId: o.id || ""
      });
      s2(this, w3) && (!o.event || o.event === "message") && s2(this, w3).call(this, m2), this.dispatchEvent(m2);
    }), a(this, I2, (o) => {
      n2(this, M2, o);
    }), a(this, A2, () => {
      n2(this, _2, undefined), s2(this, h2) === this.CONNECTING && d2(this, l2, L).call(this);
    });
    try {
      if (e2 instanceof URL)
        n2(this, u2, e2);
      else if (typeof e2 == "string")
        n2(this, u2, new URL(e2, Z()));
      else
        throw new Error("Invalid URL");
    } catch {
      throw Y("An invalid or illegal string was specified");
    }
    n2(this, f2, w2({
      onEvent: s2(this, x3),
      onRetry: s2(this, I2)
    })), n2(this, h2, this.CONNECTING), n2(this, M2, 3000), n2(this, O2, (r = i3 == null ? undefined : i3.fetch) != null ? r : globalThis.fetch), n2(this, W2, (c2 = i3 == null ? undefined : i3.withCredentials) != null ? c2 : false), d2(this, l2, L).call(this);
  }
  get readyState() {
    return s2(this, h2);
  }
  get url() {
    return s2(this, u2).href;
  }
  get withCredentials() {
    return s2(this, W2);
  }
  get onerror() {
    return s2(this, g4);
  }
  set onerror(e2) {
    n2(this, g4, e2);
  }
  get onmessage() {
    return s2(this, w3);
  }
  set onmessage(e2) {
    n2(this, w3, e2);
  }
  get onopen() {
    return s2(this, C3);
  }
  set onopen(e2) {
    n2(this, C3, e2);
  }
  addEventListener(e2, i3, r) {
    const c2 = i3;
    super.addEventListener(e2, c2, r);
  }
  removeEventListener(e2, i3, r) {
    const c2 = i3;
    super.removeEventListener(e2, c2, r);
  }
  close() {
    s2(this, _2) && clearTimeout(s2(this, _2)), s2(this, h2) !== this.CLOSED && (s2(this, p) && s2(this, p).abort(), n2(this, h2, this.CLOSED), n2(this, p, undefined));
  }
}
h2 = /* @__PURE__ */ new WeakMap, u2 = /* @__PURE__ */ new WeakMap, E4 = /* @__PURE__ */ new WeakMap, W2 = /* @__PURE__ */ new WeakMap, O2 = /* @__PURE__ */ new WeakMap, M2 = /* @__PURE__ */ new WeakMap, _2 = /* @__PURE__ */ new WeakMap, N2 = /* @__PURE__ */ new WeakMap, p = /* @__PURE__ */ new WeakMap, f2 = /* @__PURE__ */ new WeakMap, g4 = /* @__PURE__ */ new WeakMap, w3 = /* @__PURE__ */ new WeakMap, C3 = /* @__PURE__ */ new WeakMap, l2 = /* @__PURE__ */ new WeakSet, L = function() {
  n2(this, h2, this.CONNECTING), n2(this, p, new AbortController), s2(this, O2)(s2(this, u2), d2(this, l2, H2).call(this)).then(s2(this, b3)).catch(s2(this, R2));
}, b3 = /* @__PURE__ */ new WeakMap, R2 = /* @__PURE__ */ new WeakMap, H2 = function() {
  var t2;
  const e2 = {
    mode: "cors",
    redirect: "follow",
    headers: { Accept: "text/event-stream", ...s2(this, N2) ? { "Last-Event-ID": s2(this, N2) } : undefined },
    cache: "no-store",
    signal: (t2 = s2(this, p)) == null ? undefined : t2.signal
  };
  return "window" in globalThis && (e2.credentials = this.withCredentials ? "include" : "same-origin"), e2;
}, x3 = /* @__PURE__ */ new WeakMap, I2 = /* @__PURE__ */ new WeakMap, y2 = function(t2, e2) {
  var i3;
  s2(this, h2) !== this.CLOSED && n2(this, h2, this.CLOSED);
  const r = new q2("error", { code: e2, message: t2 });
  (i3 = s2(this, g4)) == null || i3.call(this, r), this.dispatchEvent(r);
}, U3 = function(t2, e2) {
  var i3;
  if (s2(this, h2) === this.CLOSED)
    return;
  n2(this, h2, this.CONNECTING);
  const r = new q2("error", { code: e2, message: t2 });
  (i3 = s2(this, g4)) == null || i3.call(this, r), this.dispatchEvent(r), n2(this, _2, setTimeout(s2(this, A2), s2(this, M2)));
}, A2 = /* @__PURE__ */ new WeakMap, S.CONNECTING = 0, S.OPEN = 1, S.CLOSED = 2;
function Z() {
  const t2 = "document" in globalThis ? globalThis.document : undefined;
  return t2 && typeof t2 == "object" && "baseURI" in t2 && typeof t2.baseURI == "string" ? t2.baseURI : undefined;
}

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client6.js
async function c2(r) {
  var t2;
  const e2 = await r.clone().json();
  if ((t2 = e2 == null ? undefined : e2.id) != null && t2.startsWith("err_")) {
    const o = new Error(e2.message);
    throw o.id = e2.id, o.code = e2.code, o.type = e2.type, o;
  }
  return r;
}

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client7.js
var d3 = () => {
  const e2 = {};
  return { on: (t2, o) => {
    var n3;
    return e2[t2] || (e2[t2] = /* @__PURE__ */ new Set), (n3 = e2[t2]) == null || n3.add(o), () => {
      var c3;
      return (c3 = e2[t2]) == null ? undefined : c3.delete(o);
    };
  }, emit: (t2, o) => {
    var n3, c3;
    (n3 = e2[t2]) == null || n3.forEach((r) => r(o)), (c3 = e2["*"]) == null || c3.forEach((r) => r({ type: t2, payload: o }));
  }, cleanup: () => {
    for (const t2 in e2)
      delete e2[t2];
  } };
};

// ../../node_modules/.bun/@botpress+webchat-client@0.7.3/node_modules/@botpress/webchat-client/dist/webchat-client2.js
var r = (o) => o.data;
var T4 = 10;
var x4 = 3000;
var te = "60000";
var k3 = (o, l3) => {
  const c3 = (...a2) => o.on(...a2);
  return new Proxy(c3, {
    get: (a2, i3) => i3 === "on" ? o.on : i3 === "disconnect" ? l3 : i3 === "cleanup" ? o.cleanup : Reflect.get(a2, i3)
  });
};
var U4 = {
  throwOnError: true
};
var ie = async ({
  clientId: o,
  apiUrl: l3,
  adminSecret: c3,
  customHeaders: a2,
  ...i3
}) => {
  const n3 = `${l3 || i.getConfig().baseUrl}/${o}`;
  i.interceptors.response._fns.length === 0 && i.interceptors.response.use(c2);
  const u3 = {
    ...U4,
    baseUrl: n3
  }, t2 = {
    ...c3 ? { "x-admin-secret": c3 } : {},
    ...a2
  };
  return k2({
    ...u3,
    headers: Object.keys(t2).length > 0 ? t2 : undefined,
    body: i3
  }).then(r);
};
var ce = ({
  conversationId: o,
  userToken: l3,
  clientId: c3,
  apiUrl: a2,
  adminSecret: i3
}) => {
  let n3 = 0, u3 = null, t2 = null;
  const v3 = d3();
  let e2 = o, s3 = l3;
  const p2 = () => {
    u3 && (clearTimeout(u3), u3 = null), t2 && (t2.close(), t2 = null);
  }, d4 = () => {
    t2 && t2.close();
    const b4 = `${`${a2 || i.getConfig().baseUrl}/${c3}`}/initialize${e2 ? `?conversationId=${e2}` : ""}`, y3 = {
      ...i3 ? { "x-admin-secret": i3 } : {},
      ...s3 ? { "x-user-key": s3 } : {}
    };
    t2 = S2(b4, y3), t2.addEventListener("open", () => v3.emit("open")), t2.addEventListener("error", (f3) => {
      n3 < T4 ? (n3++, u3 = setTimeout(() => d4(), x4)) : v3.emit("error", f3);
    }), t2.addEventListener("message", (f3) => {
      const g5 = L2(f3.data);
      g5.type === "init" && (e2 = g5.data.conversation.id ?? e2, s3 = g5.data.user.userKey ?? s3), v3.emit(g5.type, g5.data);
    });
  };
  return d4(), k3(v3, p2);
};
var le = async ({
  adminSecret: o,
  expiresAt: l3,
  userId: c3,
  apiUrl: a2,
  clientId: i3
}) => {
  const n3 = { "x-admin-secret": o }, u3 = `${a2 || i.getConfig().baseUrl}/${i3}`, t2 = {
    ...U4,
    baseUrl: u3
  };
  return P2({ ...t2, headers: n3, body: { id: c3, expiresAt: l3 } }).then(r);
};
var de = async (o, l3, c3, a2) => {
  const i3 = `${c3 || i.getConfig().baseUrl}/${o}`, n3 = {
    ...U4,
    baseUrl: i3
  };
  return E2({ ...n3, body: l3, headers: a2 }).then(r);
};
var ue = ({
  userKey: o,
  clientId: l3,
  apiUrl: c3,
  customHeaders: a2,
  advancedOptions: i3
}) => {
  const n3 = {
    "x-user-key": o,
    ...a2
  }, u3 = `${c3 || i.getConfig().baseUrl}/${l3}`, t2 = {
    ...U4,
    baseUrl: u3
  };
  return i.interceptors.response._fns.length === 0 && i.interceptors.response.use(c2), {
    createConversation: () => n({ ...t2, headers: n3, body: {} }).then(r),
    getConversation: ({ conversationId: e2 }) => c({ ...t2, headers: n3, path: { id: e2 } }).then(r),
    deleteConversation: ({ conversationId: e2 }) => t({ ...t2, headers: n3, path: { id: e2 } }).then(r),
    listConversations: ({ nextToken: e2 }) => l({ ...t2, headers: n3, query: { nextToken: e2 } }).then(r),
    listConversationMessages: ({ conversationId: e2, nextToken: s3 }) => s({
      ...t2,
      headers: n3,
      path: { id: e2 },
      query: { nextToken: s3 }
    }).then(r),
    addParticipant: ({ conversationId: e2, userId: s3 }) => d({ ...t2, headers: n3, path: { id: e2 }, body: { userId: s3 } }).then(r),
    removeParticipant: ({ conversationId: e2, userId: s3 }) => g2({ ...t2, headers: n3, path: { id: e2, userId: s3 } }).then(r),
    getParticipant: ({ conversationId: e2, userId: s3 }) => h({ ...t2, headers: n3, path: { id: e2, userId: s3 } }).then(r),
    listParticipants: ({ conversationId: e2, nextToken: s3 }) => u({ ...t2, headers: n3, path: { id: e2 }, query: { nextToken: s3 } }).then(r),
    createMessage: (e2) => y({ ...t2, headers: n3, body: e2 }).then(r),
    updateMessage: ({ messageId: e2, ...s3 }) => m({ ...t2, headers: n3, path: { id: e2 }, body: s3 }).then(r),
    getMessage: ({ messageId: e2 }) => C2({ ...t2, headers: n3, path: { id: e2 } }).then(r),
    deleteMessage: ({ messageId: e2 }) => v2({ ...t2, headers: n3, path: { id: e2 } }).then(r),
    createFile: (e2) => F({ ...t2, headers: n3, body: e2 }).then(r),
    getUser: () => i2({ ...t2, headers: n3 }).then(r),
    updateUser: (e2) => f({ ...t2, headers: n3, body: e2 }).then(r),
    deleteUser: () => M({ ...t2, headers: n3 }).then(r),
    createEvent: (e2) => b2({ ...t2, headers: n3, body: e2 }).then(r),
    getEvent: ({ eventId: e2 }) => U2({ ...t2, headers: n3, path: { id: e2 } }).then(r),
    addMessageFeedback: ({ messageId: e2, ...s3 }) => T2({ ...t2, headers: n3, path: { id: e2 }, body: s3 }).then(r),
    removeMessageFeedback: ({ messageId: e2 }) => j2({ ...t2, headers: n3, path: { id: e2 } }).then(r),
    generateUserKey: ({ adminSecret: e2, ...s3 }) => P2({ ...t2, headers: { "x-admin-secret": e2 }, body: s3 }).then(r),
    listenConversation: ({ conversationId: e2 }) => {
      let s3 = 0, p2 = null, d4 = null;
      const m2 = d3(), b4 = () => {
        p2 && (clearTimeout(p2), p2 = null), d4 && (d4.close(), d4 = null);
      }, y3 = () => {
        d4 && d4.close();
        const f3 = `${u3}/conversations/${e2}/listen`, g5 = i3 == null ? undefined : i3.eventSource;
        d4 = g5 ? g5({ url: f3, headers: n3 }) : S2(f3, n3), d4.addEventListener("open", () => m2.emit("open")), d4.addEventListener("error", (E5) => {
          s3 < T4 ? (s3++, p2 = setTimeout(() => y3(), x4)) : m2.emit("error", E5);
        }), d4.addEventListener("message", (E5) => {
          const C4 = L2(E5.data);
          m2.emit(C4.type, C4.data);
        });
      };
      return y3(), k3(m2, b4);
    }
  };
};
var L2 = (o) => {
  try {
    return JSON.parse(o);
  } catch {
    return o;
  }
};
var S2 = (o, l3) => new S(o, {
  fetch: (c3, a2) => fetch(c3, {
    ...a2,
    headers: {
      ...a2 == null ? undefined : a2.headers,
      ...l3,
      timeout: te
    }
  })
});
export {
  de as sendPerfMetrics,
  ce as initialize,
  le as generateUserKey,
  ie as createUser,
  ue as createClient
};
