@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.
- package/dist/{aiProviderStore-3N3VE6D4.mjs → aiProviderStore-337QNQB3.mjs} +2 -2
- package/dist/{chat-W5IFNEUC.mjs → chat-U4SE4JQK.mjs} +6 -6
- package/dist/chat-provider.js +242 -17
- package/dist/chat-provider.js.map +1 -1
- package/dist/chat-provider.mjs +4 -4
- package/dist/{chunk-LXD3IV6Z.mjs → chunk-2BGORTWS.mjs} +4 -4
- package/dist/{chunk-IDH2YOW3.mjs → chunk-557E5VZ2.mjs} +198 -11
- package/dist/chunk-557E5VZ2.mjs.map +1 -0
- package/dist/{chunk-QFSEZAG6.mjs → chunk-AVV7HDGR.mjs} +34 -3
- package/dist/chunk-AVV7HDGR.mjs.map +1 -0
- package/dist/{chunk-N7RMUOFB.mjs → chunk-EULV5CHD.mjs} +2 -2
- package/dist/{chunk-STMXPFAQ.mjs → chunk-GNE4TTSI.mjs} +48 -15
- package/dist/chunk-GNE4TTSI.mjs.map +1 -0
- package/dist/{chunk-BENL3EF2.mjs → chunk-H3BYFEIE.mjs} +18 -10
- package/dist/chunk-H3BYFEIE.mjs.map +1 -0
- package/dist/{chunk-HETIHZ42.mjs → chunk-NZKLKZJT.mjs} +3 -3
- package/dist/{chunk-JBXNXSAH.mjs → chunk-O54PTFJM.mjs} +460 -181
- package/dist/chunk-O54PTFJM.mjs.map +1 -0
- package/dist/{chunk-EWUUF4GE.mjs → chunk-UFSEYVRS.mjs} +3 -3
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/{gateway-oScD5tvE.d.ts → gateway-C5T5FfCy.d.mts} +32 -0
- package/dist/{gateway-oScD5tvE.d.mts → gateway-C5T5FfCy.d.ts} +32 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +738 -202
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -9
- package/dist/management/management.js +708 -202
- package/dist/management/management.js.map +1 -1
- package/dist/management/management.mjs +7 -7
- package/dist/modals/chat-modal/chat-modal.js +214 -17
- package/dist/modals/chat-modal/chat-modal.js.map +1 -1
- package/dist/modals/chat-modal/chat-modal.mjs +4 -4
- package/dist/public-types.d.mts +1 -1
- package/dist/public-types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-BENL3EF2.mjs.map +0 -1
- package/dist/chunk-IDH2YOW3.mjs.map +0 -1
- package/dist/chunk-JBXNXSAH.mjs.map +0 -1
- package/dist/chunk-QFSEZAG6.mjs.map +0 -1
- package/dist/chunk-STMXPFAQ.mjs.map +0 -1
- /package/dist/{aiProviderStore-3N3VE6D4.mjs.map → aiProviderStore-337QNQB3.mjs.map} +0 -0
- /package/dist/{chat-W5IFNEUC.mjs.map → chat-U4SE4JQK.mjs.map} +0 -0
- /package/dist/{chunk-LXD3IV6Z.mjs.map → chunk-2BGORTWS.mjs.map} +0 -0
- /package/dist/{chunk-N7RMUOFB.mjs.map → chunk-EULV5CHD.mjs.map} +0 -0
- /package/dist/{chunk-HETIHZ42.mjs.map → chunk-NZKLKZJT.mjs.map} +0 -0
- /package/dist/{chunk-EWUUF4GE.mjs.map → chunk-UFSEYVRS.mjs.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useAIProviderStore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-H3BYFEIE.mjs";
|
|
4
4
|
import "./chunk-KCI46M23.mjs";
|
|
5
5
|
import "./chunk-BJTO5JO5.mjs";
|
|
6
6
|
export {
|
|
7
7
|
useAIProviderStore
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=aiProviderStore-
|
|
9
|
+
//# sourceMappingURL=aiProviderStore-337QNQB3.mjs.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
chat_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GNE4TTSI.mjs";
|
|
4
4
|
import "./chunk-ONQMRE2G.mjs";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-EULV5CHD.mjs";
|
|
6
6
|
import "./chunk-EHNWQ4T3.mjs";
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-NZKLKZJT.mjs";
|
|
8
|
+
import "./chunk-557E5VZ2.mjs";
|
|
9
9
|
import "./chunk-7ZDS33S2.mjs";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-H3BYFEIE.mjs";
|
|
11
11
|
import "./chunk-KCI46M23.mjs";
|
|
12
12
|
import "./chunk-BJTO5JO5.mjs";
|
|
13
13
|
export {
|
|
14
14
|
chat_default as default
|
|
15
15
|
};
|
|
16
|
-
//# sourceMappingURL=chat-
|
|
16
|
+
//# sourceMappingURL=chat-U4SE4JQK.mjs.map
|
package/dist/chat-provider.js
CHANGED
|
@@ -2303,7 +2303,8 @@ var init_gateway_service = __esm({
|
|
|
2303
2303
|
index: 0,
|
|
2304
2304
|
delta: {
|
|
2305
2305
|
role: parsed.message.role,
|
|
2306
|
-
content: parsed.message.content
|
|
2306
|
+
content: parsed.message.content,
|
|
2307
|
+
tool_calls: parsed.message.tool_calls
|
|
2307
2308
|
},
|
|
2308
2309
|
finish_reason: parsed.done ? parsed.done_reason || "stop" : null
|
|
2309
2310
|
}]
|
|
@@ -3283,6 +3284,7 @@ var init_gateway_provider = __esm({
|
|
|
3283
3284
|
}
|
|
3284
3285
|
}
|
|
3285
3286
|
}
|
|
3287
|
+
const toolAwareRequest = request;
|
|
3286
3288
|
const gatewayRequest = {
|
|
3287
3289
|
model: request.model,
|
|
3288
3290
|
messages,
|
|
@@ -3291,7 +3293,8 @@ var init_gateway_provider = __esm({
|
|
|
3291
3293
|
max_tokens: request.maxTokens,
|
|
3292
3294
|
provider: this.config.provider,
|
|
3293
3295
|
// Only include top-level images for Ollama (fallback)
|
|
3294
|
-
images: this.config.provider === "ollama" ? request.images : void 0
|
|
3296
|
+
images: this.config.provider === "ollama" ? request.images : void 0,
|
|
3297
|
+
tools: toolAwareRequest.tools?.length ? toolAwareRequest.tools : void 0
|
|
3295
3298
|
};
|
|
3296
3299
|
debugLogger.debug("Gateway provider chat request", {
|
|
3297
3300
|
model: request.model,
|
|
@@ -3308,13 +3311,18 @@ var init_gateway_provider = __esm({
|
|
|
3308
3311
|
}))
|
|
3309
3312
|
});
|
|
3310
3313
|
return this.gatewayService.chat(gatewayRequest).pipe(
|
|
3311
|
-
(0, import_rxjs7.map)((response) =>
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3314
|
+
(0, import_rxjs7.map)((response) => {
|
|
3315
|
+
const choice = response.choices?.[0];
|
|
3316
|
+
const toolCalls = choice?.message?.tool_calls ?? choice?.delta?.tool_calls;
|
|
3317
|
+
return {
|
|
3318
|
+
message: {
|
|
3319
|
+
content: choice?.message?.content ?? choice?.delta?.content ?? "",
|
|
3320
|
+
role: "assistant",
|
|
3321
|
+
tool_calls: toolCalls
|
|
3322
|
+
},
|
|
3323
|
+
done: choice?.finish_reason === "stop" || choice?.finish_reason === "length" || choice?.finish_reason === "tool_calls"
|
|
3324
|
+
};
|
|
3325
|
+
})
|
|
3318
3326
|
);
|
|
3319
3327
|
}
|
|
3320
3328
|
generate(request) {
|
|
@@ -4432,6 +4440,15 @@ var useAuthenticationStore = (0, import_zustand2.create)((set) => ({
|
|
|
4432
4440
|
// src/services/auth/authenticationService.ts
|
|
4433
4441
|
init_debugLogger();
|
|
4434
4442
|
var TOKEN_KEY2 = "authToken";
|
|
4443
|
+
var AUTH_TOKEN_CHANGED_EVENT = "bandit:auth-token-changed";
|
|
4444
|
+
function emitAuthTokenChanged(token) {
|
|
4445
|
+
if (typeof window === "undefined") {
|
|
4446
|
+
return;
|
|
4447
|
+
}
|
|
4448
|
+
window.dispatchEvent(new CustomEvent(AUTH_TOKEN_CHANGED_EVENT, {
|
|
4449
|
+
detail: { token }
|
|
4450
|
+
}));
|
|
4451
|
+
}
|
|
4435
4452
|
var AuthenticationService = class {
|
|
4436
4453
|
getToken() {
|
|
4437
4454
|
const token = localStorage.getItem(TOKEN_KEY2);
|
|
@@ -4440,10 +4457,12 @@ var AuthenticationService = class {
|
|
|
4440
4457
|
setToken(token) {
|
|
4441
4458
|
localStorage.setItem(TOKEN_KEY2, token);
|
|
4442
4459
|
useAuthenticationStore.getState().setToken(token);
|
|
4460
|
+
emitAuthTokenChanged(token);
|
|
4443
4461
|
}
|
|
4444
4462
|
clearToken() {
|
|
4445
4463
|
localStorage.removeItem(TOKEN_KEY2);
|
|
4446
4464
|
useAuthenticationStore.getState().clearToken();
|
|
4465
|
+
emitAuthTokenChanged(null);
|
|
4447
4466
|
}
|
|
4448
4467
|
isAuthenticated() {
|
|
4449
4468
|
const token = useAuthenticationStore.getState().token;
|
|
@@ -5366,6 +5385,7 @@ function emitProjectDelete(id) {
|
|
|
5366
5385
|
var import_zustand9 = require("zustand");
|
|
5367
5386
|
var import_uuid3 = require("uuid");
|
|
5368
5387
|
init_packageSettingsStore();
|
|
5388
|
+
init_indexedDBService();
|
|
5369
5389
|
|
|
5370
5390
|
// src/services/conversationSync/conversationSyncService.ts
|
|
5371
5391
|
init_packageSettingsStore();
|
|
@@ -5466,9 +5486,14 @@ async function syncConversations(request) {
|
|
|
5466
5486
|
// src/store/conversationSyncStore.ts
|
|
5467
5487
|
init_debugLogger();
|
|
5468
5488
|
var DEVICE_STORAGE_KEY = "banditConversationDeviceId";
|
|
5489
|
+
var SYNC_IDENTITY_STORAGE_KEY = "banditConversationSyncIdentity";
|
|
5469
5490
|
var PAYLOAD_VERSION = 1;
|
|
5470
5491
|
var MAX_CONVERSATION_BYTES = 12 * 1024 * 1024;
|
|
5471
5492
|
var WARN_CONVERSATION_BYTES = 10 * 1024 * 1024;
|
|
5493
|
+
var PROJECT_DB_NAME = "bandit-projects";
|
|
5494
|
+
var PROJECT_DB_VERSION = 1;
|
|
5495
|
+
var PROJECT_STORE_NAME = "projects";
|
|
5496
|
+
var PROJECT_STORE_CONFIGS = [{ name: PROJECT_STORE_NAME, keyPath: "id" }];
|
|
5472
5497
|
var suppressTracking = false;
|
|
5473
5498
|
var conversationsMeta = /* @__PURE__ */ new Map();
|
|
5474
5499
|
var projectsMeta = /* @__PURE__ */ new Map();
|
|
@@ -5493,9 +5518,99 @@ function ensureDeviceId() {
|
|
|
5493
5518
|
return (0, import_uuid3.v4)();
|
|
5494
5519
|
}
|
|
5495
5520
|
}
|
|
5521
|
+
function getStoredSyncIdentity() {
|
|
5522
|
+
if (typeof window === "undefined") {
|
|
5523
|
+
return null;
|
|
5524
|
+
}
|
|
5525
|
+
try {
|
|
5526
|
+
return window.localStorage.getItem(SYNC_IDENTITY_STORAGE_KEY);
|
|
5527
|
+
} catch (error) {
|
|
5528
|
+
debugLogger.warn("conversationSyncStore: unable to read stored sync identity", { error });
|
|
5529
|
+
return null;
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
function setStoredSyncIdentity(identity) {
|
|
5533
|
+
if (typeof window === "undefined") {
|
|
5534
|
+
return;
|
|
5535
|
+
}
|
|
5536
|
+
try {
|
|
5537
|
+
if (identity) {
|
|
5538
|
+
window.localStorage.setItem(SYNC_IDENTITY_STORAGE_KEY, identity);
|
|
5539
|
+
} else {
|
|
5540
|
+
window.localStorage.removeItem(SYNC_IDENTITY_STORAGE_KEY);
|
|
5541
|
+
}
|
|
5542
|
+
} catch (error) {
|
|
5543
|
+
debugLogger.warn("conversationSyncStore: unable to persist sync identity", { error });
|
|
5544
|
+
}
|
|
5545
|
+
}
|
|
5496
5546
|
function getPackageDefaultAdvancedKnowledgeSync() {
|
|
5497
5547
|
return usePackageSettingsStore.getState().settings?.advancedKnowledgeSyncDefaultEnabled;
|
|
5498
5548
|
}
|
|
5549
|
+
function clearAutoSyncTimer() {
|
|
5550
|
+
if (autoSyncTimeout) {
|
|
5551
|
+
clearTimeout(autoSyncTimeout);
|
|
5552
|
+
autoSyncTimeout = null;
|
|
5553
|
+
}
|
|
5554
|
+
}
|
|
5555
|
+
function resolveAuthIdentity(token) {
|
|
5556
|
+
if (!token) {
|
|
5557
|
+
return null;
|
|
5558
|
+
}
|
|
5559
|
+
const claims = authenticationService.parseJwtClaims(token);
|
|
5560
|
+
if (claims?.sub) {
|
|
5561
|
+
return claims.sub;
|
|
5562
|
+
}
|
|
5563
|
+
if (claims?.email) {
|
|
5564
|
+
return `email:${claims.email.toLowerCase()}`;
|
|
5565
|
+
}
|
|
5566
|
+
return `token:${token.slice(0, 32)}`;
|
|
5567
|
+
}
|
|
5568
|
+
function buildQueueResetState() {
|
|
5569
|
+
return {
|
|
5570
|
+
pendingConversationUpserts: /* @__PURE__ */ new Set(),
|
|
5571
|
+
pendingConversationDeletes: /* @__PURE__ */ new Set(),
|
|
5572
|
+
pendingProjectUpserts: /* @__PURE__ */ new Set(),
|
|
5573
|
+
pendingProjectDeletes: /* @__PURE__ */ new Set(),
|
|
5574
|
+
conflicts: null,
|
|
5575
|
+
lastSyncAt: null,
|
|
5576
|
+
cursor: null,
|
|
5577
|
+
lastError: null,
|
|
5578
|
+
totalConversationsOnServer: void 0,
|
|
5579
|
+
totalProjectsOnServer: void 0,
|
|
5580
|
+
hasCompletedInitialUpload: false,
|
|
5581
|
+
warningConversations: [],
|
|
5582
|
+
oversizedConversations: []
|
|
5583
|
+
};
|
|
5584
|
+
}
|
|
5585
|
+
async function clearLocalStoresForIdentitySwitch(fromIdentity, toIdentity) {
|
|
5586
|
+
const conversationCount = useConversationStore.getState().conversations.length;
|
|
5587
|
+
const projectCount = useProjectStore.getState().projects.length;
|
|
5588
|
+
debugLogger.warn("conversationSyncStore: auth identity changed, clearing local conversation/project cache", {
|
|
5589
|
+
fromIdentity,
|
|
5590
|
+
toIdentity,
|
|
5591
|
+
conversationCount,
|
|
5592
|
+
projectCount
|
|
5593
|
+
});
|
|
5594
|
+
suppressTracking = true;
|
|
5595
|
+
try {
|
|
5596
|
+
await useConversationStore.getState().clearAllConversations();
|
|
5597
|
+
await indexedDBService_default.clear(
|
|
5598
|
+
PROJECT_DB_NAME,
|
|
5599
|
+
PROJECT_DB_VERSION,
|
|
5600
|
+
PROJECT_STORE_NAME,
|
|
5601
|
+
PROJECT_STORE_CONFIGS
|
|
5602
|
+
);
|
|
5603
|
+
useProjectStore.setState({ projects: [] });
|
|
5604
|
+
conversationsMeta = snapshotConversationMetaMap(useConversationStore.getState().conversations);
|
|
5605
|
+
projectsMeta = snapshotProjectMetaMap(useProjectStore.getState().projects);
|
|
5606
|
+
} catch (error) {
|
|
5607
|
+
debugLogger.error("conversationSyncStore: failed to clear local stores on auth switch", {
|
|
5608
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5609
|
+
});
|
|
5610
|
+
} finally {
|
|
5611
|
+
suppressTracking = false;
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5499
5614
|
function mapConversationToDTO(conversation) {
|
|
5500
5615
|
const updatedAtIso = (conversation.updatedAt ?? /* @__PURE__ */ new Date()).toISOString();
|
|
5501
5616
|
const createdAtIso = conversation.createdAt ? conversation.createdAt.toISOString() : null;
|
|
@@ -5864,6 +5979,9 @@ async function applyServerResults(response) {
|
|
|
5864
5979
|
}
|
|
5865
5980
|
var useConversationSyncStore = (0, import_zustand9.create)((set, get) => ({
|
|
5866
5981
|
initialized: false,
|
|
5982
|
+
hasLoadedPreference: false,
|
|
5983
|
+
initializedForToken: null,
|
|
5984
|
+
initializedForIdentity: null,
|
|
5867
5985
|
syncEnabled: false,
|
|
5868
5986
|
status: "disabled",
|
|
5869
5987
|
lastSyncAt: null,
|
|
@@ -5883,20 +6001,63 @@ var useConversationSyncStore = (0, import_zustand9.create)((set, get) => ({
|
|
|
5883
6001
|
warningConversations: [],
|
|
5884
6002
|
oversizedConversations: [],
|
|
5885
6003
|
async initialize() {
|
|
5886
|
-
if (get().initialized) {
|
|
5887
|
-
return;
|
|
5888
|
-
}
|
|
5889
6004
|
ensureTrackersInitialized();
|
|
5890
6005
|
const gatewayUrl = usePackageSettingsStore.getState().settings?.gatewayApiUrl;
|
|
6006
|
+
const token = authenticationService.getToken();
|
|
6007
|
+
const tokenIdentity = resolveAuthIdentity(token);
|
|
6008
|
+
const current = get();
|
|
6009
|
+
const storedIdentity = getStoredSyncIdentity();
|
|
6010
|
+
const knownIdentity = current.initializedForIdentity ?? storedIdentity;
|
|
6011
|
+
if (current.initialized && current.hasLoadedPreference && knownIdentity && tokenIdentity && knownIdentity === tokenIdentity) {
|
|
6012
|
+
return;
|
|
6013
|
+
}
|
|
6014
|
+
const hasIdentitySwitch = Boolean(
|
|
6015
|
+
knownIdentity && tokenIdentity && knownIdentity !== tokenIdentity
|
|
6016
|
+
);
|
|
6017
|
+
if (hasIdentitySwitch) {
|
|
6018
|
+
clearAutoSyncTimer();
|
|
6019
|
+
set({
|
|
6020
|
+
...buildQueueResetState(),
|
|
6021
|
+
syncEnabled: false,
|
|
6022
|
+
status: "disabled",
|
|
6023
|
+
hasLoadedPreference: false,
|
|
6024
|
+
initializedForToken: null,
|
|
6025
|
+
initializedForIdentity: tokenIdentity
|
|
6026
|
+
});
|
|
6027
|
+
await clearLocalStoresForIdentitySwitch(
|
|
6028
|
+
knownIdentity,
|
|
6029
|
+
tokenIdentity
|
|
6030
|
+
);
|
|
6031
|
+
setStoredSyncIdentity(tokenIdentity);
|
|
6032
|
+
}
|
|
5891
6033
|
if (!gatewayUrl) {
|
|
5892
6034
|
debugLogger.info("conversationSyncStore: gateway API URL not configured; sync disabled");
|
|
5893
|
-
|
|
6035
|
+
if (tokenIdentity) {
|
|
6036
|
+
setStoredSyncIdentity(tokenIdentity);
|
|
6037
|
+
}
|
|
6038
|
+
set({
|
|
6039
|
+
...buildQueueResetState(),
|
|
6040
|
+
initialized: true,
|
|
6041
|
+
hasLoadedPreference: false,
|
|
6042
|
+
initializedForToken: null,
|
|
6043
|
+
initializedForIdentity: tokenIdentity,
|
|
6044
|
+
status: "disabled",
|
|
6045
|
+
syncEnabled: false
|
|
6046
|
+
});
|
|
5894
6047
|
return;
|
|
5895
6048
|
}
|
|
5896
|
-
const token = authenticationService.getToken();
|
|
5897
6049
|
if (!token) {
|
|
5898
6050
|
debugLogger.info("conversationSyncStore: no authentication token; sync disabled until login");
|
|
5899
|
-
|
|
6051
|
+
clearAutoSyncTimer();
|
|
6052
|
+
set({
|
|
6053
|
+
...buildQueueResetState(),
|
|
6054
|
+
initialized: true,
|
|
6055
|
+
hasLoadedPreference: false,
|
|
6056
|
+
initializedForToken: null,
|
|
6057
|
+
initializedForIdentity: null,
|
|
6058
|
+
status: "disabled",
|
|
6059
|
+
syncEnabled: false
|
|
6060
|
+
});
|
|
5900
6061
|
return;
|
|
5901
6062
|
}
|
|
5902
6063
|
try {
|
|
@@ -5918,14 +6079,27 @@ var useConversationSyncStore = (0, import_zustand9.create)((set, get) => ({
|
|
|
5918
6079
|
isAdvancedVectorFeaturesEnabled: get().isAdvancedVectorFeaturesEnabled
|
|
5919
6080
|
}
|
|
5920
6081
|
});
|
|
5921
|
-
set({
|
|
6082
|
+
set({
|
|
6083
|
+
initialized: true,
|
|
6084
|
+
hasLoadedPreference: true,
|
|
6085
|
+
initializedForToken: token,
|
|
6086
|
+
initializedForIdentity: tokenIdentity
|
|
6087
|
+
});
|
|
6088
|
+
setStoredSyncIdentity(tokenIdentity);
|
|
5922
6089
|
if (preference.syncEnabled) {
|
|
5923
6090
|
await get().runSync({ force: true });
|
|
5924
6091
|
}
|
|
5925
6092
|
} catch (error) {
|
|
5926
6093
|
const message = error instanceof Error ? error.message : "Failed to load conversation sync preference";
|
|
5927
6094
|
debugLogger.error("conversationSyncStore: initialization failed", { error: message });
|
|
5928
|
-
set({
|
|
6095
|
+
set({
|
|
6096
|
+
initialized: true,
|
|
6097
|
+
hasLoadedPreference: false,
|
|
6098
|
+
initializedForToken: null,
|
|
6099
|
+
initializedForIdentity: tokenIdentity,
|
|
6100
|
+
status: "error",
|
|
6101
|
+
lastError: message
|
|
6102
|
+
});
|
|
5929
6103
|
}
|
|
5930
6104
|
},
|
|
5931
6105
|
async setSyncEnabled(enabled) {
|
|
@@ -5953,6 +6127,12 @@ var useConversationSyncStore = (0, import_zustand9.create)((set, get) => ({
|
|
|
5953
6127
|
isAdvancedVectorFeaturesEnabled
|
|
5954
6128
|
}
|
|
5955
6129
|
});
|
|
6130
|
+
set({
|
|
6131
|
+
hasLoadedPreference: true,
|
|
6132
|
+
initializedForToken: authenticationService.getToken(),
|
|
6133
|
+
initializedForIdentity: resolveAuthIdentity(authenticationService.getToken())
|
|
6134
|
+
});
|
|
6135
|
+
setStoredSyncIdentity(resolveAuthIdentity(authenticationService.getToken()));
|
|
5956
6136
|
if (enabled) {
|
|
5957
6137
|
set({ hasCompletedInitialUpload: false });
|
|
5958
6138
|
}
|
|
@@ -5990,6 +6170,12 @@ var useConversationSyncStore = (0, import_zustand9.create)((set, get) => ({
|
|
|
5990
6170
|
isAdvancedVectorFeaturesEnabled: enabled
|
|
5991
6171
|
}
|
|
5992
6172
|
});
|
|
6173
|
+
set({
|
|
6174
|
+
hasLoadedPreference: true,
|
|
6175
|
+
initializedForToken: authenticationService.getToken(),
|
|
6176
|
+
initializedForIdentity: resolveAuthIdentity(authenticationService.getToken())
|
|
6177
|
+
});
|
|
6178
|
+
setStoredSyncIdentity(resolveAuthIdentity(authenticationService.getToken()));
|
|
5993
6179
|
if (preference.syncEnabled && preference.isAdvancedVectorFeaturesEnabled) {
|
|
5994
6180
|
await get().runSync({ force: true });
|
|
5995
6181
|
}
|
|
@@ -6035,6 +6221,15 @@ var useConversationSyncStore = (0, import_zustand9.create)((set, get) => ({
|
|
|
6035
6221
|
debugLogger.error("conversationSyncStore: runSync error - missing auth token");
|
|
6036
6222
|
return;
|
|
6037
6223
|
}
|
|
6224
|
+
const tokenIdentity = resolveAuthIdentity(token);
|
|
6225
|
+
if (state.initializedForIdentity && tokenIdentity && state.initializedForIdentity !== tokenIdentity) {
|
|
6226
|
+
debugLogger.warn("conversationSyncStore: runSync aborted due auth identity mismatch; reinitializing", {
|
|
6227
|
+
initializedForIdentity: state.initializedForIdentity,
|
|
6228
|
+
tokenIdentity
|
|
6229
|
+
});
|
|
6230
|
+
await get().initialize();
|
|
6231
|
+
return;
|
|
6232
|
+
}
|
|
6038
6233
|
const pendingConversationIds = Array.from(state.pendingConversationUpserts);
|
|
6039
6234
|
const pendingConversationDeleteIds = Array.from(state.pendingConversationDeletes);
|
|
6040
6235
|
const pendingProjectIds = Array.from(state.pendingProjectUpserts);
|
|
@@ -10367,6 +10562,36 @@ var ChatProvider = (props) => {
|
|
|
10367
10562
|
};
|
|
10368
10563
|
initializeAsync();
|
|
10369
10564
|
}, [props.packageSettings, loadDocuments]);
|
|
10565
|
+
(0, import_react6.useEffect)(() => {
|
|
10566
|
+
const isPlaygroundRoute = typeof window !== "undefined" && window.location.pathname.includes("/playground");
|
|
10567
|
+
const isPlaygroundMode = isPlaygroundRoute || props.packageSettings.playgroundMode === true;
|
|
10568
|
+
if (isPlaygroundMode || !props.packageSettings.gatewayApiUrl) {
|
|
10569
|
+
return;
|
|
10570
|
+
}
|
|
10571
|
+
const initializeSyncState = async () => {
|
|
10572
|
+
try {
|
|
10573
|
+
await useConversationSyncStore.getState().initialize();
|
|
10574
|
+
} catch (error) {
|
|
10575
|
+
debugLogger.error("ChatProvider: deferred sync initialization failed", {
|
|
10576
|
+
error: error instanceof Error ? error.message : String(error)
|
|
10577
|
+
});
|
|
10578
|
+
}
|
|
10579
|
+
};
|
|
10580
|
+
if (typeof window === "undefined") {
|
|
10581
|
+
return;
|
|
10582
|
+
}
|
|
10583
|
+
const handleAuthTokenChange = () => {
|
|
10584
|
+
void initializeSyncState();
|
|
10585
|
+
};
|
|
10586
|
+
window.addEventListener(AUTH_TOKEN_CHANGED_EVENT, handleAuthTokenChange);
|
|
10587
|
+
window.addEventListener("pageshow", handleAuthTokenChange);
|
|
10588
|
+
window.addEventListener("focus", handleAuthTokenChange);
|
|
10589
|
+
return () => {
|
|
10590
|
+
window.removeEventListener(AUTH_TOKEN_CHANGED_EVENT, handleAuthTokenChange);
|
|
10591
|
+
window.removeEventListener("pageshow", handleAuthTokenChange);
|
|
10592
|
+
window.removeEventListener("focus", handleAuthTokenChange);
|
|
10593
|
+
};
|
|
10594
|
+
}, [props.packageSettings.gatewayApiUrl, props.packageSettings.playgroundMode]);
|
|
10370
10595
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FeatureFlagProvider, { config: featureFlagConfig, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(NotificationProvider, { children: props.children }) }) });
|
|
10371
10596
|
};
|
|
10372
10597
|
var chat_provider_default = ChatProvider;
|