From 0b2dfbb88f403d628db3d1deb11d79e54c812450 Mon Sep 17 00:00:00 2001 From: suyao Date: Sat, 20 Sep 2025 14:53:08 +0800 Subject: [PATCH] Add accessible paths management to agent configuration Move accessible paths functionality from session modal to agent modal, add validation requiring at least one path, and update form handling to inherit agent paths in sessions. --- .../components/Popups/agent/AgentModal.tsx | 66 ++++++++++++++++++- .../components/Popups/agent/SessionModal.tsx | 66 ++----------------- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/src/renderer/src/components/Popups/agent/AgentModal.tsx b/src/renderer/src/components/Popups/agent/AgentModal.tsx index 31e486079c..9a43906b5a 100644 --- a/src/renderer/src/components/Popups/agent/AgentModal.tsx +++ b/src/renderer/src/components/Popups/agent/AgentModal.tsx @@ -158,6 +158,35 @@ export const AgentModal: React.FC = ({ agent, trigger, isOpen: _isOpen, o })) }, []) + const addAccessiblePath = useCallback(async () => { + try { + const selected = await window.api.file.selectFolder() + if (!selected) { + return + } + setForm((prev) => { + if (prev.accessible_paths.includes(selected)) { + window.toast.warning(t('agent.session.accessible_paths.duplicate')) + return prev + } + return { + ...prev, + accessible_paths: [...prev.accessible_paths, selected] + } + }) + } catch (error) { + logger.error('Failed to select accessible path:', error as Error) + window.toast.error(t('agent.session.accessible_paths.select_failed')) + } + }, [t]) + + const removeAccessiblePath = useCallback((path: string) => { + setForm((prev) => ({ + ...prev, + accessible_paths: prev.accessible_paths.filter((item) => item !== path) + })) + }, []) + const modelOptions = useMemo(() => { // mocked data. not final version return (models ?? []).map((model) => ({ @@ -197,6 +226,12 @@ export const AgentModal: React.FC = ({ agent, trigger, isOpen: _isOpen, o return } + if (form.accessible_paths.length === 0) { + window.toast.error(t('agent.session.accessible_paths.required')) + loadingRef.current = false + return + } + if (isEditing(agent)) { if (!agent) { throw new Error('Agent is required for editing mode') @@ -207,7 +242,8 @@ export const AgentModal: React.FC = ({ agent, trigger, isOpen: _isOpen, o name: form.name, description: form.description, instructions: form.instructions, - model: form.model + model: form.model, + accessible_paths: [...form.accessible_paths] } satisfies UpdateAgentForm updateAgent(updatePayload) @@ -309,6 +345,34 @@ export const AgentModal: React.FC = ({ agent, trigger, isOpen: _isOpen, o value={form.description ?? ''} onValueChange={onDescChange} /> +
+
+ + {t('agent.session.accessible_paths.label')} + + +
+ {form.accessible_paths.length > 0 ? ( +
+ {form.accessible_paths.map((path) => ( +
+ + {path} + + +
+ ))} +
+ ) : ( +

{t('agent.session.accessible_paths.empty')}

+ )} +