feat(codex): require Codex 0.156 and regenerate its protocol (#13481)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
567783ecdc
commit
d5d48742c9
14 files changed
+13611
-1823
No files matched your search
@@ -17,7 +17,7 @@ import {
|
||||
} from "effect/unstable/http";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
const UPSTREAM_REF = "678157acaa819d5510adfe359abb5d0392cfe461";
|
||||
const UPSTREAM_REF = "fe74a774532af67b5a4a3dec03ce9469e17f89af";
|
||||
const USER_AGENT = "effect-codex-app-server-generator";
|
||||
const GITHUB_API_BASE =
|
||||
"https://api.github.com/repos/openai/codex/contents/codex-rs/app-server-protocol";
|
||||
@@ -145,112 +145,6 @@ const ManualSchemas: Record<string, Schema.Json> = {
|
||||
},
|
||||
};
|
||||
|
||||
// Codex 0.150 added these multi-agent values before our next full protocol
|
||||
// refresh. Keep every generated response namespace compatible with them.
|
||||
const Codex0150DefinitionSchemas: Record<string, Schema.Json> = {
|
||||
CollabAgentTool: {
|
||||
type: "string",
|
||||
enum: [
|
||||
"spawnAgent",
|
||||
"sendInput",
|
||||
"resumeAgent",
|
||||
"wait",
|
||||
"closeAgent",
|
||||
"sendMessage",
|
||||
"followupTask",
|
||||
"interruptAgent",
|
||||
"listAgents",
|
||||
],
|
||||
},
|
||||
CollabAgentToolCallStatus: {
|
||||
type: "string",
|
||||
enum: ["inProgress", "completed", "failed", "interrupted"],
|
||||
},
|
||||
PlanType: {
|
||||
type: "string",
|
||||
enum: [
|
||||
"free",
|
||||
"go",
|
||||
"plus",
|
||||
"pro",
|
||||
"prolite",
|
||||
"team",
|
||||
"self_serve_business_prolite",
|
||||
"self_serve_business_usage_based",
|
||||
"business",
|
||||
"ent26",
|
||||
"enterprise_cbp_automation",
|
||||
"enterprise_cbp_usage_based",
|
||||
"enterprise",
|
||||
"edu",
|
||||
"edu_plus",
|
||||
"edu_pro",
|
||||
"unknown",
|
||||
],
|
||||
},
|
||||
SubAgentActivityKind: {
|
||||
type: "string",
|
||||
enum: ["started", "interacted", "interrupted", "completed"],
|
||||
},
|
||||
};
|
||||
|
||||
// Pinned protocol JSON omits later CodexErrorInfo variants. Keep historical
|
||||
// thread payloads decodable; do not fold unknown values into "other".
|
||||
const CodexErrorInfoCompatibilityValues = [
|
||||
"rateLimitExceeded",
|
||||
"misalignmentPolicyViolation",
|
||||
] as const;
|
||||
|
||||
const CodexErrorInfoCompatibilityExports = new Set([
|
||||
"V2ThreadReadResponse",
|
||||
"V2ThreadResumeResponse",
|
||||
"V2ThreadRollbackResponse",
|
||||
"V2ThreadForkResponse",
|
||||
"V2TurnCompletedNotification",
|
||||
]);
|
||||
|
||||
function applyCodex0151DefinitionCompatibility(
|
||||
exportName: string,
|
||||
definitionName: string,
|
||||
definitionSchema: Schema.Json,
|
||||
): Schema.Json {
|
||||
if (
|
||||
!CodexErrorInfoCompatibilityExports.has(exportName) ||
|
||||
definitionName !== "CodexErrorInfo" ||
|
||||
typeof definitionSchema !== "object"
|
||||
) {
|
||||
return definitionSchema;
|
||||
}
|
||||
|
||||
const schema = definitionSchema as {
|
||||
readonly oneOf?: ReadonlyArray<{ readonly enum?: ReadonlyArray<string> }>;
|
||||
};
|
||||
const [firstVariant, ...remainingVariants] = schema.oneOf ?? [];
|
||||
const currentEnum = firstVariant?.enum;
|
||||
if (!currentEnum) {
|
||||
return definitionSchema;
|
||||
}
|
||||
|
||||
const missingValues = CodexErrorInfoCompatibilityValues.filter(
|
||||
(value) => !currentEnum.includes(value),
|
||||
);
|
||||
if (missingValues.length === 0) {
|
||||
return definitionSchema;
|
||||
}
|
||||
|
||||
const enumValues = [...currentEnum];
|
||||
const otherIndex = enumValues.indexOf("other");
|
||||
const nextEnum =
|
||||
otherIndex === -1
|
||||
? [...enumValues, ...missingValues]
|
||||
: [...enumValues.slice(0, otherIndex), ...missingValues, ...enumValues.slice(otherIndex)];
|
||||
|
||||
return {
|
||||
...definitionSchema,
|
||||
oneOf: [{ ...firstVariant, enum: nextEnum }, ...remainingVariants],
|
||||
};
|
||||
}
|
||||
|
||||
const getGeneratedPaths = Effect.fn("getGeneratedPaths")(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const generatedDir = path.join(import.meta.dirname, "..", "src", "_generated");
|
||||
@@ -470,61 +364,6 @@ function adaptSchemaForEffect(value: Schema.Json): Schema.Json {
|
||||
};
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(addAsyncQuestionFields);
|
||||
}
|
||||
if (value === null || typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
const properties = "properties" in value ? value.properties : undefined;
|
||||
const itemType =
|
||||
properties && typeof properties === "object" && "type" in properties
|
||||
? properties.type
|
||||
: undefined;
|
||||
if (
|
||||
properties &&
|
||||
typeof properties === "object" &&
|
||||
itemType &&
|
||||
typeof itemType === "object" &&
|
||||
"enum" in itemType &&
|
||||
Array.isArray(itemType.enum) &&
|
||||
itemType.enum.includes("agentMessage")
|
||||
) {
|
||||
return {
|
||||
...value,
|
||||
properties: {
|
||||
...Object.fromEntries(Object.entries(properties).filter(([key]) => key !== "type")),
|
||||
delivery: { anyOf: [{ type: "string", enum: ["async"] }, { type: "null" }] },
|
||||
questions: {
|
||||
anyOf: [
|
||||
{
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
title: { type: "string" },
|
||||
options: {
|
||||
anyOf: [{ type: "array", items: { type: "string" } }, { type: "null" }],
|
||||
},
|
||||
},
|
||||
required: ["title"],
|
||||
},
|
||||
},
|
||||
{ type: "null" },
|
||||
],
|
||||
},
|
||||
type: itemType,
|
||||
},
|
||||
};
|
||||
}
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([key, child]) => [key, addAsyncQuestionFields(child)]),
|
||||
);
|
||||
}
|
||||
|
||||
function toPascalCaseMethod(method: string) {
|
||||
return method
|
||||
.split("/")
|
||||
@@ -536,13 +375,14 @@ function toPascalCaseMethod(method: string) {
|
||||
}
|
||||
|
||||
function parseRequestEntries(fileContents: string): ReadonlyArray<MethodEntry> {
|
||||
const entryPattern = /\{\s*"method":\s*"([^"]+)",\s*id:\s*RequestId,\s*params:\s*([^,}]+)/g;
|
||||
// Optional params render as `params?: Foo | undefined`; their JSON schema is `NullableFoo`.
|
||||
const entryPattern = /\{\s*"method":\s*"([^"]+)",\s*id:\s*RequestId,\s*params(\??):\s*([^,}|]+)/g;
|
||||
const entries: Array<MethodEntry> = [];
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = entryPattern.exec(fileContents)) !== null) {
|
||||
entries.push({
|
||||
method: match[1]!,
|
||||
paramsType: match[2]!.trim(),
|
||||
paramsType: `${match[2] ? "Nullable" : ""}${match[3]!.trim()}`,
|
||||
});
|
||||
}
|
||||
return entries;
|
||||
@@ -800,13 +640,10 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
|
||||
);
|
||||
|
||||
for (const [definitionName, definitionSchema] of Object.entries(parsed.definitions ?? {})) {
|
||||
const compatibleDefinitionSchema =
|
||||
Codex0150DefinitionSchemas[definitionName] ??
|
||||
applyCodex0151DefinitionCompatibility(file.exportName, definitionName, definitionSchema);
|
||||
aggregateSchemas[localDefinitionNames.get(definitionName)!] = stripNullDefaults(
|
||||
normalizeNullableTypes(
|
||||
rewriteExternalRefs(
|
||||
compatibleDefinitionSchema,
|
||||
definitionSchema,
|
||||
localDefinitionNames,
|
||||
file.namespace,
|
||||
exportNameByQualifiedName,
|
||||
@@ -844,7 +681,7 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
|
||||
for (const [name, schema] of Object.entries(aggregateSchemas).toSorted(([left], [right]) =>
|
||||
left.localeCompare(right),
|
||||
)) {
|
||||
aggregateSchemas[name] = adaptSchemaForEffect(addAsyncQuestionFields(schema));
|
||||
aggregateSchemas[name] = adaptSchemaForEffect(schema);
|
||||
generator.addSchema(name, aggregateSchemas[name] as never);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user