bstp-agent-widget 0.2.99 → 0.2.101

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.
@@ -28943,12 +28943,12 @@ function fF(e) {
28943
28943
  function pF() {
28944
28944
  if (typeof sessionStorage < "u") {
28945
28945
  let e = sessionStorage.getItem(uF);
28946
- return e && fF(e) ? (sessionStorage.removeItem(uF), null) : e;
28946
+ 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
28947
  }
28948
28948
  return null;
28949
28949
  }
28950
28950
  function mF(e) {
28951
- typeof sessionStorage < "u" && sessionStorage.setItem(uF, e);
28951
+ typeof sessionStorage < "u" && (sessionStorage.setItem(uF, e), console.log("setGenaiAccessToken - Token stored in sessionStorage"));
28952
28952
  }
28953
28953
  function hF() {
28954
28954
  return typeof sessionStorage < "u" ? sessionStorage.getItem(dF) : null;
@@ -33456,7 +33456,7 @@ function vV({ baseUrl: e, prefix: t = "", withCollation: n = !0 }) {
33456
33456
  let t = fV()?.authenticated ?? !1, r = e.anonymous ?? !1;
33457
33457
  e.accessScope && (e.url = mV(e.url || "", e.accessScope, t));
33458
33458
  let i = pF(), a = hF();
33459
- i && (e.headers.Authorization = `Bearer ${i}`), a && (e.headers["x-tenant-id"] = a);
33459
+ 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
33460
  let o = dV();
33461
33461
  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
33462
  }, (e) => Promise.reject(e)), r;
@@ -33839,7 +33839,7 @@ function BV(e = !1) {
33839
33839
  return f(() => {
33840
33840
  (async () => {
33841
33841
  let r = pF();
33842
- if (r && !e) {
33842
+ if (console.log("useGenaiLogin - forceReAuth:", e, "existingToken:", !!r), r && !e) {
33843
33843
  c(r);
33844
33844
  return;
33845
33845
  }
@@ -33847,16 +33847,17 @@ function BV(e = !1) {
33847
33847
  if (!a) return;
33848
33848
  u(a);
33849
33849
  let s = `${a.serviceAccount}::${a.serviceKey}`;
33850
- if (RV === s && !e) {
33850
+ if (console.log("useGenaiLogin - currentKey:", s, "attemptedLoginKey:", RV), RV === s && !e) {
33851
33851
  zV && c(await zV);
33852
33852
  return;
33853
33853
  }
33854
- e && (RV = null, zV = null), RV = s, i(!0), o(null), zV = (async () => (await n({
33854
+ e && (console.log("useGenaiLogin - Resetting module-level state for forceReAuth"), RV = null, zV = null), RV = s, i(!0), o(null), zV = (async () => (console.log("useGenaiLogin - Attempting login"), (await n({
33855
33855
  serviceAccount: a.serviceAccount,
33856
33856
  serviceKey: a.serviceKey
33857
- })).access_token ?? null)();
33857
+ })).access_token ?? null))();
33858
33858
  try {
33859
- c(await zV);
33859
+ let e = await zV;
33860
+ c(e), console.log("useGenaiLogin - Login successful, token:", !!e);
33860
33861
  } catch (e) {
33861
33862
  console.error("GenAI login failed at app startup:", e), o("Failed to authenticate with GenAI service");
33862
33863
  } finally {
@@ -33884,24 +33885,30 @@ function WV(e, t, n = !1) {
33884
33885
  let { mutateAsync: r } = VV(), [i, a] = y(!1), [o, s] = y(null), [c, l] = y(!1);
33885
33886
  return f(() => {
33886
33887
  (async () => {
33887
- if (!e || !t) return;
33888
+ if (!e || !t) {
33889
+ console.log("useGenaiTenantSwitch - Skipping: missing loginToken or tenantId", {
33890
+ loginToken: !!e,
33891
+ tenantId: t
33892
+ });
33893
+ return;
33894
+ }
33888
33895
  let i = pF();
33889
- if (i && i !== e && !n) {
33896
+ if (console.log("useGenaiTenantSwitch - forceReAuth:", n, "existingToken:", !!i, "loginToken:", !!e), i && i !== e && !n) {
33890
33897
  l(!0);
33891
33898
  return;
33892
33899
  }
33893
- if (UV === e && !n) {
33900
+ if (console.log("useGenaiTenantSwitch - switchedForToken:", UV, "loginToken:", e), UV === e && !n) {
33894
33901
  HV && (await HV, l(!!pF()));
33895
33902
  return;
33896
33903
  }
33897
- n && (UV = null, HV = null), UV = e, a(!0), s(null), HV = (async () => {
33898
- await r({
33904
+ n && (console.log("useGenaiTenantSwitch - Resetting module-level state for forceReAuth"), UV = null, HV = null), UV = e, a(!0), s(null), HV = (async () => {
33905
+ console.log("useGenaiTenantSwitch - Attempting tenant switch for tenantId:", t), await r({
33899
33906
  tenant_id: t,
33900
33907
  token: e
33901
33908
  });
33902
33909
  })();
33903
33910
  try {
33904
- await HV, l(!0);
33911
+ await HV, l(!0), console.log("useGenaiTenantSwitch - Tenant switch successful");
33905
33912
  } catch (e) {
33906
33913
  console.error("GenAI tenant switch failed:", e), s("Failed to switch tenant");
33907
33914
  } finally {
@@ -34181,60 +34188,60 @@ function aH(e) {
34181
34188
  //#endregion
34182
34189
  //#region src/features/agent-chat/components/AgentChatLauncher/AgentChatLauncher.tsx
34183
34190
  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({
34191
+ let t = d(GP), n = t && "forceReAuth" in t ? t.forceReAuth : !1;
34192
+ console.log("AgentChatLauncher - forceReAuth:", n, "runtime:", t), GV(n);
34193
+ let { panelWidth: r, panelHeight: i, panelHeaderHeight: a, panelTopOffset: o, zIndex: s, fabPosition: c, fabButtonLabel: l, panelTitle: u, accentColor: f } = YV(e);
34194
+ aH(f);
34195
+ let p = v(!1), { messages: m, composerText: h, setComposerText: g, isLoading: _, error: y, sendMessage: b, sendInitialMessage: x, canSend: S } = kV(), { actions: C, handleActionClick: D } = XV(m, b), { runtimeInfo: O, refreshRuntimeInfo: k } = AV(), { isOpen: A, open: j, close: M } = KV({
34189
34196
  defaultOpen: !1,
34190
34197
  persist: !0,
34191
34198
  onOpen: async () => {
34192
- f.current || (f.current = !0, await O(), await b());
34199
+ p.current || (p.current = !0, await k(), await x());
34193
34200
  }
34194
- }), M = MV([p.length, g]), { isListening: N, isSupported: P, startListening: F, stopListening: ee, reset: te } = NV({
34201
+ }), N = MV([m.length, _]), { isListening: P, isSupported: F, startListening: ee, stopListening: te, reset: I } = NV({
34195
34202
  lang: PV(),
34196
34203
  continuous: !0,
34197
34204
  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, {
34205
+ onTextChange: g
34206
+ }), { panelResizableWidth: L } = $V(e, r, A), { handleSubmit: R, handleToggleVoice: ne, handleClose: re } = eH({
34207
+ isListening: P,
34208
+ stopListening: te,
34209
+ reset: I,
34210
+ sendMessage: b,
34211
+ composerText: h,
34212
+ setComposerText: g,
34213
+ startListening: ee,
34214
+ close: M
34215
+ });
34216
+ return /* @__PURE__ */ E(w, { children: [!A && /* @__PURE__ */ T(MP, {
34217
+ onClick: () => void j(),
34218
+ zIndex: s,
34219
+ position: c,
34220
+ label: l
34221
+ }), A && /* @__PURE__ */ T(EP, {
34215
34222
  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
34223
+ onClose: re,
34224
+ messages: m,
34225
+ composerText: h,
34226
+ onComposerTextChange: g,
34227
+ isLoading: _,
34228
+ error: y,
34229
+ canSend: S,
34230
+ onSubmit: R,
34231
+ actions: C,
34232
+ onActionClick: D,
34233
+ isListening: P,
34234
+ isVoiceSupported: F,
34235
+ onToggleVoice: ne,
34236
+ panelTitle: u,
34237
+ runtimeInfo: O,
34238
+ scrollViewportRef: N,
34239
+ panelWidth: r,
34240
+ panelHeight: i,
34241
+ panelHeaderHeight: a,
34242
+ panelResizableWidth: L,
34243
+ zIndex: s,
34244
+ panelTopOffset: o
34238
34245
  })] });
34239
34246
  }
34240
34247
  //#endregion
@@ -34252,29 +34259,11 @@ function cH({ config: e, children: t }) {
34252
34259
  });
34253
34260
  }
34254
34261
  //#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 = {
34262
+ //#region src/providers/ConfigProvider.tsx
34263
+ var lH = ({ children: e, config: t }) => /* @__PURE__ */ T(FV.Provider, {
34264
+ value: t,
34265
+ children: e
34266
+ }), uH = {
34278
34267
  url: {
34279
34268
  app: "http://localhost:4201",
34280
34269
  api: "https://cognitus-etiyacell.etiyacloud.com",
@@ -34320,8 +34309,11 @@ var uH = {
34320
34309
  tenantId: 54
34321
34310
  }
34322
34311
  }
34323
- };
34324
- function dH(e) {
34312
+ }, dH = null;
34313
+ function fH() {
34314
+ return dH;
34315
+ }
34316
+ function pH(e) {
34325
34317
  let t = uH.genai?.init;
34326
34318
  return !t || e.genai?.init ? e : {
34327
34319
  ...e,
@@ -34331,33 +34323,61 @@ function dH(e) {
34331
34323
  }
34332
34324
  };
34333
34325
  }
34334
- async function fH(e) {
34326
+ async function mH(e) {
34335
34327
  let t = `${(globalThis.__BASE_URL__ ?? "").replace(/\/$/, "")}/environment.json`, n = e ?? t;
34336
34328
  try {
34337
34329
  let e = await fetch(n);
34338
- return e.ok ? dH(await e.json()) : uH;
34330
+ if (!e.ok) return dH = uH, uH;
34331
+ let t = pH(await e.json());
34332
+ return dH = t, t;
34339
34333
  } catch {
34340
- return uH;
34334
+ return dH = uH, uH;
34341
34335
  }
34342
34336
  }
34343
34337
  //#endregion
34338
+ //#region src/lib/agent-widget.tsx
34339
+ function hH({ config: e, runtime: t, theme: n }) {
34340
+ pI.locale || pI.activate("en");
34341
+ let r = aH(n?.accentColor), i = fH();
34342
+ return i ? /* @__PURE__ */ T(HO, {
34343
+ i18n: pI,
34344
+ children: /* @__PURE__ */ T(Gn, {
34345
+ theme: r,
34346
+ defaultColorScheme: "auto",
34347
+ children: /* @__PURE__ */ T(qL, {
34348
+ client: pV,
34349
+ children: /* @__PURE__ */ T(lH, {
34350
+ config: i,
34351
+ children: /* @__PURE__ */ T(cH, {
34352
+ config: e,
34353
+ children: /* @__PURE__ */ T(sH, {
34354
+ runtime: t,
34355
+ children: /* @__PURE__ */ T(oH, { ...n ?? {} })
34356
+ })
34357
+ })
34358
+ })
34359
+ })
34360
+ })
34361
+ }) : (console.error("AgentChatWidget: No environment config loaded. Login will not work."), null);
34362
+ }
34363
+ //#endregion
34344
34364
  //#region src/lib/mount-widget.tsx
34345
- var pH = /* @__PURE__ */ new WeakMap();
34346
- async function mH(e, t, n) {
34365
+ var gH = /* @__PURE__ */ new WeakMap();
34366
+ async function _H(e, t, n) {
34347
34367
  try {
34348
- bV(await fH(n?.environmentUrl));
34368
+ bV(await mH(n?.environmentUrl));
34349
34369
  } catch (e) {
34350
34370
  throw console.error("Failed to initialize agent widget rest services:", e), e;
34351
34371
  }
34352
- let r = pH.get(e);
34372
+ let r = gH.get(e);
34353
34373
  r && r.unmount();
34354
34374
  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));
34375
+ return i.render(/* @__PURE__ */ T(hH, { ...t })), gH.set(e, i), () => {
34376
+ let t = gH.get(e);
34377
+ t && (t.unmount(), gH.delete(e));
34358
34378
  };
34359
34379
  }
34360
- function hH(e) {
34380
+ function vH(e) {
34361
34381
  let t = e.genai?.config;
34362
34382
  if (!t?.assistantId) throw Error("GenAI config is missing in environment.json.");
34363
34383
  return {
@@ -34365,24 +34385,24 @@ function hH(e) {
34365
34385
  agents: t.agents
34366
34386
  };
34367
34387
  }
34368
- function gH(e, t) {
34388
+ function yH(e, t) {
34369
34389
  return t ? {
34370
34390
  assistantId: t.assistantId ?? e.assistantId,
34371
34391
  agents: t.agents ?? e.agents
34372
34392
  } : e;
34373
34393
  }
34374
- function _H(e, t) {
34394
+ function bH(e, t) {
34375
34395
  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
34396
  }
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),
34397
+ async function xH(e, t) {
34398
+ let n = bH(await mH(t.environmentUrl), t.config);
34399
+ return bV(n), _H(e, {
34400
+ config: yH(vH(n), t.config),
34381
34401
  runtime: t.runtime,
34382
34402
  theme: t.theme
34383
34403
  });
34384
34404
  }
34385
34405
  //#endregion
34386
- export { lH as AgentChatWidget, mH as mountAgentChatWidget, vH as mountAgentChatWidgetFromEnvironment };
34406
+ export { hH as AgentChatWidget, _H as mountAgentChatWidget, xH as mountAgentChatWidgetFromEnvironment };
34387
34407
 
34388
34408
  //# sourceMappingURL=agent-widget.js.map