chore: normalize formatting (2-space → tabs) in stream-error-patterns files

Re-tab only — no logic changes. Follows the repo's tab-based formatting
for these files, matching the CommandCode executor/translator style.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
This commit is contained in:
2026-08-05 09:03:41 +07:00
parent e2f8323ab1
commit 2a37a4085e
8 changed files with 929 additions and 529 deletions

View File

@@ -9,39 +9,39 @@
*/
export function parsePatterns(patterns) {
if (!Array.isArray(patterns)) return [];
const out = [];
for (const entry of patterns) {
if (typeof entry !== "string" || !entry.trim()) continue;
const raw = entry.trim();
const m = raw.match(/^\/(.*)\/([a-z]*)$/s);
if (m) {
try {
out.push({ regex: new RegExp(m[1], m[2]), raw });
} catch {
// invalid regex → skip; config errors must never break requests
}
continue;
}
out.push({ text: raw.toLowerCase(), raw });
}
return out;
if (!Array.isArray(patterns)) return [];
const out = [];
for (const entry of patterns) {
if (typeof entry !== "string" || !entry.trim()) continue;
const raw = entry.trim();
const m = raw.match(/^\/(.*)\/([a-z]*)$/s);
if (m) {
try {
out.push({ regex: new RegExp(m[1], m[2]), raw });
} catch {
// invalid regex → skip; config errors must never break requests
}
continue;
}
out.push({ text: raw.toLowerCase(), raw });
}
return out;
}
export function matchStreamErrorPatterns(patterns, text) {
if (!Array.isArray(patterns) || patterns.length === 0) return null;
if (typeof text !== "string" || !text) return null;
const lower = text.toLowerCase();
for (const p of parsePatterns(patterns)) {
if (p.text && lower.includes(p.text)) return p.raw;
if (p.regex) {
p.regex.lastIndex = 0; // stateless even with /g
if (p.regex.test(text)) return p.raw;
}
}
return null;
if (!Array.isArray(patterns) || patterns.length === 0) return null;
if (typeof text !== "string" || !text) return null;
const lower = text.toLowerCase();
for (const p of parsePatterns(patterns)) {
if (p.text && lower.includes(p.text)) return p.raw;
if (p.regex) {
p.regex.lastIndex = 0; // stateless even with /g
if (p.regex.test(text)) return p.raw;
}
}
return null;
}
export function streamStatusForContent(patterns, content) {
return matchStreamErrorPatterns(patterns, content) ? "error" : "success";
return matchStreamErrorPatterns(patterns, content) ? "error" : "success";
}