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

@@ -71,11 +71,17 @@ function writeSseEvent(res: ServerResponse, event: StreamingEvent) {
}
function extractTextContent(content: string | ContentPart[]): string {
if (typeof content === "string") return content;
if (typeof content === "string") {
return content;
}
return content
.map((part) => {
if (part.type === "input_text") return part.text;
if (part.type === "output_text") return part.text;
if (part.type === "input_text") {
return part.text;
}
if (part.type === "output_text") {
return part.text;
}
return "";
})
.filter(Boolean)
@@ -127,7 +133,9 @@ function applyToolChoice(params: {
toolChoice: CreateResponseBody["tool_choice"];
}): { tools: ClientToolDefinition[]; extraSystemPrompt?: string } {
const { tools, toolChoice } = params;
if (!toolChoice) return { tools };
if (!toolChoice) {
return { tools };
}
if (toolChoice === "none") {
return { tools: [] };
@@ -176,7 +184,9 @@ export function buildAgentPrompt(input: string | ItemParam[]): {
for (const item of input) {
if (item.type === "message") {
const content = extractTextContent(item.content).trim();
if (!content) continue;
if (!content) {
continue;
}
if (item.role === "system" || item.role === "developer") {
systemParts.push(content);
@@ -210,7 +220,9 @@ export function buildAgentPrompt(input: string | ItemParam[]): {
break;
}
}
if (currentIndex < 0) currentIndex = conversationEntries.length - 1;
if (currentIndex < 0) {
currentIndex = conversationEntries.length - 1;
}
const currentEntry = conversationEntries[currentIndex]?.entry;
if (currentEntry) {
@@ -257,7 +269,9 @@ function toUsage(
}
| undefined,
): Usage {
if (!value) return createEmptyUsage();
if (!value) {
return createEmptyUsage();
}
const input = value.input ?? 0;
const output = value.output ?? 0;
const cacheRead = value.cacheRead ?? 0;
@@ -320,7 +334,9 @@ export async function handleOpenResponsesHttpRequest(
opts: OpenResponsesHttpOptions,
): Promise<boolean> {
const url = new URL(req.url ?? "/", `http://${req.headers.host || "localhost"}`);
if (url.pathname !== "/v1/responses") return false;
if (url.pathname !== "/v1/responses") {
return false;
}
if (req.method !== "POST") {
sendMethodNotAllowed(res);
@@ -346,7 +362,9 @@ export async function handleOpenResponsesHttpRequest(
? limits.maxBodyBytes
: Math.max(limits.maxBodyBytes, limits.files.maxBytes * 2, limits.images.maxBytes * 2));
const body = await readJsonBodyOrError(req, res, maxBodyBytes);
if (body === undefined) return true;
if (body === undefined) {
return true;
}
// Validate request body with Zod
const parseResult = CreateResponseBodySchema.safeParse(body);
@@ -592,9 +610,15 @@ export async function handleOpenResponsesHttpRequest(
let finalizeRequested: { status: ResponseResource["status"]; text: string } | null = null;
const maybeFinalize = () => {
if (closed) return;
if (!finalizeRequested) return;
if (!finalUsage) return;
if (closed) {
return;
}
if (!finalizeRequested) {
return;
}
if (!finalUsage) {
return;
}
const usage = finalUsage;
closed = true;
@@ -642,7 +666,9 @@ export async function handleOpenResponsesHttpRequest(
};
const requestFinalize = (status: ResponseResource["status"], text: string) => {
if (finalizeRequested) return;
if (finalizeRequested) {
return;
}
finalizeRequested = { status, text };
maybeFinalize();
};
@@ -681,14 +707,20 @@ export async function handleOpenResponsesHttpRequest(
});
unsubscribe = onAgentEvent((evt) => {
if (evt.runId !== responseId) return;
if (closed) return;
if (evt.runId !== responseId) {
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;
}
sawAssistantDelta = true;
accumulatedText += content;
@@ -740,7 +772,9 @@ export async function handleOpenResponsesHttpRequest(
finalUsage = extractUsageFromResult(result);
maybeFinalize();
if (closed) return;
if (closed) {
return;
}
// Fallback: if no streaming deltas were received, send the full response
if (!sawAssistantDelta) {
@@ -845,7 +879,9 @@ export async function handleOpenResponsesHttpRequest(
});
}
} catch (err) {
if (closed) return;
if (closed) {
return;
}
finalUsage = finalUsage ?? createEmptyUsage();
const errorResponse = createResponseResource({