Normalize generated app-server types

This commit is contained in:
murashit 2026-05-14 21:49:50 +09:00
parent ca53951300
commit 4cba750676
8 changed files with 59 additions and 9 deletions

View file

@ -17,9 +17,9 @@
"build": "node esbuild.config.mjs",
"build:prod": "node esbuild.config.mjs --production",
"dev": "node esbuild.config.mjs --watch",
"format": "prettier --write \"src/**/*.{ts,tsx,js,mjs,json,css,md}\" \"tests/**/*.{ts,tsx,js,mjs,json,css,md}\" \"*.{json,mjs,md,css}\" \"!src/generated/**\"",
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,mjs,json,css,md}\" \"tests/**/*.{ts,tsx,js,mjs,json,css,md}\" \"*.{json,mjs,md,css}\" \"!src/generated/**\"",
"generate:app-server-types": "codex app-server generate-ts --experimental --out src/generated/app-server",
"format": "prettier --write \"src/**/*.{ts,tsx,js,mjs,json,css,md}\" \"tests/**/*.{ts,tsx,js,mjs,json,css,md}\" \"scripts/**/*.{js,mjs}\" \"*.{json,mjs,md,css}\" \"!src/generated/**\"",
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,mjs,json,css,md}\" \"tests/**/*.{ts,tsx,js,mjs,json,css,md}\" \"scripts/**/*.{js,mjs}\" \"*.{json,mjs,md,css}\" \"!src/generated/**\"",
"generate:app-server-types": "codex app-server generate-ts --experimental --out src/generated/app-server && node scripts/normalize-generated-types.mjs",
"lint": "eslint src tests --max-warnings=0",
"test": "vitest run",
"typecheck": "tsc -p tsconfig.json --noEmit",

View file

@ -0,0 +1,44 @@
import { readdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
const generatedDir = path.resolve("src/generated/app-server");
const generatedHeader = "// GENERATED CODE! DO NOT MODIFY BY HAND!";
const normalizationNotice = "// This file was mechanically normalized after generation by scripts/normalize-generated-types.mjs.";
async function listTypeScriptFiles(dir) {
const entries = await readdir(dir, { withFileTypes: true });
const files = await Promise.all(
entries.map((entry) => {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) return listTypeScriptFiles(fullPath);
return entry.isFile() && entry.name.endsWith(".ts") ? [fullPath] : [];
}),
);
return files.flat();
}
function normalizeSource(source) {
let normalized = source;
do {
source = normalized;
normalized = source.replaceAll("| null | null", "| null");
} while (normalized !== source);
return normalized;
}
function addNormalizationNotice(source) {
if (source.includes(normalizationNotice)) return source;
if (!source.startsWith(generatedHeader)) return source;
return source.replace(generatedHeader, `${generatedHeader}\n${normalizationNotice}`);
}
const files = await listTypeScriptFiles(generatedDir);
await Promise.all(
files.map(async (file) => {
const source = await readFile(file, "utf8");
const normalized = normalizeSource(source);
const nextSource = normalized === source ? source : addNormalizationNotice(normalized);
if (nextSource !== source) await writeFile(file, nextSource);
}),
);

View file

@ -1,4 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was mechanically normalized after generation by scripts/normalize-generated-types.mjs.
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ModeKind } from "../ModeKind";
@ -7,4 +8,4 @@ import type { ReasoningEffort } from "../ReasoningEffort";
/**
* EXPERIMENTAL - collaboration mode preset metadata for clients.
*/
export type CollaborationModeMask = { name: string, mode: ModeKind | null, model: string | null, reasoning_effort: ReasoningEffort | null | null, };
export type CollaborationModeMask = { name: string, mode: ModeKind | null, model: string | null, reasoning_effort: ReasoningEffort | null, };

View file

@ -1,4 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was mechanically normalized after generation by scripts/normalize-generated-types.mjs.
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { JsonValue } from "../serde_json/JsonValue";
@ -26,7 +27,7 @@ path?: string | null,
/**
* Configuration overrides for the forked thread, if any.
*/
model?: string | null, modelProvider?: string | null, serviceTier?: string | null | null, cwd?: string | null, approvalPolicy?: AskForApproval | null,
model?: string | null, modelProvider?: string | null, serviceTier?: string | null, cwd?: string | null, approvalPolicy?: AskForApproval | null,
/**
* Override where approval requests are routed for review on this thread
* and subsequent turns.

View file

@ -1,4 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was mechanically normalized after generation by scripts/normalize-generated-types.mjs.
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { RealtimeOutputModality } from "../RealtimeOutputModality";
@ -13,4 +14,4 @@ export type ThreadRealtimeStartParams = { threadId: string,
* Selects text or audio output for the realtime session. Transport and voice stay
* independent so clients can choose how they connect separately from what the model emits.
*/
outputModality: RealtimeOutputModality, prompt?: string | null | null, realtimeSessionId?: string | null, transport?: ThreadRealtimeStartTransport | null, voice?: RealtimeVoice | null, };
outputModality: RealtimeOutputModality, prompt?: string | null, realtimeSessionId?: string | null, transport?: ThreadRealtimeStartTransport | null, voice?: RealtimeVoice | null, };

View file

@ -1,4 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was mechanically normalized after generation by scripts/normalize-generated-types.mjs.
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Personality } from "../Personality";
@ -35,7 +36,7 @@ path?: string | null,
/**
* Configuration overrides for the resumed thread, if any.
*/
model?: string | null, modelProvider?: string | null, serviceTier?: string | null | null, cwd?: string | null, approvalPolicy?: AskForApproval | null,
model?: string | null, modelProvider?: string | null, serviceTier?: string | null, cwd?: string | null, approvalPolicy?: AskForApproval | null,
/**
* Override where approval requests are routed for review on this thread
* and subsequent turns.

View file

@ -1,4 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was mechanically normalized after generation by scripts/normalize-generated-types.mjs.
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Personality } from "../Personality";
@ -12,7 +13,7 @@ import type { ThreadSource } from "./ThreadSource";
import type { ThreadStartSource } from "./ThreadStartSource";
import type { TurnEnvironmentParams } from "./TurnEnvironmentParams";
export type ThreadStartParams = { model?: string | null, modelProvider?: string | null, serviceTier?: string | null | null, cwd?: string | null, approvalPolicy?: AskForApproval | null,
export type ThreadStartParams = { model?: string | null, modelProvider?: string | null, serviceTier?: string | null, cwd?: string | null, approvalPolicy?: AskForApproval | null,
/**
* Override where approval requests are routed for review on this thread
* and subsequent turns.

View file

@ -1,4 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was mechanically normalized after generation by scripts/normalize-generated-types.mjs.
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { CollaborationMode } from "../CollaborationMode";
@ -57,7 +58,7 @@ model?: string | null,
/**
* Override the service tier for this turn and subsequent turns.
*/
serviceTier?: string | null | null,
serviceTier?: string | null,
/**
* Override the reasoning effort for this turn and subsequent turns.
*/