WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4aaf0f7

Browse files
authored
Update to agent-client-protocol rust sdk v0.8.0 (#105)
1 parent 5d2f85b commit 4aaf0f7

File tree

5 files changed

+570
-756
lines changed

5 files changed

+570
-756
lines changed

Cargo.lock

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "codex_acp"
1717
path = "src/lib.rs"
1818

1919
[dependencies]
20-
agent-client-protocol = { version = "0.7.0", features = ["unstable"] }
20+
agent-client-protocol = { version = "=0.8.0", features = ["unstable"] }
2121
anyhow = "1"
2222
async-trait = "0.1"
2323
clap = "4"

src/codex_agent.rs

Lines changed: 52 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use agent_client_protocol::{
22
Agent, AgentCapabilities, AuthMethod, AuthMethodId, AuthenticateRequest, AuthenticateResponse,
33
CancelNotification, ClientCapabilities, Error, Implementation, InitializeRequest,
44
InitializeResponse, LoadSessionRequest, LoadSessionResponse, McpCapabilities, McpServer,
5-
NewSessionRequest, NewSessionResponse, PromptCapabilities, PromptRequest, PromptResponse,
6-
SessionId, SetSessionModeRequest, SetSessionModeResponse, SetSessionModelRequest,
7-
SetSessionModelResponse, V1,
5+
McpServerHttp, McpServerStdio, NewSessionRequest, NewSessionResponse, PromptCapabilities,
6+
PromptRequest, PromptResponse, ProtocolVersion, SessionId, SetSessionModeRequest,
7+
SetSessionModeResponse, SetSessionModelRequest, SetSessionModelResponse,
88
};
99
use codex_core::{
1010
ConversationManager, NewConversation,
@@ -80,7 +80,7 @@ impl CodexAgent {
8080
}
8181

8282
fn session_id_from_conversation_id(conversation_id: ConversationId) -> SessionId {
83-
SessionId(conversation_id.to_string().into())
83+
SessionId::new(conversation_id.to_string())
8484
}
8585

8686
fn get_conversation(&self, session_id: &SessionId) -> Result<Rc<Conversation>, Error> {
@@ -107,28 +107,16 @@ impl Agent for CodexAgent {
107107
protocol_version,
108108
client_capabilities,
109109
client_info: _, // TODO: save and pass into Codex somehow
110-
meta: _,
110+
..
111111
} = request;
112112
debug!("Received initialize request with protocol version {protocol_version:?}",);
113-
let protocol_version = V1;
113+
let protocol_version = ProtocolVersion::V1;
114114

115115
*self.client_capabilities.lock().unwrap() = client_capabilities;
116116

117-
let agent_capabilities = AgentCapabilities {
118-
load_session: false, // Currently only able to do in-memory... which doesn't help us at the moment
119-
prompt_capabilities: PromptCapabilities {
120-
audio: false,
121-
embedded_context: true,
122-
image: true,
123-
meta: None,
124-
},
125-
mcp_capabilities: McpCapabilities {
126-
http: true,
127-
sse: false,
128-
meta: None,
129-
},
130-
meta: None,
131-
};
117+
let agent_capabilities = AgentCapabilities::new()
118+
.prompt_capabilities(PromptCapabilities::new().embedded_context(true).image(true))
119+
.mcp_capabilities(McpCapabilities::new().http(true));
132120

133121
let mut auth_methods = vec![
134122
CodexAuthMethod::ChatGpt.into(),
@@ -140,17 +128,10 @@ impl Agent for CodexAgent {
140128
auth_methods.remove(0);
141129
}
142130

143-
Ok(InitializeResponse {
144-
protocol_version,
145-
agent_capabilities,
146-
agent_info: Some(Implementation {
147-
name: "codex-acp".into(),
148-
title: Some("Codex".into()),
149-
version: env!("CARGO_PKG_VERSION").into(),
150-
}),
151-
auth_methods,
152-
meta: None,
153-
})
131+
Ok(InitializeResponse::new(protocol_version)
132+
.agent_capabilities(agent_capabilities)
133+
.agent_info(Implementation::new("codex-acp", env!("CARGO_PKG_VERSION")).title("Codex"))
134+
.auth_methods(auth_methods))
154135
}
155136

156137
async fn authenticate(
@@ -167,7 +148,7 @@ impl Agent for CodexAgent {
167148
CodexAuthMethod::CodexApiKey | CodexAuthMethod::OpenAiApiKey,
168149
)
169150
| (AuthMode::ChatGPT, CodexAuthMethod::ChatGpt) => {
170-
return Ok(AuthenticateResponse { meta: None });
151+
return Ok(AuthenticateResponse::new());
171152
}
172153
_ => {}
173154
}
@@ -195,7 +176,7 @@ impl Agent for CodexAgent {
195176
}
196177
CodexAuthMethod::CodexApiKey => {
197178
let api_key = read_codex_api_key_from_env().ok_or_else(|| {
198-
Error::internal_error().with_data(format!("{CODEX_API_KEY_ENV_VAR} is not set"))
179+
Error::internal_error().data(format!("{CODEX_API_KEY_ENV_VAR} is not set"))
199180
})?;
200181
codex_login::login_with_api_key(
201182
&self.config.codex_home,
@@ -206,8 +187,7 @@ impl Agent for CodexAgent {
206187
}
207188
CodexAuthMethod::OpenAiApiKey => {
208189
let api_key = read_openai_api_key_from_env().ok_or_else(|| {
209-
Error::internal_error()
210-
.with_data(format!("{OPENAI_API_KEY_ENV_VAR} is not set"))
190+
Error::internal_error().data(format!("{OPENAI_API_KEY_ENV_VAR} is not set"))
211191
})?;
212192
codex_login::login_with_api_key(
213193
&self.config.codex_home,
@@ -220,17 +200,15 @@ impl Agent for CodexAgent {
220200

221201
self.auth_manager.reload();
222202

223-
Ok(AuthenticateResponse { meta: None })
203+
Ok(AuthenticateResponse::new())
224204
}
225205

226206
async fn new_session(&self, request: NewSessionRequest) -> Result<NewSessionResponse, Error> {
227207
// Check before sending if authentication was successful or not
228208
self.check_auth()?;
229209

230210
let NewSessionRequest {
231-
cwd,
232-
mcp_servers,
233-
meta: _meta,
211+
cwd, mcp_servers, ..
234212
} = request;
235213
info!("Creating new session with cwd: {}", cwd.display());
236214

@@ -245,8 +223,10 @@ impl Agent for CodexAgent {
245223
for mcp_server in mcp_servers {
246224
match mcp_server {
247225
// Not supported in codex
248-
McpServer::Sse { .. } => {}
249-
McpServer::Http { name, url, headers } => {
226+
McpServer::Sse(..) => {}
227+
McpServer::Http(McpServerHttp {
228+
name, url, headers, ..
229+
}) => {
250230
config.mcp_servers.insert(
251231
name,
252232
McpServerConfig {
@@ -268,12 +248,13 @@ impl Agent for CodexAgent {
268248
},
269249
);
270250
}
271-
McpServer::Stdio {
251+
McpServer::Stdio(McpServerStdio {
272252
name,
273253
command,
274254
args,
275255
env,
276-
} => {
256+
..
257+
}) => {
277258
config.mcp_servers.insert(
278259
name,
279260
McpServerConfig {
@@ -296,6 +277,7 @@ impl Agent for CodexAgent {
296277
},
297278
);
298279
}
280+
_ => {}
299281
}
300282
}
301283

@@ -325,12 +307,14 @@ impl Agent for CodexAgent {
325307

326308
debug!("Created new session with {} MCP servers", num_mcp_servers);
327309

328-
Ok(NewSessionResponse {
329-
session_id,
330-
modes: load.modes,
331-
models: load.models,
332-
meta: None,
333-
})
310+
let mut response = NewSessionResponse::new(session_id);
311+
if let Some(modes) = load.modes {
312+
response = response.modes(modes);
313+
}
314+
if let Some(models) = load.models {
315+
response = response.models(models);
316+
}
317+
Ok(response)
334318
}
335319

336320
async fn load_session(
@@ -361,10 +345,7 @@ impl Agent for CodexAgent {
361345
let conversation = self.get_conversation(&request.session_id)?;
362346
let stop_reason = conversation.prompt(request).await?;
363347

364-
Ok(PromptResponse {
365-
stop_reason,
366-
meta: None,
367-
})
348+
Ok(PromptResponse::new(stop_reason))
368349
}
369350

370351
async fn cancel(&self, args: CancelNotification) -> Result<(), Error> {
@@ -407,45 +388,30 @@ enum CodexAuthMethod {
407388

408389
impl From<CodexAuthMethod> for AuthMethodId {
409390
fn from(method: CodexAuthMethod) -> Self {
410-
Self(
411-
match method {
412-
CodexAuthMethod::ChatGpt => "chatgpt",
413-
CodexAuthMethod::CodexApiKey => "codex-api-key",
414-
CodexAuthMethod::OpenAiApiKey => "openai-api-key",
415-
}
416-
.into(),
417-
)
391+
Self::new(match method {
392+
CodexAuthMethod::ChatGpt => "chatgpt",
393+
CodexAuthMethod::CodexApiKey => "codex-api-key",
394+
CodexAuthMethod::OpenAiApiKey => "openai-api-key",
395+
})
418396
}
419397
}
420398

421399
impl From<CodexAuthMethod> for AuthMethod {
422400
fn from(method: CodexAuthMethod) -> Self {
423401
match method {
424-
CodexAuthMethod::ChatGpt => Self {
425-
id: method.into(),
426-
name: "Login with ChatGPT".into(),
427-
description: Some(
428-
"Use your ChatGPT login with Codex CLI (requires a paid ChatGPT subscription)"
429-
.into(),
430-
),
431-
meta: None,
432-
},
433-
CodexAuthMethod::CodexApiKey => Self {
434-
id: method.into(),
435-
name: format!("Use {CODEX_API_KEY_ENV_VAR}"),
436-
description: Some(format!(
402+
CodexAuthMethod::ChatGpt => Self::new(method, "Login with ChatGPT").description(
403+
"Use your ChatGPT login with Codex CLI (requires a paid ChatGPT subscription)",
404+
),
405+
CodexAuthMethod::CodexApiKey => {
406+
Self::new(method, format!("Use {CODEX_API_KEY_ENV_VAR}")).description(format!(
437407
"Requires setting the `{CODEX_API_KEY_ENV_VAR}` environment variable."
438-
)),
439-
meta: None,
440-
},
441-
CodexAuthMethod::OpenAiApiKey => Self {
442-
id: method.into(),
443-
name: format!("Use {OPENAI_API_KEY_ENV_VAR}"),
444-
description: Some(format!(
408+
))
409+
}
410+
CodexAuthMethod::OpenAiApiKey => {
411+
Self::new(method, format!("Use {OPENAI_API_KEY_ENV_VAR}")).description(format!(
445412
"Requires setting the `{OPENAI_API_KEY_ENV_VAR}` environment variable."
446-
)),
447-
meta: None,
448-
},
413+
))
414+
}
449415
}
450416
}
451417
}
@@ -458,7 +424,7 @@ impl TryFrom<AuthMethodId> for CodexAuthMethod {
458424
"chatgpt" => Ok(CodexAuthMethod::ChatGpt),
459425
"codex-api-key" => Ok(CodexAuthMethod::CodexApiKey),
460426
"openai-api-key" => Ok(CodexAuthMethod::OpenAiApiKey),
461-
_ => Err(Error::invalid_params().with_data("unsupported authentication method")),
427+
_ => Err(Error::invalid_params().data("unsupported authentication method")),
462428
}
463429
}
464430
}

0 commit comments

Comments
 (0)