refactor: compact generated protocol metadata

This commit is contained in:
Peter Steinberger
2026-05-05 20:47:29 +01:00
parent 9abf01faf0
commit 782963ae66
15 changed files with 821 additions and 21167 deletions

View File

@@ -5,20 +5,10 @@
"required": ["arguments", "callId", "threadId", "tool", "turnId"],
"properties": {
"arguments": true,
"callId": {
"type": "string"
},
"namespace": {
"type": ["string", "null"]
},
"threadId": {
"type": "string"
},
"tool": {
"type": "string"
},
"turnId": {
"type": "string"
}
"callId": { "type": "string" },
"namespace": { "type": ["string", "null"] },
"threadId": { "type": "string" },
"tool": { "type": "string" },
"turnId": { "type": "string" }
}
}

View File

@@ -4,18 +4,10 @@
"type": "object",
"required": ["error", "threadId", "turnId", "willRetry"],
"properties": {
"error": {
"$ref": "#/definitions/TurnError"
},
"threadId": {
"type": "string"
},
"turnId": {
"type": "string"
},
"willRetry": {
"type": "boolean"
}
"error": { "$ref": "#/definitions/TurnError" },
"threadId": { "type": "string" },
"turnId": { "type": "string" },
"willRetry": { "type": "boolean" }
},
"definitions": {
"CodexErrorInfo": {
@@ -43,11 +35,7 @@
"httpConnectionFailed": {
"type": "object",
"properties": {
"httpStatusCode": {
"type": ["integer", "null"],
"format": "uint16",
"minimum": 0.0
}
"httpStatusCode": { "type": ["integer", "null"], "format": "uint16", "minimum": 0 }
}
}
},
@@ -62,11 +50,7 @@
"responseStreamConnectionFailed": {
"type": "object",
"properties": {
"httpStatusCode": {
"type": ["integer", "null"],
"format": "uint16",
"minimum": 0.0
}
"httpStatusCode": { "type": ["integer", "null"], "format": "uint16", "minimum": 0 }
}
}
},
@@ -81,11 +65,7 @@
"responseStreamDisconnected": {
"type": "object",
"properties": {
"httpStatusCode": {
"type": ["integer", "null"],
"format": "uint16",
"minimum": 0.0
}
"httpStatusCode": { "type": ["integer", "null"], "format": "uint16", "minimum": 0 }
}
}
},
@@ -100,11 +80,7 @@
"responseTooManyFailedAttempts": {
"type": "object",
"properties": {
"httpStatusCode": {
"type": ["integer", "null"],
"format": "uint16",
"minimum": 0.0
}
"httpStatusCode": { "type": ["integer", "null"], "format": "uint16", "minimum": 0 }
}
}
},
@@ -119,11 +95,7 @@
"activeTurnNotSteerable": {
"type": "object",
"required": ["turnKind"],
"properties": {
"turnKind": {
"$ref": "#/definitions/NonSteerableTurnKind"
}
}
"properties": { "turnKind": { "$ref": "#/definitions/NonSteerableTurnKind" } }
}
},
"additionalProperties": false,
@@ -131,31 +103,16 @@
}
]
},
"NonSteerableTurnKind": {
"type": "string",
"enum": ["review", "compact"]
},
"NonSteerableTurnKind": { "type": "string", "enum": ["review", "compact"] },
"TurnError": {
"type": "object",
"required": ["message"],
"properties": {
"additionalDetails": {
"default": null,
"type": ["string", "null"]
},
"additionalDetails": { "default": null, "type": ["string", "null"] },
"codexErrorInfo": {
"anyOf": [
{
"$ref": "#/definitions/CodexErrorInfo"
},
{
"type": "null"
}
]
"anyOf": [{ "$ref": "#/definitions/CodexErrorInfo" }, { "type": "null" }]
},
"message": {
"type": "string"
}
"message": { "type": "string" }
}
}
}

View File

@@ -4,19 +4,8 @@
"type": "object",
"required": ["requiresOpenaiAuth"],
"properties": {
"account": {
"anyOf": [
{
"$ref": "#/definitions/Account"
},
{
"type": "null"
}
]
},
"requiresOpenaiAuth": {
"type": "boolean"
}
"account": { "anyOf": [{ "$ref": "#/definitions/Account" }, { "type": "null" }] },
"requiresOpenaiAuth": { "type": "boolean" }
},
"definitions": {
"Account": {
@@ -25,11 +14,7 @@
"type": "object",
"required": ["type"],
"properties": {
"type": {
"type": "string",
"enum": ["apiKey"],
"title": "ApiKeyAccountType"
}
"type": { "type": "string", "enum": ["apiKey"], "title": "ApiKeyAccountType" }
},
"title": "ApiKeyAccount"
},
@@ -37,17 +22,9 @@
"type": "object",
"required": ["email", "planType", "type"],
"properties": {
"email": {
"type": "string"
},
"planType": {
"$ref": "#/definitions/PlanType"
},
"type": {
"type": "string",
"enum": ["chatgpt"],
"title": "ChatgptAccountType"
}
"email": { "type": "string" },
"planType": { "$ref": "#/definitions/PlanType" },
"type": { "type": "string", "enum": ["chatgpt"], "title": "ChatgptAccountType" }
},
"title": "ChatgptAccount"
},

View File

@@ -4,12 +4,7 @@
"type": "object",
"required": ["data"],
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Model"
}
},
"data": { "type": "array", "items": { "$ref": "#/definitions/Model" } },
"nextCursor": {
"description": "Opaque cursor to pass to the next call to continue after the last item. If None, there are no more items to return.",
"type": ["string", "null"]
@@ -44,101 +39,46 @@
"supportedReasoningEfforts"
],
"properties": {
"additionalSpeedTiers": {
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"additionalSpeedTiers": { "default": [], "type": "array", "items": { "type": "string" } },
"availabilityNux": {
"anyOf": [
{
"$ref": "#/definitions/ModelAvailabilityNux"
},
{
"type": "null"
}
]
},
"defaultReasoningEffort": {
"$ref": "#/definitions/ReasoningEffort"
},
"description": {
"type": "string"
},
"displayName": {
"type": "string"
},
"hidden": {
"type": "boolean"
},
"id": {
"type": "string"
"anyOf": [{ "$ref": "#/definitions/ModelAvailabilityNux" }, { "type": "null" }]
},
"defaultReasoningEffort": { "$ref": "#/definitions/ReasoningEffort" },
"description": { "type": "string" },
"displayName": { "type": "string" },
"hidden": { "type": "boolean" },
"id": { "type": "string" },
"inputModalities": {
"default": ["text", "image"],
"type": "array",
"items": {
"$ref": "#/definitions/InputModality"
}
},
"isDefault": {
"type": "boolean"
},
"model": {
"type": "string"
"items": { "$ref": "#/definitions/InputModality" }
},
"isDefault": { "type": "boolean" },
"model": { "type": "string" },
"supportedReasoningEfforts": {
"type": "array",
"items": {
"$ref": "#/definitions/ReasoningEffortOption"
}
},
"supportsPersonality": {
"default": false,
"type": "boolean"
},
"upgrade": {
"type": ["string", "null"]
"items": { "$ref": "#/definitions/ReasoningEffortOption" }
},
"supportsPersonality": { "default": false, "type": "boolean" },
"upgrade": { "type": ["string", "null"] },
"upgradeInfo": {
"anyOf": [
{
"$ref": "#/definitions/ModelUpgradeInfo"
},
{
"type": "null"
}
]
"anyOf": [{ "$ref": "#/definitions/ModelUpgradeInfo" }, { "type": "null" }]
}
}
},
"ModelAvailabilityNux": {
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
"properties": { "message": { "type": "string" } }
},
"ModelUpgradeInfo": {
"type": "object",
"required": ["model"],
"properties": {
"migrationMarkdown": {
"type": ["string", "null"]
},
"model": {
"type": "string"
},
"modelLink": {
"type": ["string", "null"]
},
"upgradeCopy": {
"type": ["string", "null"]
}
"migrationMarkdown": { "type": ["string", "null"] },
"model": { "type": "string" },
"modelLink": { "type": ["string", "null"] },
"upgradeCopy": { "type": ["string", "null"] }
}
},
"ReasoningEffort": {
@@ -150,12 +90,8 @@
"type": "object",
"required": ["description", "reasoningEffort"],
"properties": {
"description": {
"type": "string"
},
"reasoningEffort": {
"$ref": "#/definitions/ReasoningEffort"
}
"description": { "type": "string" },
"reasoningEffort": { "$ref": "#/definitions/ReasoningEffort" }
}
}
}

View File

@@ -1466,7 +1466,7 @@ type DynamicToolBuildParams = {
sandboxSessionKey: string;
sandbox: Awaited<ReturnType<typeof resolveSandboxContext>>;
runAbortController: AbortController;
sessionAgentId: string | undefined;
sessionAgentId: string;
pluginConfig: CodexPluginConfig;
onYieldDetected: () => void;
};

View File

@@ -160,12 +160,16 @@ async function compareGeneratedProtocolMirror(
failures.push(`protocol-generated/json/${schema}: missing local schema (${String(error)})`);
continue;
}
if (source !== target) {
if (normalizeJsonSchema(source) !== normalizeJsonSchema(target)) {
failures.push(`protocol-generated/json/${schema}: differs from source schema`);
}
}
}
function normalizeJsonSchema(source: string): string {
return JSON.stringify(JSON.parse(source));
}
async function listFiles(root: string, suffix: string): Promise<string[]> {
const files: string[] = [];
async function visit(dir: string): Promise<void> {

View File

@@ -6,6 +6,7 @@ import { loadChannelConfigSurfaceModule } from "./load-channel-config-surface.ts
const GENERATED_BY = "scripts/generate-bundled-channel-config-metadata.ts";
const DEFAULT_OUTPUT_PATH = "src/config/bundled-channel-config-metadata.generated.ts";
const GENERATED_JSON_CHUNK_SIZE = 16 * 1024;
type BundledPluginSource = {
dirName: string;
@@ -141,6 +142,15 @@ function formatTypeScriptModule(source: string, outputPath: string, repoRoot: st
});
}
function formatJsonStringChunks(value: unknown): string {
const json = JSON.stringify(value);
const chunks: string[] = [];
for (let index = 0; index < json.length; index += GENERATED_JSON_CHUNK_SIZE) {
chunks.push(JSON.stringify(json.slice(index, index + GENERATED_JSON_CHUNK_SIZE)));
}
return chunks.join(",\n ");
}
function resolveChannelUnsupportedSecretRefSurfacePatterns(
source: BundledPluginSource,
channelId: string,
@@ -223,10 +233,27 @@ export async function writeBundledChannelConfigMetadataModule(params?: {
const repoRoot = path.resolve(params?.repoRoot ?? process.cwd());
const outputPath = params?.outputPath ?? DEFAULT_OUTPUT_PATH;
const entries = await collectBundledChannelConfigMetadata({ repoRoot });
const chunks = formatJsonStringChunks(entries);
const next = formatTypeScriptModule(
`// Auto-generated by ${GENERATED_BY}. Do not edit directly.
export const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA = ${JSON.stringify(entries, null, 2)} as const;
type BundledChannelConfigMetadata = {
pluginId: string;
channelId: string;
label?: string;
description?: string;
schema: Record<string, unknown>;
uiHints?: Record<string, unknown>;
unsupportedSecretRefSurfacePatterns?: readonly string[];
};
const RAW_BUNDLED_CHANNEL_CONFIG_METADATA = [
${chunks},
].join("");
export const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA = JSON.parse(
RAW_BUNDLED_CHANNEL_CONFIG_METADATA,
) as readonly BundledChannelConfigMetadata[];
`,
outputPath,
repoRoot,

View File

@@ -102,19 +102,7 @@ export function readGeneratedBundledChannelConfigs(repoRoot) {
return new Map();
}
const source = fs.readFileSync(metadataPath, "utf8");
const match = source.match(
/export const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA = ([\s\S]*?) as const;/u,
);
if (!match?.[1]) {
return new Map();
}
let entries;
try {
entries = JSON5.parse(match[1]);
} catch {
return new Map();
}
const entries = readGeneratedBundledChannelConfigEntries(source);
if (!Array.isArray(entries)) {
return new Map();
}
@@ -145,6 +133,35 @@ export function readGeneratedBundledChannelConfigs(repoRoot) {
return byPlugin;
}
function readGeneratedBundledChannelConfigEntries(source) {
const legacyMatch = source.match(
/export const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA = ([\s\S]*?) as const;/u,
);
if (legacyMatch?.[1]) {
try {
return JSON5.parse(legacyMatch[1]);
} catch {
return undefined;
}
}
const compactMatch = source.match(
/const RAW_BUNDLED_CHANNEL_CONFIG_METADATA = \[([\s\S]*?)\]\.join\(""\);/u,
);
if (!compactMatch?.[1]) {
return undefined;
}
try {
const chunks = JSON5.parse(`[${compactMatch[1]}]`);
if (!Array.isArray(chunks) || chunks.some((chunk) => typeof chunk !== "string")) {
return undefined;
}
return JSON.parse(chunks.join(""));
} catch {
return undefined;
}
}
export function mergeGeneratedChannelConfigs(manifest, generatedChannelConfigs) {
if (!generatedChannelConfigs || Object.keys(generatedChannelConfigs).length === 0) {
return manifest;

View File

@@ -20,7 +20,11 @@ try {
for (const schema of selectedCodexAppServerJsonSchemas) {
await fs.mkdir(path.dirname(path.join(targetRoot, "json", schema)), { recursive: true });
await fs.copyFile(path.join(source.jsonRoot, schema), path.join(targetRoot, "json", schema));
const schemaSource = await fs.readFile(path.join(source.jsonRoot, schema), "utf8");
await fs.writeFile(
path.join(targetRoot, "json", schema),
`${JSON.stringify(JSON.parse(schemaSource))}\n`,
);
}
} finally {
await source.cleanup();

File diff suppressed because one or more lines are too long

View File

@@ -87,7 +87,7 @@ export {
} from "../agents/pi-embedded-subscribe.tools.js";
export { normalizeUsage } from "../agents/usage.js";
export { resolveOpenClawAgentDir } from "./agent-dir-compat.js";
export { resolveSessionAgentIds } from "../agents/agent-scope.js";
export { resolveAgentDir, resolveSessionAgentIds } from "../agents/agent-scope.js";
export { resolveModelAuthMode } from "../agents/model-auth.js";
export { supportsModelTools } from "../agents/model-tool-support.js";
export { resolveAttemptSpawnWorkspaceDir } from "../agents/pi-embedded-runner/run/attempt.thread-helpers.js";