@burtson-labs/bandit-engine 2.0.99 → 2.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{aiProviderStore-337QNQB3.mjs → aiProviderStore-FTD277QP.mjs} +2 -2
- package/dist/chat-PMO3WTM4.mjs +16 -0
- package/dist/chat-provider.js +152 -111
- package/dist/chat-provider.js.map +1 -1
- package/dist/chat-provider.mjs +5 -5
- package/dist/{chunk-J2PMXOV2.mjs → chunk-37JLV5PU.mjs} +18 -143
- package/dist/chunk-37JLV5PU.mjs.map +1 -0
- package/dist/{chunk-H3BYFEIE.mjs → chunk-43MLINPL.mjs} +157 -7
- package/dist/chunk-43MLINPL.mjs.map +1 -0
- package/dist/{chunk-L2EKYO4F.mjs → chunk-BN3D45E2.mjs} +4 -4
- package/dist/{chunk-ZLXWNTFK.mjs → chunk-HAUDGBUS.mjs} +3 -5
- package/dist/{chunk-ZLXWNTFK.mjs.map → chunk-HAUDGBUS.mjs.map} +1 -1
- package/dist/{chunk-I7WBZVTR.mjs → chunk-JTDQTYJR.mjs} +13 -13
- package/dist/chunk-JTDQTYJR.mjs.map +1 -0
- package/dist/{chunk-RUMVTVNM.mjs → chunk-KYC7CC6C.mjs} +2 -2
- package/dist/{chunk-C2SY64XM.mjs → chunk-R3HBSHLE.mjs} +92 -46
- package/dist/chunk-R3HBSHLE.mjs.map +1 -0
- package/dist/{chunk-AGT77Z3A.mjs → chunk-RN3AKXKI.mjs} +4 -4
- package/dist/{chunk-IVLVUNIB.mjs → chunk-VIKZPBVO.mjs} +5 -5
- package/dist/{chunk-OSSZ7Z2O.mjs → chunk-VTKRZNLI.mjs} +8 -6
- package/dist/{chunk-OSSZ7Z2O.mjs.map → chunk-VTKRZNLI.mjs.map} +1 -1
- package/dist/index.js +106 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -12
- package/dist/index.mjs.map +1 -1
- package/dist/management/management.js +252 -182
- package/dist/management/management.js.map +1 -1
- package/dist/management/management.mjs +8 -8
- package/dist/modals/chat-modal/chat-modal.js +161 -121
- package/dist/modals/chat-modal/chat-modal.js.map +1 -1
- package/dist/modals/chat-modal/chat-modal.mjs +4 -4
- package/package.json +1 -1
- package/dist/chat-IOBCRT5Y.mjs +0 -16
- package/dist/chunk-C2SY64XM.mjs.map +0 -1
- package/dist/chunk-H3BYFEIE.mjs.map +0 -1
- package/dist/chunk-I7WBZVTR.mjs.map +0 -1
- package/dist/chunk-J2PMXOV2.mjs.map +0 -1
- /package/dist/{aiProviderStore-337QNQB3.mjs.map → aiProviderStore-FTD277QP.mjs.map} +0 -0
- /package/dist/{chat-IOBCRT5Y.mjs.map → chat-PMO3WTM4.mjs.map} +0 -0
- /package/dist/{chunk-L2EKYO4F.mjs.map → chunk-BN3D45E2.mjs.map} +0 -0
- /package/dist/{chunk-RUMVTVNM.mjs.map → chunk-KYC7CC6C.mjs.map} +0 -0
- /package/dist/{chunk-AGT77Z3A.mjs.map → chunk-RN3AKXKI.mjs.map} +0 -0
- /package/dist/{chunk-IVLVUNIB.mjs.map → chunk-VIKZPBVO.mjs.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-KCI46M23.mjs";
|
|
4
4
|
|
|
5
5
|
// src/store/aiProviderStore.ts
|
|
6
|
-
import { create } from "zustand";
|
|
6
|
+
import { create as create2 } from "zustand";
|
|
7
7
|
|
|
8
8
|
// src/services/ai-provider/providers/ollama.provider.ts
|
|
9
9
|
import { map as map2 } from "rxjs";
|
|
@@ -1020,6 +1020,131 @@ import { map as map12 } from "rxjs";
|
|
|
1020
1020
|
// src/services/gateway/gateway.service.ts
|
|
1021
1021
|
import axios, { AxiosHeaders } from "axios";
|
|
1022
1022
|
import { catchError as catchError2, from as from5, lastValueFrom as lastValueFrom2, map as map6, Observable as Observable6, of as of2, shareReplay as shareReplay2, timeout as timeout2 } from "rxjs";
|
|
1023
|
+
|
|
1024
|
+
// src/store/authenticationStore.ts
|
|
1025
|
+
import { create } from "zustand";
|
|
1026
|
+
var TOKEN_KEY = "authToken";
|
|
1027
|
+
var validToken = null;
|
|
1028
|
+
var user = null;
|
|
1029
|
+
var rawToken = localStorage.getItem(TOKEN_KEY);
|
|
1030
|
+
if (rawToken) {
|
|
1031
|
+
try {
|
|
1032
|
+
const base64Url = rawToken.split(".")[1];
|
|
1033
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
1034
|
+
const jsonPayload = decodeURIComponent(
|
|
1035
|
+
atob(base64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
1036
|
+
);
|
|
1037
|
+
const decoded = JSON.parse(jsonPayload);
|
|
1038
|
+
if (decoded.exp * 1e3 > Date.now()) {
|
|
1039
|
+
validToken = rawToken;
|
|
1040
|
+
user = decoded;
|
|
1041
|
+
}
|
|
1042
|
+
} catch {
|
|
1043
|
+
validToken = null;
|
|
1044
|
+
user = null;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
var useAuthenticationStore = create((set) => ({
|
|
1048
|
+
token: validToken,
|
|
1049
|
+
user,
|
|
1050
|
+
authError: null,
|
|
1051
|
+
setToken: (token) => {
|
|
1052
|
+
if (token) {
|
|
1053
|
+
try {
|
|
1054
|
+
const base64Url = token.split(".")[1];
|
|
1055
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
1056
|
+
const jsonPayload = decodeURIComponent(
|
|
1057
|
+
atob(base64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
1058
|
+
);
|
|
1059
|
+
const user2 = JSON.parse(jsonPayload);
|
|
1060
|
+
localStorage.setItem(TOKEN_KEY, token);
|
|
1061
|
+
set({ token, authError: null, user: user2 });
|
|
1062
|
+
} catch {
|
|
1063
|
+
set({ token: null, authError: "Invalid token", user: null });
|
|
1064
|
+
}
|
|
1065
|
+
} else {
|
|
1066
|
+
set({ token: null, authError: null, user: null });
|
|
1067
|
+
}
|
|
1068
|
+
},
|
|
1069
|
+
clearToken: () => {
|
|
1070
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
1071
|
+
set({ token: null, authError: null, user: null });
|
|
1072
|
+
}
|
|
1073
|
+
}));
|
|
1074
|
+
var readPersistedToken = () => {
|
|
1075
|
+
try {
|
|
1076
|
+
const raw = localStorage.getItem(TOKEN_KEY);
|
|
1077
|
+
if (!raw) return null;
|
|
1078
|
+
const base64 = raw.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
1079
|
+
const json = decodeURIComponent(
|
|
1080
|
+
atob(base64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
1081
|
+
);
|
|
1082
|
+
const decoded = JSON.parse(json);
|
|
1083
|
+
return decoded.exp * 1e3 > Date.now() ? raw : null;
|
|
1084
|
+
} catch {
|
|
1085
|
+
return null;
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
// src/services/auth/authenticationService.ts
|
|
1090
|
+
var TOKEN_KEY2 = "authToken";
|
|
1091
|
+
var AUTH_TOKEN_CHANGED_EVENT = "bandit:auth-token-changed";
|
|
1092
|
+
function emitAuthTokenChanged(token) {
|
|
1093
|
+
if (typeof window === "undefined") {
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
window.dispatchEvent(new CustomEvent(AUTH_TOKEN_CHANGED_EVENT, {
|
|
1097
|
+
detail: { token }
|
|
1098
|
+
}));
|
|
1099
|
+
}
|
|
1100
|
+
var AuthenticationService = class {
|
|
1101
|
+
getToken() {
|
|
1102
|
+
const token = localStorage.getItem(TOKEN_KEY2);
|
|
1103
|
+
return token;
|
|
1104
|
+
}
|
|
1105
|
+
setToken(token) {
|
|
1106
|
+
localStorage.setItem(TOKEN_KEY2, token);
|
|
1107
|
+
useAuthenticationStore.getState().setToken(token);
|
|
1108
|
+
emitAuthTokenChanged(token);
|
|
1109
|
+
}
|
|
1110
|
+
clearToken() {
|
|
1111
|
+
localStorage.removeItem(TOKEN_KEY2);
|
|
1112
|
+
useAuthenticationStore.getState().clearToken();
|
|
1113
|
+
emitAuthTokenChanged(null);
|
|
1114
|
+
}
|
|
1115
|
+
isAuthenticated() {
|
|
1116
|
+
const token = useAuthenticationStore.getState().token;
|
|
1117
|
+
return !!token && !this.isTokenExpired(token);
|
|
1118
|
+
}
|
|
1119
|
+
isTokenExpired(token) {
|
|
1120
|
+
try {
|
|
1121
|
+
if (!token) return true;
|
|
1122
|
+
const decoded = this.parseJwtClaims(token);
|
|
1123
|
+
if (!decoded) return true;
|
|
1124
|
+
return decoded.exp * 1e3 < Date.now();
|
|
1125
|
+
} catch {
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
parseJwtClaims(token) {
|
|
1130
|
+
try {
|
|
1131
|
+
const base64Url = token.split(".")[1];
|
|
1132
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
1133
|
+
const jsonPayload = decodeURIComponent(
|
|
1134
|
+
atob(base64).split("").map((c) => {
|
|
1135
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
1136
|
+
}).join("")
|
|
1137
|
+
);
|
|
1138
|
+
return JSON.parse(jsonPayload);
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
debugLogger.error("Failed to parse JWT claims:", { error });
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
var authenticationService = new AuthenticationService();
|
|
1146
|
+
|
|
1147
|
+
// src/services/gateway/gateway.service.ts
|
|
1023
1148
|
var GatewayService = class {
|
|
1024
1149
|
constructor(_baseUrl, _tokenFactory, _feedbackEmail) {
|
|
1025
1150
|
this._baseUrl = _baseUrl;
|
|
@@ -1060,7 +1185,10 @@ var GatewayService = class {
|
|
|
1060
1185
|
});
|
|
1061
1186
|
instance.interceptors.response.use(
|
|
1062
1187
|
(response) => response,
|
|
1063
|
-
(error) =>
|
|
1188
|
+
(error) => {
|
|
1189
|
+
this._handleAuthFailure(error);
|
|
1190
|
+
return Promise.reject(this._normalizeAxiosError(error));
|
|
1191
|
+
}
|
|
1064
1192
|
);
|
|
1065
1193
|
return instance;
|
|
1066
1194
|
}
|
|
@@ -1081,6 +1209,24 @@ var GatewayService = class {
|
|
|
1081
1209
|
}
|
|
1082
1210
|
return new Error(error.message);
|
|
1083
1211
|
}
|
|
1212
|
+
_handleAuthFailure(error) {
|
|
1213
|
+
const status = error.response?.status;
|
|
1214
|
+
if (status !== 401 && status !== 403) {
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const data = error.response?.data;
|
|
1218
|
+
const code = data?.code;
|
|
1219
|
+
if (code !== "FORCE_RELOGIN" && code !== "ACCOUNT_LOCKED") {
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
try {
|
|
1223
|
+
authenticationService.clearToken();
|
|
1224
|
+
} catch {
|
|
1225
|
+
}
|
|
1226
|
+
if (typeof window !== "undefined" && typeof window.dispatchEvent === "function") {
|
|
1227
|
+
window.dispatchEvent(new CustomEvent("auth:force-relogin", { detail: { code } }));
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1084
1230
|
_createHttpError(message, response) {
|
|
1085
1231
|
return Object.assign(new Error(message), { response });
|
|
1086
1232
|
}
|
|
@@ -1448,15 +1594,15 @@ var GatewayService = class {
|
|
|
1448
1594
|
);
|
|
1449
1595
|
}
|
|
1450
1596
|
_getHeaders() {
|
|
1451
|
-
const
|
|
1597
|
+
const rawToken2 = this._tokenFactory();
|
|
1452
1598
|
const headers = {
|
|
1453
1599
|
"Content-Type": "application/json"
|
|
1454
1600
|
};
|
|
1455
|
-
if (!
|
|
1601
|
+
if (!rawToken2) {
|
|
1456
1602
|
debugLogger.warn("GatewayService: No token found, skipping Authorization header");
|
|
1457
1603
|
return headers;
|
|
1458
1604
|
}
|
|
1459
|
-
const token =
|
|
1605
|
+
const token = rawToken2.trim();
|
|
1460
1606
|
if (token === "") {
|
|
1461
1607
|
debugLogger.warn("GatewayService: Token factory returned empty string");
|
|
1462
1608
|
return headers;
|
|
@@ -2928,7 +3074,7 @@ var AIProviderFactory = class {
|
|
|
2928
3074
|
};
|
|
2929
3075
|
|
|
2930
3076
|
// src/store/aiProviderStore.ts
|
|
2931
|
-
var useAIProviderStore =
|
|
3077
|
+
var useAIProviderStore = create2((set, get) => ({
|
|
2932
3078
|
provider: null,
|
|
2933
3079
|
config: null,
|
|
2934
3080
|
setProvider: (provider, config) => set({ provider, config }),
|
|
@@ -2954,8 +3100,12 @@ var useAIProviderStore = create((set, get) => ({
|
|
|
2954
3100
|
}));
|
|
2955
3101
|
|
|
2956
3102
|
export {
|
|
3103
|
+
useAuthenticationStore,
|
|
3104
|
+
readPersistedToken,
|
|
3105
|
+
AUTH_TOKEN_CHANGED_EVENT,
|
|
3106
|
+
authenticationService,
|
|
2957
3107
|
GatewayService,
|
|
2958
3108
|
AIProviderFactory,
|
|
2959
3109
|
useAIProviderStore
|
|
2960
3110
|
};
|
|
2961
|
-
//# sourceMappingURL=chunk-
|
|
3111
|
+
//# sourceMappingURL=chunk-43MLINPL.mjs.map
|