Replace NodeJS dict aliases with maps and named field reads
Agents / agent (pull_request) Has been skipped
Check / check (pull_request) Successful in 49s

This commit is contained in:
Danny Kim
2026-10-19 02:30:54 +09:00
parent 32806120b3
commit c8ffb9cc6f
15 changed files with 275 additions and 196 deletions
+10 -10
View File
@@ -1,4 +1,4 @@
import { isObject } from "#common";
import { field, isObject } from "#common";
import { AgentAuthError } from "#profiles";
export function openCodeArgs(model: string, prompt: string): string[] {
@@ -56,13 +56,14 @@ export function openCodeError(output: string): Error | null {
} catch {
continue;
}
if (!isObject(event)) continue;
const { type, error } = event;
if (type !== "error" || !isObject(error)) {
const error = field(event, "error");
if (field(event, "type") !== "error" || !isObject(error)) {
continue;
}
const { name, data } = error;
const { message, statusCode } = isObject(data) ? data : {};
const name = field(error, "name");
const data = field(error, "data");
const message = field(data, "message");
const statusCode = field(data, "statusCode");
const detail = `opencode ${typeof name === "string" ? name : "error"}${
typeof statusCode === "number" ? ` (API error ${statusCode})` : ""
}: ${typeof message === "string" ? message : "unknown error"}`;
@@ -81,10 +82,9 @@ export function parseOpenCodeEvents(output: string): string {
for (const line of output.split("\n")) {
if (line.trim() === "") continue;
const event: unknown = JSON.parse(line);
if (!isObject(event)) continue;
const { type, part } = event;
if (type !== "text" || !isObject(part)) continue;
const { text } = part;
const part = field(event, "part");
if (field(event, "type") !== "text" || !isObject(part)) continue;
const text = field(part, "text");
if (typeof text === "string" && text.trim() !== "") result = text;
}
if (result === null) {