@burtson-labs/bandit-engine 2.0.165 → 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.
- package/README.md +4 -1
- package/dist/aiProviderStore-HY5G4QAK.mjs +8 -0
- package/dist/chat-RCMZYACB.mjs +15 -0
- package/dist/chat-provider.js +175 -109
- package/dist/chat-provider.js.map +1 -1
- package/dist/chat-provider.mjs +6 -7
- package/dist/{chunk-FEIDGXVR.mjs → chunk-33OSALGS.mjs} +24 -6
- package/dist/{chunk-FEIDGXVR.mjs.map → chunk-33OSALGS.mjs.map} +1 -1
- package/dist/{chunk-LKGBO5OP.mjs → chunk-6KRAPGXE.mjs} +12 -84
- package/dist/chunk-6KRAPGXE.mjs.map +1 -0
- package/dist/{chunk-6VDL4SLX.mjs → chunk-75OBTJPN.mjs} +5 -5
- package/dist/{chunk-QHGGV4KJ.mjs → chunk-A6W6XIDD.mjs} +6 -6
- package/dist/{chunk-J6LSSK3G.mjs → chunk-GRPTCHFN.mjs} +149 -41
- package/dist/chunk-GRPTCHFN.mjs.map +1 -0
- package/dist/{chunk-ASWUEAWM.mjs → chunk-IB2LPSQQ.mjs} +2 -2
- package/dist/{chunk-RNCASZ2Y.mjs → chunk-M4DWPNZZ.mjs} +10 -10
- package/dist/{chunk-NGGTQVGX.mjs → chunk-MM3NRLVR.mjs} +3 -3
- package/dist/{chunk-RLW4RBIR.mjs → chunk-Q2DINRIU.mjs} +4 -4
- package/dist/{chunk-WSUUW7T2.mjs → chunk-WSZE3DDJ.mjs} +7 -7
- package/dist/{chunk-2EM4ATKI.mjs → chunk-YH5YWK4K.mjs} +2 -2
- package/dist/index.d.mts +92 -1
- package/dist/index.d.ts +92 -1
- package/dist/index.js +188 -130
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -20
- package/dist/index.mjs.map +1 -1
- package/dist/management/management.js +159 -120
- package/dist/management/management.js.map +1 -1
- package/dist/management/management.mjs +9 -10
- package/dist/{memoryUtils-2FVXDSS6.mjs → memoryUtils-HGCYEUCD.mjs} +1 -3
- package/dist/{memoryUtils-2FVXDSS6.mjs.map → memoryUtils-HGCYEUCD.mjs.map} +1 -1
- package/dist/modals/chat-modal/chat-modal.js +149 -30
- package/dist/modals/chat-modal/chat-modal.js.map +1 -1
- package/dist/modals/chat-modal/chat-modal.mjs +5 -6
- package/dist/modelStore-F6JQUXGG.mjs +8 -0
- package/dist/shared/custom-element.mjs +0 -1
- package/docs/03_provider_integration.md +5 -2
- package/package.json +1 -1
- package/dist/aiProviderStore-M4BVEKUB.mjs +0 -9
- package/dist/chat-EMKHB23B.mjs +0 -16
- package/dist/chunk-BJTO5JO5.mjs +0 -11
- package/dist/chunk-J6LSSK3G.mjs.map +0 -1
- package/dist/chunk-LKGBO5OP.mjs.map +0 -1
- package/dist/modelStore-7YYELPF6.mjs +0 -9
- package/dist/modelStore-7YYELPF6.mjs.map +0 -1
- /package/dist/{aiProviderStore-M4BVEKUB.mjs.map → aiProviderStore-HY5G4QAK.mjs.map} +0 -0
- /package/dist/{chat-EMKHB23B.mjs.map → chat-RCMZYACB.mjs.map} +0 -0
- /package/dist/{chunk-6VDL4SLX.mjs.map → chunk-75OBTJPN.mjs.map} +0 -0
- /package/dist/{chunk-QHGGV4KJ.mjs.map → chunk-A6W6XIDD.mjs.map} +0 -0
- /package/dist/{chunk-ASWUEAWM.mjs.map → chunk-IB2LPSQQ.mjs.map} +0 -0
- /package/dist/{chunk-RNCASZ2Y.mjs.map → chunk-M4DWPNZZ.mjs.map} +0 -0
- /package/dist/{chunk-NGGTQVGX.mjs.map → chunk-MM3NRLVR.mjs.map} +0 -0
- /package/dist/{chunk-RLW4RBIR.mjs.map → chunk-Q2DINRIU.mjs.map} +0 -0
- /package/dist/{chunk-WSUUW7T2.mjs.map → chunk-WSZE3DDJ.mjs.map} +0 -0
- /package/dist/{chunk-2EM4ATKI.mjs.map → chunk-YH5YWK4K.mjs.map} +0 -0
- /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
|
-
|
|
56
|
-
user = null;
|
|
57
|
-
rawToken = localStorage.getItem(TOKEN_KEY);
|
|
58
|
-
if (rawToken) {
|
|
55
|
+
decodeClaims = (token) => {
|
|
59
56
|
try {
|
|
60
|
-
const base64Url =
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
return JSON.parse(jsonPayload);
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
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);
|
|
70
75
|
} catch {
|
|
71
|
-
|
|
72
|
-
user = null;
|
|
76
|
+
return null;
|
|
73
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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
|
});
|
|
@@ -241,7 +234,7 @@ function emitAuthTokenChanged(token) {
|
|
|
241
234
|
detail: { token }
|
|
242
235
|
}));
|
|
243
236
|
}
|
|
244
|
-
var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, AuthenticationService, authenticationService;
|
|
237
|
+
var TOKEN_KEY2, AUTH_TOKEN_CHANGED_EVENT, readLocalStorage, writeLocalStorage, AuthenticationService, authenticationService;
|
|
245
238
|
var init_authenticationService = __esm({
|
|
246
239
|
"src/services/auth/authenticationService.ts"() {
|
|
247
240
|
"use strict";
|
|
@@ -249,21 +242,103 @@ var init_authenticationService = __esm({
|
|
|
249
242
|
init_debugLogger();
|
|
250
243
|
TOKEN_KEY2 = "authToken";
|
|
251
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
|
+
};
|
|
252
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
|
+
}
|
|
253
284
|
getToken() {
|
|
254
|
-
|
|
255
|
-
|
|
285
|
+
if (this.storageMode === "memory") {
|
|
286
|
+
return useAuthenticationStore.getState().token;
|
|
287
|
+
}
|
|
288
|
+
return readLocalStorage();
|
|
256
289
|
}
|
|
257
290
|
setToken(token) {
|
|
258
|
-
|
|
291
|
+
this.revision += 1;
|
|
292
|
+
if (this.storageMode === "localStorage") {
|
|
293
|
+
writeLocalStorage(token);
|
|
294
|
+
} else {
|
|
295
|
+
writeLocalStorage(null);
|
|
296
|
+
}
|
|
259
297
|
useAuthenticationStore.getState().setToken(token);
|
|
298
|
+
this.mirror(() => this.persistence?.write(token));
|
|
260
299
|
emitAuthTokenChanged(token);
|
|
261
300
|
}
|
|
262
301
|
clearToken() {
|
|
263
|
-
|
|
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);
|
|
264
310
|
useAuthenticationStore.getState().clearToken();
|
|
311
|
+
this.mirror(() => this.persistence?.clear());
|
|
265
312
|
emitAuthTokenChanged(null);
|
|
266
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
|
+
}
|
|
267
342
|
isAuthenticated() {
|
|
268
343
|
const token = useAuthenticationStore.getState().token;
|
|
269
344
|
return !!token && !this.isTokenExpired(token);
|
|
@@ -293,6 +368,16 @@ var init_authenticationService = __esm({
|
|
|
293
368
|
return null;
|
|
294
369
|
}
|
|
295
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
|
+
}
|
|
296
381
|
};
|
|
297
382
|
authenticationService = new AuthenticationService();
|
|
298
383
|
}
|
|
@@ -4881,13 +4966,35 @@ var init_gateway_service = __esm({
|
|
|
4881
4966
|
});
|
|
4882
4967
|
instance.interceptors.response.use(
|
|
4883
4968
|
(response) => response,
|
|
4884
|
-
(error) => {
|
|
4969
|
+
async (error) => {
|
|
4970
|
+
const retried = await this._retryAfterRefresh(instance, error);
|
|
4971
|
+
if (retried) return retried;
|
|
4885
4972
|
this._handleAuthFailure(error);
|
|
4886
4973
|
return Promise.reject(this._normalizeAxiosError(error));
|
|
4887
4974
|
}
|
|
4888
4975
|
);
|
|
4889
4976
|
return instance;
|
|
4890
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
|
+
}
|
|
4891
4998
|
_normalizeAxiosError(error) {
|
|
4892
4999
|
if (error.response) {
|
|
4893
5000
|
return this._createHttpError(
|
|
@@ -9607,14 +9714,28 @@ function isJWTExpired(payload) {
|
|
|
9607
9714
|
if (!payload.exp) return false;
|
|
9608
9715
|
return Date.now() >= payload.exp * 1e3;
|
|
9609
9716
|
}
|
|
9610
|
-
var import_react, import_jsx_runtime, FeatureFlagContext, coerceNumber, coerceBoolean, FeatureFlagProvider, useFeatureFlag;
|
|
9717
|
+
var import_react, import_jsx_runtime, readSessionToken, FeatureFlagContext, coerceNumber, coerceBoolean, FeatureFlagProvider, useFeatureFlag;
|
|
9611
9718
|
var init_FeatureFlagContext = __esm({
|
|
9612
9719
|
"src/contexts/FeatureFlagContext.tsx"() {
|
|
9613
9720
|
"use strict";
|
|
9614
9721
|
import_react = require("react");
|
|
9615
9722
|
init_featureFlags();
|
|
9616
9723
|
init_debugLogger();
|
|
9724
|
+
init_authenticationService();
|
|
9617
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
|
+
};
|
|
9618
9739
|
FeatureFlagContext = (0, import_react.createContext)(void 0);
|
|
9619
9740
|
coerceNumber = (value, fallback) => {
|
|
9620
9741
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
@@ -9664,7 +9785,7 @@ var init_FeatureFlagContext = __esm({
|
|
|
9664
9785
|
let effectiveTier = currentTier || subscriptionType || "oss";
|
|
9665
9786
|
if (typeof window !== "undefined") {
|
|
9666
9787
|
try {
|
|
9667
|
-
const token =
|
|
9788
|
+
const token = readSessionToken(jwtStorageKey);
|
|
9668
9789
|
if (token) {
|
|
9669
9790
|
jwtFound = true;
|
|
9670
9791
|
const payload = decodeJWT(token);
|
|
@@ -9750,10 +9871,13 @@ var init_FeatureFlagContext = __esm({
|
|
|
9750
9871
|
setCurrentTier(e.detail.tier);
|
|
9751
9872
|
}
|
|
9752
9873
|
};
|
|
9874
|
+
const handleSessionChange = () => refreshEvaluation();
|
|
9753
9875
|
window.addEventListener("storage", handleStorageChange);
|
|
9876
|
+
window.addEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
|
|
9754
9877
|
window.addEventListener("bandit:tier-updated", handleTierUpdate);
|
|
9755
9878
|
return () => {
|
|
9756
9879
|
window.removeEventListener("storage", handleStorageChange);
|
|
9880
|
+
window.removeEventListener(AUTH_TOKEN_CHANGED_EVENT, handleSessionChange);
|
|
9757
9881
|
window.removeEventListener("bandit:tier-updated", handleTierUpdate);
|
|
9758
9882
|
};
|
|
9759
9883
|
}, [refreshEvaluation, config.jwtStorageKey]);
|
|
@@ -31116,6 +31240,7 @@ var init_chat2 = __esm({
|
|
|
31116
31240
|
// src/index.ts
|
|
31117
31241
|
var index_exports = {};
|
|
31118
31242
|
__export(index_exports, {
|
|
31243
|
+
AUTH_TOKEN_CHANGED_EVENT: () => AUTH_TOKEN_CHANGED_EVENT,
|
|
31119
31244
|
Chat: () => chat_default,
|
|
31120
31245
|
ChatModal: () => chat_modal_default,
|
|
31121
31246
|
ChatProvider: () => chat_provider_default,
|
|
@@ -31136,6 +31261,7 @@ __export(index_exports, {
|
|
|
31136
31261
|
StreamingTTSClient: () => StreamingTTSClient,
|
|
31137
31262
|
SubscriptionExpiredGuard: () => SubscriptionExpiredGuard,
|
|
31138
31263
|
SubscriptionExpiredModal: () => SubscriptionExpiredModal,
|
|
31264
|
+
TOKEN_KEY: () => TOKEN_KEY2,
|
|
31139
31265
|
TTSState: () => TTSState,
|
|
31140
31266
|
VectorDatabaseService: () => VectorDatabaseService,
|
|
31141
31267
|
VectorMigrationService: () => VectorMigrationService,
|
|
@@ -31210,6 +31336,11 @@ init_common_types();
|
|
|
31210
31336
|
init_authenticationService();
|
|
31211
31337
|
init_debugLogger();
|
|
31212
31338
|
init_indexedDBService();
|
|
31339
|
+
var sessionTokenFactory = (label) => () => {
|
|
31340
|
+
const token = authenticationService.getToken();
|
|
31341
|
+
debugLogger.info(`AIProviderInit: ${label}`, { hasToken: !!token });
|
|
31342
|
+
return token;
|
|
31343
|
+
};
|
|
31213
31344
|
var AIProviderInitService = class _AIProviderInitService {
|
|
31214
31345
|
static instance;
|
|
31215
31346
|
constructor() {
|
|
@@ -31289,25 +31420,7 @@ var AIProviderInitService = class _AIProviderInitService {
|
|
|
31289
31420
|
providerConfig = {
|
|
31290
31421
|
type: "ollama" /* OLLAMA */,
|
|
31291
31422
|
baseUrl: settings.ollamaUrl,
|
|
31292
|
-
tokenFactory: (
|
|
31293
|
-
let token = authenticationService.getToken();
|
|
31294
|
-
if (!token) {
|
|
31295
|
-
token = localStorage.getItem("authToken");
|
|
31296
|
-
}
|
|
31297
|
-
if (!token) {
|
|
31298
|
-
try {
|
|
31299
|
-
const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
|
|
31300
|
-
const authStore = useAuthenticationStore2.getState();
|
|
31301
|
-
token = authStore.token;
|
|
31302
|
-
} catch (e) {
|
|
31303
|
-
}
|
|
31304
|
-
}
|
|
31305
|
-
debugLogger.info("AIProviderInit: Token factory called", {
|
|
31306
|
-
hasToken: !!token,
|
|
31307
|
-
localStorage: !!localStorage.getItem("authToken")
|
|
31308
|
-
});
|
|
31309
|
-
return token;
|
|
31310
|
-
}
|
|
31423
|
+
tokenFactory: sessionTokenFactory("Token factory called")
|
|
31311
31424
|
};
|
|
31312
31425
|
debugLogger.info("Using legacy Ollama config", providerConfig);
|
|
31313
31426
|
}
|
|
@@ -31330,25 +31443,7 @@ var AIProviderInitService = class _AIProviderInitService {
|
|
|
31330
31443
|
const fallbackConfig = {
|
|
31331
31444
|
type: "ollama" /* OLLAMA */,
|
|
31332
31445
|
baseUrl: settings.ollamaUrl || "http://localhost:11434",
|
|
31333
|
-
tokenFactory: ()
|
|
31334
|
-
let token = authenticationService.getToken();
|
|
31335
|
-
if (!token) {
|
|
31336
|
-
token = localStorage.getItem("authToken");
|
|
31337
|
-
}
|
|
31338
|
-
if (!token) {
|
|
31339
|
-
try {
|
|
31340
|
-
const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
|
|
31341
|
-
const authStore = useAuthenticationStore2.getState();
|
|
31342
|
-
token = authStore.token;
|
|
31343
|
-
} catch (e) {
|
|
31344
|
-
}
|
|
31345
|
-
}
|
|
31346
|
-
debugLogger.info("AIProviderInit: Fallback tokenFactory", {
|
|
31347
|
-
hasToken: !!token,
|
|
31348
|
-
localStorage: !!localStorage.getItem("authToken")
|
|
31349
|
-
});
|
|
31350
|
-
return token;
|
|
31351
|
-
}
|
|
31446
|
+
tokenFactory: sessionTokenFactory("Fallback tokenFactory")
|
|
31352
31447
|
};
|
|
31353
31448
|
const { createProvider } = useAIProviderStore.getState();
|
|
31354
31449
|
createProvider(fallbackConfig);
|
|
@@ -31361,25 +31456,7 @@ var AIProviderInitService = class _AIProviderInitService {
|
|
|
31361
31456
|
const localFallbackConfig = {
|
|
31362
31457
|
type: "ollama" /* OLLAMA */,
|
|
31363
31458
|
baseUrl: "http://localhost:11434",
|
|
31364
|
-
tokenFactory: (
|
|
31365
|
-
let token = authenticationService.getToken();
|
|
31366
|
-
if (!token) {
|
|
31367
|
-
token = localStorage.getItem("authToken");
|
|
31368
|
-
}
|
|
31369
|
-
if (!token) {
|
|
31370
|
-
try {
|
|
31371
|
-
const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
|
|
31372
|
-
const authStore = useAuthenticationStore2.getState();
|
|
31373
|
-
token = authStore.token;
|
|
31374
|
-
} catch (e) {
|
|
31375
|
-
}
|
|
31376
|
-
}
|
|
31377
|
-
debugLogger.info("AIProviderInit: Local fallback tokenFactory", {
|
|
31378
|
-
hasToken: !!token,
|
|
31379
|
-
localStorage: !!localStorage.getItem("authToken")
|
|
31380
|
-
});
|
|
31381
|
-
return token;
|
|
31382
|
-
}
|
|
31459
|
+
tokenFactory: sessionTokenFactory("Local fallback tokenFactory")
|
|
31383
31460
|
};
|
|
31384
31461
|
const { createProvider } = useAIProviderStore.getState();
|
|
31385
31462
|
createProvider(localFallbackConfig);
|
|
@@ -31451,27 +31528,7 @@ var AIProviderInitService = class _AIProviderInitService {
|
|
|
31451
31528
|
});
|
|
31452
31529
|
return config;
|
|
31453
31530
|
}
|
|
31454
|
-
config.tokenFactory = (
|
|
31455
|
-
let token = authenticationService.getToken();
|
|
31456
|
-
if (!token && typeof localStorage !== "undefined") {
|
|
31457
|
-
try {
|
|
31458
|
-
token = localStorage.getItem("authToken");
|
|
31459
|
-
} catch {
|
|
31460
|
-
}
|
|
31461
|
-
}
|
|
31462
|
-
if (!token) {
|
|
31463
|
-
try {
|
|
31464
|
-
const { useAuthenticationStore: useAuthenticationStore2 } = require("../../store/authenticationStore");
|
|
31465
|
-
const authStore = useAuthenticationStore2.getState();
|
|
31466
|
-
token = authStore.token;
|
|
31467
|
-
} catch {
|
|
31468
|
-
}
|
|
31469
|
-
}
|
|
31470
|
-
debugLogger.info("AIProviderInit: Token factory resolved auth token", {
|
|
31471
|
-
hasToken: !!token
|
|
31472
|
-
});
|
|
31473
|
-
return token;
|
|
31474
|
-
};
|
|
31531
|
+
config.tokenFactory = sessionTokenFactory("Token factory resolved auth token");
|
|
31475
31532
|
}
|
|
31476
31533
|
return config;
|
|
31477
31534
|
}
|
|
@@ -45225,7 +45282,7 @@ var SubscriptionExpiredModal = ({
|
|
|
45225
45282
|
"Account: ",
|
|
45226
45283
|
/* @__PURE__ */ (0, import_jsx_runtime64.jsx)("strong", { children: userEmail })
|
|
45227
45284
|
] }),
|
|
45228
|
-
/* @__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." }),
|
|
45229
45286
|
/* @__PURE__ */ (0, import_jsx_runtime64.jsx)(import_material62.Box, { sx: {
|
|
45230
45287
|
bgcolor: "background.paper",
|
|
45231
45288
|
border: 1,
|
|
@@ -45247,10 +45304,10 @@ var SubscriptionExpiredModal = ({
|
|
|
45247
45304
|
startIcon: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(import_react89.Home, {}),
|
|
45248
45305
|
size: "large",
|
|
45249
45306
|
sx: { minWidth: 140 },
|
|
45250
|
-
children: "Go Home"
|
|
45307
|
+
children: IS_STORE_BUILD ? "My Account" : "Go Home"
|
|
45251
45308
|
}
|
|
45252
45309
|
),
|
|
45253
|
-
!IS_STORE_BUILD && /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
|
|
45310
|
+
(!IS_STORE_BUILD || onManageSubscription) && /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
|
|
45254
45311
|
import_material62.Button,
|
|
45255
45312
|
{
|
|
45256
45313
|
onClick: handleManageSubscription,
|
|
@@ -45259,7 +45316,7 @@ var SubscriptionExpiredModal = ({
|
|
|
45259
45316
|
size: "large",
|
|
45260
45317
|
color: "primary",
|
|
45261
45318
|
sx: { minWidth: 140 },
|
|
45262
|
-
children: "Renew Subscription"
|
|
45319
|
+
children: IS_STORE_BUILD ? "View Pro Options" : "Renew Subscription"
|
|
45263
45320
|
}
|
|
45264
45321
|
)
|
|
45265
45322
|
] })
|
|
@@ -45271,6 +45328,7 @@ var SubscriptionExpiredModal = ({
|
|
|
45271
45328
|
// src/guards/SubscriptionExpiredGuard.tsx
|
|
45272
45329
|
var import_react90 = require("react");
|
|
45273
45330
|
init_useFeatures();
|
|
45331
|
+
init_authenticationService();
|
|
45274
45332
|
var import_jsx_runtime65 = require("react/jsx-runtime");
|
|
45275
45333
|
var SubscriptionExpiredGuard = ({
|
|
45276
45334
|
children,
|
|
@@ -45298,11 +45356,9 @@ var SubscriptionExpiredGuard = ({
|
|
|
45298
45356
|
const evaluation = getFullEvaluation();
|
|
45299
45357
|
const extractedEmail = userEmail || evaluation?.metadata?.jwtFound ? (() => {
|
|
45300
45358
|
try {
|
|
45301
|
-
const token =
|
|
45359
|
+
const token = authenticationService.getToken();
|
|
45302
45360
|
if (token) {
|
|
45303
|
-
|
|
45304
|
-
const payload = JSON.parse(atob(parts[1]));
|
|
45305
|
-
return payload.email;
|
|
45361
|
+
return authenticationService.parseJwtClaims(token)?.email;
|
|
45306
45362
|
}
|
|
45307
45363
|
} catch (e) {
|
|
45308
45364
|
}
|
|
@@ -45484,6 +45540,7 @@ init_vectorMigrationService();
|
|
|
45484
45540
|
init_useVectorStore();
|
|
45485
45541
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45486
45542
|
0 && (module.exports = {
|
|
45543
|
+
AUTH_TOKEN_CHANGED_EVENT,
|
|
45487
45544
|
Chat,
|
|
45488
45545
|
ChatModal,
|
|
45489
45546
|
ChatProvider,
|
|
@@ -45504,6 +45561,7 @@ init_useVectorStore();
|
|
|
45504
45561
|
StreamingTTSClient,
|
|
45505
45562
|
SubscriptionExpiredGuard,
|
|
45506
45563
|
SubscriptionExpiredModal,
|
|
45564
|
+
TOKEN_KEY,
|
|
45507
45565
|
TTSState,
|
|
45508
45566
|
VectorDatabaseService,
|
|
45509
45567
|
VectorMigrationService,
|