@burtson-labs/bandit-engine 2.0.51 → 2.0.53

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 (48) hide show
  1. package/dist/{aiProviderStore-3N3VE6D4.mjs → aiProviderStore-337QNQB3.mjs} +2 -2
  2. package/dist/{chat-W5IFNEUC.mjs → chat-U4SE4JQK.mjs} +6 -6
  3. package/dist/chat-provider.js +242 -17
  4. package/dist/chat-provider.js.map +1 -1
  5. package/dist/chat-provider.mjs +4 -4
  6. package/dist/{chunk-LXD3IV6Z.mjs → chunk-2BGORTWS.mjs} +4 -4
  7. package/dist/{chunk-IDH2YOW3.mjs → chunk-557E5VZ2.mjs} +198 -11
  8. package/dist/chunk-557E5VZ2.mjs.map +1 -0
  9. package/dist/{chunk-QFSEZAG6.mjs → chunk-AVV7HDGR.mjs} +34 -3
  10. package/dist/chunk-AVV7HDGR.mjs.map +1 -0
  11. package/dist/{chunk-N7RMUOFB.mjs → chunk-EULV5CHD.mjs} +2 -2
  12. package/dist/{chunk-STMXPFAQ.mjs → chunk-GNE4TTSI.mjs} +48 -15
  13. package/dist/chunk-GNE4TTSI.mjs.map +1 -0
  14. package/dist/{chunk-BENL3EF2.mjs → chunk-H3BYFEIE.mjs} +18 -10
  15. package/dist/chunk-H3BYFEIE.mjs.map +1 -0
  16. package/dist/{chunk-HETIHZ42.mjs → chunk-NZKLKZJT.mjs} +3 -3
  17. package/dist/{chunk-JBXNXSAH.mjs → chunk-O54PTFJM.mjs} +460 -181
  18. package/dist/chunk-O54PTFJM.mjs.map +1 -0
  19. package/dist/{chunk-EWUUF4GE.mjs → chunk-UFSEYVRS.mjs} +3 -3
  20. package/dist/cli.js +1 -1
  21. package/dist/cli.js.map +1 -1
  22. package/dist/{gateway-oScD5tvE.d.ts → gateway-C5T5FfCy.d.mts} +32 -0
  23. package/dist/{gateway-oScD5tvE.d.mts → gateway-C5T5FfCy.d.ts} +32 -0
  24. package/dist/index.d.mts +2 -2
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +738 -202
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +9 -9
  29. package/dist/management/management.js +708 -202
  30. package/dist/management/management.js.map +1 -1
  31. package/dist/management/management.mjs +7 -7
  32. package/dist/modals/chat-modal/chat-modal.js +214 -17
  33. package/dist/modals/chat-modal/chat-modal.js.map +1 -1
  34. package/dist/modals/chat-modal/chat-modal.mjs +4 -4
  35. package/dist/public-types.d.mts +1 -1
  36. package/dist/public-types.d.ts +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunk-BENL3EF2.mjs.map +0 -1
  39. package/dist/chunk-IDH2YOW3.mjs.map +0 -1
  40. package/dist/chunk-JBXNXSAH.mjs.map +0 -1
  41. package/dist/chunk-QFSEZAG6.mjs.map +0 -1
  42. package/dist/chunk-STMXPFAQ.mjs.map +0 -1
  43. /package/dist/{aiProviderStore-3N3VE6D4.mjs.map → aiProviderStore-337QNQB3.mjs.map} +0 -0
  44. /package/dist/{chat-W5IFNEUC.mjs.map → chat-U4SE4JQK.mjs.map} +0 -0
  45. /package/dist/{chunk-LXD3IV6Z.mjs.map → chunk-2BGORTWS.mjs.map} +0 -0
  46. /package/dist/{chunk-N7RMUOFB.mjs.map → chunk-EULV5CHD.mjs.map} +0 -0
  47. /package/dist/{chunk-HETIHZ42.mjs.map → chunk-NZKLKZJT.mjs.map} +0 -0
  48. /package/dist/{chunk-EWUUF4GE.mjs.map → chunk-UFSEYVRS.mjs.map} +0 -0
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  ChatProvider,
3
3
  chat_provider_default
4
- } from "./chunk-QFSEZAG6.mjs";
4
+ } from "./chunk-AVV7HDGR.mjs";
5
5
  import "./chunk-ONQMRE2G.mjs";
6
- import "./chunk-EWUUF4GE.mjs";
6
+ import "./chunk-UFSEYVRS.mjs";
7
7
  import "./chunk-EHNWQ4T3.mjs";
8
- import "./chunk-IDH2YOW3.mjs";
8
+ import "./chunk-557E5VZ2.mjs";
9
9
  import "./chunk-7ZDS33S2.mjs";
10
- import "./chunk-BENL3EF2.mjs";
10
+ import "./chunk-H3BYFEIE.mjs";
11
11
  import "./chunk-KCI46M23.mjs";
12
12
  import "./chunk-BJTO5JO5.mjs";
13
13
  export {
@@ -8,14 +8,14 @@ import {
8
8
  useNotificationService,
9
9
  useTTS,
10
10
  useVoiceStore
11
- } from "./chunk-HETIHZ42.mjs";
11
+ } from "./chunk-NZKLKZJT.mjs";
12
12
  import {
13
13
  brandingService_default,
14
14
  toTitleCase,
15
15
  useAIQueryStore,
16
16
  useConversationStore,
17
17
  useMemoryStore
18
- } from "./chunk-IDH2YOW3.mjs";
18
+ } from "./chunk-557E5VZ2.mjs";
19
19
  import {
20
20
  indexedDBService_default,
21
21
  useModelStore,
@@ -24,7 +24,7 @@ import {
24
24
  } from "./chunk-7ZDS33S2.mjs";
25
25
  import {
26
26
  useAIProviderStore
27
- } from "./chunk-BENL3EF2.mjs";
27
+ } from "./chunk-H3BYFEIE.mjs";
28
28
  import {
29
29
  debugLogger
30
30
  } from "./chunk-KCI46M23.mjs";
@@ -2807,4 +2807,4 @@ export {
2807
2807
  MAX_WINDOWED_HEIGHT,
2808
2808
  chat_modal_default
2809
2809
  };
2810
- //# sourceMappingURL=chunk-LXD3IV6Z.mjs.map
2810
+ //# sourceMappingURL=chunk-2BGORTWS.mjs.map
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-7ZDS33S2.mjs";
6
6
  import {
7
7
  useAIProviderStore
8
- } from "./chunk-BENL3EF2.mjs";
8
+ } from "./chunk-H3BYFEIE.mjs";
9
9
  import {
10
10
  debugLogger
11
11
  } from "./chunk-KCI46M23.mjs";
@@ -63,6 +63,15 @@ var useAuthenticationStore = create((set) => ({
63
63
 
64
64
  // src/services/auth/authenticationService.ts
65
65
  var TOKEN_KEY2 = "authToken";
66
+ var AUTH_TOKEN_CHANGED_EVENT = "bandit:auth-token-changed";
67
+ function emitAuthTokenChanged(token) {
68
+ if (typeof window === "undefined") {
69
+ return;
70
+ }
71
+ window.dispatchEvent(new CustomEvent(AUTH_TOKEN_CHANGED_EVENT, {
72
+ detail: { token }
73
+ }));
74
+ }
66
75
  var AuthenticationService = class {
67
76
  getToken() {
68
77
  const token = localStorage.getItem(TOKEN_KEY2);
@@ -71,10 +80,12 @@ var AuthenticationService = class {
71
80
  setToken(token) {
72
81
  localStorage.setItem(TOKEN_KEY2, token);
73
82
  useAuthenticationStore.getState().setToken(token);
83
+ emitAuthTokenChanged(token);
74
84
  }
75
85
  clearToken() {
76
86
  localStorage.removeItem(TOKEN_KEY2);
77
87
  useAuthenticationStore.getState().clearToken();
88
+ emitAuthTokenChanged(null);
78
89
  }
79
90
  isAuthenticated() {
80
91
  const token = useAuthenticationStore.getState().token;
@@ -1076,9 +1087,14 @@ async function syncConversations(request) {
1076
1087
 
1077
1088
  // src/store/conversationSyncStore.ts
1078
1089
  var DEVICE_STORAGE_KEY = "banditConversationDeviceId";
1090
+ var SYNC_IDENTITY_STORAGE_KEY = "banditConversationSyncIdentity";
1079
1091
  var PAYLOAD_VERSION = 1;
1080
1092
  var MAX_CONVERSATION_BYTES = 12 * 1024 * 1024;
1081
1093
  var WARN_CONVERSATION_BYTES = 10 * 1024 * 1024;
1094
+ var PROJECT_DB_NAME = "bandit-projects";
1095
+ var PROJECT_DB_VERSION = 1;
1096
+ var PROJECT_STORE_NAME = "projects";
1097
+ var PROJECT_STORE_CONFIGS = [{ name: PROJECT_STORE_NAME, keyPath: "id" }];
1082
1098
  var suppressTracking = false;
1083
1099
  var conversationsMeta = /* @__PURE__ */ new Map();
1084
1100
  var projectsMeta = /* @__PURE__ */ new Map();
@@ -1103,9 +1119,99 @@ function ensureDeviceId() {
1103
1119
  return uuidv43();
1104
1120
  }
1105
1121
  }
1122
+ function getStoredSyncIdentity() {
1123
+ if (typeof window === "undefined") {
1124
+ return null;
1125
+ }
1126
+ try {
1127
+ return window.localStorage.getItem(SYNC_IDENTITY_STORAGE_KEY);
1128
+ } catch (error) {
1129
+ debugLogger.warn("conversationSyncStore: unable to read stored sync identity", { error });
1130
+ return null;
1131
+ }
1132
+ }
1133
+ function setStoredSyncIdentity(identity) {
1134
+ if (typeof window === "undefined") {
1135
+ return;
1136
+ }
1137
+ try {
1138
+ if (identity) {
1139
+ window.localStorage.setItem(SYNC_IDENTITY_STORAGE_KEY, identity);
1140
+ } else {
1141
+ window.localStorage.removeItem(SYNC_IDENTITY_STORAGE_KEY);
1142
+ }
1143
+ } catch (error) {
1144
+ debugLogger.warn("conversationSyncStore: unable to persist sync identity", { error });
1145
+ }
1146
+ }
1106
1147
  function getPackageDefaultAdvancedKnowledgeSync() {
1107
1148
  return usePackageSettingsStore.getState().settings?.advancedKnowledgeSyncDefaultEnabled;
1108
1149
  }
1150
+ function clearAutoSyncTimer() {
1151
+ if (autoSyncTimeout) {
1152
+ clearTimeout(autoSyncTimeout);
1153
+ autoSyncTimeout = null;
1154
+ }
1155
+ }
1156
+ function resolveAuthIdentity(token) {
1157
+ if (!token) {
1158
+ return null;
1159
+ }
1160
+ const claims = authenticationService.parseJwtClaims(token);
1161
+ if (claims?.sub) {
1162
+ return claims.sub;
1163
+ }
1164
+ if (claims?.email) {
1165
+ return `email:${claims.email.toLowerCase()}`;
1166
+ }
1167
+ return `token:${token.slice(0, 32)}`;
1168
+ }
1169
+ function buildQueueResetState() {
1170
+ return {
1171
+ pendingConversationUpserts: /* @__PURE__ */ new Set(),
1172
+ pendingConversationDeletes: /* @__PURE__ */ new Set(),
1173
+ pendingProjectUpserts: /* @__PURE__ */ new Set(),
1174
+ pendingProjectDeletes: /* @__PURE__ */ new Set(),
1175
+ conflicts: null,
1176
+ lastSyncAt: null,
1177
+ cursor: null,
1178
+ lastError: null,
1179
+ totalConversationsOnServer: void 0,
1180
+ totalProjectsOnServer: void 0,
1181
+ hasCompletedInitialUpload: false,
1182
+ warningConversations: [],
1183
+ oversizedConversations: []
1184
+ };
1185
+ }
1186
+ async function clearLocalStoresForIdentitySwitch(fromIdentity, toIdentity) {
1187
+ const conversationCount = useConversationStore.getState().conversations.length;
1188
+ const projectCount = useProjectStore.getState().projects.length;
1189
+ debugLogger.warn("conversationSyncStore: auth identity changed, clearing local conversation/project cache", {
1190
+ fromIdentity,
1191
+ toIdentity,
1192
+ conversationCount,
1193
+ projectCount
1194
+ });
1195
+ suppressTracking = true;
1196
+ try {
1197
+ await useConversationStore.getState().clearAllConversations();
1198
+ await indexedDBService_default.clear(
1199
+ PROJECT_DB_NAME,
1200
+ PROJECT_DB_VERSION,
1201
+ PROJECT_STORE_NAME,
1202
+ PROJECT_STORE_CONFIGS
1203
+ );
1204
+ useProjectStore.setState({ projects: [] });
1205
+ conversationsMeta = snapshotConversationMetaMap(useConversationStore.getState().conversations);
1206
+ projectsMeta = snapshotProjectMetaMap(useProjectStore.getState().projects);
1207
+ } catch (error) {
1208
+ debugLogger.error("conversationSyncStore: failed to clear local stores on auth switch", {
1209
+ error: error instanceof Error ? error.message : String(error)
1210
+ });
1211
+ } finally {
1212
+ suppressTracking = false;
1213
+ }
1214
+ }
1109
1215
  function mapConversationToDTO(conversation) {
1110
1216
  const updatedAtIso = (conversation.updatedAt ?? /* @__PURE__ */ new Date()).toISOString();
1111
1217
  const createdAtIso = conversation.createdAt ? conversation.createdAt.toISOString() : null;
@@ -1474,6 +1580,9 @@ async function applyServerResults(response) {
1474
1580
  }
1475
1581
  var useConversationSyncStore = create6((set, get) => ({
1476
1582
  initialized: false,
1583
+ hasLoadedPreference: false,
1584
+ initializedForToken: null,
1585
+ initializedForIdentity: null,
1477
1586
  syncEnabled: false,
1478
1587
  status: "disabled",
1479
1588
  lastSyncAt: null,
@@ -1493,20 +1602,63 @@ var useConversationSyncStore = create6((set, get) => ({
1493
1602
  warningConversations: [],
1494
1603
  oversizedConversations: [],
1495
1604
  async initialize() {
1496
- if (get().initialized) {
1497
- return;
1498
- }
1499
1605
  ensureTrackersInitialized();
1500
1606
  const gatewayUrl = usePackageSettingsStore.getState().settings?.gatewayApiUrl;
1607
+ const token = authenticationService.getToken();
1608
+ const tokenIdentity = resolveAuthIdentity(token);
1609
+ const current = get();
1610
+ const storedIdentity = getStoredSyncIdentity();
1611
+ const knownIdentity = current.initializedForIdentity ?? storedIdentity;
1612
+ if (current.initialized && current.hasLoadedPreference && knownIdentity && tokenIdentity && knownIdentity === tokenIdentity) {
1613
+ return;
1614
+ }
1615
+ const hasIdentitySwitch = Boolean(
1616
+ knownIdentity && tokenIdentity && knownIdentity !== tokenIdentity
1617
+ );
1618
+ if (hasIdentitySwitch) {
1619
+ clearAutoSyncTimer();
1620
+ set({
1621
+ ...buildQueueResetState(),
1622
+ syncEnabled: false,
1623
+ status: "disabled",
1624
+ hasLoadedPreference: false,
1625
+ initializedForToken: null,
1626
+ initializedForIdentity: tokenIdentity
1627
+ });
1628
+ await clearLocalStoresForIdentitySwitch(
1629
+ knownIdentity,
1630
+ tokenIdentity
1631
+ );
1632
+ setStoredSyncIdentity(tokenIdentity);
1633
+ }
1501
1634
  if (!gatewayUrl) {
1502
1635
  debugLogger.info("conversationSyncStore: gateway API URL not configured; sync disabled");
1503
- set({ initialized: true, status: "disabled", syncEnabled: false });
1636
+ if (tokenIdentity) {
1637
+ setStoredSyncIdentity(tokenIdentity);
1638
+ }
1639
+ set({
1640
+ ...buildQueueResetState(),
1641
+ initialized: true,
1642
+ hasLoadedPreference: false,
1643
+ initializedForToken: null,
1644
+ initializedForIdentity: tokenIdentity,
1645
+ status: "disabled",
1646
+ syncEnabled: false
1647
+ });
1504
1648
  return;
1505
1649
  }
1506
- const token = authenticationService.getToken();
1507
1650
  if (!token) {
1508
1651
  debugLogger.info("conversationSyncStore: no authentication token; sync disabled until login");
1509
- set({ initialized: true, status: "disabled", syncEnabled: false });
1652
+ clearAutoSyncTimer();
1653
+ set({
1654
+ ...buildQueueResetState(),
1655
+ initialized: true,
1656
+ hasLoadedPreference: false,
1657
+ initializedForToken: null,
1658
+ initializedForIdentity: null,
1659
+ status: "disabled",
1660
+ syncEnabled: false
1661
+ });
1510
1662
  return;
1511
1663
  }
1512
1664
  try {
@@ -1528,14 +1680,27 @@ var useConversationSyncStore = create6((set, get) => ({
1528
1680
  isAdvancedVectorFeaturesEnabled: get().isAdvancedVectorFeaturesEnabled
1529
1681
  }
1530
1682
  });
1531
- set({ initialized: true });
1683
+ set({
1684
+ initialized: true,
1685
+ hasLoadedPreference: true,
1686
+ initializedForToken: token,
1687
+ initializedForIdentity: tokenIdentity
1688
+ });
1689
+ setStoredSyncIdentity(tokenIdentity);
1532
1690
  if (preference.syncEnabled) {
1533
1691
  await get().runSync({ force: true });
1534
1692
  }
1535
1693
  } catch (error) {
1536
1694
  const message = error instanceof Error ? error.message : "Failed to load conversation sync preference";
1537
1695
  debugLogger.error("conversationSyncStore: initialization failed", { error: message });
1538
- set({ initialized: true, status: "error", lastError: message });
1696
+ set({
1697
+ initialized: true,
1698
+ hasLoadedPreference: false,
1699
+ initializedForToken: null,
1700
+ initializedForIdentity: tokenIdentity,
1701
+ status: "error",
1702
+ lastError: message
1703
+ });
1539
1704
  }
1540
1705
  },
1541
1706
  async setSyncEnabled(enabled) {
@@ -1563,6 +1728,12 @@ var useConversationSyncStore = create6((set, get) => ({
1563
1728
  isAdvancedVectorFeaturesEnabled
1564
1729
  }
1565
1730
  });
1731
+ set({
1732
+ hasLoadedPreference: true,
1733
+ initializedForToken: authenticationService.getToken(),
1734
+ initializedForIdentity: resolveAuthIdentity(authenticationService.getToken())
1735
+ });
1736
+ setStoredSyncIdentity(resolveAuthIdentity(authenticationService.getToken()));
1566
1737
  if (enabled) {
1567
1738
  set({ hasCompletedInitialUpload: false });
1568
1739
  }
@@ -1600,6 +1771,12 @@ var useConversationSyncStore = create6((set, get) => ({
1600
1771
  isAdvancedVectorFeaturesEnabled: enabled
1601
1772
  }
1602
1773
  });
1774
+ set({
1775
+ hasLoadedPreference: true,
1776
+ initializedForToken: authenticationService.getToken(),
1777
+ initializedForIdentity: resolveAuthIdentity(authenticationService.getToken())
1778
+ });
1779
+ setStoredSyncIdentity(resolveAuthIdentity(authenticationService.getToken()));
1603
1780
  if (preference.syncEnabled && preference.isAdvancedVectorFeaturesEnabled) {
1604
1781
  await get().runSync({ force: true });
1605
1782
  }
@@ -1645,6 +1822,15 @@ var useConversationSyncStore = create6((set, get) => ({
1645
1822
  debugLogger.error("conversationSyncStore: runSync error - missing auth token");
1646
1823
  return;
1647
1824
  }
1825
+ const tokenIdentity = resolveAuthIdentity(token);
1826
+ if (state.initializedForIdentity && tokenIdentity && state.initializedForIdentity !== tokenIdentity) {
1827
+ debugLogger.warn("conversationSyncStore: runSync aborted due auth identity mismatch; reinitializing", {
1828
+ initializedForIdentity: state.initializedForIdentity,
1829
+ tokenIdentity
1830
+ });
1831
+ await get().initialize();
1832
+ return;
1833
+ }
1648
1834
  const pendingConversationIds = Array.from(state.pendingConversationUpserts);
1649
1835
  const pendingConversationDeleteIds = Array.from(state.pendingConversationDeletes);
1650
1836
  const pendingProjectIds = Array.from(state.pendingProjectUpserts);
@@ -4693,7 +4879,7 @@ var useVectorStore = () => {
4693
4879
  const [hasCompatibleProvider, setHasCompatibleProvider] = useState2(false);
4694
4880
  const checkProviderCompatibility = useCallback2(async () => {
4695
4881
  try {
4696
- const { useAIProviderStore: useAIProviderStore2 } = await import("./aiProviderStore-3N3VE6D4.mjs");
4882
+ const { useAIProviderStore: useAIProviderStore2 } = await import("./aiProviderStore-337QNQB3.mjs");
4697
4883
  const aiProviderState = useAIProviderStore2.getState();
4698
4884
  const provider = aiProviderState.provider;
4699
4885
  const config = aiProviderState.config;
@@ -5699,6 +5885,7 @@ var NotificationProvider = ({
5699
5885
 
5700
5886
  export {
5701
5887
  useAuthenticationStore,
5888
+ AUTH_TOKEN_CHANGED_EVENT,
5702
5889
  authenticationService,
5703
5890
  useAIQueryStore,
5704
5891
  sanitizeConversationName,
@@ -5737,4 +5924,4 @@ export {
5737
5924
  useNotification,
5738
5925
  NotificationProvider
5739
5926
  };
5740
- //# sourceMappingURL=chunk-IDH2YOW3.mjs.map
5927
+ //# sourceMappingURL=chunk-557E5VZ2.mjs.map