Skip to content

Commit 1811b10

Browse files
authored
🐛 Bugfix: When creating a new Agent, the user is not prompted to save it before debugging
🐛 Bugfix: When creating a new Agent, the user is not prompted to save it before debugging 🐛 Bugfix: Agent modification of unsaved prompts can bypass information verification 🐛 Bugfix: When an Agent is selected and another Agent is imported, it will prompt that there are modifications 🐛 Bugfix: Creating agents will inherit tool parameters wrongly from previous selected agent
2 parents 9b574e1 + c63cb3d commit 1811b10

File tree

5 files changed

+65
-12
lines changed

5 files changed

+65
-12
lines changed

frontend/app/[locale]/agents/components/AgentSetupOrchestrator.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,15 +500,17 @@ export default function AgentSetupOrchestrator({
500500

501501
const confirmOrRun = useCallback(
502502
(action: PendingAction) => {
503-
if (hasUnsavedChanges) {
503+
// In creation mode, always show save confirmation dialog when clicking debug
504+
// Also show when there are unsaved changes
505+
if ((isCreatingNewAgent && !isEditingAgent) || hasUnsavedChanges) {
504506
setPendingAction(() => action);
505507
setConfirmContext("switch");
506508
setIsSaveConfirmOpen(true);
507509
} else {
508510
void Promise.resolve(action());
509511
}
510512
},
511-
[hasUnsavedChanges]
513+
[hasUnsavedChanges, isCreatingNewAgent, isEditingAgent]
512514
);
513515

514516
const handleToolConfigDraftSave = useCallback(
@@ -905,6 +907,8 @@ export default function AgentSetupOrchestrator({
905907
setSelectedTools([]);
906908
setEnabledToolIds([]);
907909
setEnabledAgentIds([]);
910+
setToolConfigDrafts({});
911+
setMainAgentId?.(null);
908912

909913
// Clear business logic model to allow default from global settings
910914
// The useEffect in PromptManager will set it to the default from localStorage
@@ -916,6 +920,12 @@ export default function AgentSetupOrchestrator({
916920
setMainAgentModel(null);
917921
setMainAgentModelId(null);
918922

923+
try {
924+
await onToolsRefresh?.(false);
925+
} catch (error) {
926+
log.error("Failed to refresh tools in creation mode:", error);
927+
}
928+
919929
onEditingStateChange?.(false, null);
920930
};
921931

@@ -1545,7 +1555,8 @@ export default function AgentSetupOrchestrator({
15451555
message.success(
15461556
translationFn("businessLogic.config.error.agentImportSuccess")
15471557
);
1548-
await refreshAgentList(translationFn);
1558+
// Don't clear tools when importing to avoid triggering false unsaved changes indicator
1559+
await refreshAgentList(translationFn, false);
15491560
return true;
15501561
}
15511562

@@ -1745,9 +1756,26 @@ export default function AgentSetupOrchestrator({
17451756
skipUnsavedCheckRef.current = false;
17461757
}, 0);
17471758
onEditingStateChange?.(false, null);
1759+
} else {
1760+
// If deleting another agent that is in enabledAgentIds, remove it and update baseline
1761+
// to avoid triggering false unsaved changes indicator
1762+
const deletedId = Number(agentToDelete.id);
1763+
if (enabledAgentIds.includes(deletedId)) {
1764+
const updatedEnabledAgentIds = enabledAgentIds.filter(
1765+
(id) => id !== deletedId
1766+
);
1767+
setEnabledAgentIds(updatedEnabledAgentIds);
1768+
// Update baseline to reflect this change so it doesn't trigger unsaved changes
1769+
if (baselineRef.current) {
1770+
baselineRef.current = {
1771+
...baselineRef.current,
1772+
enabledAgentIds: updatedEnabledAgentIds.sort((a, b) => a - b),
1773+
};
1774+
}
1775+
}
17481776
}
1749-
// Refresh agent list
1750-
refreshAgentList(t);
1777+
// Refresh agent list without clearing tools to avoid triggering false unsaved changes indicator
1778+
refreshAgentList(t, false);
17511779
} else {
17521780
message.error(
17531781
result.message || t("businessLogic.config.error.agentDeleteFailed")
@@ -2144,6 +2172,10 @@ export default function AgentSetupOrchestrator({
21442172
// Only close modal, don't execute discard logic
21452173
setIsSaveConfirmOpen(false);
21462174
}}
2175+
canSave={localCanSaveAgent}
2176+
invalidReason={
2177+
localCanSaveAgent ? undefined : getLocalButtonTitle() || undefined
2178+
}
21472179
/>
21482180
{/* Duplicate import confirmation */}
21492181
<Modal

frontend/app/[locale]/agents/components/SaveConfirmModal.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ interface SaveConfirmModalProps {
1212
onSave: AsyncOrSyncHandler;
1313
onClose?: AsyncOrSyncHandler;
1414
width?: number;
15+
canSave?: boolean;
16+
invalidReason?: string;
1517
}
1618

1719
export default function SaveConfirmModal({
@@ -20,6 +22,8 @@ export default function SaveConfirmModal({
2022
onSave,
2123
onClose,
2224
width = 520,
25+
canSave = true,
26+
invalidReason,
2327
}: SaveConfirmModalProps) {
2428
const { t } = useTranslation("common");
2529

@@ -46,10 +50,14 @@ export default function SaveConfirmModal({
4650
centered
4751
footer={
4852
<div className="flex justify-end mt-4 gap-3">
49-
<Button onClick={handleCancel}>{t("agentConfig.modals.saveConfirm.discard")}</Button>
50-
<Button type="primary" onClick={handleSave}>
51-
{t("agentConfig.modals.saveConfirm.save")}
53+
<Button onClick={handleCancel}>
54+
{t("agentConfig.modals.saveConfirm.discard")}
5255
</Button>
56+
{canSave ? (
57+
<Button type="primary" onClick={handleSave}>
58+
{t("agentConfig.modals.saveConfirm.save")}
59+
</Button>
60+
) : null}
5361
</div>
5462
}
5563
width={width}
@@ -61,9 +69,19 @@ export default function SaveConfirmModal({
6169
style={{ fontSize: "48px" }}
6270
/>
6371
<div className="ml-3 mt-2">
64-
<div className="text-sm leading-6">
65-
{t("agentConfig.modals.saveConfirm.content")}
66-
</div>
72+
{canSave ? (
73+
<div className="text-sm leading-6">
74+
{t("agentConfig.modals.saveConfirm.content")}
75+
</div>
76+
) : (
77+
<div className="text-sm leading-6 flex flex-col gap-2">
78+
<span>
79+
{t("agentConfig.modals.saveConfirm.invalidContent", {
80+
invalidReason,
81+
})}
82+
</span>
83+
</div>
84+
)}
6785
</div>
6886
</div>
6987
</div>

frontend/app/[locale]/agents/components/tool/ToolConfigModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ export default function ToolConfigModal({
8484
return;
8585
}
8686

87-
// In creation mode we do not have an agent ID yet, so use the tool's default params.
87+
// In creation mode (no agent ID), always use backend-provided default params
8888
if (!normalizedAgentId) {
8989
setCurrentParams(buildDefaultParams());
9090
return;
9191
}
9292

9393
setIsLoading(true);
9494
try {
95+
// In edit mode, load tool config for the specific agent
9596
const result = await searchToolConfig(
9697
parseInt(tool.id),
9798
normalizedAgentId

frontend/public/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@
926926
"agentConfig.agents.listFetchFailedDebug": "Failed to fetch Agent list:",
927927
"agentConfig.modals.saveConfirm.title": "Unsaved changes",
928928
"agentConfig.modals.saveConfirm.content": "You have unsaved changes. Would you like to save them now?",
929+
"agentConfig.modals.saveConfirm.invalidContent": "Current configuration cannot be saved: {{invalidReason}}. Please modify and try again.",
929930
"agentConfig.modals.saveConfirm.discard": "Discard",
930931
"agentConfig.modals.saveConfirm.save": "Save",
931932

frontend/public/locales/zh/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@
926926
"agentConfig.agents.listFetchFailedDebug": "获取 Agent 列表失败:",
927927
"agentConfig.modals.saveConfirm.title": "未保存的更改",
928928
"agentConfig.modals.saveConfirm.content": "当前Agent有未保存的更改。是否现在保存?",
929+
"agentConfig.modals.saveConfirm.invalidContent": "当前配置无法保存:{{invalidReason}}。请修改后重试。",
929930
"agentConfig.modals.saveConfirm.discard": "放弃更改",
930931
"agentConfig.modals.saveConfirm.save": "保存",
931932

0 commit comments

Comments
 (0)