@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,14 +1,14 @@
1
1
  import {
2
2
  management_default
3
- } from "../chunk-JBXNXSAH.mjs";
4
- import "../chunk-N7RMUOFB.mjs";
5
- import "../chunk-EWUUF4GE.mjs";
3
+ } from "../chunk-O54PTFJM.mjs";
4
+ import "../chunk-EULV5CHD.mjs";
5
+ import "../chunk-UFSEYVRS.mjs";
6
6
  import "../chunk-EHNWQ4T3.mjs";
7
- import "../chunk-LXD3IV6Z.mjs";
8
- import "../chunk-HETIHZ42.mjs";
9
- import "../chunk-IDH2YOW3.mjs";
7
+ import "../chunk-2BGORTWS.mjs";
8
+ import "../chunk-NZKLKZJT.mjs";
9
+ import "../chunk-557E5VZ2.mjs";
10
10
  import "../chunk-7ZDS33S2.mjs";
11
- import "../chunk-BENL3EF2.mjs";
11
+ import "../chunk-H3BYFEIE.mjs";
12
12
  import "../chunk-KCI46M23.mjs";
13
13
  import "../chunk-BJTO5JO5.mjs";
14
14
  export {
@@ -1603,7 +1603,8 @@ var init_gateway_service = __esm({
1603
1603
  index: 0,
1604
1604
  delta: {
1605
1605
  role: parsed.message.role,
1606
- content: parsed.message.content
1606
+ content: parsed.message.content,
1607
+ tool_calls: parsed.message.tool_calls
1607
1608
  },
1608
1609
  finish_reason: parsed.done ? parsed.done_reason || "stop" : null
1609
1610
  }]
@@ -2583,6 +2584,7 @@ var init_gateway_provider = __esm({
2583
2584
  }
2584
2585
  }
2585
2586
  }
2587
+ const toolAwareRequest = request;
2586
2588
  const gatewayRequest = {
2587
2589
  model: request.model,
2588
2590
  messages,
@@ -2591,7 +2593,8 @@ var init_gateway_provider = __esm({
2591
2593
  max_tokens: request.maxTokens,
2592
2594
  provider: this.config.provider,
2593
2595
  // Only include top-level images for Ollama (fallback)
2594
- images: this.config.provider === "ollama" ? request.images : void 0
2596
+ images: this.config.provider === "ollama" ? request.images : void 0,
2597
+ tools: toolAwareRequest.tools?.length ? toolAwareRequest.tools : void 0
2595
2598
  };
2596
2599
  debugLogger.debug("Gateway provider chat request", {
2597
2600
  model: request.model,
@@ -2608,13 +2611,18 @@ var init_gateway_provider = __esm({
2608
2611
  }))
2609
2612
  });
2610
2613
  return this.gatewayService.chat(gatewayRequest).pipe(
2611
- (0, import_rxjs7.map)((response) => ({
2612
- message: {
2613
- content: response.choices?.[0]?.message?.content || response.choices?.[0]?.delta?.content || "",
2614
- role: "assistant"
2615
- },
2616
- done: response.choices?.[0]?.finish_reason === "stop" || response.choices?.[0]?.finish_reason === "length"
2617
- }))
2614
+ (0, import_rxjs7.map)((response) => {
2615
+ const choice = response.choices?.[0];
2616
+ const toolCalls = choice?.message?.tool_calls ?? choice?.delta?.tool_calls;
2617
+ return {
2618
+ message: {
2619
+ content: choice?.message?.content ?? choice?.delta?.content ?? "",
2620
+ role: "assistant",
2621
+ tool_calls: toolCalls
2622
+ },
2623
+ done: choice?.finish_reason === "stop" || choice?.finish_reason === "length" || choice?.finish_reason === "tool_calls"
2624
+ };
2625
+ })
2618
2626
  );
2619
2627
  }
2620
2628
  generate(request) {
@@ -7845,6 +7853,15 @@ init_packageSettingsStore();
7845
7853
  // src/services/auth/authenticationService.ts
7846
7854
  init_debugLogger();
7847
7855
  var TOKEN_KEY2 = "authToken";
7856
+ var AUTH_TOKEN_CHANGED_EVENT = "bandit:auth-token-changed";
7857
+ function emitAuthTokenChanged(token) {
7858
+ if (typeof window === "undefined") {
7859
+ return;
7860
+ }
7861
+ window.dispatchEvent(new CustomEvent(AUTH_TOKEN_CHANGED_EVENT, {
7862
+ detail: { token }
7863
+ }));
7864
+ }
7848
7865
  var AuthenticationService = class {
7849
7866
  getToken() {
7850
7867
  const token = localStorage.getItem(TOKEN_KEY2);
@@ -7853,10 +7870,12 @@ var AuthenticationService = class {
7853
7870
  setToken(token) {
7854
7871
  localStorage.setItem(TOKEN_KEY2, token);
7855
7872
  useAuthenticationStore.getState().setToken(token);
7873
+ emitAuthTokenChanged(token);
7856
7874
  }
7857
7875
  clearToken() {
7858
7876
  localStorage.removeItem(TOKEN_KEY2);
7859
7877
  useAuthenticationStore.getState().clearToken();
7878
+ emitAuthTokenChanged(null);
7860
7879
  }
7861
7880
  isAuthenticated() {
7862
7881
  const token = useAuthenticationStore.getState().token;
@@ -7890,6 +7909,9 @@ var AuthenticationService = class {
7890
7909
  };
7891
7910
  var authenticationService = new AuthenticationService();
7892
7911
 
7912
+ // src/store/conversationSyncStore.ts
7913
+ init_indexedDBService();
7914
+
7893
7915
  // src/services/conversationSync/conversationSyncService.ts
7894
7916
  init_packageSettingsStore();
7895
7917
  init_debugLogger();
@@ -7989,9 +8011,14 @@ async function syncConversations(request) {
7989
8011
  // src/store/conversationSyncStore.ts
7990
8012
  init_debugLogger();
7991
8013
  var DEVICE_STORAGE_KEY = "banditConversationDeviceId";
8014
+ var SYNC_IDENTITY_STORAGE_KEY = "banditConversationSyncIdentity";
7992
8015
  var PAYLOAD_VERSION = 1;
7993
8016
  var MAX_CONVERSATION_BYTES = 12 * 1024 * 1024;
7994
8017
  var WARN_CONVERSATION_BYTES = 10 * 1024 * 1024;
8018
+ var PROJECT_DB_NAME = "bandit-projects";
8019
+ var PROJECT_DB_VERSION = 1;
8020
+ var PROJECT_STORE_NAME = "projects";
8021
+ var PROJECT_STORE_CONFIGS = [{ name: PROJECT_STORE_NAME, keyPath: "id" }];
7995
8022
  var suppressTracking = false;
7996
8023
  var conversationsMeta = /* @__PURE__ */ new Map();
7997
8024
  var projectsMeta = /* @__PURE__ */ new Map();
@@ -8016,9 +8043,99 @@ function ensureDeviceId() {
8016
8043
  return (0, import_uuid4.v4)();
8017
8044
  }
8018
8045
  }
8046
+ function getStoredSyncIdentity() {
8047
+ if (typeof window === "undefined") {
8048
+ return null;
8049
+ }
8050
+ try {
8051
+ return window.localStorage.getItem(SYNC_IDENTITY_STORAGE_KEY);
8052
+ } catch (error) {
8053
+ debugLogger.warn("conversationSyncStore: unable to read stored sync identity", { error });
8054
+ return null;
8055
+ }
8056
+ }
8057
+ function setStoredSyncIdentity(identity) {
8058
+ if (typeof window === "undefined") {
8059
+ return;
8060
+ }
8061
+ try {
8062
+ if (identity) {
8063
+ window.localStorage.setItem(SYNC_IDENTITY_STORAGE_KEY, identity);
8064
+ } else {
8065
+ window.localStorage.removeItem(SYNC_IDENTITY_STORAGE_KEY);
8066
+ }
8067
+ } catch (error) {
8068
+ debugLogger.warn("conversationSyncStore: unable to persist sync identity", { error });
8069
+ }
8070
+ }
8019
8071
  function getPackageDefaultAdvancedKnowledgeSync() {
8020
8072
  return usePackageSettingsStore.getState().settings?.advancedKnowledgeSyncDefaultEnabled;
8021
8073
  }
8074
+ function clearAutoSyncTimer() {
8075
+ if (autoSyncTimeout) {
8076
+ clearTimeout(autoSyncTimeout);
8077
+ autoSyncTimeout = null;
8078
+ }
8079
+ }
8080
+ function resolveAuthIdentity(token) {
8081
+ if (!token) {
8082
+ return null;
8083
+ }
8084
+ const claims = authenticationService.parseJwtClaims(token);
8085
+ if (claims?.sub) {
8086
+ return claims.sub;
8087
+ }
8088
+ if (claims?.email) {
8089
+ return `email:${claims.email.toLowerCase()}`;
8090
+ }
8091
+ return `token:${token.slice(0, 32)}`;
8092
+ }
8093
+ function buildQueueResetState() {
8094
+ return {
8095
+ pendingConversationUpserts: /* @__PURE__ */ new Set(),
8096
+ pendingConversationDeletes: /* @__PURE__ */ new Set(),
8097
+ pendingProjectUpserts: /* @__PURE__ */ new Set(),
8098
+ pendingProjectDeletes: /* @__PURE__ */ new Set(),
8099
+ conflicts: null,
8100
+ lastSyncAt: null,
8101
+ cursor: null,
8102
+ lastError: null,
8103
+ totalConversationsOnServer: void 0,
8104
+ totalProjectsOnServer: void 0,
8105
+ hasCompletedInitialUpload: false,
8106
+ warningConversations: [],
8107
+ oversizedConversations: []
8108
+ };
8109
+ }
8110
+ async function clearLocalStoresForIdentitySwitch(fromIdentity, toIdentity) {
8111
+ const conversationCount = useConversationStore.getState().conversations.length;
8112
+ const projectCount = useProjectStore.getState().projects.length;
8113
+ debugLogger.warn("conversationSyncStore: auth identity changed, clearing local conversation/project cache", {
8114
+ fromIdentity,
8115
+ toIdentity,
8116
+ conversationCount,
8117
+ projectCount
8118
+ });
8119
+ suppressTracking = true;
8120
+ try {
8121
+ await useConversationStore.getState().clearAllConversations();
8122
+ await indexedDBService_default.clear(
8123
+ PROJECT_DB_NAME,
8124
+ PROJECT_DB_VERSION,
8125
+ PROJECT_STORE_NAME,
8126
+ PROJECT_STORE_CONFIGS
8127
+ );
8128
+ useProjectStore.setState({ projects: [] });
8129
+ conversationsMeta = snapshotConversationMetaMap(useConversationStore.getState().conversations);
8130
+ projectsMeta = snapshotProjectMetaMap(useProjectStore.getState().projects);
8131
+ } catch (error) {
8132
+ debugLogger.error("conversationSyncStore: failed to clear local stores on auth switch", {
8133
+ error: error instanceof Error ? error.message : String(error)
8134
+ });
8135
+ } finally {
8136
+ suppressTracking = false;
8137
+ }
8138
+ }
8022
8139
  function mapConversationToDTO(conversation) {
8023
8140
  const updatedAtIso = (conversation.updatedAt ?? /* @__PURE__ */ new Date()).toISOString();
8024
8141
  const createdAtIso = conversation.createdAt ? conversation.createdAt.toISOString() : null;
@@ -8387,6 +8504,9 @@ async function applyServerResults(response) {
8387
8504
  }
8388
8505
  var useConversationSyncStore = (0, import_zustand11.create)((set, get) => ({
8389
8506
  initialized: false,
8507
+ hasLoadedPreference: false,
8508
+ initializedForToken: null,
8509
+ initializedForIdentity: null,
8390
8510
  syncEnabled: false,
8391
8511
  status: "disabled",
8392
8512
  lastSyncAt: null,
@@ -8406,20 +8526,63 @@ var useConversationSyncStore = (0, import_zustand11.create)((set, get) => ({
8406
8526
  warningConversations: [],
8407
8527
  oversizedConversations: [],
8408
8528
  async initialize() {
8409
- if (get().initialized) {
8410
- return;
8411
- }
8412
8529
  ensureTrackersInitialized();
8413
8530
  const gatewayUrl = usePackageSettingsStore.getState().settings?.gatewayApiUrl;
8531
+ const token = authenticationService.getToken();
8532
+ const tokenIdentity = resolveAuthIdentity(token);
8533
+ const current = get();
8534
+ const storedIdentity = getStoredSyncIdentity();
8535
+ const knownIdentity = current.initializedForIdentity ?? storedIdentity;
8536
+ if (current.initialized && current.hasLoadedPreference && knownIdentity && tokenIdentity && knownIdentity === tokenIdentity) {
8537
+ return;
8538
+ }
8539
+ const hasIdentitySwitch = Boolean(
8540
+ knownIdentity && tokenIdentity && knownIdentity !== tokenIdentity
8541
+ );
8542
+ if (hasIdentitySwitch) {
8543
+ clearAutoSyncTimer();
8544
+ set({
8545
+ ...buildQueueResetState(),
8546
+ syncEnabled: false,
8547
+ status: "disabled",
8548
+ hasLoadedPreference: false,
8549
+ initializedForToken: null,
8550
+ initializedForIdentity: tokenIdentity
8551
+ });
8552
+ await clearLocalStoresForIdentitySwitch(
8553
+ knownIdentity,
8554
+ tokenIdentity
8555
+ );
8556
+ setStoredSyncIdentity(tokenIdentity);
8557
+ }
8414
8558
  if (!gatewayUrl) {
8415
8559
  debugLogger.info("conversationSyncStore: gateway API URL not configured; sync disabled");
8416
- set({ initialized: true, status: "disabled", syncEnabled: false });
8560
+ if (tokenIdentity) {
8561
+ setStoredSyncIdentity(tokenIdentity);
8562
+ }
8563
+ set({
8564
+ ...buildQueueResetState(),
8565
+ initialized: true,
8566
+ hasLoadedPreference: false,
8567
+ initializedForToken: null,
8568
+ initializedForIdentity: tokenIdentity,
8569
+ status: "disabled",
8570
+ syncEnabled: false
8571
+ });
8417
8572
  return;
8418
8573
  }
8419
- const token = authenticationService.getToken();
8420
8574
  if (!token) {
8421
8575
  debugLogger.info("conversationSyncStore: no authentication token; sync disabled until login");
8422
- set({ initialized: true, status: "disabled", syncEnabled: false });
8576
+ clearAutoSyncTimer();
8577
+ set({
8578
+ ...buildQueueResetState(),
8579
+ initialized: true,
8580
+ hasLoadedPreference: false,
8581
+ initializedForToken: null,
8582
+ initializedForIdentity: null,
8583
+ status: "disabled",
8584
+ syncEnabled: false
8585
+ });
8423
8586
  return;
8424
8587
  }
8425
8588
  try {
@@ -8441,14 +8604,27 @@ var useConversationSyncStore = (0, import_zustand11.create)((set, get) => ({
8441
8604
  isAdvancedVectorFeaturesEnabled: get().isAdvancedVectorFeaturesEnabled
8442
8605
  }
8443
8606
  });
8444
- set({ initialized: true });
8607
+ set({
8608
+ initialized: true,
8609
+ hasLoadedPreference: true,
8610
+ initializedForToken: token,
8611
+ initializedForIdentity: tokenIdentity
8612
+ });
8613
+ setStoredSyncIdentity(tokenIdentity);
8445
8614
  if (preference.syncEnabled) {
8446
8615
  await get().runSync({ force: true });
8447
8616
  }
8448
8617
  } catch (error) {
8449
8618
  const message = error instanceof Error ? error.message : "Failed to load conversation sync preference";
8450
8619
  debugLogger.error("conversationSyncStore: initialization failed", { error: message });
8451
- set({ initialized: true, status: "error", lastError: message });
8620
+ set({
8621
+ initialized: true,
8622
+ hasLoadedPreference: false,
8623
+ initializedForToken: null,
8624
+ initializedForIdentity: tokenIdentity,
8625
+ status: "error",
8626
+ lastError: message
8627
+ });
8452
8628
  }
8453
8629
  },
8454
8630
  async setSyncEnabled(enabled) {
@@ -8476,6 +8652,12 @@ var useConversationSyncStore = (0, import_zustand11.create)((set, get) => ({
8476
8652
  isAdvancedVectorFeaturesEnabled
8477
8653
  }
8478
8654
  });
8655
+ set({
8656
+ hasLoadedPreference: true,
8657
+ initializedForToken: authenticationService.getToken(),
8658
+ initializedForIdentity: resolveAuthIdentity(authenticationService.getToken())
8659
+ });
8660
+ setStoredSyncIdentity(resolveAuthIdentity(authenticationService.getToken()));
8479
8661
  if (enabled) {
8480
8662
  set({ hasCompletedInitialUpload: false });
8481
8663
  }
@@ -8513,6 +8695,12 @@ var useConversationSyncStore = (0, import_zustand11.create)((set, get) => ({
8513
8695
  isAdvancedVectorFeaturesEnabled: enabled
8514
8696
  }
8515
8697
  });
8698
+ set({
8699
+ hasLoadedPreference: true,
8700
+ initializedForToken: authenticationService.getToken(),
8701
+ initializedForIdentity: resolveAuthIdentity(authenticationService.getToken())
8702
+ });
8703
+ setStoredSyncIdentity(resolveAuthIdentity(authenticationService.getToken()));
8516
8704
  if (preference.syncEnabled && preference.isAdvancedVectorFeaturesEnabled) {
8517
8705
  await get().runSync({ force: true });
8518
8706
  }
@@ -8558,6 +8746,15 @@ var useConversationSyncStore = (0, import_zustand11.create)((set, get) => ({
8558
8746
  debugLogger.error("conversationSyncStore: runSync error - missing auth token");
8559
8747
  return;
8560
8748
  }
8749
+ const tokenIdentity = resolveAuthIdentity(token);
8750
+ if (state.initializedForIdentity && tokenIdentity && state.initializedForIdentity !== tokenIdentity) {
8751
+ debugLogger.warn("conversationSyncStore: runSync aborted due auth identity mismatch; reinitializing", {
8752
+ initializedForIdentity: state.initializedForIdentity,
8753
+ tokenIdentity
8754
+ });
8755
+ await get().initialize();
8756
+ return;
8757
+ }
8561
8758
  const pendingConversationIds = Array.from(state.pendingConversationUpserts);
8562
8759
  const pendingConversationDeleteIds = Array.from(state.pendingConversationDeletes);
8563
8760
  const pendingProjectIds = Array.from(state.pendingProjectUpserts);