1414
1515use std:: cell:: Cell ;
1616
17- use agent_client_protocol:: { self as acp, Client as _} ;
17+ use agent_client_protocol:: { self as acp, Client as _, SessionConfigOptionValue } ;
1818use serde_json:: json;
1919use tokio:: sync:: { mpsc, oneshot} ;
2020use tokio_util:: compat:: { TokioAsyncReadCompatExt as _, TokioAsyncWriteCompatExt as _} ;
@@ -42,17 +42,8 @@ impl acp::Agent for ExampleAgent {
4242 arguments : acp:: InitializeRequest ,
4343 ) -> Result < acp:: InitializeResponse , acp:: Error > {
4444 log:: info!( "Received initialize request {arguments:?}" ) ;
45- Ok ( acp:: InitializeResponse {
46- protocol_version : acp:: V1 ,
47- agent_capabilities : acp:: AgentCapabilities :: default ( ) ,
48- auth_methods : Vec :: new ( ) ,
49- agent_info : Some ( acp:: Implementation {
50- name : "example-agent" . to_string ( ) ,
51- title : Some ( "Example Agent" . to_string ( ) ) ,
52- version : "0.1.0" . to_string ( ) ,
53- } ) ,
54- meta : None ,
55- } )
45+ Ok ( acp:: InitializeResponse :: new ( acp:: ProtocolVersion :: V1 )
46+ . agent_info ( acp:: Implementation :: new ( "example-agent" , "0.1.0" ) . title ( "Example Agent" ) ) )
5647 }
5748
5849 async fn authenticate (
@@ -70,26 +61,15 @@ impl acp::Agent for ExampleAgent {
7061 log:: info!( "Received new session request {arguments:?}" ) ;
7162 let session_id = self . next_session_id . get ( ) ;
7263 self . next_session_id . set ( session_id + 1 ) ;
73- Ok ( acp:: NewSessionResponse {
74- session_id : acp:: SessionId ( session_id. to_string ( ) . into ( ) ) ,
75- modes : None ,
76- #[ cfg( feature = "unstable_session_model" ) ]
77- models : None ,
78- meta : None ,
79- } )
64+ Ok ( acp:: NewSessionResponse :: new ( session_id. to_string ( ) ) )
8065 }
8166
8267 async fn load_session (
8368 & self ,
8469 arguments : acp:: LoadSessionRequest ,
8570 ) -> Result < acp:: LoadSessionResponse , acp:: Error > {
8671 log:: info!( "Received load session request {arguments:?}" ) ;
87- Ok ( acp:: LoadSessionResponse {
88- modes : None ,
89- #[ cfg( feature = "unstable_session_model" ) ]
90- models : None ,
91- meta : None ,
92- } )
72+ Ok ( acp:: LoadSessionResponse :: new ( ) )
9373 }
9474
9575 async fn prompt (
@@ -101,23 +81,16 @@ impl acp::Agent for ExampleAgent {
10181 let ( tx, rx) = oneshot:: channel ( ) ;
10282 self . session_update_tx
10383 . send ( (
104- acp:: SessionNotification {
105- session_id : arguments. session_id . clone ( ) ,
106- update : acp:: SessionUpdate :: AgentMessageChunk ( acp:: ContentChunk {
107- content,
108- meta : None ,
109- } ) ,
110- meta : None ,
111- } ,
84+ acp:: SessionNotification :: new (
85+ arguments. session_id . clone ( ) ,
86+ acp:: SessionUpdate :: AgentMessageChunk ( acp:: ContentChunk :: new ( content) ) ,
87+ ) ,
11288 tx,
11389 ) )
11490 . map_err ( |_| acp:: Error :: internal_error ( ) ) ?;
11591 rx. await . map_err ( |_| acp:: Error :: internal_error ( ) ) ?;
11692 }
117- Ok ( acp:: PromptResponse {
118- stop_reason : acp:: StopReason :: EndTurn ,
119- meta : None ,
120- } )
93+ Ok ( acp:: PromptResponse :: new ( acp:: StopReason :: EndTurn ) )
12194 }
12295
12396 async fn cancel ( & self , args : acp:: CancelNotification ) -> Result < ( ) , acp:: Error > {
@@ -147,17 +120,19 @@ impl acp::Agent for ExampleAgent {
147120 args : acp:: SetSessionConfigOptionRequest ,
148121 ) -> Result < acp:: SetSessionConfigOptionResponse , acp:: Error > {
149122 log:: info!( "Received set session config option request {args:?}" ) ;
150- Ok ( acp:: SetSessionConfigOptionResponse :: new ( vec ! [
151- acp:: SessionConfigOption :: select(
152- args. config_id,
153- "Example Option" ,
154- args. value,
155- vec![
156- acp:: SessionConfigSelectOption :: new( "option1" , "Option 1" ) ,
157- acp:: SessionConfigSelectOption :: new( "option2" , "Option 2" ) ,
158- ] ) ,
159- ) ,
160- ] ) )
123+ let SessionConfigOptionValue :: ValueId { value } = args. value else {
124+ return Err ( acp:: Error :: invalid_params ( ) ) ;
125+ } ;
126+ let option = acp:: SessionConfigOption :: select (
127+ args. config_id ,
128+ "Example Option" ,
129+ value,
130+ vec ! [
131+ acp:: SessionConfigSelectOption :: new( "option1" , "Option 1" ) ,
132+ acp:: SessionConfigSelectOption :: new( "option2" , "Option 2" ) ,
133+ ] ,
134+ ) ;
135+ Ok ( acp:: SetSessionConfigOptionResponse :: new ( vec ! [ option] ) )
161136 }
162137
163138 async fn ext_method ( & self , args : acp:: ExtRequest ) -> Result < acp:: ExtResponse , acp:: Error > {
@@ -166,7 +141,9 @@ impl acp::Agent for ExampleAgent {
166141 args. method,
167142 args. params
168143 ) ;
169- Ok ( serde_json:: value:: to_raw_value ( & json ! ( { "example" : "response" } ) ) ?. into ( ) )
144+ Ok ( acp:: ExtResponse :: new (
145+ serde_json:: value:: to_raw_value ( & json ! ( { "example" : "response" } ) ) ?. into ( ) ,
146+ ) )
170147 }
171148
172149 async fn ext_notification ( & self , args : acp:: ExtNotification ) -> Result < ( ) , acp:: Error > {
0 commit comments