@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/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-WSZE3DDJ.mjs";
4
+ import "./chunk-ONQMRE2G.mjs";
5
+ import "./chunk-IB2LPSQQ.mjs";
6
+ import "./chunk-MM3NRLVR.mjs";
7
+ import "./chunk-Q2DINRIU.mjs";
8
+ import "./chunk-33OSALGS.mjs";
9
+ import "./chunk-YH5YWK4K.mjs";
10
+ import "./chunk-GRPTCHFN.mjs";
11
+ import "./chunk-HNXPDIWC.mjs";
12
+ export {
13
+ chat_default as default
14
+ };
15
+ //# sourceMappingURL=chat-RCMZYACB.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
  }));
@@ -144,11 +148,20 @@ var init_debugLogger = __esm({
144
148
  */
145
149
  debug(message, context) {
146
150
  }
151
+ verboseEnabled() {
152
+ if (this.isDevelopment) return true;
153
+ try {
154
+ return typeof localStorage !== "undefined" && localStorage.getItem("bandit:debug") === "1";
155
+ } catch {
156
+ return false;
157
+ }
158
+ }
147
159
  /**
148
- * Info logs - shown in both development and production
149
- * Used for important user-facing information
160
+ * Info logs - shown in development, or in production when localStorage
161
+ * `bandit:debug` is "1"
150
162
  */
151
163
  info(message, context) {
164
+ if (!this.verboseEnabled()) return;
152
165
  const prefix = this.isDevelopment ? "\u2139\uFE0F [INFO]" : "[INFO]";
153
166
  if (context) {
154
167
  console.info(`${prefix} ${message}`, context);
@@ -218,7 +231,7 @@ function emitAuthTokenChanged(token) {
218
231
  detail: { token }
219
232
  }));
220
233
  }
221
- var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, AuthenticationService, authenticationService;
234
+ var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, readLocalStorage, writeLocalStorage, AuthenticationService, authenticationService;
222
235
  var init_authenticationService = __esm({
223
236
  "src/services/auth/authenticationService.ts"() {
224
237
  "use strict";
@@ -226,21 +239,103 @@ var init_authenticationService = __esm({
226
239
  init_debugLogger();
227
240
  TOKEN_KEY2 = "authToken";
228
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
+ };
229
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
+ }
230
281
  getToken() {
231
- const token = localStorage.getItem(TOKEN_KEY2);
232
- return token;
282
+ if (this.storageMode === "memory") {
283
+ return useAuthenticationStore.getState().token;
284
+ }
285
+ return readLocalStorage();
233
286
  }
234
287
  setToken(token) {
235
- localStorage.setItem(TOKEN_KEY2, token);
288
+ this.revision += 1;
289
+ if (this.storageMode === "localStorage") {
290
+ writeLocalStorage(token);
291
+ } else {
292
+ writeLocalStorage(null);
293
+ }
236
294
  useAuthenticationStore.getState().setToken(token);
295
+ this.mirror(() => this.persistence?.write(token));
237
296
  emitAuthTokenChanged(token);
238
297
  }
239
298
  clearToken() {
240
- 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);
241
307
  useAuthenticationStore.getState().clearToken();
308
+ this.mirror(() => this.persistence?.clear());
242
309
  emitAuthTokenChanged(null);
243
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
+ }
244
339
  isAuthenticated() {
245
340
  const token = useAuthenticationStore.getState().token;
246
341
  return !!token && !this.isTokenExpired(token);
@@ -270,6 +365,16 @@ var init_authenticationService = __esm({
270
365
  return null;
271
366
  }
272
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
+ }
273
378
  };
274
379
  authenticationService = new AuthenticationService();
275
380
  }
@@ -2322,13 +2427,35 @@ var init_gateway_service = __esm({
2322
2427
  });
2323
2428
  instance.interceptors.response.use(
2324
2429
  (response) => response,
2325
- (error) => {
2430
+ async (error) => {
2431
+ const retried = await this._retryAfterRefresh(instance, error);
2432
+ if (retried) return retried;
2326
2433
  this._handleAuthFailure(error);
2327
2434
  return Promise.reject(this._normalizeAxiosError(error));
2328
2435
  }
2329
2436
  );
2330
2437
  return instance;
2331
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
+ }
2332
2459
  _normalizeAxiosError(error) {
2333
2460
  if (error.response) {
2334
2461
  return this._createHttpError(
@@ -9065,7 +9192,21 @@ var OSS_DEFAULT_FEATURES = {
9065
9192
 
9066
9193
  // src/contexts/FeatureFlagContext.tsx
9067
9194
  init_debugLogger();
9195
+ init_authenticationService();
9068
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
+ };
9069
9210
  var FeatureFlagContext = (0, import_react.createContext)(void 0);
9070
9211
  function decodeJWT(token) {
9071
9212
  try {
@@ -9131,7 +9272,7 @@ var FeatureFlagProvider = ({ config, children }) => {
9131
9272
  let effectiveTier = currentTier || subscriptionType || "oss";
9132
9273
  if (typeof window !== "undefined") {
9133
9274
  try {
9134
- const token = localStorage.getItem(jwtStorageKey);
9275
+ const token = readSessionToken(jwtStorageKey);
9135
9276
  if (token) {
9136
9277
  jwtFound = true;
9137
9278
  const payload = decodeJWT(token);
@@ -9217,10 +9358,13 @@ var FeatureFlagProvider = ({ config, children }) => {
9217
9358
  setCurrentTier(e.detail.tier);
9218
9359
  }
9219
9360
  };
9361
+ const handleSessionChange = () => refreshEvaluation();
9220
9362
  window.addEventListener("storage", handleStorageChange);
9363
+ window.addEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
9221
9364
  window.addEventListener("bandit:tier-updated", handleTierUpdate);
9222
9365
  return () => {
9223
9366
  window.removeEventListener("storage", handleStorageChange);
9367
+ window.removeEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
9224
9368
  window.removeEventListener("bandit:tier-updated", handleTierUpdate);
9225
9369
  };
9226
9370
  }, [refreshEvaluation, config.jwtStorageKey]);
@@ -10295,6 +10439,11 @@ init_common_types();
10295
10439
  init_authenticationService();
10296
10440
  init_debugLogger();
10297
10441
  init_indexedDBService();
10442
+ var sessionTokenFactory = (label) => () => {
10443
+ const token = authenticationService.getToken();
10444
+ debugLogger.info(`AIProviderInit: ${label}`, { hasToken: !!token });
10445
+ return token;
10446
+ };
10298
10447
  var AIProviderInitService = class _AIProviderInitService {
10299
10448
  static instance;
10300
10449
  constructor() {
@@ -10374,25 +10523,7 @@ var AIProviderInitService = class _AIProviderInitService {
10374
10523
  providerConfig = {
10375
10524
  type: "ollama" /* OLLAMA */,
10376
10525
  baseUrl: settings.ollamaUrl,
10377
- tokenFactory: () => {
10378
- let token = authenticationService.getToken();
10379
- if (!token) {
10380
- token = localStorage.getItem("authToken");
10381
- }
10382
- if (!token) {
10383
- try {
10384
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10385
- const authStore = useAuthenticationStore2.getState();
10386
- token = authStore.token;
10387
- } catch (e) {
10388
- }
10389
- }
10390
- debugLogger.info("AIProviderInit: Token factory called", {
10391
- hasToken: !!token,
10392
- localStorage: !!localStorage.getItem("authToken")
10393
- });
10394
- return token;
10395
- }
10526
+ tokenFactory: sessionTokenFactory("Token factory called")
10396
10527
  };
10397
10528
  debugLogger.info("Using legacy Ollama config", providerConfig);
10398
10529
  }
@@ -10415,25 +10546,7 @@ var AIProviderInitService = class _AIProviderInitService {
10415
10546
  const fallbackConfig = {
10416
10547
  type: "ollama" /* OLLAMA */,
10417
10548
  baseUrl: settings.ollamaUrl || "http://localhost:11434",
10418
- tokenFactory: () => {
10419
- let token = authenticationService.getToken();
10420
- if (!token) {
10421
- token = localStorage.getItem("authToken");
10422
- }
10423
- if (!token) {
10424
- try {
10425
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10426
- const authStore = useAuthenticationStore2.getState();
10427
- token = authStore.token;
10428
- } catch (e) {
10429
- }
10430
- }
10431
- debugLogger.info("AIProviderInit: Fallback tokenFactory", {
10432
- hasToken: !!token,
10433
- localStorage: !!localStorage.getItem("authToken")
10434
- });
10435
- return token;
10436
- }
10549
+ tokenFactory: sessionTokenFactory("Fallback tokenFactory")
10437
10550
  };
10438
10551
  const { createProvider } = useAIProviderStore.getState();
10439
10552
  createProvider(fallbackConfig);
@@ -10446,25 +10559,7 @@ var AIProviderInitService = class _AIProviderInitService {
10446
10559
  const localFallbackConfig = {
10447
10560
  type: "ollama" /* OLLAMA */,
10448
10561
  baseUrl: "http://localhost:11434",
10449
- tokenFactory: () => {
10450
- let token = authenticationService.getToken();
10451
- if (!token) {
10452
- token = localStorage.getItem("authToken");
10453
- }
10454
- if (!token) {
10455
- try {
10456
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10457
- const authStore = useAuthenticationStore2.getState();
10458
- token = authStore.token;
10459
- } catch (e) {
10460
- }
10461
- }
10462
- debugLogger.info("AIProviderInit: Local fallback tokenFactory", {
10463
- hasToken: !!token,
10464
- localStorage: !!localStorage.getItem("authToken")
10465
- });
10466
- return token;
10467
- }
10562
+ tokenFactory: sessionTokenFactory("Local fallback tokenFactory")
10468
10563
  };
10469
10564
  const { createProvider } = useAIProviderStore.getState();
10470
10565
  createProvider(localFallbackConfig);
@@ -10536,27 +10631,7 @@ var AIProviderInitService = class _AIProviderInitService {
10536
10631
  });
10537
10632
  return config;
10538
10633
  }
10539
- config.tokenFactory = () => {
10540
- let token = authenticationService.getToken();
10541
- if (!token && typeof localStorage !== "undefined") {
10542
- try {
10543
- token = localStorage.getItem("authToken");
10544
- } catch {
10545
- }
10546
- }
10547
- if (!token) {
10548
- try {
10549
- const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
10550
- const authStore = useAuthenticationStore2.getState();
10551
- token = authStore.token;
10552
- } catch {
10553
- }
10554
- }
10555
- debugLogger.info("AIProviderInit: Token factory resolved auth token", {
10556
- hasToken: !!token
10557
- });
10558
- return token;
10559
- };
10634
+ config.tokenFactory = sessionTokenFactory("Token factory resolved auth token");
10560
10635
  }
10561
10636
  return config;
10562
10637
  }