@@ -37,6 +37,38 @@ bool AgentSession::start( const std::function<void( bool )>& onReady ) {
3737 return false ;
3838}
3939
40+ bool AgentSession::startLoaded ( const std::string& sessionId,
41+ const std::function<void ( bool )>& onReady ) {
42+ if ( mClient ->start () ) {
43+ InitializeRequest req;
44+ req.clientCapabilities .terminal = true ;
45+ req.clientCapabilities .fsReadTextFile = true ;
46+ req.clientCapabilities .fsWriteTextFile = true ;
47+
48+ mClient ->initialize ( req, [this , sessionId, onReady]( const InitializeResponse& ires ) {
49+ if ( ires.agentCapabilities .loadSession ) {
50+ LoadSessionRequest lreq;
51+ lreq.sessionId = sessionId;
52+ lreq.cwd = mClient ->isReady () ? mClient ->getConfig ().workingDirectory : " " ;
53+ mClient ->loadSession ( lreq, [this , sessionId, onReady]( const LoadSessionResponse& ) {
54+ mSessionId = sessionId;
55+ if ( onReady )
56+ onReady ( true );
57+ } );
58+ } else {
59+ // Agent doesn't support loading, fallback to new session?
60+ // For now let's just fail or call onReady(false)
61+ if ( onReady )
62+ onReady ( false );
63+ }
64+ } );
65+ return true ;
66+ }
67+ if ( onReady )
68+ onReady ( false );
69+ return false ;
70+ }
71+
4072void AgentSession::stop () {
4173 if ( mClient )
4274 mClient ->stop ();
@@ -58,6 +90,11 @@ void AgentSession::cancel() {
5890 }
5991}
6092
93+ void AgentSession::setTerminalData ( const std::string& terminalId, UITerminal* uiTerm ) {
94+ mTerminals [terminalId] =
95+ TermData{ uiTerm->getTerm (), uiTerm->getTerm ()->getTerminal (), uiTerm };
96+ }
97+
6198void AgentSession::setupClient () {
6299 mClient ->onSessionUpdate = [this ]( const json& msg ) {
63100 if ( onSessionUpdate )
@@ -92,10 +129,8 @@ void AgentSession::setupClient() {
92129 CreateTerminalResponse res;
93130 std::string termId = String::format ( " term-%u" , String::hash ( req.command ) );
94131 res.terminalId = termId;
95- // Wait for UI? No, ACPClient is running in threads. We just trigger the event
96- // and return the ID.
97132 if ( onTerminalCreated ) {
98- onTerminalCreated ( nullptr , termId );
133+ onTerminalCreated ( req , termId );
99134 }
100135 cb ( res );
101136 };
0 commit comments