Replace NodeJS dict aliases with maps and named field reads
This commit is contained in:
+10
-10
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user