Skip to content

Commit 5bb9ff7

Browse files
authored
πŸ› Agents with abnormal status should also be allowed to operate #1683
2 parents 75b6a0a + 0e04b30 commit 5bb9ff7

File tree

8 files changed

+111
-58
lines changed

8 files changed

+111
-58
lines changed

β€Žfrontend/app/[locale]/chat/page.tsxβ€Ž

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect } from "react";
3+
import { useEffect, useRef } from "react";
44
import { useAuth } from "@/hooks/useAuth";
55

66
import { useConfig } from "@/hooks/useConfig";
@@ -12,20 +12,36 @@ import { ChatInterface } from "./internal/chatInterface";
1212
export default function ChatPage() {
1313
const { appConfig } = useConfig();
1414
const { user, isLoading: userLoading, isSpeedMode } = useAuth();
15+
const canAccessProtectedData = isSpeedMode || (!userLoading && !!user);
16+
const sessionExpiredTriggeredRef = useRef(false);
1517

1618
useEffect(() => {
19+
if (!canAccessProtectedData) {
20+
return;
21+
}
1722
// Load config from backend when entering chat page
1823
configService.loadConfigToFrontend();
1924

2025
if (appConfig.appName) {
2126
document.title = `${appConfig.appName}`;
2227
}
23-
}, [appConfig.appName]);
28+
}, [appConfig.appName, canAccessProtectedData]);
2429

2530
// Require login on chat page when unauthenticated (full mode only)
2631
// Trigger SESSION_EXPIRED event to show "Login Expired" modal instead of directly opening login modal
2732
useEffect(() => {
28-
if (!isSpeedMode && !userLoading && !user) {
33+
if (isSpeedMode) {
34+
sessionExpiredTriggeredRef.current = false;
35+
return;
36+
}
37+
38+
if (user) {
39+
sessionExpiredTriggeredRef.current = false;
40+
return;
41+
}
42+
43+
if (!userLoading && !sessionExpiredTriggeredRef.current) {
44+
sessionExpiredTriggeredRef.current = true;
2945
window.dispatchEvent(
3046
new CustomEvent(EVENTS.SESSION_EXPIRED, {
3147
detail: { message: "Session expired, please sign in again" },
@@ -35,7 +51,7 @@ export default function ChatPage() {
3551
}, [isSpeedMode, user, userLoading]);
3652

3753
// Avoid rendering and backend calls when unauthenticated (full mode only)
38-
if (!isSpeedMode && (!user || userLoading)) {
54+
if (!canAccessProtectedData) {
3955
return null;
4056
}
4157

β€Žfrontend/app/[locale]/setup/agents/components/agent/SubAgentPool.tsxβ€Ž

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,8 @@ export default function SubAgentPool({
428428
onClick={(e) => {
429429
e.preventDefault();
430430
e.stopPropagation();
431-
if (isEffectivelyAvailable) {
432-
handleViewCallRelationship(agent);
433-
}
431+
handleViewCallRelationship(agent);
434432
}}
435-
disabled={!isEffectivelyAvailable}
436433
className="agent-action-button agent-action-button-blue"
437434
/>
438435
</TooltipTrigger>
@@ -451,11 +448,8 @@ export default function SubAgentPool({
451448
onClick={(e) => {
452449
e.preventDefault();
453450
e.stopPropagation();
454-
if (isEffectivelyAvailable) {
455-
onExportAgent(agent);
456-
}
451+
onExportAgent(agent);
457452
}}
458-
disabled={!isEffectivelyAvailable}
459453
className="agent-action-button agent-action-button-green"
460454
/>
461455
</TooltipTrigger>
@@ -475,11 +469,8 @@ export default function SubAgentPool({
475469
onClick={(e) => {
476470
e.preventDefault();
477471
e.stopPropagation();
478-
if (isEffectivelyAvailable) {
479-
onDeleteAgent(agent);
480-
}
472+
onDeleteAgent(agent);
481473
}}
482-
disabled={!isEffectivelyAvailable}
483474
className="agent-action-button agent-action-button-red"
484475
/>
485476
</TooltipTrigger>

β€Žfrontend/app/[locale]/setup/agents/config.tsxβ€Ž

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ export type AgentConfigHandle = {
5252
reloadCurrentAgentData: () => Promise<void>;
5353
};
5454

55-
export default forwardRef<AgentConfigHandle, {}>(function AgentConfig(
56-
_props,
55+
interface AgentConfigProps {
56+
canAccessProtectedData: boolean;
57+
}
58+
59+
export default forwardRef<AgentConfigHandle, AgentConfigProps>(function AgentConfig(
60+
{ canAccessProtectedData },
5761
ref
5862
) {
5963
const { t } = useTranslation("common");
@@ -293,6 +297,9 @@ export default forwardRef<AgentConfigHandle, {}>(function AgentConfig(
293297

294298
// Load tools when page is loaded
295299
useEffect(() => {
300+
if (!canAccessProtectedData) {
301+
return;
302+
}
296303
// Check embedding configuration once when entering the page
297304
try {
298305
const modelConfig = configStore.getModelConfig();
@@ -332,7 +339,7 @@ export default forwardRef<AgentConfigHandle, {}>(function AgentConfig(
332339
};
333340

334341
loadTools();
335-
}, [t]);
342+
}, [canAccessProtectedData, t]);
336343

337344
// Get agent list
338345
const fetchAgents = async () => {
@@ -371,8 +378,11 @@ export default forwardRef<AgentConfigHandle, {}>(function AgentConfig(
371378

372379
// Get agent list when component is loaded
373380
useEffect(() => {
381+
if (!canAccessProtectedData) {
382+
return;
383+
}
374384
fetchAgents();
375-
}, []);
385+
}, [canAccessProtectedData]);
376386

377387
// Use refs to store latest values to avoid recreating event listener
378388
const businessLogicRef = useRef(businessLogic);

β€Žfrontend/app/[locale]/setup/agents/page.tsxβ€Ž

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ export default function AgentSetupPage() {
2525
const agentConfigRef = useRef<AgentConfigHandle | null>(null);
2626
const [showSaveConfirm, setShowSaveConfirm] = useState(false);
2727
const pendingNavRef = useRef<null | (() => void)>(null);
28+
const sessionExpiredTriggeredRef = useRef(false);
2829
const { message } = App.useApp();
2930
const router = useRouter();
3031
const { t } = useTranslation();
31-
const {
32-
user,
33-
isLoading: userLoading,
34-
isSpeedMode
35-
} = useAuth();
32+
const { user, isLoading: userLoading, isSpeedMode } = useAuth();
33+
const canAccessProtectedData = isSpeedMode || (!isSpeedMode && !userLoading && !!user);
3634

3735
const [connectionStatus, setConnectionStatus] = useState<ConnectionStatus>(
3836
CONNECTION_STATUS.PROCESSING
@@ -43,13 +41,17 @@ export default function AgentSetupPage() {
4341
// Check login status and permission
4442
// Trigger SESSION_EXPIRED event to show "Login Expired" modal instead of directly opening login modal
4543
useEffect(() => {
46-
if (!isSpeedMode && !userLoading && !user) {
44+
if (isSpeedMode) {
45+
sessionExpiredTriggeredRef.current = false;
46+
} else if (user) {
47+
sessionExpiredTriggeredRef.current = false;
48+
} else if (!userLoading && !sessionExpiredTriggeredRef.current) {
49+
sessionExpiredTriggeredRef.current = true;
4750
window.dispatchEvent(
4851
new CustomEvent(EVENTS.SESSION_EXPIRED, {
4952
detail: { message: "Session expired, please sign in again" },
5053
})
5154
);
52-
return;
5355
}
5456

5557
// Only admin users can access this page (full mode)
@@ -61,10 +63,10 @@ export default function AgentSetupPage() {
6163

6264
// Check the connection status when the page is initialized
6365
useEffect(() => {
64-
if (isSpeedMode || (user && !userLoading)) {
66+
if (canAccessProtectedData) {
6567
checkModelEngineConnection();
6668
}
67-
}, [isSpeedMode, user, userLoading]);
69+
}, [canAccessProtectedData]);
6870

6971
// Function to check the ModelEngine connection status
7072
const checkModelEngineConnection = async () => {
@@ -153,7 +155,9 @@ export default function AgentSetupPage() {
153155
transition={pageTransition}
154156
style={{ width: "100%", height: "100%" }}
155157
>
156-
<AgentConfig ref={agentConfigRef} />
158+
{canAccessProtectedData ? (
159+
<AgentConfig ref={agentConfigRef} canAccessProtectedData={canAccessProtectedData} />
160+
) : null}
157161
</motion.div>
158162
</SetupLayout>
159163
<SaveConfirmModal

β€Žfrontend/app/[locale]/setup/knowledges/page.tsxβ€Ž

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import React, { useState, useEffect } from "react";
3+
import React, { useState, useEffect, useRef } from "react";
44
import { useRouter } from "next/navigation";
55
import { useTranslation } from "react-i18next";
66

@@ -27,6 +27,8 @@ export default function KnowledgeSetupPage() {
2727
const router = useRouter();
2828
const { t } = useTranslation();
2929
const { user, isLoading: userLoading, isSpeedMode } = useAuth();
30+
const canAccessProtectedData = isSpeedMode || (!userLoading && !!user);
31+
const sessionExpiredTriggeredRef = useRef(false);
3032

3133
const [connectionStatus, setConnectionStatus] = useState<ConnectionStatus>(
3234
CONNECTION_STATUS.PROCESSING
@@ -37,19 +39,29 @@ export default function KnowledgeSetupPage() {
3739
// Check login status and permission
3840
// Trigger SESSION_EXPIRED event to show "Login Expired" modal instead of directly opening login modal
3941
useEffect(() => {
40-
if (!isSpeedMode && !userLoading && !user) {
42+
if (isSpeedMode) {
43+
sessionExpiredTriggeredRef.current = false;
44+
return;
45+
}
46+
47+
if (user) {
48+
sessionExpiredTriggeredRef.current = false;
49+
return;
50+
}
51+
52+
if (!userLoading && !sessionExpiredTriggeredRef.current) {
53+
sessionExpiredTriggeredRef.current = true;
4154
window.dispatchEvent(
4255
new CustomEvent(EVENTS.SESSION_EXPIRED, {
4356
detail: { message: "Session expired, please sign in again" },
4457
})
4558
);
46-
return;
4759
}
4860
}, [isSpeedMode, user, userLoading]);
4961

5062
// Check the connection status when the page is initialized
5163
useEffect(() => {
52-
if (!(isSpeedMode || user)) return;
64+
if (!canAccessProtectedData) return;
5365
checkModelEngineConnection();
5466

5567
// Trigger knowledge base data acquisition when the page is initialized
@@ -72,7 +84,7 @@ export default function KnowledgeSetupPage() {
7284
};
7385

7486
loadConfigForNormalUser();
75-
}, [isSpeedMode, user]);
87+
}, [canAccessProtectedData]);
7688

7789
// Function to check the ModelEngine connection status
7890
const checkModelEngineConnection = async () => {
@@ -178,16 +190,18 @@ export default function KnowledgeSetupPage() {
178190
nextText={t("setup.navigation.button.next")}
179191
completeText={t("setup.navigation.button.complete")}
180192
>
181-
<motion.div
182-
initial="initial"
183-
animate="in"
184-
exit="out"
185-
variants={pageVariants}
186-
transition={pageTransition}
187-
style={{ width: "100%", height: "100%" }}
188-
>
189-
<DataConfig isActive={true} />
190-
</motion.div>
193+
{canAccessProtectedData ? (
194+
<motion.div
195+
initial="initial"
196+
animate="in"
197+
exit="out"
198+
variants={pageVariants}
199+
transition={pageTransition}
200+
style={{ width: "100%", height: "100%" }}
201+
>
202+
<DataConfig isActive={true} />
203+
</motion.div>
204+
) : null}
191205
</SetupLayout>
192206
);
193207
}

β€Žfrontend/app/[locale]/setup/models/components/modelConfig.tsxβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface ModelConfigSectionRef {
8686

8787
interface ModelConfigSectionProps {
8888
skipVerification?: boolean;
89+
canAccessProtectedData?: boolean;
8990
}
9091

9192
export const ModelConfigSection = forwardRef<
@@ -94,7 +95,7 @@ export const ModelConfigSection = forwardRef<
9495
>((props, ref): ReactNode => {
9596
const { t } = useTranslation();
9697
const { message } = App.useApp();
97-
const { skipVerification = false } = props;
98+
const { skipVerification = false, canAccessProtectedData = false } = props;
9899
const { modelConfig, updateModelConfig } = useConfig();
99100
const modelData = getModelData(t);
100101

@@ -155,6 +156,9 @@ export const ModelConfigSection = forwardRef<
155156

156157
// Initialize loading
157158
useEffect(() => {
159+
if (!canAccessProtectedData) {
160+
return;
161+
}
158162
// Load configuration from backend first, then load model lists when component mounts
159163
const fetchData = async () => {
160164
await configService.loadConfigToFrontend();
@@ -163,7 +167,7 @@ export const ModelConfigSection = forwardRef<
163167
};
164168

165169
fetchData();
166-
}, [skipVerification]);
170+
}, [canAccessProtectedData, skipVerification]);
167171

168172
// Listen to field error highlight events
169173
useEffect(() => {

β€Žfrontend/app/[locale]/setup/models/config.tsxβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { Title } = Typography
1919
// Add interface definition
2020
interface AppModelConfigProps {
2121
skipModelVerification?: boolean;
22+
canAccessProtectedData?: boolean;
2223
onSelectedModelsChange?: (
2324
selected: Record<string, Record<string, string>>
2425
) => void;
@@ -32,6 +33,7 @@ interface AppModelConfigProps {
3233

3334
export default function AppModelConfig({
3435
skipModelVerification = false,
36+
canAccessProtectedData = false,
3537
onSelectedModelsChange,
3638
onEmbeddingConnectivityChange,
3739
forwardedRef,
@@ -159,6 +161,7 @@ export default function AppModelConfig({
159161
<ModelConfigSection
160162
ref={modelConfigRef as any}
161163
skipVerification={skipModelVerification}
164+
canAccessProtectedData={canAccessProtectedData}
162165
/>
163166
</div>
164167
</div>

0 commit comments

Comments
Β (0)