fix: parse escaped retryable error messages

This commit is contained in:
2026-07-08 10:08:25 +08:00
parent a62f2cf1b9
commit 5d48ef5880
4 changed files with 64 additions and 15 deletions
+8 -1
View File
@@ -15,6 +15,13 @@ export const DEFAULT_LISTEN_PORT = 4610;
export const DEFAULT_HEALTH_PATH = "/__codex_retry_gateway/health";
export const DEFAULT_REASONING_MATCH_MODE = "formula_518n_minus_2";
export const DEFAULT_REASONING_EQUALS = [516, 1034, 1552];
export function expandEscapedLineBreaks(value) {
return `${value ?? ""}`
.replace(/\\r\\n/g, "\n")
.replace(/\\n/g, "\n")
.replace(/\\r/g, "\n");
}
function escapeRegExp(value) {
return `${value}`.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -204,7 +211,7 @@ export function normalizePhraseArray(values, fallback = []) {
const source = values === undefined || values === null ? fallback : values;
const queue = Array.isArray(source) ? source.flat(Infinity) : [source];
const normalized = queue
.flatMap((value) => (typeof value === "string" ? value.split(/\r?\n/) : [value]))
.flatMap((value) => (typeof value === "string" ? expandEscapedLineBreaks(value).split(/\r?\n/) : [value]))
.map((value) => `${value ?? ""}`.trim())
.filter(Boolean);