Skip to content

Commit c568369

Browse files
authored
🐛 fix(operation): isolate loading state to current active topic (#10360)
* fix(operation): isolate loading state to current active topic - Modified isMainWindowAgentRuntimeRunning to only check operations in current active topic - Prevents loading state from other topics affecting the send button - Added comprehensive test case to verify topic isolation - Fixes issue where switching topics would still show loading state from previous topic * test: fix isMainWindowAgentRuntimeRunning tests to set active context - Added activeId and activeTopicId setup in test cases - Ensured operation context matches active context for proper filtering - Fixed tests to align with new getCurrentContextOperations-based implementation * fix: change activeTopicId from null to undefined in tests - Fixed TypeScript type error where null is not assignable to string | undefined - Changed all activeTopicId: null to activeTopicId: undefined * fix: check if operation's message is in current displayed messages - Changed from using getCurrentContextOperations to checking message presence - Prevents loading state from showing when switching back to default topic - Operation's context topicId is captured at creation time and doesn't update - Now checks if operation's message is in activeDisplayMessages instead * refactor * refactor to fix * try to fix stylelint ci issue * fix tests * fix tests
1 parent 19f7d74 commit c568369

File tree

24 files changed

+341
-300
lines changed

24 files changed

+341
-300
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,15 @@
396396
"access": "public",
397397
"registry": "https://registry.npmjs.org"
398398
},
399+
"overrides": {
400+
"stylelint-config-clean-order": "7.0.0"
401+
},
399402
"pnpm": {
400403
"onlyBuiltDependencies": [
401404
"@vercel/speed-insights"
402-
]
405+
],
406+
"overrides": {
407+
"stylelint-config-clean-order": "7.0.0"
408+
}
403409
}
404410
}

packages/database/src/repositories/knowledge/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ export class KnowledgeRepo {
129129
};
130130
});
131131

132-
console.log('[KnowledgeRepo.query] Fetched items:', {
133-
count: mappedResults.length,
134-
documents: mappedResults.filter((item) => item.sourceType === 'document'),
135-
sampleEditorData: mappedResults.find((item) => item.sourceType === 'document')?.editorData,
136-
});
137-
138132
return mappedResults;
139133
}
140134

@@ -308,7 +302,10 @@ export class KnowledgeRepo {
308302

309303
// Exclude custom/document and source_type='file' from Documents category
310304
if (category === FilesTabs.Documents) {
311-
whereConditions.push(sql`${documents.fileType} != ${'custom/document'}`, sql`${documents.sourceType} != ${'file'}`);
305+
whereConditions.push(
306+
sql`${documents.fileType} != ${'custom/document'}`,
307+
sql`${documents.sourceType} != ${'file'}`,
308+
);
312309
}
313310
} else if (fileTypePrefix) {
314311
whereConditions.push(sql`${documents.fileType} ILIKE ${`${fileTypePrefix}%`}`);
@@ -338,7 +335,7 @@ export class KnowledgeRepo {
338335
// Documents don't have knowledge base association currently, so skip if knowledgeBaseId is set
339336
if (knowledgeBaseId) {
340337
return sql`
341-
SELECT
338+
SELECT
342339
NULL::varchar(30) as id,
343340
NULL::text as name,
344341
NULL::varchar(255) as file_type,

packages/types/src/user/settings/keyVaults.ts

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -51,73 +51,5 @@ export interface SearchEngineKeyVaults {
5151
}
5252

5353
export interface UserKeyVaults extends SearchEngineKeyVaults {
54-
ai21?: OpenAICompatibleKeyVault;
55-
ai302?: OpenAICompatibleKeyVault;
56-
ai360?: OpenAICompatibleKeyVault;
57-
aihubmix?: OpenAICompatibleKeyVault;
58-
akashchat?: OpenAICompatibleKeyVault;
59-
anthropic?: OpenAICompatibleKeyVault;
60-
azure?: AzureOpenAIKeyVault;
61-
azureai?: AzureOpenAIKeyVault;
62-
baichuan?: OpenAICompatibleKeyVault;
63-
bedrock?: AWSBedrockKeyVault;
64-
bfl?: any;
65-
cerebras?: OpenAICompatibleKeyVault;
66-
cloudflare?: CloudflareKeyVault;
67-
cohere?: OpenAICompatibleKeyVault;
68-
cometapi?: OpenAICompatibleKeyVault;
69-
comfyui?: ComfyUIKeyVault;
70-
deepseek?: OpenAICompatibleKeyVault;
71-
fal?: FalKeyVault;
72-
fireworksai?: OpenAICompatibleKeyVault;
73-
giteeai?: OpenAICompatibleKeyVault;
74-
github?: OpenAICompatibleKeyVault;
75-
google?: OpenAICompatibleKeyVault;
76-
groq?: OpenAICompatibleKeyVault;
77-
higress?: OpenAICompatibleKeyVault;
78-
huggingface?: OpenAICompatibleKeyVault;
79-
hunyuan?: OpenAICompatibleKeyVault;
80-
infiniai?: OpenAICompatibleKeyVault;
81-
internlm?: OpenAICompatibleKeyVault;
82-
jina?: OpenAICompatibleKeyVault;
83-
lmstudio?: OpenAICompatibleKeyVault;
84-
lobehub?: any;
85-
minimax?: OpenAICompatibleKeyVault;
86-
mistral?: OpenAICompatibleKeyVault;
87-
modelscope?: OpenAICompatibleKeyVault;
88-
moonshot?: OpenAICompatibleKeyVault;
89-
nebius?: OpenAICompatibleKeyVault;
90-
newapi?: OpenAICompatibleKeyVault;
91-
novita?: OpenAICompatibleKeyVault;
92-
nvidia?: OpenAICompatibleKeyVault;
93-
ollama?: OpenAICompatibleKeyVault;
94-
ollamacloud?: OpenAICompatibleKeyVault;
95-
openai?: OpenAICompatibleKeyVault;
96-
openrouter?: OpenAICompatibleKeyVault;
97-
password?: string;
98-
perplexity?: OpenAICompatibleKeyVault;
99-
ppio?: OpenAICompatibleKeyVault;
100-
qiniu?: OpenAICompatibleKeyVault;
101-
qwen?: OpenAICompatibleKeyVault;
102-
sambanova?: OpenAICompatibleKeyVault;
10354
search1api?: OpenAICompatibleKeyVault;
104-
sensenova?: OpenAICompatibleKeyVault;
105-
siliconcloud?: OpenAICompatibleKeyVault;
106-
spark?: OpenAICompatibleKeyVault;
107-
stepfun?: OpenAICompatibleKeyVault;
108-
taichu?: OpenAICompatibleKeyVault;
109-
tencentcloud?: OpenAICompatibleKeyVault;
110-
togetherai?: OpenAICompatibleKeyVault;
111-
upstage?: OpenAICompatibleKeyVault;
112-
v0?: OpenAICompatibleKeyVault;
113-
vercelaigateway?: OpenAICompatibleKeyVault;
114-
vertexai?: VertexAIKeyVault;
115-
vllm?: OpenAICompatibleKeyVault;
116-
volcengine?: OpenAICompatibleKeyVault;
117-
wenxin?: OpenAICompatibleKeyVault;
118-
xai?: OpenAICompatibleKeyVault;
119-
xinference?: OpenAICompatibleKeyVault;
120-
zenmux?: OpenAICompatibleKeyVault;
121-
zeroone?: OpenAICompatibleKeyVault;
122-
zhipu?: OpenAICompatibleKeyVault;
12355
}

src/features/ChatList/Error/AccessCodeForm.tsx

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/services/__tests__/_auth.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ const mockTogetherAIAPIKey = 'togetherai-api-key';
2323
// mock the traditional zustand
2424
vi.mock('zustand/traditional');
2525

26-
const setModelProviderConfig = <T extends GlobalLLMProviderKey>(
27-
provider: T,
28-
config: Partial<UserKeyVaults[T]>,
29-
) => {
26+
const setModelProviderConfig = (provider: string, config: any) => {
3027
useUserStore.setState({
3128
settings: { keyVaults: { [provider]: config } },
3229
});

src/services/__tests__/share.test.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/services/_auth.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ModelProvider } from 'model-bank';
1313

1414
import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';
1515
import { useUserStore } from '@/store/user';
16-
import { keyVaultsConfigSelectors, userProfileSelectors } from '@/store/user/selectors';
16+
import { userProfileSelectors } from '@/store/user/selectors';
1717
import { obfuscatePayloadWithXOR } from '@/utils/client/xor-obfuscation';
1818

1919
import { resolveRuntimeProvider } from './chat/helper';
@@ -105,10 +105,9 @@ export const getProviderAuthPayload = (
105105
};
106106

107107
const createAuthTokenWithPayload = (payload = {}) => {
108-
const accessCode = keyVaultsConfigSelectors.password(useUserStore.getState());
109108
const userId = userProfileSelectors.userId(useUserStore.getState());
110109

111-
return obfuscatePayloadWithXOR<ClientSecretPayload>({ accessCode, userId, ...payload });
110+
return obfuscatePayloadWithXOR<ClientSecretPayload>({ userId, ...payload });
112111
};
113112

114113
interface AuthParams {

src/services/_header.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
LOBE_CHAT_ACCESS_CODE,
3-
LOBE_USER_ID,
4-
OPENAI_API_KEY_HEADER_KEY,
5-
OPENAI_END_POINT,
6-
} from '@/const/fetch';
1+
import { LOBE_USER_ID, OPENAI_API_KEY_HEADER_KEY, OPENAI_END_POINT } from '@/const/fetch';
72
import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';
83
import { useUserStore } from '@/store/user';
9-
import { keyVaultsConfigSelectors } from '@/store/user/selectors';
104

115
/**
126
* TODO: Need to be removed after tts refactor
@@ -22,7 +16,6 @@ export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
2216
// eslint-disable-next-line no-undef
2317
return {
2418
...header,
25-
[LOBE_CHAT_ACCESS_CODE]: keyVaultsConfigSelectors.password(state),
2619
[LOBE_USER_ID]: state.user?.id || '',
2720
[OPENAI_API_KEY_HEADER_KEY]: keyVaults.apiKey || '',
2821
[OPENAI_END_POINT]: keyVaults.baseURL || '',

src/store/chat/agents/__tests__/createAgentExecutors/call-llm.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ describe('call_llm executor', () => {
5858
sessionId: 'test-session',
5959
topicId: 'test-topic',
6060
}),
61+
expect.objectContaining({
62+
operationId: expect.any(String),
63+
}),
6164
);
6265
});
6366

@@ -229,6 +232,9 @@ describe('call_llm executor', () => {
229232
expect.objectContaining({
230233
parentId: 'msg_payload_parent',
231234
}),
235+
expect.objectContaining({
236+
operationId: expect.any(String),
237+
}),
232238
);
233239
});
234240

@@ -262,6 +268,9 @@ describe('call_llm executor', () => {
262268
expect.objectContaining({
263269
parentId: 'msg_context_parent',
264270
}),
271+
expect.objectContaining({
272+
operationId: expect.any(String),
273+
}),
265274
);
266275
});
267276
});
@@ -1061,6 +1070,9 @@ describe('call_llm executor', () => {
10611070
model: 'claude-3-opus',
10621071
provider: 'anthropic',
10631072
}),
1073+
expect.objectContaining({
1074+
operationId: expect.any(String),
1075+
}),
10641076
);
10651077
expect(mockStore.internal_fetchAIChatMessage).toHaveBeenCalledWith(
10661078
expect.objectContaining({
@@ -1180,6 +1192,9 @@ describe('call_llm executor', () => {
11801192
expect.objectContaining({
11811193
threadId,
11821194
}),
1195+
expect.objectContaining({
1196+
operationId: expect.any(String),
1197+
}),
11831198
);
11841199
});
11851200

@@ -1211,6 +1226,9 @@ describe('call_llm executor', () => {
12111226
expect.objectContaining({
12121227
threadId: undefined,
12131228
}),
1229+
expect.objectContaining({
1230+
operationId: expect.any(String),
1231+
}),
12141232
);
12151233
});
12161234
});

0 commit comments

Comments
 (0)