Skip to content

Commit e175c33

Browse files
authored
πŸ› Bugfix in createmode cannot edit tool & cannot change agent model id
πŸ› Bugfix in createmode cannot edit tool & cannot change agent model id
2 parents b91149a + ffba9f5 commit e175c33

5 files changed

Lines changed: 96 additions & 90 deletions

File tree

β€Žfrontend/app/[locale]/agents/components/AgentConfigComp.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export default function AgentConfigComp({}: AgentConfigCompProps) {
143143
<Col xs={24} className="h-full">
144144
<ToolManagement
145145
toolGroups={groupedTools}
146-
editable={editable}
146+
isCreatingMode={isCreatingMode}
147147
currentAgentId={currentAgentId?? undefined}
148148
/>
149149
</Col>

β€Žfrontend/app/[locale]/agents/components/agentConfig/ToolManagement.tsxβ€Ž

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Settings } from "lucide-react";
1616

1717
interface ToolManagementProps {
1818
toolGroups: ToolGroup[];
19-
editable?: boolean;
19+
isCreatingMode?: boolean;
2020
currentAgentId?: number | undefined;
2121
}
2222

@@ -26,12 +26,13 @@ interface ToolManagementProps {
2626
*/
2727
export default function ToolManagement({
2828
toolGroups,
29-
editable = true,
29+
isCreatingMode = true,
3030
currentAgentId,
3131
}: ToolManagementProps) {
3232
const { t } = useTranslation("common");
3333
const queryClient = useQueryClient();
3434

35+
const editable = currentAgentId !== null || isCreatingMode;
3536
// Get state from store
3637
const usedTools = useAgentConfigStore((state) => state.editedAgent.tools);
3738
const updateTools = useAgentConfigStore((state) => state.updateTools);
@@ -49,45 +50,50 @@ export default function ToolManagement({
4950
const [toolParams, setToolParams] = useState<ToolParam[]>([]);
5051

5152
// Get tool info for selected tool (when checking if config is needed)
52-
const { data: selectedToolInfo } = useToolInfo(
53+
const { data: selectedToolInfo, isLoading: isToolInfoLoading } = useToolInfo(
5354
(selectedTool) ? parseInt(selectedTool.id) : null,
5455
currentAgentId ?? null
5556
);
5657

5758
// Effect to handle tool selection when tool info is loaded
5859
useEffect(() => {
59-
if (selectedTool && selectedToolInfo) {
60-
// Use instance params if available, otherwise use default params
61-
const mergedParams = selectedTool.initParams?.map((param: ToolParam) => {
60+
let mergedParams: ToolParam[];
61+
62+
if (isCreatingMode && selectedTool) {
63+
mergedParams = selectedTool.initParams || [];
64+
} else if (selectedTool && selectedToolInfo) {
65+
mergedParams = selectedTool.initParams?.map((param: ToolParam) => {
6266
const instanceValue = selectedToolInfo?.params?.[param.name];
6367
return {
6468
...param,
6569
value: instanceValue !== undefined ? instanceValue : param.value,
6670
};
6771
}) || [];
68-
setToolParams(mergedParams);
69-
70-
const hasEmptyRequiredParams = mergedParams.some(
71-
(param: ToolParam) => param.required &&
72+
} else {
73+
return;
74+
}
75+
setToolParams(mergedParams);
76+
const hasEmptyRequiredParams = mergedParams.some(
77+
(param: ToolParam) => param.required &&
7278
(param.value === undefined || param.value === '' || param.value === null)
73-
);
74-
if (isClickSetting || hasEmptyRequiredParams) {
75-
// Open modal for configuration with pre-calculated params
76-
setIsToolModalOpen(true);
77-
setIsClickSetting(false)
78-
} else {
79-
// Add tool directly
80-
const newSelectedTools = [...usedTools, {
81-
...selectedTool,
82-
initParams: mergedParams
83-
}];
84-
updateTools(newSelectedTools);
85-
setSelectedTool(null); // Clear selected tool
86-
setIsClickSetting(false)
87-
}
88-
79+
);
80+
if (isClickSetting || hasEmptyRequiredParams) {
81+
// Open modal for configuration with pre-calculated params
82+
setIsToolModalOpen(true);
83+
setIsClickSetting(false)
84+
} else {
85+
// Add tool directly
86+
const newSelectedTools = [...usedTools, {
87+
...selectedTool,
88+
initParams: mergedParams
89+
}];
90+
updateTools(newSelectedTools);
91+
setSelectedTool(null); // Clear selected tool
92+
setIsClickSetting(false)
8993
}
90-
}, [selectedTool, selectedToolInfo]);
94+
95+
96+
}, [selectedTool, isToolInfoLoading]);
9197

9298
// Create selected tool ID set for efficient lookup
9399
const selectedToolIdsSet = new Set(
@@ -109,48 +115,55 @@ export default function ToolManagement({
109115
};
110116

111117
const handleToolModalSave = async (params: ToolParam[]) => {
112-
if (!selectedTool || !currentAgentId) return;
118+
if (!selectedTool) return;
113119

114-
try {
115120
// Convert params to backend format
116121
const paramsObj = params.reduce((acc, param) => {
117122
acc[param.name] = param.value;
118123
return acc;
119124
}, {} as Record<string, any>);
120125

121-
// Save tool config
122-
const isEnabled = true; // New tool is enabled by default
123-
const result = await updateToolConfig(
124-
parseInt(selectedTool.id),
125-
currentAgentId,
126-
paramsObj,
127-
isEnabled
128-
);
129-
130-
if (result.success) {
131-
// Add tool to selected tools with updated params
132-
const updatedTool = { ...selectedTool, initParams: params };
133-
const newSelectedTools = [...usedTools, updatedTool];
134-
updateTools(newSelectedTools);
135-
136-
message.success(t("toolConfig.message.saveSuccess"));
126+
if (isCreatingMode) {
127+
saveToolConfig(params);
128+
} else if (currentAgentId) {
137129

138-
queryClient.invalidateQueries({
139-
queryKey: ["toolInfo", parseInt(selectedTool.id), currentAgentId]
140-
});
130+
try {
131+
const isEnabled = true; // New tool is enabled by default
132+
const result = await updateToolConfig(
133+
parseInt(selectedTool.id),
134+
currentAgentId,
135+
paramsObj,
136+
isEnabled
137+
);
141138

142-
setIsToolModalOpen(false);
143-
setSelectedTool(null);
144-
setToolParams([]);
145-
setIsClickSetting(false)
146-
} else {
147-
message.error(result.message || t("toolConfig.message.saveError"));
139+
if (result.success) {
140+
saveToolConfig(params);
141+
queryClient.invalidateQueries({
142+
queryKey: ["toolInfo", parseInt(selectedTool.id), currentAgentId]
143+
});
144+
} else {
145+
message.error(result.message || t("toolConfig.message.saveError"));
146+
}
147+
} catch (error) {
148+
message.error(t("toolConfig.message.saveError"));
149+
}
148150
}
149-
} catch (error) {
150-
message.error(t("toolConfig.message.saveError"));
151-
}
152151
};
153152

153+
154+
const saveToolConfig = async (params: ToolParam[]) => {
155+
// Add tool to selected tools with updated params
156+
const updatedTool = { ...selectedTool!, initParams: params };
157+
const newSelectedTools = [...usedTools, updatedTool];
158+
updateTools(newSelectedTools);
159+
160+
message.success(t("toolConfig.message.saveSuccess"));
161+
162+
setIsToolModalOpen(false);
163+
setSelectedTool(null);
164+
setToolParams([]);
165+
setIsClickSetting(false)
166+
}
154167
const handleToolSettingsClick = (tool: Tool) => {
155168
setIsClickSetting(true)
156169
setSelectedTool(tool);
@@ -164,7 +177,6 @@ export default function ToolManagement({
164177
const isCurrentlySelected = usedTools.some(
165178
(t) => parseInt(t.id) === toolId
166179
);
167-
168180
if (isCurrentlySelected) {
169181
const newSelectedTools = usedTools.filter((t) => parseInt(t.id) !== toolId);
170182
updateTools(newSelectedTools);

β€Žfrontend/app/[locale]/agents/components/agentInfo/AgentGenerateDetail.tsxβ€Ž

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,15 @@ export default function AgentGenerateDetail({
399399
>
400400
<Select
401401
placeholder={t("businessLogic.config.modelPlaceholder")}
402-
onChange={(value) => onUpdateProfile({ model: value })}
402+
onChange={(value) => {
403+
const selectedModel = availableLlmModels.find(
404+
(m) => m.displayName === value
405+
);
406+
onUpdateProfile({
407+
model: value,
408+
model_id: selectedModel?.id || 0,
409+
});
410+
}}
403411
>
404412
{availableLlmModels.map((model) => (
405413
<Select.Option

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -843,21 +843,16 @@ export const ModelConfigSection = forwardRef<
843843
>
844844
<Row gutter={[8, 8]} style={{ width: "100%" }}>
845845
<Col xs={24} sm={12} md={6} lg={6} xl={6}>
846-
<Button
847-
type="primary"
848-
size="middle"
846+
<Button
847+
type="primary"
848+
size="middle"
849849
onClick={handleSyncModels}
850850
style={{ width: "100%" }}
851+
icon={<RefreshCw size={16} />}
851852
block
852853
>
853-
<RefreshCw className="mr-1" size={16} />
854-
<span style={{ marginLeft: 4 }}>
855-
<span className="hidden xl:inline button-text-full">
856-
{t("modelConfig.button.syncModelEngine")}
857-
</span>
858-
<span className="xl:hidden button-text-short">
859-
{t("modelConfig.button.sync")}
860-
</span>
854+
<span className="button-text-full">
855+
{t("modelConfig.button.syncModelEngine")}
861856
</span>
862857
</Button>
863858
</Col>
@@ -873,12 +868,9 @@ export const ModelConfigSection = forwardRef<
873868
style={{ width: "100%" }}
874869
block
875870
>
876-
<span className="hidden xl:inline button-text-full">
871+
<span className="button-text-full">
877872
{t("modelConfig.button.addCustomModel")}
878873
</span>
879-
<span className="xl:hidden button-text-short">
880-
{t("modelConfig.button.add")}
881-
</span>
882874
</Button>
883875
</Col>
884876
<Col xs={24} sm={12} md={6} lg={6} xl={6}>
@@ -890,12 +882,9 @@ export const ModelConfigSection = forwardRef<
890882
style={{ width: "100%" }}
891883
block
892884
>
893-
<span className="hidden xl:inline button-text-full">
885+
<span className="button-text-full">
894886
{t("modelConfig.button.editCustomModel")}
895887
</span>
896-
<span className="xl:hidden button-text-short">
897-
{t("modelConfig.button.edit")}
898-
</span>
899888
</Button>
900889
</Col>
901890
<Col xs={24} sm={12} md={6} lg={6} xl={6}>
@@ -908,12 +897,9 @@ export const ModelConfigSection = forwardRef<
908897
style={{ width: "100%" }}
909898
block
910899
>
911-
<span className="hidden xl:inline button-text-full">
900+
<span className="button-text-full">
912901
{t("modelConfig.button.checkConnectivity")}
913902
</span>
914-
<span className="xl:hidden button-text-short">
915-
{t("modelConfig.button.check")}
916-
</span>
917903
</Button>
918904
</Col>
919905
</Row>

β€Žfrontend/styles/globals.cssβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@
317317
}
318318
}
319319

320-
@media (min-width: 1280px) {
321-
.button-text-full {
322-
display: inline !important;
323-
}
324-
.button-text-short {
325-
display: none !important;
326-
}
320+
321+
.button-text-full {
322+
display: inline !important;
323+
overflow: hidden;
324+
text-overflow: ellipsis;
325+
white-space: nowrap;
326+
max-width: 100%;
327327
}
328328

329329
/* Selected table row: draw full-height left stripe inside first cell */

0 commit comments

Comments
Β (0)