@burtson-labs/bandit-engine 2.0.165 → 2.0.167

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 (61) hide show
  1. package/README.md +4 -1
  2. package/dist/aiProviderStore-HY5G4QAK.mjs +8 -0
  3. package/dist/chat-6N5B7A7F.mjs +15 -0
  4. package/dist/chat-provider.js +175 -109
  5. package/dist/chat-provider.js.map +1 -1
  6. package/dist/chat-provider.mjs +6 -7
  7. package/dist/{chunk-FEIDGXVR.mjs → chunk-46OGYEME.mjs} +24 -6
  8. package/dist/{chunk-FEIDGXVR.mjs.map → chunk-46OGYEME.mjs.map} +1 -1
  9. package/dist/{chunk-ASWUEAWM.mjs → chunk-5BZWJQ5O.mjs} +2 -2
  10. package/dist/{chunk-LKGBO5OP.mjs → chunk-CABOLDNR.mjs} +12 -84
  11. package/dist/chunk-CABOLDNR.mjs.map +1 -0
  12. package/dist/{chunk-NGGTQVGX.mjs → chunk-E5WMDLE3.mjs} +3 -3
  13. package/dist/{chunk-J6LSSK3G.mjs → chunk-GRPTCHFN.mjs} +149 -41
  14. package/dist/chunk-GRPTCHFN.mjs.map +1 -0
  15. package/dist/{chunk-RLW4RBIR.mjs → chunk-KDIL5WUL.mjs} +4 -4
  16. package/dist/{chunk-6VDL4SLX.mjs → chunk-N4BQ6HKL.mjs} +5 -5
  17. package/dist/{chunk-RNCASZ2Y.mjs → chunk-PK3LFBGC.mjs} +10 -10
  18. package/dist/{chunk-WSUUW7T2.mjs → chunk-SHYNXDRO.mjs} +10 -7
  19. package/dist/chunk-SHYNXDRO.mjs.map +1 -0
  20. package/dist/{chunk-2EM4ATKI.mjs → chunk-SZJB5FLZ.mjs} +2 -2
  21. package/dist/{chunk-2EM4ATKI.mjs.map → chunk-SZJB5FLZ.mjs.map} +1 -1
  22. package/dist/{chunk-QHGGV4KJ.mjs → chunk-US4TG745.mjs} +6 -6
  23. package/dist/index.d.mts +94 -3
  24. package/dist/index.d.ts +94 -3
  25. package/dist/index.js +191 -130
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +21 -20
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/management/management.js +162 -120
  30. package/dist/management/management.js.map +1 -1
  31. package/dist/management/management.mjs +9 -10
  32. package/dist/{memoryUtils-2FVXDSS6.mjs → memoryUtils-HGCYEUCD.mjs} +1 -3
  33. package/dist/{memoryUtils-2FVXDSS6.mjs.map → memoryUtils-HGCYEUCD.mjs.map} +1 -1
  34. package/dist/modals/chat-modal/chat-modal.js +149 -30
  35. package/dist/modals/chat-modal/chat-modal.js.map +1 -1
  36. package/dist/modals/chat-modal/chat-modal.mjs +5 -6
  37. package/dist/modelStore-TFNX4GEC.mjs +8 -0
  38. package/dist/{public-0EYmtpGD.d.mts → public-DJa4Db00.d.mts} +9 -0
  39. package/dist/{public-0EYmtpGD.d.ts → public-DJa4Db00.d.ts} +9 -0
  40. package/dist/public-types.d.mts +1 -1
  41. package/dist/public-types.d.ts +1 -1
  42. package/dist/shared/custom-element.mjs +0 -1
  43. package/docs/03_provider_integration.md +5 -2
  44. package/package.json +1 -1
  45. package/dist/aiProviderStore-M4BVEKUB.mjs +0 -9
  46. package/dist/chat-EMKHB23B.mjs +0 -16
  47. package/dist/chunk-BJTO5JO5.mjs +0 -11
  48. package/dist/chunk-J6LSSK3G.mjs.map +0 -1
  49. package/dist/chunk-LKGBO5OP.mjs.map +0 -1
  50. package/dist/chunk-WSUUW7T2.mjs.map +0 -1
  51. package/dist/modelStore-7YYELPF6.mjs +0 -9
  52. package/dist/modelStore-7YYELPF6.mjs.map +0 -1
  53. /package/dist/{aiProviderStore-M4BVEKUB.mjs.map → aiProviderStore-HY5G4QAK.mjs.map} +0 -0
  54. /package/dist/{chat-EMKHB23B.mjs.map → chat-6N5B7A7F.mjs.map} +0 -0
  55. /package/dist/{chunk-ASWUEAWM.mjs.map → chunk-5BZWJQ5O.mjs.map} +0 -0
  56. /package/dist/{chunk-NGGTQVGX.mjs.map → chunk-E5WMDLE3.mjs.map} +0 -0
  57. /package/dist/{chunk-RLW4RBIR.mjs.map → chunk-KDIL5WUL.mjs.map} +0 -0
  58. /package/dist/{chunk-6VDL4SLX.mjs.map → chunk-N4BQ6HKL.mjs.map} +0 -0
  59. /package/dist/{chunk-RNCASZ2Y.mjs.map → chunk-PK3LFBGC.mjs.map} +0 -0
  60. /package/dist/{chunk-QHGGV4KJ.mjs.map → chunk-US4TG745.mjs.map} +0 -0
  61. /package/dist/{chunk-BJTO5JO5.mjs.map → modelStore-TFNX4GEC.mjs.map} +0 -0
package/README.md CHANGED
@@ -961,7 +961,10 @@ const chatPackageSettings = {
961
961
  rolesClaimKey: "roles", // JWT claim key for user roles
962
962
  subscriptionTypeClaimKey: "subscriptionType", // JWT claim for subscription type
963
963
  isSubscribedClaimKey: "isSubscribed", // JWT claim for subscription status
964
- jwtStorageKey: "authToken", // Local storage key for JWT token
964
+ // Where to look for the JWT when the engine's own session (authenticationService)
965
+ // holds none, e.g. a host that keeps its token under a different localStorage key.
966
+ // The engine's session is read first and may live in memory only.
967
+ jwtStorageKey: "authToken",
965
968
  adminRole: "admin", // Admin role name for elevated access
966
969
 
967
970
  // Development settings
@@ -0,0 +1,8 @@
1
+ import {
2
+ useAIProviderStore
3
+ } from "./chunk-GRPTCHFN.mjs";
4
+ import "./chunk-HNXPDIWC.mjs";
5
+ export {
6
+ useAIProviderStore
7
+ };
8
+ //# sourceMappingURL=aiProviderStore-HY5G4QAK.mjs.map
@@ -0,0 +1,15 @@
1
+ import {
2
+ chat_default
3
+ } from "./chunk-SHYNXDRO.mjs";
4
+ import "./chunk-ONQMRE2G.mjs";
5
+ import "./chunk-5BZWJQ5O.mjs";
6
+ import "./chunk-E5WMDLE3.mjs";
7
+ import "./chunk-KDIL5WUL.mjs";
8
+ import "./chunk-46OGYEME.mjs";
9
+ import "./chunk-SZJB5FLZ.mjs";
10
+ import "./chunk-GRPTCHFN.mjs";
11
+ import "./chunk-HNXPDIWC.mjs";
12
+ export {
13
+ chat_default as default
14
+ };
15
+ //# sourceMappingURL=chat-6N5B7A7F.mjs.map
@@ -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;
49
+ var import_zustand2, TOKEN_KEY, decodeClaims, validOrNull, readLegacyStorage, validToken, user, rawToken, useAuthenticationStore;
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,7 +100,6 @@ 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
  }));
@@ -227,7 +231,7 @@ function emitAuthTokenChanged(token) {
227
231
  detail: { token }
228
232
  }));
229
233
  }
230
- var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, AuthenticationService, authenticationService;
234
+ var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, readLocalStorage, writeLocalStorage, AuthenticationService, authenticationService;
231
235
  var init_authenticationService = __esm({
232
236
  "src/services/auth/authenticationService.ts"() {
233
237
  "use strict";
@@ -235,21 +239,103 @@ var init_authenticationService = __esm({
235
239
  init_debugLogger();
236
240
  TOKEN_KEY2 = "authToken";
237
241
  AUTH_TOKEN_CHANGED_EVENT = "bandit:auth-token-changed";
242
+ readLocalStorage = () => {
243
+ try {
244
+ return typeof localStorage === "undefined" ? null : localStorage.getItem(TOKEN_KEY2);
245
+ } catch {
246
+ return null;
247
+ }
248
+ };
249
+ writeLocalStorage = (token) => {
250
+ try {
251
+ if (typeof localStorage === "undefined") return;
252
+ if (token) localStorage.setItem(TOKEN_KEY2, token);
253
+ else localStorage.removeItem(TOKEN_KEY2);
254
+ } catch {
255
+ }
256
+ };
238
257
  AuthenticationService = class {
258
+ storageMode = "localStorage";
259
+ persistence = null;
260
+ handlers = {};
261
+ /** Bumped on every setToken/clearToken; async flows compare it to detect a superseded session. */
262
+ revision = 0;
263
+ refreshInFlight = null;
264
+ lastPersist = Promise.resolve();
265
+ /**
266
+ * Pick the storage contract for this host. Call once at boot, before the
267
+ * first `setToken`. Switching modes never moves a token by itself: the
268
+ * host migrates (e.g. reads the legacy localStorage value, then clears it).
269
+ */
270
+ configureSession(config) {
271
+ this.storageMode = config.storage;
272
+ this.persistence = config.persistence ?? null;
273
+ this.handlers = config.handlers ?? {};
274
+ }
275
+ getStorageMode() {
276
+ return this.storageMode;
277
+ }
278
+ getSessionRevision() {
279
+ return this.revision;
280
+ }
239
281
  getToken() {
240
- const token = localStorage.getItem(TOKEN_KEY2);
241
- return token;
282
+ if (this.storageMode === "memory") {
283
+ return useAuthenticationStore.getState().token;
284
+ }
285
+ return readLocalStorage();
242
286
  }
243
287
  setToken(token) {
244
- localStorage.setItem(TOKEN_KEY2, token);
288
+ this.revision += 1;
289
+ if (this.storageMode === "localStorage") {
290
+ writeLocalStorage(token);
291
+ } else {
292
+ writeLocalStorage(null);
293
+ }
245
294
  useAuthenticationStore.getState().setToken(token);
295
+ this.mirror(() => this.persistence?.write(token));
246
296
  emitAuthTokenChanged(token);
247
297
  }
248
298
  clearToken() {
249
- localStorage.removeItem(TOKEN_KEY2);
299
+ this.revision += 1;
300
+ const current = this.getToken() ?? useAuthenticationStore.getState().token;
301
+ try {
302
+ this.handlers.beforeClear?.(current);
303
+ } catch (error) {
304
+ debugLogger.warn("Auth beforeClear handler failed", { error });
305
+ }
306
+ writeLocalStorage(null);
250
307
  useAuthenticationStore.getState().clearToken();
308
+ this.mirror(() => this.persistence?.clear());
251
309
  emitAuthTokenChanged(null);
252
310
  }
311
+ /** True when the host registered a silent refresh path. */
312
+ canRefresh() {
313
+ return typeof this.handlers.refresh === "function";
314
+ }
315
+ /**
316
+ * Ask the host for a fresh token. Concurrent callers share one attempt.
317
+ * Resolves false when no refresh path exists or it did not produce a token.
318
+ */
319
+ tryRefresh() {
320
+ const refresh = this.handlers.refresh;
321
+ if (!refresh) return Promise.resolve(false);
322
+ if (this.refreshInFlight) return this.refreshInFlight;
323
+ this.refreshInFlight = (async () => {
324
+ try {
325
+ return await refresh();
326
+ } catch (error) {
327
+ debugLogger.warn("Auth refresh handler failed", { error });
328
+ return false;
329
+ } finally {
330
+ this.refreshInFlight = null;
331
+ }
332
+ })();
333
+ return this.refreshInFlight;
334
+ }
335
+ /** Resolves once the most recent persistence write/clear has settled. */
336
+ whenPersisted() {
337
+ return this.lastPersist;
338
+ }
253
339
  isAuthenticated() {
254
340
  const token = useAuthenticationStore.getState().token;
255
341
  return !!token && !this.isTokenExpired(token);
@@ -279,6 +365,16 @@ var init_authenticationService = __esm({
279
365
  return null;
280
366
  }
281
367
  }
368
+ mirror(run) {
369
+ const attempt = (async () => {
370
+ try {
371
+ await run();
372
+ } catch (error) {
373
+ debugLogger.warn("Auth token persistence failed", { error });
374
+ }
375
+ })();
376
+ this.lastPersist = attempt;
377
+ }
282
378
  };
283
379
  authenticationService = new AuthenticationService();
284
380
  }
@@ -2331,13 +2427,35 @@ var init_gateway_service = __esm({
2331
2427
  });
2332
2428
  instance.interceptors.response.use(
2333
2429
  (response) => response,
2334
- (error) => {
2430
+ async (error) => {
2431
+ const retried = await this._retryAfterRefresh(instance, error);
2432
+ if (retried) return retried;
2335
2433
  this._handleAuthFailure(error);
2336
2434
  return Promise.reject(this._normalizeAxiosError(error));
2337
2435
  }
2338
2436
  );
2339
2437
  return instance;
2340
2438
  }
2439
+ /**
2440
+ * A bare 401 on a host with a silent refresh path (HttpOnly refresh cookie,
2441
+ * native device token) usually means the access token aged out mid-session.
2442
+ * Refresh once and replay the request with the new token instead of
2443
+ * signing the user out; a failed refresh falls through to the sign-out path.
2444
+ */
2445
+ async _retryAfterRefresh(instance, error) {
2446
+ const config = error.config;
2447
+ if (!config || config._banditAuthRetried || error.response?.status !== 401) return null;
2448
+ if (!authenticationService.canRefresh()) return null;
2449
+ const data = error.response?.data;
2450
+ if (data?.code && data.code !== "TOKEN_EXPIRED") return null;
2451
+ try {
2452
+ if (!await authenticationService.tryRefresh()) return null;
2453
+ } catch {
2454
+ return null;
2455
+ }
2456
+ config._banditAuthRetried = true;
2457
+ return instance.request(config);
2458
+ }
2341
2459
  _normalizeAxiosError(error) {
2342
2460
  if (error.response) {
2343
2461
  return this._createHttpError(
@@ -9074,7 +9192,21 @@ var OSS_DEFAULT_FEATURES = {
9074
9192
 
9075
9193
  // src/contexts/FeatureFlagContext.tsx
9076
9194
  init_debugLogger();
9195
+ init_authenticationService();
9077
9196
  var import_jsx_runtime = require("react/jsx-runtime");
9197
+ var readSessionToken = (jwtStorageKey) => {
9198
+ const fromStorage = () => {
9199
+ try {
9200
+ return localStorage.getItem(jwtStorageKey);
9201
+ } catch {
9202
+ return null;
9203
+ }
9204
+ };
9205
+ if (jwtStorageKey && jwtStorageKey !== TOKEN_KEY2) {
9206
+ return fromStorage() ?? authenticationService.getToken();
9207
+ }
9208
+ return authenticationService.getToken() ?? fromStorage();
9209
+ };
9078
9210
  var FeatureFlagContext = (0, import_react.createContext)(void 0);
9079
9211
  function decodeJWT(token) {
9080
9212
  try {
@@ -9140,7 +9272,7 @@ var FeatureFlagProvider = ({ config, children }) => {
9140
9272
  let effectiveTier = currentTier || subscriptionType || "oss";
9141
9273
  if (typeof window !== "undefined") {
9142
9274
  try {
9143
- const token = localStorage.getItem(jwtStorageKey);
9275
+ const token = readSessionToken(jwtStorageKey);
9144
9276
  if (token) {
9145
9277
  jwtFound = true;
9146
9278
  const payload = decodeJWT(token);
@@ -9226,10 +9358,13 @@ var FeatureFlagProvider = ({ config, children }) => {
9226
9358
  setCurrentTier(e.detail.tier);
9227
9359
  }
9228
9360
  };
9361
+ const handleSessionChange = () => refreshEvaluation();
9229
9362
  window.addEventListener("storage", handleStorageChange);
9363
+ window.addEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
9230
9364
  window.addEventListener("bandit:tier-updated", handleTierUpdate);
9231
9365
  return () => {
9232
9366
  window.removeEventListener("storage", handleStorageChange);
9367
+ window.removeEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
9233
9368
  window.removeEventListener("bandit:tier-updated", handleTierUpdate);
9234
9369
  };
9235
9370
  }, [refreshEvaluation, config.jwtStorageKey]);
@@ -10304,6 +10439,11 @@ init_common_types();
10304
10439
  init_authenticationService();
10305
10440
  init_debugLogger();
10306
10441
  init_indexedDBService();
10442
+ var sessionTokenFactory = (label) => () => {
10443
+ const token = authenticationService.getToken();
10444
+ debugLogger.info(`AIProviderInit: ${label}`, { hasToken: !!token });
10445
+ return token;
10446
+ };
10307
10447
  var AIProviderInitService = class _AIProviderInitService {
10308
10448
  static instance;
10309
10449
  constructor() {
@@ -10383,25 +10523,7 @@ var AIProviderInitService = class _AIProviderInitService {
10383
10523
  providerConfig = {
10384
10524
  type: "ollama" /* OLLAMA */,
10385
10525
  baseUrl: settings.ollamaUrl,
10386
- tokenFactory: () => {
10387
- let token = authenticationService.getToken();
10388
- if (!token) {
10389
- token = localStorage.getItem("authToken");
10390
- }
10391
- if (!token) {
10392
- try {
10393
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10394
- const authStore = useAuthenticationStore2.getState();
10395
- token = authStore.token;
10396
- } catch (e) {
10397
- }
10398
- }
10399
- debugLogger.info("AIProviderInit: Token factory called", {
10400
- hasToken: !!token,
10401
- localStorage: !!localStorage.getItem("authToken")
10402
- });
10403
- return token;
10404
- }
10526
+ tokenFactory: sessionTokenFactory("Token factory called")
10405
10527
  };
10406
10528
  debugLogger.info("Using legacy Ollama config", providerConfig);
10407
10529
  }
@@ -10424,25 +10546,7 @@ var AIProviderInitService = class _AIProviderInitService {
10424
10546
  const fallbackConfig = {
10425
10547
  type: "ollama" /* OLLAMA */,
10426
10548
  baseUrl: settings.ollamaUrl || "http://localhost:11434",
10427
- tokenFactory: () => {
10428
- let token = authenticationService.getToken();
10429
- if (!token) {
10430
- token = localStorage.getItem("authToken");
10431
- }
10432
- if (!token) {
10433
- try {
10434
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10435
- const authStore = useAuthenticationStore2.getState();
10436
- token = authStore.token;
10437
- } catch (e) {
10438
- }
10439
- }
10440
- debugLogger.info("AIProviderInit: Fallback tokenFactory", {
10441
- hasToken: !!token,
10442
- localStorage: !!localStorage.getItem("authToken")
10443
- });
10444
- return token;
10445
- }
10549
+ tokenFactory: sessionTokenFactory("Fallback tokenFactory")
10446
10550
  };
10447
10551
  const { createProvider } = useAIProviderStore.getState();
10448
10552
  createProvider(fallbackConfig);
@@ -10455,25 +10559,7 @@ var AIProviderInitService = class _AIProviderInitService {
10455
10559
  const localFallbackConfig = {
10456
10560
  type: "ollama" /* OLLAMA */,
10457
10561
  baseUrl: "http://localhost:11434",
10458
- tokenFactory: () => {
10459
- let token = authenticationService.getToken();
10460
- if (!token) {
10461
- token = localStorage.getItem("authToken");
10462
- }
10463
- if (!token) {
10464
- try {
10465
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10466
- const authStore = useAuthenticationStore2.getState();
10467
- token = authStore.token;
10468
- } catch (e) {
10469
- }
10470
- }
10471
- debugLogger.info("AIProviderInit: Local fallback tokenFactory", {
10472
- hasToken: !!token,
10473
- localStorage: !!localStorage.getItem("authToken")
10474
- });
10475
- return token;
10476
- }
10562
+ tokenFactory: sessionTokenFactory("Local fallback tokenFactory")
10477
10563
  };
10478
10564
  const { createProvider } = useAIProviderStore.getState();
10479
10565
  createProvider(localFallbackConfig);
@@ -10545,27 +10631,7 @@ var AIProviderInitService = class _AIProviderInitService {
10545
10631
  });
10546
10632
  return config;
10547
10633
  }
10548
- config.tokenFactory = () => {
10549
- let token = authenticationService.getToken();
10550
- if (!token && typeof localStorage !== "undefined") {
10551
- try {
10552
- token = localStorage.getItem("authToken");
10553
- } catch {
10554
- }
10555
- }
10556
- if (!token) {
10557
- try {
10558
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10559
- const authStore = useAuthenticationStore2.getState();
10560
- token = authStore.token;
10561
- } catch {
10562
- }
10563
- }
10564
- debugLogger.info("AIProviderInit: Token factory resolved auth token", {
10565
- hasToken: !!token
10566
- });
10567
- return token;
10568
- };
10634
+ config.tokenFactory = sessionTokenFactory("Token factory resolved auth token");
10569
10635
  }
10570
10636
  return config;
10571
10637
  }