@burtson-labs/bandit-engine 2.0.164 → 2.0.166

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.
Files changed (59) hide show
  1. package/README.md +4 -1
  2. package/dist/aiProviderStore-HY5G4QAK.mjs +8 -0
  3. package/dist/chat-RCMZYACB.mjs +15 -0
  4. package/dist/chat-provider.js +186 -111
  5. package/dist/chat-provider.js.map +1 -1
  6. package/dist/chat-provider.mjs +7 -8
  7. package/dist/{chunk-J6SWNO7Z.mjs → chunk-33OSALGS.mjs} +25 -7
  8. package/dist/{chunk-J6SWNO7Z.mjs.map → chunk-33OSALGS.mjs.map} +1 -1
  9. package/dist/{chunk-5KBTOCQZ.mjs → chunk-6KRAPGXE.mjs} +13 -85
  10. package/dist/chunk-6KRAPGXE.mjs.map +1 -0
  11. package/dist/{chunk-VBHI4TJC.mjs → chunk-75OBTJPN.mjs} +6 -6
  12. package/dist/{chunk-URZSIL7X.mjs → chunk-A6W6XIDD.mjs} +7 -7
  13. package/dist/{chunk-CQJGUYRW.mjs → chunk-GRPTCHFN.mjs} +150 -42
  14. package/dist/chunk-GRPTCHFN.mjs.map +1 -0
  15. package/dist/{chunk-OCVZVBQQ.mjs → chunk-HNXPDIWC.mjs} +12 -3
  16. package/dist/chunk-HNXPDIWC.mjs.map +1 -0
  17. package/dist/{chunk-IZX2J65Q.mjs → chunk-IB2LPSQQ.mjs} +2 -2
  18. package/dist/{chunk-PNQRS5EN.mjs → chunk-M4DWPNZZ.mjs} +11 -11
  19. package/dist/{chunk-O6P37PFR.mjs → chunk-MM3NRLVR.mjs} +4 -4
  20. package/dist/{chunk-WLNZL6SP.mjs → chunk-Q2DINRIU.mjs} +6 -6
  21. package/dist/{chunk-WLNZL6SP.mjs.map → chunk-Q2DINRIU.mjs.map} +1 -1
  22. package/dist/{chunk-JYBQAKSZ.mjs → chunk-WSZE3DDJ.mjs} +8 -8
  23. package/dist/{chunk-TY5VL3SG.mjs → chunk-YH5YWK4K.mjs} +3 -3
  24. package/dist/index.d.mts +97 -4
  25. package/dist/index.d.ts +97 -4
  26. package/dist/index.js +200 -133
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +22 -21
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/management/management.js +171 -123
  31. package/dist/management/management.js.map +1 -1
  32. package/dist/management/management.mjs +10 -11
  33. package/dist/{memoryUtils-2FVXDSS6.mjs → memoryUtils-HGCYEUCD.mjs} +1 -3
  34. package/dist/{memoryUtils-2FVXDSS6.mjs.map → memoryUtils-HGCYEUCD.mjs.map} +1 -1
  35. package/dist/modals/chat-modal/chat-modal.js +161 -33
  36. package/dist/modals/chat-modal/chat-modal.js.map +1 -1
  37. package/dist/modals/chat-modal/chat-modal.mjs +6 -7
  38. package/dist/modelStore-F6JQUXGG.mjs +8 -0
  39. package/dist/shared/custom-element.mjs +0 -1
  40. package/docs/03_provider_integration.md +5 -2
  41. package/package.json +1 -1
  42. package/dist/aiProviderStore-PEGSX4PK.mjs +0 -9
  43. package/dist/chat-OSAVW6L2.mjs +0 -16
  44. package/dist/chunk-5KBTOCQZ.mjs.map +0 -1
  45. package/dist/chunk-BJTO5JO5.mjs +0 -11
  46. package/dist/chunk-CQJGUYRW.mjs.map +0 -1
  47. package/dist/chunk-OCVZVBQQ.mjs.map +0 -1
  48. package/dist/modelStore-7XYYDCNC.mjs +0 -9
  49. package/dist/modelStore-7XYYDCNC.mjs.map +0 -1
  50. /package/dist/{aiProviderStore-PEGSX4PK.mjs.map → aiProviderStore-HY5G4QAK.mjs.map} +0 -0
  51. /package/dist/{chat-OSAVW6L2.mjs.map → chat-RCMZYACB.mjs.map} +0 -0
  52. /package/dist/{chunk-VBHI4TJC.mjs.map → chunk-75OBTJPN.mjs.map} +0 -0
  53. /package/dist/{chunk-URZSIL7X.mjs.map → chunk-A6W6XIDD.mjs.map} +0 -0
  54. /package/dist/{chunk-IZX2J65Q.mjs.map → chunk-IB2LPSQQ.mjs.map} +0 -0
  55. /package/dist/{chunk-PNQRS5EN.mjs.map → chunk-M4DWPNZZ.mjs.map} +0 -0
  56. /package/dist/{chunk-O6P37PFR.mjs.map → chunk-MM3NRLVR.mjs.map} +0 -0
  57. /package/dist/{chunk-JYBQAKSZ.mjs.map → chunk-WSZE3DDJ.mjs.map} +0 -0
  58. /package/dist/{chunk-TY5VL3SG.mjs.map → chunk-YH5YWK4K.mjs.map} +0 -0
  59. /package/dist/{chunk-BJTO5JO5.mjs.map → modelStore-F6JQUXGG.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -46,31 +46,42 @@ var init_packageSettingsStore = __esm({
46
46
  });
47
47
 
48
48
  // src/store/authenticationStore.ts
49
- var import_zustand2, TOKEN_KEY, validToken, user, rawToken, useAuthenticationStore, readPersistedToken;
49
+ var import_zustand2, TOKEN_KEY, decodeClaims, validOrNull, readLegacyStorage, validToken, user, rawToken, useAuthenticationStore, readPersistedToken;
50
50
  var init_authenticationStore = __esm({
51
51
  "src/store/authenticationStore.ts"() {
52
52
  "use strict";
53
53
  import_zustand2 = require("zustand");
54
54
  TOKEN_KEY = "authToken";
55
- validToken = null;
56
- user = null;
57
- rawToken = localStorage.getItem(TOKEN_KEY);
58
- if (rawToken) {
55
+ decodeClaims = (token) => {
59
56
  try {
60
- const base64Url = rawToken.split(".")[1];
57
+ const base64Url = token.split(".")[1];
61
58
  const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
62
59
  const jsonPayload = decodeURIComponent(
63
60
  atob(base64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
64
61
  );
65
- const decoded = JSON.parse(jsonPayload);
66
- if (decoded.exp * 1e3 > Date.now()) {
67
- validToken = rawToken;
68
- user = decoded;
69
- }
62
+ return JSON.parse(jsonPayload);
70
63
  } catch {
71
- validToken = null;
72
- user = null;
64
+ return null;
73
65
  }
66
+ };
67
+ validOrNull = (raw) => {
68
+ if (!raw) return null;
69
+ const decoded = decodeClaims(raw);
70
+ return decoded && decoded.exp * 1e3 > Date.now() ? raw : null;
71
+ };
72
+ readLegacyStorage = () => {
73
+ try {
74
+ return typeof localStorage === "undefined" ? null : localStorage.getItem(TOKEN_KEY);
75
+ } catch {
76
+ return null;
77
+ }
78
+ };
79
+ validToken = null;
80
+ user = null;
81
+ rawToken = readLegacyStorage();
82
+ if (rawToken) {
83
+ validToken = validOrNull(rawToken);
84
+ user = validToken ? decodeClaims(validToken) : null;
74
85
  }
75
86
  useAuthenticationStore = (0, import_zustand2.create)((set) => ({
76
87
  token: validToken,
@@ -78,16 +89,10 @@ var init_authenticationStore = __esm({
78
89
  authError: null,
79
90
  setToken: (token) => {
80
91
  if (token) {
81
- try {
82
- const base64Url = token.split(".")[1];
83
- const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
84
- const jsonPayload = decodeURIComponent(
85
- atob(base64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
86
- );
87
- const user2 = JSON.parse(jsonPayload);
88
- localStorage.setItem(TOKEN_KEY, token);
89
- set({ token, authError: null, user: user2 });
90
- } catch {
92
+ const decoded = decodeClaims(token);
93
+ if (decoded) {
94
+ set({ token, authError: null, user: decoded });
95
+ } else {
91
96
  set({ token: null, authError: "Invalid token", user: null });
92
97
  }
93
98
  } else {
@@ -95,23 +100,11 @@ var init_authenticationStore = __esm({
95
100
  }
96
101
  },
97
102
  clearToken: () => {
98
- localStorage.removeItem(TOKEN_KEY);
99
103
  set({ token: null, authError: null, user: null });
100
104
  }
101
105
  }));
102
106
  readPersistedToken = () => {
103
- try {
104
- const raw = localStorage.getItem(TOKEN_KEY);
105
- if (!raw) return null;
106
- const base64 = raw.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
107
- const json2 = decodeURIComponent(
108
- atob(base64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
109
- );
110
- const decoded = JSON.parse(json2);
111
- return decoded.exp * 1e3 > Date.now() ? raw : null;
112
- } catch {
113
- return null;
114
- }
107
+ return validOrNull(readLegacyStorage()) ?? validOrNull(useAuthenticationStore.getState().token);
115
108
  };
116
109
  }
117
110
  });
@@ -158,11 +151,20 @@ var init_debugLogger = __esm({
158
151
  */
159
152
  debug(message, context) {
160
153
  }
154
+ verboseEnabled() {
155
+ if (this.isDevelopment) return true;
156
+ try {
157
+ return typeof localStorage !== "undefined" && localStorage.getItem("bandit:debug") === "1";
158
+ } catch {
159
+ return false;
160
+ }
161
+ }
161
162
  /**
162
- * Info logs - shown in both development and production
163
- * Used for important user-facing information
163
+ * Info logs - shown in development, or in production when localStorage
164
+ * `bandit:debug` is "1"
164
165
  */
165
166
  info(message, context) {
167
+ if (!this.verboseEnabled()) return;
166
168
  const prefix = this.isDevelopment ? "\u2139\uFE0F [INFO]" : "[INFO]";
167
169
  if (context) {
168
170
  console.info(`${prefix} ${message}`, context);
@@ -232,7 +234,7 @@ function emitAuthTokenChanged(token) {
232
234
  detail: { token }
233
235
  }));
234
236
  }
235
- var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, AuthenticationService, authenticationService;
237
+ var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, readLocalStorage, writeLocalStorage, AuthenticationService, authenticationService;
236
238
  var init_authenticationService = __esm({
237
239
  "src/services/auth/authenticationService.ts"() {
238
240
  "use strict";
@@ -240,21 +242,103 @@ var init_authenticationService = __esm({
240
242
  init_debugLogger();
241
243
  TOKEN_KEY2 = "authToken";
242
244
  AUTH_TOKEN_CHANGED_EVENT = "bandit:auth-token-changed";
245
+ readLocalStorage = () => {
246
+ try {
247
+ return typeof localStorage === "undefined" ? null : localStorage.getItem(TOKEN_KEY2);
248
+ } catch {
249
+ return null;
250
+ }
251
+ };
252
+ writeLocalStorage = (token) => {
253
+ try {
254
+ if (typeof localStorage === "undefined") return;
255
+ if (token) localStorage.setItem(TOKEN_KEY2, token);
256
+ else localStorage.removeItem(TOKEN_KEY2);
257
+ } catch {
258
+ }
259
+ };
243
260
  AuthenticationService = class {
261
+ storageMode = "localStorage";
262
+ persistence = null;
263
+ handlers = {};
264
+ /** Bumped on every setToken/clearToken; async flows compare it to detect a superseded session. */
265
+ revision = 0;
266
+ refreshInFlight = null;
267
+ lastPersist = Promise.resolve();
268
+ /**
269
+ * Pick the storage contract for this host. Call once at boot, before the
270
+ * first `setToken`. Switching modes never moves a token by itself: the
271
+ * host migrates (e.g. reads the legacy localStorage value, then clears it).
272
+ */
273
+ configureSession(config) {
274
+ this.storageMode = config.storage;
275
+ this.persistence = config.persistence ?? null;
276
+ this.handlers = config.handlers ?? {};
277
+ }
278
+ getStorageMode() {
279
+ return this.storageMode;
280
+ }
281
+ getSessionRevision() {
282
+ return this.revision;
283
+ }
244
284
  getToken() {
245
- const token = localStorage.getItem(TOKEN_KEY2);
246
- return token;
285
+ if (this.storageMode === "memory") {
286
+ return useAuthenticationStore.getState().token;
287
+ }
288
+ return readLocalStorage();
247
289
  }
248
290
  setToken(token) {
249
- localStorage.setItem(TOKEN_KEY2, token);
291
+ this.revision += 1;
292
+ if (this.storageMode === "localStorage") {
293
+ writeLocalStorage(token);
294
+ } else {
295
+ writeLocalStorage(null);
296
+ }
250
297
  useAuthenticationStore.getState().setToken(token);
298
+ this.mirror(() => this.persistence?.write(token));
251
299
  emitAuthTokenChanged(token);
252
300
  }
253
301
  clearToken() {
254
- localStorage.removeItem(TOKEN_KEY2);
302
+ this.revision += 1;
303
+ const current = this.getToken() ?? useAuthenticationStore.getState().token;
304
+ try {
305
+ this.handlers.beforeClear?.(current);
306
+ } catch (error) {
307
+ debugLogger.warn("Auth beforeClear handler failed", { error });
308
+ }
309
+ writeLocalStorage(null);
255
310
  useAuthenticationStore.getState().clearToken();
311
+ this.mirror(() => this.persistence?.clear());
256
312
  emitAuthTokenChanged(null);
257
313
  }
314
+ /** True when the host registered a silent refresh path. */
315
+ canRefresh() {
316
+ return typeof this.handlers.refresh === "function";
317
+ }
318
+ /**
319
+ * Ask the host for a fresh token. Concurrent callers share one attempt.
320
+ * Resolves false when no refresh path exists or it did not produce a token.
321
+ */
322
+ tryRefresh() {
323
+ const refresh = this.handlers.refresh;
324
+ if (!refresh) return Promise.resolve(false);
325
+ if (this.refreshInFlight) return this.refreshInFlight;
326
+ this.refreshInFlight = (async () => {
327
+ try {
328
+ return await refresh();
329
+ } catch (error) {
330
+ debugLogger.warn("Auth refresh handler failed", { error });
331
+ return false;
332
+ } finally {
333
+ this.refreshInFlight = null;
334
+ }
335
+ })();
336
+ return this.refreshInFlight;
337
+ }
338
+ /** Resolves once the most recent persistence write/clear has settled. */
339
+ whenPersisted() {
340
+ return this.lastPersist;
341
+ }
258
342
  isAuthenticated() {
259
343
  const token = useAuthenticationStore.getState().token;
260
344
  return !!token && !this.isTokenExpired(token);
@@ -284,6 +368,16 @@ var init_authenticationService = __esm({
284
368
  return null;
285
369
  }
286
370
  }
371
+ mirror(run) {
372
+ const attempt = (async () => {
373
+ try {
374
+ await run();
375
+ } catch (error) {
376
+ debugLogger.warn("Auth token persistence failed", { error });
377
+ }
378
+ })();
379
+ this.lastPersist = attempt;
380
+ }
287
381
  };
288
382
  authenticationService = new AuthenticationService();
289
383
  }
@@ -4872,13 +4966,35 @@ var init_gateway_service = __esm({
4872
4966
  });
4873
4967
  instance.interceptors.response.use(
4874
4968
  (response) => response,
4875
- (error) => {
4969
+ async (error) => {
4970
+ const retried = await this._retryAfterRefresh(instance, error);
4971
+ if (retried) return retried;
4876
4972
  this._handleAuthFailure(error);
4877
4973
  return Promise.reject(this._normalizeAxiosError(error));
4878
4974
  }
4879
4975
  );
4880
4976
  return instance;
4881
4977
  }
4978
+ /**
4979
+ * A bare 401 on a host with a silent refresh path (HttpOnly refresh cookie,
4980
+ * native device token) usually means the access token aged out mid-session.
4981
+ * Refresh once and replay the request with the new token instead of
4982
+ * signing the user out; a failed refresh falls through to the sign-out path.
4983
+ */
4984
+ async _retryAfterRefresh(instance, error) {
4985
+ const config = error.config;
4986
+ if (!config || config._banditAuthRetried || error.response?.status !== 401) return null;
4987
+ if (!authenticationService.canRefresh()) return null;
4988
+ const data = error.response?.data;
4989
+ if (data?.code && data.code !== "TOKEN_EXPIRED") return null;
4990
+ try {
4991
+ if (!await authenticationService.tryRefresh()) return null;
4992
+ } catch {
4993
+ return null;
4994
+ }
4995
+ config._banditAuthRetried = true;
4996
+ return instance.request(config);
4997
+ }
4882
4998
  _normalizeAxiosError(error) {
4883
4999
  if (error.response) {
4884
5000
  return this._createHttpError(
@@ -9598,14 +9714,28 @@ function isJWTExpired(payload) {
9598
9714
  if (!payload.exp) return false;
9599
9715
  return Date.now() >= payload.exp * 1e3;
9600
9716
  }
9601
- var import_react, import_jsx_runtime, FeatureFlagContext, coerceNumber, coerceBoolean, FeatureFlagProvider, useFeatureFlag;
9717
+ var import_react, import_jsx_runtime, readSessionToken, FeatureFlagContext, coerceNumber, coerceBoolean, FeatureFlagProvider, useFeatureFlag;
9602
9718
  var init_FeatureFlagContext = __esm({
9603
9719
  "src/contexts/FeatureFlagContext.tsx"() {
9604
9720
  "use strict";
9605
9721
  import_react = require("react");
9606
9722
  init_featureFlags();
9607
9723
  init_debugLogger();
9724
+ init_authenticationService();
9608
9725
  import_jsx_runtime = require("react/jsx-runtime");
9726
+ readSessionToken = (jwtStorageKey) => {
9727
+ const fromStorage = () => {
9728
+ try {
9729
+ return localStorage.getItem(jwtStorageKey);
9730
+ } catch {
9731
+ return null;
9732
+ }
9733
+ };
9734
+ if (jwtStorageKey && jwtStorageKey !== TOKEN_KEY2) {
9735
+ return fromStorage() ?? authenticationService.getToken();
9736
+ }
9737
+ return authenticationService.getToken() ?? fromStorage();
9738
+ };
9609
9739
  FeatureFlagContext = (0, import_react.createContext)(void 0);
9610
9740
  coerceNumber = (value, fallback) => {
9611
9741
  if (typeof value === "number" && Number.isFinite(value)) {
@@ -9655,7 +9785,7 @@ var init_FeatureFlagContext = __esm({
9655
9785
  let effectiveTier = currentTier || subscriptionType || "oss";
9656
9786
  if (typeof window !== "undefined") {
9657
9787
  try {
9658
- const token = localStorage.getItem(jwtStorageKey);
9788
+ const token = readSessionToken(jwtStorageKey);
9659
9789
  if (token) {
9660
9790
  jwtFound = true;
9661
9791
  const payload = decodeJWT(token);
@@ -9741,10 +9871,13 @@ var init_FeatureFlagContext = __esm({
9741
9871
  setCurrentTier(e.detail.tier);
9742
9872
  }
9743
9873
  };
9874
+ const handleSessionChange = () => refreshEvaluation();
9744
9875
  window.addEventListener("storage", handleStorageChange);
9876
+ window.addEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
9745
9877
  window.addEventListener("bandit:tier-updated", handleTierUpdate);
9746
9878
  return () => {
9747
9879
  window.removeEventListener("storage", handleStorageChange);
9880
+ window.removeEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
9748
9881
  window.removeEventListener("bandit:tier-updated", handleTierUpdate);
9749
9882
  };
9750
9883
  }, [refreshEvaluation, config.jwtStorageKey]);
@@ -13890,7 +14023,7 @@ var init_voiceService = __esm({
13890
14023
  }
13891
14024
  const token = authenticationService.getToken();
13892
14025
  if (!token) {
13893
- debugLogger.warn("No JWT token available - skipping voice models fetch");
14026
+ debugLogger.info("No JWT token available - skipping voice models fetch");
13894
14027
  const emptyModels = {
13895
14028
  models: [],
13896
14029
  defaultModel: "",
@@ -31107,6 +31240,7 @@ var init_chat2 = __esm({
31107
31240
  // src/index.ts
31108
31241
  var index_exports = {};
31109
31242
  __export(index_exports, {
31243
+ AUTH_TOKEN_CHANGED_EVENT: () => AUTH_TOKEN_CHANGED_EVENT,
31110
31244
  Chat: () => chat_default,
31111
31245
  ChatModal: () => chat_modal_default,
31112
31246
  ChatProvider: () => chat_provider_default,
@@ -31127,6 +31261,7 @@ __export(index_exports, {
31127
31261
  StreamingTTSClient: () => StreamingTTSClient,
31128
31262
  SubscriptionExpiredGuard: () => SubscriptionExpiredGuard,
31129
31263
  SubscriptionExpiredModal: () => SubscriptionExpiredModal,
31264
+ TOKEN_KEY: () => TOKEN_KEY2,
31130
31265
  TTSState: () => TTSState,
31131
31266
  VectorDatabaseService: () => VectorDatabaseService,
31132
31267
  VectorMigrationService: () => VectorMigrationService,
@@ -31201,6 +31336,11 @@ init_common_types();
31201
31336
  init_authenticationService();
31202
31337
  init_debugLogger();
31203
31338
  init_indexedDBService();
31339
+ var sessionTokenFactory = (label) => () => {
31340
+ const token = authenticationService.getToken();
31341
+ debugLogger.info(`AIProviderInit: ${label}`, { hasToken: !!token });
31342
+ return token;
31343
+ };
31204
31344
  var AIProviderInitService = class _AIProviderInitService {
31205
31345
  static instance;
31206
31346
  constructor() {
@@ -31280,25 +31420,7 @@ var AIProviderInitService = class _AIProviderInitService {
31280
31420
  providerConfig = {
31281
31421
  type: "ollama" /* OLLAMA */,
31282
31422
  baseUrl: settings.ollamaUrl,
31283
- tokenFactory: () => {
31284
- let token = authenticationService.getToken();
31285
- if (!token) {
31286
- token = localStorage.getItem("authToken");
31287
- }
31288
- if (!token) {
31289
- try {
31290
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
31291
- const authStore = useAuthenticationStore2.getState();
31292
- token = authStore.token;
31293
- } catch (e) {
31294
- }
31295
- }
31296
- debugLogger.info("AIProviderInit: Token factory called", {
31297
- hasToken: !!token,
31298
- localStorage: !!localStorage.getItem("authToken")
31299
- });
31300
- return token;
31301
- }
31423
+ tokenFactory: sessionTokenFactory("Token factory called")
31302
31424
  };
31303
31425
  debugLogger.info("Using legacy Ollama config", providerConfig);
31304
31426
  }
@@ -31321,25 +31443,7 @@ var AIProviderInitService = class _AIProviderInitService {
31321
31443
  const fallbackConfig = {
31322
31444
  type: "ollama" /* OLLAMA */,
31323
31445
  baseUrl: settings.ollamaUrl || "http://localhost:11434",
31324
- tokenFactory: () => {
31325
- let token = authenticationService.getToken();
31326
- if (!token) {
31327
- token = localStorage.getItem("authToken");
31328
- }
31329
- if (!token) {
31330
- try {
31331
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
31332
- const authStore = useAuthenticationStore2.getState();
31333
- token = authStore.token;
31334
- } catch (e) {
31335
- }
31336
- }
31337
- debugLogger.info("AIProviderInit: Fallback tokenFactory", {
31338
- hasToken: !!token,
31339
- localStorage: !!localStorage.getItem("authToken")
31340
- });
31341
- return token;
31342
- }
31446
+ tokenFactory: sessionTokenFactory("Fallback tokenFactory")
31343
31447
  };
31344
31448
  const { createProvider } = useAIProviderStore.getState();
31345
31449
  createProvider(fallbackConfig);
@@ -31352,25 +31456,7 @@ var AIProviderInitService = class _AIProviderInitService {
31352
31456
  const localFallbackConfig = {
31353
31457
  type: "ollama" /* OLLAMA */,
31354
31458
  baseUrl: "http://localhost:11434",
31355
- tokenFactory: () => {
31356
- let token = authenticationService.getToken();
31357
- if (!token) {
31358
- token = localStorage.getItem("authToken");
31359
- }
31360
- if (!token) {
31361
- try {
31362
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
31363
- const authStore = useAuthenticationStore2.getState();
31364
- token = authStore.token;
31365
- } catch (e) {
31366
- }
31367
- }
31368
- debugLogger.info("AIProviderInit: Local fallback tokenFactory", {
31369
- hasToken: !!token,
31370
- localStorage: !!localStorage.getItem("authToken")
31371
- });
31372
- return token;
31373
- }
31459
+ tokenFactory: sessionTokenFactory("Local fallback tokenFactory")
31374
31460
  };
31375
31461
  const { createProvider } = useAIProviderStore.getState();
31376
31462
  createProvider(localFallbackConfig);
@@ -31442,27 +31528,7 @@ var AIProviderInitService = class _AIProviderInitService {
31442
31528
  });
31443
31529
  return config;
31444
31530
  }
31445
- config.tokenFactory = () => {
31446
- let token = authenticationService.getToken();
31447
- if (!token && typeof localStorage !== "undefined") {
31448
- try {
31449
- token = localStorage.getItem("authToken");
31450
- } catch {
31451
- }
31452
- }
31453
- if (!token) {
31454
- try {
31455
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
31456
- const authStore = useAuthenticationStore2.getState();
31457
- token = authStore.token;
31458
- } catch {
31459
- }
31460
- }
31461
- debugLogger.info("AIProviderInit: Token factory resolved auth token", {
31462
- hasToken: !!token
31463
- });
31464
- return token;
31465
- };
31531
+ config.tokenFactory = sessionTokenFactory("Token factory resolved auth token");
31466
31532
  }
31467
31533
  return config;
31468
31534
  }
@@ -45216,7 +45282,7 @@ var SubscriptionExpiredModal = ({
45216
45282
  "Account: ",
45217
45283
  /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("strong", { children: userEmail })
45218
45284
  ] }),
45219
- /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(import_material62.Typography, { variant: "body1", sx: { textAlign: "center", color: "text.secondary" }, children: IS_STORE_BUILD ? "Premium features are unavailable on this account right now." : "To continue using all features, please renew your subscription or return to the main application." }),
45285
+ /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(import_material62.Typography, { variant: "body1", sx: { textAlign: "center", color: "text.secondary" }, children: IS_STORE_BUILD ? "Premium features are unavailable on this account right now. You can subscribe to Pro in the app or review your account." : "To continue using all features, please renew your subscription or return to the main application." }),
45220
45286
  /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(import_material62.Box, { sx: {
45221
45287
  bgcolor: "background.paper",
45222
45288
  border: 1,
@@ -45238,10 +45304,10 @@ var SubscriptionExpiredModal = ({
45238
45304
  startIcon: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(import_react89.Home, {}),
45239
45305
  size: "large",
45240
45306
  sx: { minWidth: 140 },
45241
- children: "Go Home"
45307
+ children: IS_STORE_BUILD ? "My Account" : "Go Home"
45242
45308
  }
45243
45309
  ),
45244
- !IS_STORE_BUILD && /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
45310
+ (!IS_STORE_BUILD || onManageSubscription) && /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
45245
45311
  import_material62.Button,
45246
45312
  {
45247
45313
  onClick: handleManageSubscription,
@@ -45250,7 +45316,7 @@ var SubscriptionExpiredModal = ({
45250
45316
  size: "large",
45251
45317
  color: "primary",
45252
45318
  sx: { minWidth: 140 },
45253
- children: "Renew Subscription"
45319
+ children: IS_STORE_BUILD ? "View Pro Options" : "Renew Subscription"
45254
45320
  }
45255
45321
  )
45256
45322
  ] })
@@ -45262,6 +45328,7 @@ var SubscriptionExpiredModal = ({
45262
45328
  // src/guards/SubscriptionExpiredGuard.tsx
45263
45329
  var import_react90 = require("react");
45264
45330
  init_useFeatures();
45331
+ init_authenticationService();
45265
45332
  var import_jsx_runtime65 = require("react/jsx-runtime");
45266
45333
  var SubscriptionExpiredGuard = ({
45267
45334
  children,
@@ -45289,11 +45356,9 @@ var SubscriptionExpiredGuard = ({
45289
45356
  const evaluation = getFullEvaluation();
45290
45357
  const extractedEmail = userEmail || evaluation?.metadata?.jwtFound ? (() => {
45291
45358
  try {
45292
- const token = localStorage.getItem("authToken");
45359
+ const token = authenticationService.getToken();
45293
45360
  if (token) {
45294
- const parts = token.split(".");
45295
- const payload = JSON.parse(atob(parts[1]));
45296
- return payload.email;
45361
+ return authenticationService.parseJwtClaims(token)?.email;
45297
45362
  }
45298
45363
  } catch (e) {
45299
45364
  }
@@ -45475,6 +45540,7 @@ init_vectorMigrationService();
45475
45540
  init_useVectorStore();
45476
45541
  // Annotate the CommonJS export names for ESM import in node:
45477
45542
  0 && (module.exports = {
45543
+ AUTH_TOKEN_CHANGED_EVENT,
45478
45544
  Chat,
45479
45545
  ChatModal,
45480
45546
  ChatProvider,
@@ -45495,6 +45561,7 @@ init_useVectorStore();
45495
45561
  StreamingTTSClient,
45496
45562
  SubscriptionExpiredGuard,
45497
45563
  SubscriptionExpiredModal,
45564
+ TOKEN_KEY,
45498
45565
  TTSState,
45499
45566
  VectorDatabaseService,
45500
45567
  VectorMigrationService,