fix: resolve build errors

main
Peter Steinberger 2025-12-23 03:00:04 +01:00
parent 183270b443
commit 279500cba4
5 changed files with 51 additions and 7 deletions

View File

@ -77,6 +77,16 @@ type StringParamOptions = {
label?: string; label?: string;
}; };
function readStringParam(
params: Record<string, unknown>,
key: string,
options: StringParamOptions & { required: true },
): string;
function readStringParam(
params: Record<string, unknown>,
key: string,
options?: StringParamOptions,
): string | undefined;
function readStringParam( function readStringParam(
params: Record<string, unknown>, params: Record<string, unknown>,
key: string, key: string,
@ -783,7 +793,12 @@ function createCanvasTool(): AnyAgentTool {
payload?: { result?: string }; payload?: { result?: string };
}; };
const result = raw?.payload?.result; const result = raw?.payload?.result;
if (result) return { content: [{ type: "text", text: result }] }; if (result) {
return {
content: [{ type: "text", text: result }],
details: { result },
};
}
return jsonResult({ ok: true }); return jsonResult({ ok: true });
} }
case "snapshot": { case "snapshot": {

View File

@ -15,7 +15,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value && typeof value === "object" && !Array.isArray(value)); return Boolean(value && typeof value === "object" && !Array.isArray(value));
} }
async function readJson(pathname: string): Promise<unknown | null> { async function readJson(pathname: string): Promise<unknown> {
try { try {
const raw = await fs.readFile(pathname, "utf8"); const raw = await fs.readFile(pathname, "utf8");
return JSON.parse(raw) as unknown; return JSON.parse(raw) as unknown;

View File

@ -251,9 +251,11 @@ export function registerBrowserAgentRoutes(
typeof rec.value === "boolean" typeof rec.value === "boolean"
? rec.value ? rec.value
: undefined; : undefined;
return { ref, type, value }; const parsed: BrowserFormField =
value === undefined ? { ref, type } : { ref, type, value };
return parsed;
}) })
.filter((field): field is BrowserFormField => Boolean(field)); .filter((field): field is BrowserFormField => field !== null);
if (!fields.length) return jsonError(res, 400, "fields are required"); if (!fields.length) return jsonError(res, 400, "fields are required");
await pw.fillFormViaPlaywright({ await pw.fillFormViaPlaywright({
cdpPort, cdpPort,

View File

@ -6,6 +6,7 @@ import {
browserArmFileChooser, browserArmFileChooser,
browserNavigate, browserNavigate,
} from "../browser/client-actions.js"; } from "../browser/client-actions.js";
import type { BrowserFormField } from "../browser/client-actions-core.js";
import { danger } from "../globals.js"; import { danger } from "../globals.js";
import { defaultRuntime } from "../runtime.js"; import { defaultRuntime } from "../runtime.js";
import type { BrowserParentOpts } from "./browser-cli-shared.js"; import type { BrowserParentOpts } from "./browser-cli-shared.js";
@ -18,14 +19,37 @@ async function readFile(path: string): Promise<string> {
async function readFields(opts: { async function readFields(opts: {
fields?: string; fields?: string;
fieldsFile?: string; fieldsFile?: string;
}): Promise<Array<Record<string, unknown>>> { }): Promise<BrowserFormField[]> {
const payload = opts.fieldsFile const payload = opts.fieldsFile
? await readFile(opts.fieldsFile) ? await readFile(opts.fieldsFile)
: (opts.fields ?? ""); : (opts.fields ?? "");
if (!payload.trim()) throw new Error("fields are required"); if (!payload.trim()) throw new Error("fields are required");
const parsed = JSON.parse(payload) as unknown; const parsed = JSON.parse(payload) as unknown;
if (!Array.isArray(parsed)) throw new Error("fields must be an array"); if (!Array.isArray(parsed)) throw new Error("fields must be an array");
return parsed as Array<Record<string, unknown>>; return parsed.map((entry, index) => {
if (!entry || typeof entry !== "object") {
throw new Error(`fields[${index}] must be an object`);
}
const rec = entry as Record<string, unknown>;
const ref = typeof rec.ref === "string" ? rec.ref.trim() : "";
const type = typeof rec.type === "string" ? rec.type.trim() : "";
if (!ref || !type) {
throw new Error(`fields[${index}] must include ref and type`);
}
if (
typeof rec.value === "string" ||
typeof rec.value === "number" ||
typeof rec.value === "boolean"
) {
return { ref, type, value: rec.value };
}
if (rec.value === undefined || rec.value === null) {
return { ref, type };
}
throw new Error(
`fields[${index}].value must be string, number, boolean, or null`,
);
});
} }
export function registerBrowserActionInputCommands( export function registerBrowserActionInputCommands(

View File

@ -9,5 +9,8 @@ export function rawDataToString(
if (typeof data === "string") return data; if (typeof data === "string") return data;
if (Buffer.isBuffer(data)) return data.toString(encoding); if (Buffer.isBuffer(data)) return data.toString(encoding);
if (Array.isArray(data)) return Buffer.concat(data).toString(encoding); if (Array.isArray(data)) return Buffer.concat(data).toString(encoding);
return Buffer.from(data as ArrayBuffer | ArrayBufferView).toString(encoding); if (data instanceof ArrayBuffer) {
return Buffer.from(data).toString(encoding);
}
return Buffer.from(String(data)).toString(encoding);
} }