fix(codex): the protocol generator runs again on Effect rc.115 (#13480)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5.5 authored and GitHub committed 2026-09-24 14:10:02 -07:00
1 parent f3cb2a1fee
commit 567783ecdc
3 files changed
+23842 -22371

No files matched your search

@@ -119,7 +119,7 @@ const McpElicitationFormField = Schema.Struct({
type: Schema.optionalKey(NullableMcpElicitationString),
title: Schema.optionalKey(NullableMcpElicitationString),
description: Schema.optionalKey(NullableMcpElicitationString),
default: Schema.optionalKey(Schema.Unknown),
default: Schema.optionalKey(Schema.Json),
enum: Schema.optionalKey(Schema.NullOr(Schema.Array(Schema.String))),
enumNames: Schema.optionalKey(Schema.NullOr(Schema.Array(Schema.String))),
oneOf: Schema.optionalKey(
@@ -442,7 +442,7 @@ export function toMcpElicitationResponse(
? "always"
: undefined;
const form = mcpElicitationFormFields(payload);
const content: Record<string, unknown> = {};
const content: Record<string, Schema.Json> = {};
for (const [key, field] of Object.entries(form?.properties ?? {})) {
const options = mcpElicitationFieldOptions(field);
@@ -269,8 +269,13 @@ const ensureGeneratedDir = Effect.fn("ensureGeneratedDir")(function* () {
});
const fetchText = Effect.fn("fetchText")(function* (url: string) {
// Unauthenticated GitHub API calls are capped at 60/hour; set GITHUB_TOKEN to lift that.
const token = process.env.GITHUB_TOKEN;
return yield* HttpClientRequest.get(url).pipe(
HttpClientRequest.setHeader("user-agent", USER_AGENT),
token && url.startsWith("https://api.github.com/")
? HttpClientRequest.bearerToken(token)
: (request) => request,
HttpClient.execute,
Effect.flatMap(HttpClientResponse.filterStatusOk),
Effect.flatMap((okResponse) => okResponse.text),
@@ -387,6 +392,84 @@ function stripNullDefaults(value: Schema.Json): Schema.Json {
) as Schema.Json;
}
type JsonSchemaNode = { readonly [key: string]: Schema.Json };
function isJsonSchemaNode(value: Schema.Json | undefined): value is JsonSchemaNode {
return value !== null && typeof value === "object" && !Array.isArray(value);
}
// Adapts Codex's JSON Schema to Effect's importer, visiting only schema
// positions so a field literally named "properties" is left alone:
// - Effect imports an object without additionalProperties as an open record.
// Codex omits it for plain structs, so close objects that list properties.
// - Effect cannot intersect shared object fields with object alternatives,
// which Codex uses for "one of these keys plus shared fields"
// (image_url | file_id). Fold the shared fields into each alternative.
function adaptSchemaForEffect(value: Schema.Json): Schema.Json {
if (!isJsonSchemaNode(value)) {
return value;
}
const node: Record<string, Schema.Json> = { ...value };
for (const key of ["items", "additionalProperties"]) {
const child = node[key];
if (isJsonSchemaNode(child)) node[key] = adaptSchemaForEffect(child);
}
for (const key of ["anyOf", "oneOf", "allOf"]) {
const child = node[key];
if (Array.isArray(child)) node[key] = child.map(adaptSchemaForEffect);
}
for (const key of ["properties", "definitions"]) {
const child = node[key];
if (isJsonSchemaNode(child)) {
node[key] = Object.fromEntries(
Object.entries(child).map(([name, schema]) => [name, adaptSchemaForEffect(schema)]),
);
}
}
const { properties } = node;
if (
isJsonSchemaNode(properties) &&
Object.keys(properties).length > 0 &&
!("additionalProperties" in node)
) {
node.additionalProperties = false;
}
const alternativesKey = "anyOf" in node ? "anyOf" : "oneOf";
const alternatives = node[alternativesKey];
if (
!isJsonSchemaNode(properties) ||
!Array.isArray(alternatives) ||
!alternatives.every(
(alternative) => isJsonSchemaNode(alternative) && alternative.type === "object",
)
) {
return node;
}
const {
properties: _shared,
required,
type: _type,
additionalProperties: _closed,
...rest
} = node;
const sharedRequired = Array.isArray(required) ? required : [];
return {
...rest,
[alternativesKey]: alternatives.map((alternative) => {
const branch = alternative as JsonSchemaNode;
const branchProperties = isJsonSchemaNode(branch.properties) ? branch.properties : {};
const branchRequired = Array.isArray(branch.required) ? branch.required : [];
return {
...branch,
properties: { ...properties, ...branchProperties },
required: [...new Set([...sharedRequired, ...branchRequired])],
};
}),
};
}
// Codex 0.153 adds async questions to agent messages. Keep older protocol
// fields until the next full refresh, including every thread history namespace.
function addAsyncQuestionFields(value: Schema.Json): Schema.Json {
@@ -649,7 +732,7 @@ function rewriteExternalRefs(
const definitionName = child.slice("#/definitions/".length);
const localRewrite = localDefinitionNames.get(definitionName);
if (localRewrite) {
return [key, `#/definitions/${localRewrite}`];
return [key, `#/components/schemas/${localRewrite}`];
}
const candidates = [
@@ -670,7 +753,7 @@ function rewriteExternalRefs(
throw new Error(`Missing rewritten definition for ref: ${child}`);
}
return [key, `#/definitions/${rewritten}`];
return [key, `#/components/schemas/${rewritten}`];
}
return [
@@ -761,7 +844,7 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
for (const [name, schema] of Object.entries(aggregateSchemas).toSorted(([left], [right]) =>
left.localeCompare(right),
)) {
aggregateSchemas[name] = addAsyncQuestionFields(schema);
aggregateSchemas[name] = adaptSchemaForEffect(addAsyncQuestionFields(schema));
generator.addSchema(name, aggregateSchemas[name] as never);
}
File diff suppressed because it is too large. Load diff