Skip to content

Commit 03acb3f

Browse files
committed
Branched WIP that needs to be merged with the new changes from develop.
1 parent bbba9b9 commit 03acb3f

9 files changed

Lines changed: 318 additions & 48 deletions

File tree

bin/assets/plugins/aiassistant.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@
506506
"gemini-cli": {
507507
"enabled": true,
508508
"command": "gemini",
509-
"args": ["--experimental-acp"]
509+
"args": ["--experimental-acp", "--model=auto"]
510510
},
511511
"opencode": {
512512
"enabled": true,

src/tools/ecode/plugins/aiassistant/acpclient.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ void ACPClient::newSession( const NewSessionRequest& req,
216216
} );
217217
}
218218

219+
void ACPClient::loadSession( const LoadSessionRequest& req,
220+
const std::function<void( const LoadSessionResponse& )>& cb ) {
221+
write( { { "method", "session/load" }, { "params", req.toJson() } },
222+
[cb]( const IdType&, const json& resp ) {
223+
if ( resp.contains( "result" ) && cb ) {
224+
cb( LoadSessionResponse( resp["result"] ) );
225+
}
226+
} );
227+
}
228+
219229
void ACPClient::prompt( const PromptRequest& req,
220230
const std::function<void( const PromptResponse& )>& cb ) {
221231
write( { { "method", "session/prompt" }, { "params", req.toJson() } },

src/tools/ecode/plugins/aiassistant/acpclient.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class ACPClient {
4747
const std::function<void( const InitializeResponse& )>& cb );
4848
void newSession( const NewSessionRequest& req,
4949
const std::function<void( const NewSessionResponse& )>& cb );
50+
void loadSession( const LoadSessionRequest& req,
51+
const std::function<void( const LoadSessionResponse& )>& cb );
5052
void prompt( const PromptRequest& req, const std::function<void( const PromptResponse& )>& cb );
5153

5254
// Notifications to agent

src/tools/ecode/plugins/aiassistant/acpprotocol.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ NewSessionResponse::NewSessionResponse( const json& body ) {
6060
configOptions = body["configOptions"];
6161
}
6262

63+
json LoadSessionRequest::toJson() const {
64+
json j = { { "sessionId", sessionId }, { "cwd", cwd } };
65+
if ( mcpServers.is_null() ) {
66+
j["mcpServers"] = json::array();
67+
} else {
68+
j["mcpServers"] = mcpServers;
69+
}
70+
return j;
71+
}
72+
73+
LoadSessionResponse::LoadSessionResponse( const json& body ) {
74+
if ( body.contains( "configOptions" ) )
75+
configOptions = body["configOptions"];
76+
}
77+
6378
json PromptRequest::toJson() const {
6479
return { { "sessionId", sessionId }, { "prompt", prompt } };
6580
}

src/tools/ecode/plugins/aiassistant/acpprotocol.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ struct NewSessionResponse {
6363
NewSessionResponse( const json& body );
6464
};
6565

66+
struct LoadSessionRequest {
67+
std::string sessionId;
68+
std::string cwd;
69+
json mcpServers;
70+
71+
LoadSessionRequest() = default;
72+
json toJson() const;
73+
};
74+
75+
struct LoadSessionResponse {
76+
json configOptions;
77+
78+
LoadSessionResponse() = default;
79+
LoadSessionResponse( const json& body );
80+
};
81+
6682
struct PromptRequest {
6783
std::string sessionId;
6884
json prompt; // Array of ContentBlock

src/tools/ecode/plugins/aiassistant/agentsession.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4072
void 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+
6198
void 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
};

src/tools/ecode/plugins/aiassistant/agentsession.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AgentSession {
2121
~AgentSession();
2222

2323
bool start( const std::function<void( bool )>& onReady );
24+
bool startLoaded( const std::string& sessionId, const std::function<void( bool )>& onReady );
2425
void stop();
2526

2627
void prompt( const PromptRequest& req, const std::function<void( const PromptResponse& )>& cb );
@@ -32,11 +33,14 @@ class AgentSession {
3233
std::function<void( const RequestPermissionRequest&,
3334
std::function<void( const RequestPermissionResponse& )> )>
3435
onRequestPermission;
35-
std::function<void( UITerminal*, const std::string& terminalId )> onTerminalCreated;
36+
std::function<void( const CreateTerminalRequest&, const std::string& terminalId )>
37+
onTerminalCreated;
3638

3739
std::string getSessionId() const { return mSessionId; }
3840
ACPClient* getClient() const { return mClient.get(); }
3941

42+
void setTerminalData( const std::string& terminalId, UITerminal* uiTerm );
43+
4044
protected:
4145
std::shared_ptr<ThreadPool> mThreadPool;
4246
std::unique_ptr<ACPClient> mClient;

0 commit comments

Comments
 (0)