11import * as acp from "@agentclientprotocol/sdk" ;
22import type { MessageConnection } from "vscode-jsonrpc/node" ;
3- import type { NewConversationResponse } from "./app-server" ;
43import { CodexClient } from "./CodexClient" ;
54import { CodexEventHandler } from "./CodexEventHandler" ;
5+ import type { JsonValue } from "./app-server/serde_json/JsonValue" ;
66
77export interface SessionState {
88 sessionId : string ,
@@ -11,24 +11,29 @@ export interface SessionState {
1111}
1212
1313export class CodexACPAgent implements acp . Agent {
14- private readonly sessions : Map < string , SessionState > ;
1514 private readonly codexClient : CodexClient ;
1615 private readonly connection : acp . AgentSideConnection ;
16+ private readonly config : JsonObject | null ;
17+ private readonly modelProvider : string | null ;
18+
19+ private readonly sessions : Map < string , SessionState > ;
1720
18- constructor ( connection : acp . AgentSideConnection , codexConnection : MessageConnection ) {
21+ constructor ( connection : acp . AgentSideConnection , codexConnection : MessageConnection , codexConfig ?: JsonObject , modelProvider ?: string ) {
1922 this . sessions = new Map ( ) ;
2023 this . codexClient = new CodexClient ( codexConnection ) ;
2124 this . connection = connection ;
25+ this . config = codexConfig ?? null ;
26+ this . modelProvider = modelProvider ?? null ;
2227 }
2328
2429 async initialize (
2530 _params : acp . InitializeRequest ,
2631 ) : Promise < acp . InitializeResponse > {
2732 await this . codexClient . initialize ( {
2833 clientInfo : {
29- name : "CodexConsoleClient ",
30- version : "0.1.0" ,
31- title : "Codex ACP"
34+ name : _params . clientInfo ?. name ?? "CodexACPAgent ",
35+ version : _params . clientInfo ?. version ?? "0.1.0" ,
36+ title : _params . clientInfo ?. title ?? "Codex ACP"
3237 }
3338 } ) ;
3439 return {
@@ -42,13 +47,13 @@ export class CodexACPAgent implements acp.Agent {
4247 async newSession (
4348 _params : acp . NewSessionRequest ,
4449 ) : Promise < acp . NewSessionResponse > {
45- const threadStartResponse = await this . codexClient . threadStart ( {
50+ const threadStartResponse = await this . codexClient . threadStart ( {
51+ config : this . config ,
52+ modelProvider : this . modelProvider ,
4653 model : null ,
47- modelProvider : null ,
4854 cwd : _params . cwd ,
4955 approvalPolicy : "never" ,
5056 sandbox : null ,
51- config : null ,
5257 baseInstructions : null ,
5358 developerInstructions : null ,
5459 } )
@@ -121,7 +126,7 @@ export class CodexACPAgent implements acp.Agent {
121126
122127 await this . codexClient . turnStart ( {
123128 threadId : sessionState . sessionId ,
124- input : [ { type : "text" , text : prompt } ] ,
129+ input : [ { type : "text" , text : prompt } ] ,
125130 approvalPolicy : null ,
126131 sandboxPolicy : null ,
127132 summary : null ,
@@ -138,4 +143,6 @@ export class CodexACPAgent implements acp.Agent {
138143 await this . codexClient . close ( )
139144 this . sessions . get ( params . sessionId ) ?. pendingPrompt ?. abort ( ) ;
140145 }
141- }
146+ }
147+
148+ export type JsonObject = { [ key in string ] ?: JsonValue }
0 commit comments