11import {
22 AlertCircle ,
3+ ArrowLeft ,
34 Bot ,
45 Check ,
56 FileCode2 ,
@@ -62,6 +63,7 @@ export function CustomAgentManagerDialog({
6263 const [ error , setError ] = useState < string > ( ) ;
6364 const [ notice , setNotice ] = useState < string > ( ) ;
6465 const [ confirmDelete , setConfirmDelete ] = useState ( false ) ;
66+ const [ mobilePane , setMobilePane ] = useState < "list" | "editor" > ( "list" ) ;
6567
6668 const dirty = Boolean ( draft && draft . content !== draft . originalContent ) ;
6769 const scopedAgents = useMemo (
@@ -153,6 +155,7 @@ export function CustomAgentManagerDialog({
153155 const selectScope = ( scope : CustomAgentScope ) : void => {
154156 if ( scope === activeScope || ! confirmDiscard ( ) ) return ;
155157 setActiveScope ( scope ) ;
158+ setMobilePane ( "list" ) ;
156159 setNotice ( undefined ) ;
157160 setError ( undefined ) ;
158161 const first = agents . find ( ( agent ) => agent . scope === scope ) ;
@@ -172,7 +175,11 @@ export function CustomAgentManagerDialog({
172175
173176 const selectAgent = ( agent : CustomAgentDescriptor ) : void => {
174177 const key = customAgentKey ( agent ) ;
175- if ( key === selectedKey || ! confirmDiscard ( ) ) return ;
178+ if ( key === selectedKey ) {
179+ setMobilePane ( "editor" ) ;
180+ return ;
181+ }
182+ if ( ! confirmDiscard ( ) ) return ;
176183 setSelectedKey ( key ) ;
177184 setDraft ( {
178185 scope : agent . scope ,
@@ -183,6 +190,7 @@ export function CustomAgentManagerDialog({
183190 setNotice ( undefined ) ;
184191 setError ( undefined ) ;
185192 setConfirmDelete ( false ) ;
193+ setMobilePane ( "editor" ) ;
186194 } ;
187195
188196 const createAgent = ( ) : void => {
@@ -197,6 +205,7 @@ export function CustomAgentManagerDialog({
197205 setNotice ( undefined ) ;
198206 setError ( undefined ) ;
199207 setConfirmDelete ( false ) ;
208+ setMobilePane ( "editor" ) ;
200209 window . setTimeout ( ( ) => editorRef . current ?. focus ( ) , 0 ) ;
201210 } ;
202211
@@ -239,6 +248,7 @@ export function CustomAgentManagerDialog({
239248 setConfirmDelete ( false ) ;
240249 setSelectedKey ( undefined ) ;
241250 setDraft ( undefined ) ;
251+ setMobilePane ( "list" ) ;
242252 setNotice ( t ( "agents.deleted" ) ) ;
243253 await loadAgents ( undefined , activeScope ) ;
244254 } catch ( nextError ) {
@@ -253,6 +263,25 @@ export function CustomAgentManagerDialog({
253263 void loadAgents ( selectedKey , activeScope ) ;
254264 } ;
255265
266+ const showAgentList = ( ) : void => {
267+ if ( ! confirmDiscard ( ) ) return ;
268+ if ( ! draft ?. relativePath ) {
269+ setSelectedKey ( undefined ) ;
270+ setDraft ( undefined ) ;
271+ } else if ( selectedAgent ) {
272+ setDraft ( {
273+ scope : selectedAgent . scope ,
274+ relativePath : selectedAgent . relativePath ,
275+ content : selectedAgent . content ,
276+ originalContent : selectedAgent . content ,
277+ } ) ;
278+ }
279+ setError ( undefined ) ;
280+ setNotice ( undefined ) ;
281+ setConfirmDelete ( false ) ;
282+ setMobilePane ( "list" ) ;
283+ } ;
284+
256285 const handleEditorKeyDown = (
257286 event : ReactKeyboardEvent < HTMLTextAreaElement > ,
258287 ) : void => {
@@ -332,7 +361,7 @@ export function CustomAgentManagerDialog({
332361 </ button >
333362 </ div >
334363
335- < div className = " agent-manager-body" >
364+ < div className = { ` agent-manager-body ${ mobilePane === "editor" ? "mobile-editor-open" : "" } ` } >
336365 < aside className = "agent-manager-list-pane" >
337366 < div className = "agent-manager-list-heading" >
338367 < div >
@@ -387,7 +416,15 @@ export function CustomAgentManagerDialog({
387416 { draft ? (
388417 < >
389418 < div className = "agent-manager-editor-heading" >
390- < div >
419+ < button
420+ className = "agent-manager-mobile-back"
421+ type = "button"
422+ aria-label = { t ( "agents.backToList" ) }
423+ onClick = { showAgentList }
424+ >
425+ < ArrowLeft size = { 18 } />
426+ </ button >
427+ < div className = "agent-manager-editor-meta" >
391428 < span > { draft . relativePath ? selectedAgent ?. name ?? draft . relativePath : t ( "agents.untitled" ) } </ span >
392429 < small > { draft . relativePath ? selectedAgent ?. path : t ( "agents.newHint" ) } </ small >
393430 </ div >
0 commit comments