chore: Enable "curly" rule to avoid single-statement if confusion/errors.

This commit is contained in:
cpojer
2026-01-31 16:19:20 +09:00
parent 009b16fab8
commit 5ceff756e1
1266 changed files with 27871 additions and 9393 deletions

View File

@@ -45,17 +45,27 @@ function asMessages(val: unknown): OpenAiChatMessage[] {
}
function extractTextContent(content: unknown): string {
if (typeof content === "string") return content;
if (typeof content === "string") {
return content;
}
if (Array.isArray(content)) {
return content
.map((part) => {
if (!part || typeof part !== "object") return "";
if (!part || typeof part !== "object") {
return "";
}
const type = (part as { type?: unknown }).type;
const text = (part as { text?: unknown }).text;
const inputText = (part as { input_text?: unknown }).input_text;
if (type === "text" && typeof text === "string") return text;
if (type === "input_text" && typeof text === "string") return text;
if (typeof inputText === "string") return inputText;
if (type === "text" && typeof text === "string") {
return text;
}
if (type === "input_text" && typeof text === "string") {
return text;
}
if (typeof inputText === "string") {
return inputText;
}
return "";
})
.filter(Boolean)
@@ -75,10 +85,14 @@ function buildAgentPrompt(messagesUnknown: unknown): {
[];
for (const msg of messages) {
if (!msg || typeof msg !== "object") continue;
if (!msg || typeof msg !== "object") {
continue;
}
const role = typeof msg.role === "string" ? msg.role.trim() : "";
const content = extractTextContent(msg.content).trim();
if (!role || !content) continue;
if (!role || !content) {
continue;
}
if (role === "system" || role === "developer") {
systemParts.push(content);
continue;
@@ -115,7 +129,9 @@ function buildAgentPrompt(messagesUnknown: unknown): {
break;
}
}
if (currentIndex < 0) currentIndex = conversationEntries.length - 1;
if (currentIndex < 0) {
currentIndex = conversationEntries.length - 1;
}
const currentEntry = conversationEntries[currentIndex]?.entry;
if (currentEntry) {
const historyEntries = conversationEntries.slice(0, currentIndex).map((entry) => entry.entry);
@@ -147,7 +163,9 @@ function resolveOpenAiSessionKey(params: {
}
function coerceRequest(val: unknown): OpenAiChatCompletionRequest {
if (!val || typeof val !== "object") return {};
if (!val || typeof val !== "object") {
return {};
}
return val as OpenAiChatCompletionRequest;
}
@@ -157,7 +175,9 @@ export async function handleOpenAiHttpRequest(
opts: OpenAiHttpOptions,
): Promise<boolean> {
const url = new URL(req.url ?? "/", `http://${req.headers.host || "localhost"}`);
if (url.pathname !== "/v1/chat/completions") return false;
if (url.pathname !== "/v1/chat/completions") {
return false;
}
if (req.method !== "POST") {
sendMethodNotAllowed(res);
@@ -177,7 +197,9 @@ export async function handleOpenAiHttpRequest(
}
const body = await readJsonBodyOrError(req, res, opts.maxBodyBytes ?? 1024 * 1024);
if (body === undefined) return true;
if (body === undefined) {
return true;
}
const payload = coerceRequest(body);
const stream = Boolean(payload.stream);
@@ -254,14 +276,20 @@ export async function handleOpenAiHttpRequest(
let closed = false;
const unsubscribe = onAgentEvent((evt) => {
if (evt.runId !== runId) return;
if (closed) return;
if (evt.runId !== runId) {
return;
}
if (closed) {
return;
}
if (evt.stream === "assistant") {
const delta = evt.data?.delta;
const text = evt.data?.text;
const content = typeof delta === "string" ? delta : typeof text === "string" ? text : "";
if (!content) return;
if (!content) {
return;
}
if (!wroteRole) {
wroteRole = true;
@@ -323,7 +351,9 @@ export async function handleOpenAiHttpRequest(
deps,
);
if (closed) return;
if (closed) {
return;
}
if (!sawAssistantDelta) {
if (!wroteRole) {
@@ -362,7 +392,9 @@ export async function handleOpenAiHttpRequest(
});
}
} catch (err) {
if (closed) return;
if (closed) {
return;
}
writeSse(res, {
id: runId,
object: "chat.completion.chunk",