bstp-agent-widget 0.2.100 → 0.2.102

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28149,13 +28149,9 @@ var xP = /* @__PURE__ */ function(e) {
28149
28149
  //#endregion
28150
28150
  //#region src/components/AgentChat/AgentChatPanel/AgentChatPanelContentBody.tsx
28151
28151
  function SP({ messages: e, isLoading: t, error: n, scrollViewportRef: r, onWidgetEvent: i }) {
28152
- return /* @__PURE__ */ E(Qv, {
28152
+ return /* @__PURE__ */ T(Qv, {
28153
28153
  className: TT.body,
28154
- children: [n && /* @__PURE__ */ T(ef, {
28155
- size: "xs",
28156
- c: "red",
28157
- children: n
28158
- }), /* @__PURE__ */ T(dc, {
28154
+ children: /* @__PURE__ */ T(dc, {
28159
28155
  h: "100%",
28160
28156
  type: "auto",
28161
28157
  offsetScrollbars: !0,
@@ -28163,28 +28159,36 @@ function SP({ messages: e, isLoading: t, error: n, scrollViewportRef: r, onWidge
28163
28159
  children: /* @__PURE__ */ E(Qv, {
28164
28160
  gap: "sm",
28165
28161
  className: TT.messageList,
28166
- children: [e.map((e) => /* @__PURE__ */ T(Y, {
28167
- className: `${TT.messageBubble} ${e.sentBy === xP.USER ? TT.messageBubbleUser : TT.messageBubbleAssistant}`,
28168
- children: e.sentBy === xP.ASSISTANT ? /* @__PURE__ */ T(bP, {
28169
- content: e.text,
28170
- onWidgetEvent: i
28171
- }) : /* @__PURE__ */ T(ef, {
28172
- className: TT.userText,
28173
- children: e.text
28162
+ children: [
28163
+ n && /* @__PURE__ */ T(Yd, {
28164
+ color: "red",
28165
+ variant: "light",
28166
+ children: n
28167
+ }),
28168
+ e.map((e) => /* @__PURE__ */ T(Y, {
28169
+ className: `${TT.messageBubble} ${e.sentBy === xP.USER ? TT.messageBubbleUser : TT.messageBubbleAssistant}`,
28170
+ children: e.sentBy === xP.ASSISTANT ? /* @__PURE__ */ T(bP, {
28171
+ content: e.text,
28172
+ onWidgetEvent: i
28173
+ }) : /* @__PURE__ */ T(ef, {
28174
+ className: TT.userText,
28175
+ children: e.text
28176
+ })
28177
+ }, e.id)),
28178
+ t && /* @__PURE__ */ T(Y, {
28179
+ className: `${TT.messageBubble} ${TT.messageBubbleAssistant}`,
28180
+ children: /* @__PURE__ */ T(PP, { messages: [
28181
+ "Thinking",
28182
+ "Analyzing your request",
28183
+ "Searching for information",
28184
+ "Processing data",
28185
+ "Preparing response",
28186
+ "Almost there"
28187
+ ] })
28174
28188
  })
28175
- }, e.id)), t && /* @__PURE__ */ T(Y, {
28176
- className: `${TT.messageBubble} ${TT.messageBubbleAssistant}`,
28177
- children: /* @__PURE__ */ T(PP, { messages: [
28178
- "Thinking",
28179
- "Analyzing your request",
28180
- "Searching for information",
28181
- "Processing data",
28182
- "Preparing response",
28183
- "Almost there"
28184
- ] })
28185
- })]
28189
+ ]
28186
28190
  })
28187
- })]
28191
+ })
28188
28192
  });
28189
28193
  }
28190
28194
  var CP = {
@@ -28833,7 +28837,12 @@ function WP({ items: e, title: t = "Details", advantages: n = [], price: r, pric
28833
28837
  }
28834
28838
  //#endregion
28835
28839
  //#region src/context/AgentChatRuntimeContext.tsx
28836
- var GP = o(null);
28840
+ var GP = o({
28841
+ customerId: "",
28842
+ customerToken: "",
28843
+ language: "en",
28844
+ forceReAuth: !1
28845
+ });
28837
28846
  //#endregion
28838
28847
  //#region src/hooks/useAgentChatRuntime.ts
28839
28848
  function KP() {
@@ -28854,13 +28863,13 @@ function JP() {
28854
28863
  //#endregion
28855
28864
  //#region src/mappers/agent-chat-runtime.mapper.ts
28856
28865
  function YP(e) {
28857
- return "customerId" in e ? e.customerId : e.getCustomerId();
28866
+ return e.customerId;
28858
28867
  }
28859
- async function XP(e) {
28860
- return "customerToken" in e ? e.customerToken : e.getCustomerToken();
28868
+ function XP(e) {
28869
+ return e.customerToken;
28861
28870
  }
28862
28871
  function ZP(e) {
28863
- return "language" in e ? e.language ?? null : "getLanguage" in e && e.getLanguage ? e.getLanguage() : null;
28872
+ return e.language ?? null;
28864
28873
  }
28865
28874
  //#endregion
28866
28875
  //#region src/mappers/agent-chat-config.mapper.ts
@@ -28943,12 +28952,12 @@ function fF(e) {
28943
28952
  function pF() {
28944
28953
  if (typeof sessionStorage < "u") {
28945
28954
  let e = sessionStorage.getItem(uF);
28946
- return e && fF(e) ? (sessionStorage.removeItem(uF), null) : e;
28955
+ return e && fF(e) ? (console.log("getGenaiAccessToken - Token expired, removing from sessionStorage"), sessionStorage.removeItem(uF), null) : (console.log("getGenaiAccessToken - Token retrieved from sessionStorage:", !!e), e);
28947
28956
  }
28948
28957
  return null;
28949
28958
  }
28950
28959
  function mF(e) {
28951
- typeof sessionStorage < "u" && sessionStorage.setItem(uF, e);
28960
+ typeof sessionStorage < "u" && (sessionStorage.setItem(uF, e), console.log("setGenaiAccessToken - Token stored in sessionStorage"));
28952
28961
  }
28953
28962
  function hF() {
28954
28963
  return typeof sessionStorage < "u" ? sessionStorage.getItem(dF) : null;
@@ -33456,7 +33465,7 @@ function vV({ baseUrl: e, prefix: t = "", withCollation: n = !0 }) {
33456
33465
  let t = fV()?.authenticated ?? !1, r = e.anonymous ?? !1;
33457
33466
  e.accessScope && (e.url = mV(e.url || "", e.accessScope, t));
33458
33467
  let i = pF(), a = hF();
33459
- i && (e.headers.Authorization = `Bearer ${i}`), a && (e.headers["x-tenant-id"] = a);
33468
+ console.log("RestService interceptor - genaiToken:", !!i, "tenantId:", a, "url:", e.url), i && (e.headers.Authorization = `Bearer ${i}`), a && (e.headers["x-tenant-id"] = a);
33460
33469
  let o = dV();
33461
33470
  return o && !r && (e.headers.Authorization = o), n && (e.headers.Collation = pI.locale), !e.headers.has("Content-Type") && !(e.data instanceof FormData) && (e.headers["Content-Type"] = "application/json"), e.method?.toLowerCase() === "get" && (e.data = {}), e;
33462
33471
  }, (e) => Promise.reject(e)), r;
@@ -33833,13 +33842,16 @@ function IV() {
33833
33842
  var LV = EV({
33834
33843
  mutationKey: ["genai", "login"],
33835
33844
  mutationFn: async ({ serviceAccount: e, serviceKey: t }) => TV.loginToGenai(e, t)
33836
- }), RV = null, zV = null;
33837
- function BV(e = !1) {
33845
+ }), RV = new lV("useGenaiLogin"), zV = null, BV = null;
33846
+ function VV(e = !1) {
33838
33847
  let t = IV(), { mutateAsync: n } = LV(), [r, i] = y(!1), [a, o] = y(null), [s, c] = y(null), [l, u] = y(null);
33839
33848
  return f(() => {
33840
33849
  (async () => {
33841
33850
  let r = pF();
33842
- if (r && !e) {
33851
+ if (RV.debug("Checking existing token", {
33852
+ forceReAuth: e,
33853
+ hasExistingToken: !!r
33854
+ }), r && !e) {
33843
33855
  c(r);
33844
33856
  return;
33845
33857
  }
@@ -33847,20 +33859,24 @@ function BV(e = !1) {
33847
33859
  if (!a) return;
33848
33860
  u(a);
33849
33861
  let s = `${a.serviceAccount}::${a.serviceKey}`;
33850
- if (RV === s && !e) {
33851
- zV && c(await zV);
33862
+ if (RV.debug("Checking login key", {
33863
+ currentKey: s,
33864
+ attemptedLoginKey: zV
33865
+ }), zV === s && !e) {
33866
+ BV && c(await BV);
33852
33867
  return;
33853
33868
  }
33854
- e && (RV = null, zV = null), RV = s, i(!0), o(null), zV = (async () => (await n({
33869
+ e && (RV.info("Resetting module-level state for forceReAuth"), zV = null, BV = null), zV = s, i(!0), o(null), BV = (async () => (RV.info("Attempting login"), (await n({
33855
33870
  serviceAccount: a.serviceAccount,
33856
33871
  serviceKey: a.serviceKey
33857
- })).access_token ?? null)();
33872
+ })).access_token ?? null))();
33858
33873
  try {
33859
- c(await zV);
33874
+ let e = await BV;
33875
+ c(e), RV.info("Login successful", { hasToken: !!e });
33860
33876
  } catch (e) {
33861
- console.error("GenAI login failed at app startup:", e), o("Failed to authenticate with GenAI service");
33877
+ RV.error("GenAI login failed", { error: e instanceof Error ? e.message : String(e) }), o("Failed to authenticate with GenAI service");
33862
33878
  } finally {
33863
- zV = null, i(!1);
33879
+ BV = null, i(!1);
33864
33880
  }
33865
33881
  })();
33866
33882
  }, [
@@ -33876,36 +33892,42 @@ function BV(e = !1) {
33876
33892
  }
33877
33893
  //#endregion
33878
33894
  //#region src/queries/genai/useTenantSwitchMutation.ts
33879
- var VV = EV({
33895
+ var HV = EV({
33880
33896
  mutationKey: ["genai", "tenant-switch"],
33881
33897
  mutationFn: async ({ tenant_id: e, token: t }) => TV.switchTenant(e, t)
33882
- }), HV = null, UV = null;
33883
- function WV(e, t, n = !1) {
33884
- let { mutateAsync: r } = VV(), [i, a] = y(!1), [o, s] = y(null), [c, l] = y(!1);
33898
+ }), UV = null, WV = null;
33899
+ function GV(e, t, n = !1) {
33900
+ let { mutateAsync: r } = HV(), [i, a] = y(!1), [o, s] = y(null), [c, l] = y(!1);
33885
33901
  return f(() => {
33886
33902
  (async () => {
33887
- if (!e || !t) return;
33903
+ if (!e || !t) {
33904
+ console.log("useGenaiTenantSwitch - Skipping: missing loginToken or tenantId", {
33905
+ loginToken: !!e,
33906
+ tenantId: t
33907
+ });
33908
+ return;
33909
+ }
33888
33910
  let i = pF();
33889
- if (i && i !== e && !n) {
33911
+ if (console.log("useGenaiTenantSwitch - forceReAuth:", n, "existingToken:", !!i, "loginToken:", !!e), i && i !== e && !n) {
33890
33912
  l(!0);
33891
33913
  return;
33892
33914
  }
33893
- if (UV === e && !n) {
33894
- HV && (await HV, l(!!pF()));
33915
+ if (console.log("useGenaiTenantSwitch - switchedForToken:", WV, "loginToken:", e), WV === e && !n) {
33916
+ UV && (await UV, l(!!pF()));
33895
33917
  return;
33896
33918
  }
33897
- n && (UV = null, HV = null), UV = e, a(!0), s(null), HV = (async () => {
33898
- await r({
33919
+ n && (console.log("useGenaiTenantSwitch - Resetting module-level state for forceReAuth"), WV = null, UV = null), WV = e, a(!0), s(null), UV = (async () => {
33920
+ console.log("useGenaiTenantSwitch - Attempting tenant switch for tenantId:", t), await r({
33899
33921
  tenant_id: t,
33900
33922
  token: e
33901
33923
  });
33902
33924
  })();
33903
33925
  try {
33904
- await HV, l(!0);
33926
+ await UV, l(!0), console.log("useGenaiTenantSwitch - Tenant switch successful");
33905
33927
  } catch (e) {
33906
33928
  console.error("GenAI tenant switch failed:", e), s("Failed to switch tenant");
33907
33929
  } finally {
33908
- HV = null, a(!1);
33930
+ UV = null, a(!1);
33909
33931
  }
33910
33932
  })();
33911
33933
  }, [
@@ -33921,8 +33943,8 @@ function WV(e, t, n = !1) {
33921
33943
  }
33922
33944
  //#endregion
33923
33945
  //#region src/hooks/useGenaiAuth.ts
33924
- function GV(e = !1) {
33925
- let { isLoggingIn: t, loginError: n, loginToken: r, genaiInit: i } = BV(e), { isSwitching: a, switchError: o, hasToken: s } = WV(r, i?.tenantId, e);
33946
+ function KV(e = !1) {
33947
+ let { isLoggingIn: t, loginError: n, loginToken: r, genaiInit: i } = VV(e), { isSwitching: a, switchError: o, hasToken: s } = GV(r, i?.tenantId, e);
33926
33948
  return {
33927
33949
  isAuthenticating: t || a,
33928
33950
  authError: n ?? o,
@@ -33931,7 +33953,7 @@ function GV(e = !1) {
33931
33953
  }
33932
33954
  //#endregion
33933
33955
  //#region src/hooks/usePanelState.ts
33934
- function KV(e = {}) {
33956
+ function qV(e = {}) {
33935
33957
  let { defaultOpen: t = !1, persist: n = !0 } = e, [r, i] = nt({
33936
33958
  key: n ? IN.PANEL_OPEN : `panel-state-${Date.now()}`,
33937
33959
  defaultValue: t,
@@ -33962,14 +33984,14 @@ function KV(e = {}) {
33962
33984
  }
33963
33985
  //#endregion
33964
33986
  //#region src/hooks/useAgentChatUiOptions.ts
33965
- var qV = {
33987
+ var JV = {
33966
33988
  bottom: 24,
33967
33989
  right: 24
33968
- }, JV = 1e4;
33969
- function YV(e) {
33970
- let t = e?.panelWidth ?? 420, n = e?.panelHeight ?? "100%", r = e?.panelHeaderHeight ?? 56, i = e?.panelTopOffset, a = e?.zIndex ?? JV, o = {
33971
- ...typeof e?.fabTopOffset == "number" ? { top: e.fabTopOffset } : { bottom: e?.fabBottomOffset ?? qV.bottom },
33972
- ...typeof e?.fabLeftOffset == "number" ? { left: e.fabLeftOffset } : { right: e?.fabRightOffset ?? qV.right }
33990
+ }, YV = 1e4;
33991
+ function XV(e) {
33992
+ let t = e?.panelWidth ?? 420, n = e?.panelHeight ?? "100%", r = e?.panelHeaderHeight ?? 56, i = e?.panelTopOffset, a = e?.zIndex ?? YV, o = {
33993
+ ...typeof e?.fabTopOffset == "number" ? { top: e.fabTopOffset } : { bottom: e?.fabBottomOffset ?? JV.bottom },
33994
+ ...typeof e?.fabLeftOffset == "number" ? { left: e.fabLeftOffset } : { right: e?.fabRightOffset ?? JV.right }
33973
33995
  }, s = e?.panelTitle ?? "Agent Chat";
33974
33996
  return {
33975
33997
  panelWidth: t,
@@ -33985,7 +34007,7 @@ function YV(e) {
33985
34007
  }
33986
34008
  //#endregion
33987
34009
  //#region src/hooks/useAgentChatActions.ts
33988
- function XV(e, t) {
34010
+ function ZV(e, t) {
33989
34011
  let n = v([]);
33990
34012
  return {
33991
34013
  actions: _(() => {
@@ -34001,7 +34023,7 @@ function XV(e, t) {
34001
34023
  }
34002
34024
  //#endregion
34003
34025
  //#region src/hooks/useResizable.ts
34004
- function ZV(e = {}) {
34026
+ function QV(e = {}) {
34005
34027
  let { axis: t = "y", direction: n = 1, onResizeChange: r } = e, [i, a] = y(0), o = v({
34006
34028
  startPos: 0,
34007
34029
  startOffset: 0
@@ -34039,7 +34061,7 @@ function ZV(e = {}) {
34039
34061
  }
34040
34062
  //#endregion
34041
34063
  //#region src/hooks/useAgentChatLayout.ts
34042
- var QV = [
34064
+ var $V = [
34043
34065
  "#root main",
34044
34066
  "#root",
34045
34067
  "main",
@@ -34047,9 +34069,9 @@ var QV = [
34047
34069
  "#app",
34048
34070
  "body"
34049
34071
  ];
34050
- function $V(e, t, n) {
34072
+ function eH(e, t, n) {
34051
34073
  let r = v(Math.max(280, t ?? 420)), i = v(n ?? !1), a = v(null), o = u(() => {
34052
- let t = e?.hostContainerSelector, n = [...t ? t.split(",").map((e) => e.trim()).filter(Boolean) : [], ...QV];
34074
+ let t = e?.hostContainerSelector, n = [...t ? t.split(",").map((e) => e.trim()).filter(Boolean) : [], ...$V];
34053
34075
  for (let e of n) {
34054
34076
  let t = document.querySelector(e);
34055
34077
  if (t) return t;
@@ -34075,7 +34097,7 @@ function $V(e, t, n) {
34075
34097
  }
34076
34098
  let { element: n, inlinePaddingBefore: r, widthApplied: i } = a.current;
34077
34099
  e !== i && (n.style.paddingRight = r, n.style.paddingRight = `calc(${r || "0px"} + ${e}px)`, a.current.widthApplied = e);
34078
- }, [o]), c = ZV({
34100
+ }, [o]), c = QV({
34079
34101
  axis: "x",
34080
34102
  direction: -1,
34081
34103
  onResizeChange: u((e) => {
@@ -34100,7 +34122,7 @@ function $V(e, t, n) {
34100
34122
  }
34101
34123
  //#endregion
34102
34124
  //#region src/hooks/useAgentChatVoiceHandlers.ts
34103
- function eH({ isListening: e, stopListening: t, reset: n, sendMessage: r, composerText: i, setComposerText: a, startListening: o, close: s }) {
34125
+ function tH({ isListening: e, stopListening: t, reset: n, sendMessage: r, composerText: i, setComposerText: a, startListening: o, close: s }) {
34104
34126
  return {
34105
34127
  handleSubmit: () => {
34106
34128
  e && t(), n(), r(i);
@@ -34115,7 +34137,7 @@ function eH({ isListening: e, stopListening: t, reset: n, sendMessage: r, compos
34115
34137
  }
34116
34138
  //#endregion
34117
34139
  //#region src/utils/color-utils.ts
34118
- function tH(e) {
34140
+ function nH(e) {
34119
34141
  let t = 0, n = 0, r = 0;
34120
34142
  if (e.startsWith("rgb")) {
34121
34143
  let i = e.match(/\d+/g);
@@ -34130,16 +34152,16 @@ function tH(e) {
34130
34152
  b: r
34131
34153
  };
34132
34154
  }
34133
- function nH(e, t) {
34134
- let { r: n, g: r, b: i } = tH(e), a = t / 100;
34155
+ function rH(e, t) {
34156
+ let { r: n, g: r, b: i } = nH(e), a = t / 100;
34135
34157
  return `rgb(${Math.min(255, n + (255 - n) * a)}, ${Math.min(255, r + (255 - r) * a)}, ${Math.min(255, i + (255 - i) * a)})`;
34136
34158
  }
34137
- function rH(e, t) {
34138
- let { r: n, g: r, b: i } = tH(e), a = t / 100;
34159
+ function iH(e, t) {
34160
+ let { r: n, g: r, b: i } = nH(e), a = t / 100;
34139
34161
  return `rgb(${Math.max(0, n - n * a)}, ${Math.max(0, r - r * a)}, ${Math.max(0, i - i * a)})`;
34140
34162
  }
34141
- function iH(e) {
34142
- let { r: t, g: n, b: r } = tH(e);
34163
+ function aH(e) {
34164
+ let { r: t, g: n, b: r } = nH(e);
34143
34165
  return [
34144
34166
  `rgb(${t + 50}, ${n + 50}, ${r + 50})`,
34145
34167
  `rgb(${t + 40}, ${n + 40}, ${r + 40})`,
@@ -34156,10 +34178,10 @@ function iH(e) {
34156
34178
  }
34157
34179
  //#endregion
34158
34180
  //#region src/hooks/useAccentColor.ts
34159
- function aH(e) {
34181
+ function oH(e) {
34160
34182
  let t = _(() => {
34161
34183
  if (e) try {
34162
- let t = iH(e);
34184
+ let t = aH(e);
34163
34185
  if (t && t.length === 11) return nT({
34164
34186
  colors: { accent: t },
34165
34187
  primaryColor: "accent"
@@ -34171,8 +34193,8 @@ function aH(e) {
34171
34193
  }, [e]);
34172
34194
  return f(() => {
34173
34195
  try {
34174
- let t = document.documentElement, n = e || "#414275", r = nH(n, 40), i = rH(n, 15);
34175
- t.style.setProperty("--agent-accent-color", n), t.style.setProperty("--agent-accent-color-light", nH(n, 40)), t.style.setProperty("--agent-accent-color-dark", i), t.style.setProperty("--agent-accent-bg", n), t.style.setProperty("--agent-accent-bg-light", r), t.style.setProperty("--agent-accent-border", n), t.style.setProperty("--agent-accent-text", "#ffffff"), t.style.setProperty("--agent-accent-text-muted", "rgba(255, 255, 255, 0.8)"), console.log("CSS variables set successfully");
34196
+ let t = document.documentElement, n = e || "#414275", r = rH(n, 40), i = iH(n, 15);
34197
+ t.style.setProperty("--agent-accent-color", n), t.style.setProperty("--agent-accent-color-light", rH(n, 40)), t.style.setProperty("--agent-accent-color-dark", i), t.style.setProperty("--agent-accent-bg", n), t.style.setProperty("--agent-accent-bg-light", r), t.style.setProperty("--agent-accent-border", n), t.style.setProperty("--agent-accent-text", "#ffffff"), t.style.setProperty("--agent-accent-text-muted", "rgba(255, 255, 255, 0.8)"), console.log("CSS variables set successfully");
34176
34198
  } catch (e) {
34177
34199
  console.error("Failed to set accent color CSS properties:", e);
34178
34200
  }
@@ -34180,101 +34202,92 @@ function aH(e) {
34180
34202
  }
34181
34203
  //#endregion
34182
34204
  //#region src/features/agent-chat/components/AgentChatLauncher/AgentChatLauncher.tsx
34183
- function oH(e) {
34184
- let t = d(GP);
34185
- GV(t && "forceReAuth" in t ? t.forceReAuth : !1);
34186
- let { panelWidth: n, panelHeight: r, panelHeaderHeight: i, panelTopOffset: a, zIndex: o, fabPosition: s, fabButtonLabel: c, panelTitle: l, accentColor: u } = YV(e);
34187
- aH(u);
34188
- let f = v(!1), { messages: p, composerText: m, setComposerText: h, isLoading: g, error: _, sendMessage: y, sendInitialMessage: b, canSend: x } = kV(), { actions: S, handleActionClick: C } = XV(p, y), { runtimeInfo: D, refreshRuntimeInfo: O } = AV(), { isOpen: k, open: A, close: j } = KV({
34205
+ function sH(e) {
34206
+ let t = d(GP).forceReAuth, { isAuthenticating: n, hasToken: r } = KV(t), { panelWidth: i, panelHeight: a, panelHeaderHeight: o, panelTopOffset: s, zIndex: c, fabPosition: l, fabButtonLabel: u, panelTitle: p, accentColor: m } = XV(e);
34207
+ oH(m);
34208
+ let h = v(!1), { messages: g, composerText: _, setComposerText: y, isLoading: b, error: x, sendMessage: S, sendInitialMessage: C, canSend: D } = kV(), { actions: O, handleActionClick: k } = ZV(g, S), { runtimeInfo: A, refreshRuntimeInfo: j } = AV(), { isOpen: M, open: N, close: P } = qV({
34189
34209
  defaultOpen: !1,
34190
34210
  persist: !0,
34191
34211
  onOpen: async () => {
34192
- f.current || (f.current = !0, await O(), await b());
34212
+ h.current || (h.current = !0, await j());
34193
34213
  }
34194
- }), M = MV([p.length, g]), { isListening: N, isSupported: P, startListening: F, stopListening: ee, reset: te } = NV({
34214
+ });
34215
+ f(() => {
34216
+ (async () => {
34217
+ h.current && M && !n && r && (await C(), h.current = !1);
34218
+ })();
34219
+ }, [
34220
+ M,
34221
+ n,
34222
+ r,
34223
+ C
34224
+ ]);
34225
+ let F = MV([g.length, b]), { isListening: ee, isSupported: te, startListening: I, stopListening: L, reset: R } = NV({
34195
34226
  lang: PV(),
34196
34227
  continuous: !0,
34197
34228
  pauseOnSubmit: !0,
34198
- onTextChange: h
34199
- }), { panelResizableWidth: I } = $V(e, n, k), { handleSubmit: L, handleToggleVoice: R, handleClose: ne } = eH({
34200
- isListening: N,
34201
- stopListening: ee,
34202
- reset: te,
34203
- sendMessage: y,
34204
- composerText: m,
34205
- setComposerText: h,
34206
- startListening: F,
34207
- close: j
34208
- });
34209
- return /* @__PURE__ */ E(w, { children: [!k && /* @__PURE__ */ T(MP, {
34210
- onClick: () => void A(),
34211
- zIndex: o,
34212
- position: s,
34213
- label: c
34214
- }), k && /* @__PURE__ */ T(EP, {
34229
+ onTextChange: y
34230
+ }), { panelResizableWidth: ne } = eH(e, i, M), { handleSubmit: re, handleToggleVoice: ie, handleClose: ae } = tH({
34231
+ isListening: ee,
34232
+ stopListening: L,
34233
+ reset: R,
34234
+ sendMessage: S,
34235
+ composerText: _,
34236
+ setComposerText: y,
34237
+ startListening: I,
34238
+ close: P
34239
+ });
34240
+ return /* @__PURE__ */ E(w, { children: [!M && /* @__PURE__ */ T(MP, {
34241
+ onClick: () => void N(),
34242
+ zIndex: c,
34243
+ position: l,
34244
+ label: u
34245
+ }), M && /* @__PURE__ */ T(EP, {
34215
34246
  visible: !0,
34216
- onClose: ne,
34217
- messages: p,
34218
- composerText: m,
34219
- onComposerTextChange: h,
34220
- isLoading: g,
34221
- error: _,
34222
- canSend: x,
34223
- onSubmit: L,
34224
- actions: S,
34225
- onActionClick: C,
34226
- isListening: N,
34227
- isVoiceSupported: P,
34228
- onToggleVoice: R,
34229
- panelTitle: l,
34230
- runtimeInfo: D,
34231
- scrollViewportRef: M,
34232
- panelWidth: n,
34233
- panelHeight: r,
34234
- panelHeaderHeight: i,
34235
- panelResizableWidth: I,
34236
- zIndex: o,
34237
- panelTopOffset: a
34247
+ onClose: ae,
34248
+ messages: g,
34249
+ composerText: _,
34250
+ onComposerTextChange: y,
34251
+ isLoading: b,
34252
+ error: x,
34253
+ canSend: D,
34254
+ onSubmit: re,
34255
+ actions: O,
34256
+ onActionClick: k,
34257
+ isListening: ee,
34258
+ isVoiceSupported: te,
34259
+ onToggleVoice: ie,
34260
+ panelTitle: p,
34261
+ runtimeInfo: A,
34262
+ scrollViewportRef: F,
34263
+ panelWidth: i,
34264
+ panelHeight: a,
34265
+ panelHeaderHeight: o,
34266
+ panelResizableWidth: ne,
34267
+ zIndex: c,
34268
+ panelTopOffset: s
34238
34269
  })] });
34239
34270
  }
34240
34271
  //#endregion
34241
34272
  //#region src/providers/AgentChatProviders.tsx
34242
- function sH({ runtime: e, children: t }) {
34273
+ function cH({ runtime: e, children: t }) {
34243
34274
  return /* @__PURE__ */ T(GP.Provider, {
34244
34275
  value: e,
34245
34276
  children: t
34246
34277
  });
34247
34278
  }
34248
- function cH({ config: e, children: t }) {
34279
+ function lH({ config: e, children: t }) {
34249
34280
  return /* @__PURE__ */ T(qP.Provider, {
34250
34281
  value: e,
34251
34282
  children: t
34252
34283
  });
34253
34284
  }
34254
34285
  //#endregion
34255
- //#region src/lib/agent-widget.tsx
34256
- function lH({ config: e, runtime: t, theme: n }) {
34257
- return pI.locale || pI.activate("en"), /* @__PURE__ */ T(HO, {
34258
- i18n: pI,
34259
- children: /* @__PURE__ */ T(Gn, {
34260
- theme: aH(n?.accentColor),
34261
- defaultColorScheme: "auto",
34262
- children: /* @__PURE__ */ T(qL, {
34263
- client: pV,
34264
- children: /* @__PURE__ */ T(cH, {
34265
- config: e,
34266
- children: /* @__PURE__ */ T(sH, {
34267
- runtime: t,
34268
- children: /* @__PURE__ */ T(oH, { ...n ?? {} })
34269
- })
34270
- })
34271
- })
34272
- })
34273
- });
34274
- }
34275
- //#endregion
34276
- //#region src/lib/config.service.ts
34277
- var uH = {
34286
+ //#region src/providers/ConfigProvider.tsx
34287
+ var uH = ({ children: e, config: t }) => /* @__PURE__ */ T(FV.Provider, {
34288
+ value: t,
34289
+ children: e
34290
+ }), dH = {
34278
34291
  url: {
34279
34292
  app: "http://localhost:4201",
34280
34293
  api: "https://cognitus-etiyacell.etiyacloud.com",
@@ -34320,9 +34333,12 @@ var uH = {
34320
34333
  tenantId: 54
34321
34334
  }
34322
34335
  }
34323
- };
34324
- function dH(e) {
34325
- let t = uH.genai?.init;
34336
+ }, fH = null;
34337
+ function pH() {
34338
+ return fH;
34339
+ }
34340
+ function mH(e) {
34341
+ let t = dH.genai?.init;
34326
34342
  return !t || e.genai?.init ? e : {
34327
34343
  ...e,
34328
34344
  genai: {
@@ -34331,33 +34347,61 @@ function dH(e) {
34331
34347
  }
34332
34348
  };
34333
34349
  }
34334
- async function fH(e) {
34350
+ async function hH(e) {
34335
34351
  let t = `${(globalThis.__BASE_URL__ ?? "").replace(/\/$/, "")}/environment.json`, n = e ?? t;
34336
34352
  try {
34337
34353
  let e = await fetch(n);
34338
- return e.ok ? dH(await e.json()) : uH;
34354
+ if (!e.ok) return fH = dH, dH;
34355
+ let t = mH(await e.json());
34356
+ return fH = t, t;
34339
34357
  } catch {
34340
- return uH;
34358
+ return fH = dH, dH;
34341
34359
  }
34342
34360
  }
34343
34361
  //#endregion
34362
+ //#region src/lib/agent-widget.tsx
34363
+ function gH({ config: e, runtime: t, theme: n }) {
34364
+ pI.locale || pI.activate("en");
34365
+ let r = oH(n?.accentColor), i = pH();
34366
+ return i ? /* @__PURE__ */ T(HO, {
34367
+ i18n: pI,
34368
+ children: /* @__PURE__ */ T(Gn, {
34369
+ theme: r,
34370
+ defaultColorScheme: "auto",
34371
+ children: /* @__PURE__ */ T(qL, {
34372
+ client: pV,
34373
+ children: /* @__PURE__ */ T(uH, {
34374
+ config: i,
34375
+ children: /* @__PURE__ */ T(lH, {
34376
+ config: e,
34377
+ children: /* @__PURE__ */ T(cH, {
34378
+ runtime: t,
34379
+ children: /* @__PURE__ */ T(sH, { ...n ?? {} })
34380
+ })
34381
+ })
34382
+ })
34383
+ })
34384
+ })
34385
+ }) : (console.error("AgentChatWidget: No environment config loaded. Login will not work."), null);
34386
+ }
34387
+ //#endregion
34344
34388
  //#region src/lib/mount-widget.tsx
34345
- var pH = /* @__PURE__ */ new WeakMap();
34346
- async function mH(e, t, n) {
34389
+ var _H = /* @__PURE__ */ new WeakMap();
34390
+ async function vH(e, t, n) {
34347
34391
  try {
34348
- bV(await fH(n?.environmentUrl));
34392
+ bV(await hH(n?.environmentUrl));
34349
34393
  } catch (e) {
34350
34394
  throw console.error("Failed to initialize agent widget rest services:", e), e;
34351
34395
  }
34352
- let r = pH.get(e);
34396
+ let r = _H.get(e);
34353
34397
  r && r.unmount();
34354
34398
  let i = D(e);
34355
- return i.render(/* @__PURE__ */ T(lH, { ...t })), pH.set(e, i), () => {
34356
- let t = pH.get(e);
34357
- t && (t.unmount(), pH.delete(e));
34399
+ return i.render(/* @__PURE__ */ T(gH, { ...t })), _H.set(e, i), () => {
34400
+ let t = _H.get(e);
34401
+ t && (t.unmount(), _H.delete(e));
34358
34402
  };
34359
34403
  }
34360
- function hH(e) {
34404
+ function yH(e) {
34361
34405
  let t = e.genai?.config;
34362
34406
  if (!t?.assistantId) throw Error("GenAI config is missing in environment.json.");
34363
34407
  return {
@@ -34365,24 +34409,24 @@ function hH(e) {
34365
34409
  agents: t.agents
34366
34410
  };
34367
34411
  }
34368
- function gH(e, t) {
34412
+ function bH(e, t) {
34369
34413
  return t ? {
34370
34414
  assistantId: t.assistantId ?? e.assistantId,
34371
34415
  agents: t.agents ?? e.agents
34372
34416
  } : e;
34373
34417
  }
34374
- function _H(e, t) {
34418
+ function xH(e, t) {
34375
34419
  return t ? (e.genai ||= {}, e.genai.config || (e.genai.config = {}), typeof t.assistantId == "number" && (e.genai.config.assistantId = t.assistantId), t.agents && (e.genai.config.agents = t.agents), e) : e;
34376
34420
  }
34377
- async function vH(e, t) {
34378
- let n = _H(await fH(t.environmentUrl), t.config);
34379
- return bV(n), mH(e, {
34380
- config: gH(hH(n), t.config),
34421
+ async function SH(e, t) {
34422
+ let n = xH(await hH(t.environmentUrl), t.config);
34423
+ return bV(n), vH(e, {
34424
+ config: bH(yH(n), t.config),
34381
34425
  runtime: t.runtime,
34382
34426
  theme: t.theme
34383
34427
  });
34384
34428
  }
34385
34429
  //#endregion
34386
- export { lH as AgentChatWidget, mH as mountAgentChatWidget, vH as mountAgentChatWidgetFromEnvironment };
34430
+ export { gH as AgentChatWidget, vH as mountAgentChatWidget, SH as mountAgentChatWidgetFromEnvironment };
34387
34431
 
34388
34432
  //# sourceMappingURL=agent-widget.js.map