@@ -17,7 +17,7 @@ import {
1717} from "effect/unstable/http" ;
1818import { ChildProcess , ChildProcessSpawner } from "effect/unstable/process" ;
1919
20- const UPSTREAM_REF = "678157acaa819d5510adfe359abb5d0392cfe461 " ;
20+ const UPSTREAM_REF = "fe74a774532af67b5a4a3dec03ce9469e17f89af " ;
2121const USER_AGENT = "effect-codex-app-server-generator" ;
2222const GITHUB_API_BASE =
2323 "https://api.github.com/repos/openai/codex/contents/codex-rs/app-server-protocol" ;
@@ -145,112 +145,6 @@ const ManualSchemas: Record<string, Schema.Json> = {
145145 } ,
146146} ;
147147
148- // Codex 0.150 added these multi-agent values before our next full protocol
149- // refresh. Keep every generated response namespace compatible with them.
150- const Codex0150DefinitionSchemas : Record < string , Schema . Json > = {
151- CollabAgentTool : {
152- type : "string" ,
153- enum : [
154- "spawnAgent" ,
155- "sendInput" ,
156- "resumeAgent" ,
157- "wait" ,
158- "closeAgent" ,
159- "sendMessage" ,
160- "followupTask" ,
161- "interruptAgent" ,
162- "listAgents" ,
163- ] ,
164- } ,
165- CollabAgentToolCallStatus : {
166- type : "string" ,
167- enum : [ "inProgress" , "completed" , "failed" , "interrupted" ] ,
168- } ,
169- PlanType : {
170- type : "string" ,
171- enum : [
172- "free" ,
173- "go" ,
174- "plus" ,
175- "pro" ,
176- "prolite" ,
177- "team" ,
178- "self_serve_business_prolite" ,
179- "self_serve_business_usage_based" ,
180- "business" ,
181- "ent26" ,
182- "enterprise_cbp_automation" ,
183- "enterprise_cbp_usage_based" ,
184- "enterprise" ,
185- "edu" ,
186- "edu_plus" ,
187- "edu_pro" ,
188- "unknown" ,
189- ] ,
190- } ,
191- SubAgentActivityKind : {
192- type : "string" ,
193- enum : [ "started" , "interacted" , "interrupted" , "completed" ] ,
194- } ,
195- } ;
196-
197- // Pinned protocol JSON omits later CodexErrorInfo variants. Keep historical
198- // thread payloads decodable; do not fold unknown values into "other".
199- const CodexErrorInfoCompatibilityValues = [
200- "rateLimitExceeded" ,
201- "misalignmentPolicyViolation" ,
202- ] as const ;
203-
204- const CodexErrorInfoCompatibilityExports = new Set ( [
205- "V2ThreadReadResponse" ,
206- "V2ThreadResumeResponse" ,
207- "V2ThreadRollbackResponse" ,
208- "V2ThreadForkResponse" ,
209- "V2TurnCompletedNotification" ,
210- ] ) ;
211-
212- function applyCodex0151DefinitionCompatibility (
213- exportName : string ,
214- definitionName : string ,
215- definitionSchema : Schema . Json ,
216- ) : Schema . Json {
217- if (
218- ! CodexErrorInfoCompatibilityExports . has ( exportName ) ||
219- definitionName !== "CodexErrorInfo" ||
220- typeof definitionSchema !== "object"
221- ) {
222- return definitionSchema ;
223- }
224-
225- const schema = definitionSchema as {
226- readonly oneOf ?: ReadonlyArray < { readonly enum ?: ReadonlyArray < string > } > ;
227- } ;
228- const [ firstVariant , ...remainingVariants ] = schema . oneOf ?? [ ] ;
229- const currentEnum = firstVariant ?. enum ;
230- if ( ! currentEnum ) {
231- return definitionSchema ;
232- }
233-
234- const missingValues = CodexErrorInfoCompatibilityValues . filter (
235- ( value ) => ! currentEnum . includes ( value ) ,
236- ) ;
237- if ( missingValues . length === 0 ) {
238- return definitionSchema ;
239- }
240-
241- const enumValues = [ ...currentEnum ] ;
242- const otherIndex = enumValues . indexOf ( "other" ) ;
243- const nextEnum =
244- otherIndex === - 1
245- ? [ ...enumValues , ...missingValues ]
246- : [ ...enumValues . slice ( 0 , otherIndex ) , ...missingValues , ...enumValues . slice ( otherIndex ) ] ;
247-
248- return {
249- ...definitionSchema ,
250- oneOf : [ { ...firstVariant , enum : nextEnum } , ...remainingVariants ] ,
251- } ;
252- }
253-
254148const getGeneratedPaths = Effect . fn ( "getGeneratedPaths" ) ( function * ( ) {
255149 const path = yield * Path . Path ;
256150 const generatedDir = path . join ( import . meta. dirname , ".." , "src" , "_generated" ) ;
@@ -470,61 +364,6 @@ function adaptSchemaForEffect(value: Schema.Json): Schema.Json {
470364 } ;
471365}
472366
473- // Codex 0.153 adds async questions to agent messages. Keep older protocol
474- // fields until the next full refresh, including every thread history namespace.
475- function addAsyncQuestionFields ( value : Schema . Json ) : Schema . Json {
476- if ( Array . isArray ( value ) ) {
477- return value . map ( addAsyncQuestionFields ) ;
478- }
479- if ( value === null || typeof value !== "object" ) {
480- return value ;
481- }
482- const properties = "properties" in value ? value . properties : undefined ;
483- const itemType =
484- properties && typeof properties === "object" && "type" in properties
485- ? properties . type
486- : undefined ;
487- if (
488- properties &&
489- typeof properties === "object" &&
490- itemType &&
491- typeof itemType === "object" &&
492- "enum" in itemType &&
493- Array . isArray ( itemType . enum ) &&
494- itemType . enum . includes ( "agentMessage" )
495- ) {
496- return {
497- ...value ,
498- properties : {
499- ...Object . fromEntries ( Object . entries ( properties ) . filter ( ( [ key ] ) => key !== "type" ) ) ,
500- delivery : { anyOf : [ { type : "string" , enum : [ "async" ] } , { type : "null" } ] } ,
501- questions : {
502- anyOf : [
503- {
504- type : "array" ,
505- items : {
506- type : "object" ,
507- properties : {
508- title : { type : "string" } ,
509- options : {
510- anyOf : [ { type : "array" , items : { type : "string" } } , { type : "null" } ] ,
511- } ,
512- } ,
513- required : [ "title" ] ,
514- } ,
515- } ,
516- { type : "null" } ,
517- ] ,
518- } ,
519- type : itemType ,
520- } ,
521- } ;
522- }
523- return Object . fromEntries (
524- Object . entries ( value ) . map ( ( [ key , child ] ) => [ key , addAsyncQuestionFields ( child ) ] ) ,
525- ) ;
526- }
527-
528367function toPascalCaseMethod ( method : string ) {
529368 return method
530369 . split ( "/" )
@@ -536,13 +375,14 @@ function toPascalCaseMethod(method: string) {
536375}
537376
538377function parseRequestEntries ( fileContents : string ) : ReadonlyArray < MethodEntry > {
539- const entryPattern = / \{ \s * " m e t h o d " : \s * " ( [ ^ " ] + ) " , \s * i d : \s * R e q u e s t I d , \s * p a r a m s : \s * ( [ ^ , } ] + ) / g;
378+ // Optional params render as `params?: Foo | undefined`; their JSON schema is `NullableFoo`.
379+ const entryPattern = / \{ \s * " m e t h o d " : \s * " ( [ ^ " ] + ) " , \s * i d : \s * R e q u e s t I d , \s * p a r a m s ( \? ? ) : \s * ( [ ^ , } | ] + ) / g;
540380 const entries : Array < MethodEntry > = [ ] ;
541381 let match : RegExpExecArray | null ;
542382 while ( ( match = entryPattern . exec ( fileContents ) ) !== null ) {
543383 entries . push ( {
544384 method : match [ 1 ] ! ,
545- paramsType : match [ 2 ] ! . trim ( ) ,
385+ paramsType : ` ${ match [ 2 ] ? "Nullable" : "" } ${ match [ 3 ] ! . trim ( ) } ` ,
546386 } ) ;
547387 }
548388 return entries ;
@@ -800,13 +640,10 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
800640 ) ;
801641
802642 for ( const [ definitionName , definitionSchema ] of Object . entries ( parsed . definitions ?? { } ) ) {
803- const compatibleDefinitionSchema =
804- Codex0150DefinitionSchemas [ definitionName ] ??
805- applyCodex0151DefinitionCompatibility ( file . exportName , definitionName , definitionSchema ) ;
806643 aggregateSchemas [ localDefinitionNames . get ( definitionName ) ! ] = stripNullDefaults (
807644 normalizeNullableTypes (
808645 rewriteExternalRefs (
809- compatibleDefinitionSchema ,
646+ definitionSchema ,
810647 localDefinitionNames ,
811648 file . namespace ,
812649 exportNameByQualifiedName ,
@@ -844,7 +681,7 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
844681 for ( const [ name , schema ] of Object . entries ( aggregateSchemas ) . toSorted ( ( [ left ] , [ right ] ) =>
845682 left . localeCompare ( right ) ,
846683 ) ) {
847- aggregateSchemas [ name ] = adaptSchemaForEffect ( addAsyncQuestionFields ( schema ) ) ;
684+ aggregateSchemas [ name ] = adaptSchemaForEffect ( schema ) ;
848685 generator . addSchema ( name , aggregateSchemas [ name ] as never ) ;
849686 }
850687
0 commit comments