|
1 | 1 | import type { AgentToolResult } from "openclaw/plugin-sdk/agent-core"; |
| 2 | +import { |
| 3 | +readNonNegativeIntegerParam, |
| 4 | +readPositiveIntegerParam, |
| 5 | +} from "openclaw/plugin-sdk/param-readers"; |
2 | 6 | import { |
3 | 7 | DEFAULT_AI_SNAPSHOT_MAX_CHARS, |
4 | 8 | browserAct, |
@@ -346,16 +350,18 @@ export async function executeSnapshotAction(params: {
|
346 | 350 | input.refs === "aria" || input.refs === "role" ? input.refs : undefined; |
347 | 351 | const hasMaxChars = Object.hasOwn(input, "maxChars"); |
348 | 352 | const targetId = normalizeOptionalString(input.targetId); |
349 | | -const limit = |
350 | | -typeof input.limit === "number" && Number.isFinite(input.limit) ? input.limit : undefined; |
351 | | -const maxChars = |
352 | | -typeof input.maxChars === "number" && Number.isFinite(input.maxChars) && input.maxChars > 0 |
353 | | - ? Math.floor(input.maxChars) |
354 | | - : undefined; |
| 353 | +const limit = readPositiveIntegerParam(input, "limit", { |
| 354 | +message: "limit must be a positive integer.", |
| 355 | +}); |
| 356 | +const maxCharsRaw = readNonNegativeIntegerParam(input, "maxChars", { |
| 357 | +message: "maxChars must be a non-negative integer.", |
| 358 | +}); |
| 359 | +const maxChars = maxCharsRaw !== undefined && maxCharsRaw > 0 ? maxCharsRaw : undefined; |
355 | 360 | const interactive = typeof input.interactive === "boolean" ? input.interactive : undefined; |
356 | 361 | const compact = typeof input.compact === "boolean" ? input.compact : undefined; |
357 | | -const depth = |
358 | | -typeof input.depth === "number" && Number.isFinite(input.depth) ? input.depth : undefined; |
| 362 | +const depth = readNonNegativeIntegerParam(input, "depth", { |
| 363 | +message: "depth must be a non-negative integer.", |
| 364 | +}); |
359 | 365 | const selector = normalizeOptionalString(input.selector); |
360 | 366 | const frame = normalizeOptionalString(input.frame); |
361 | 367 | const resolvedMaxChars = |
@@ -369,7 +375,9 @@ export async function executeSnapshotAction(params: {
|
369 | 375 | ? maxChars |
370 | 376 | : undefined; |
371 | 377 | const snapshotTimeoutMs = |
372 | | -normalizePositiveTimeoutMs(input.timeoutMs) ?? DEFAULT_BROWSER_SNAPSHOT_TIMEOUT_MS; |
| 378 | +readPositiveIntegerParam(input, "timeoutMs", { |
| 379 | +message: "timeoutMs must be a positive integer.", |
| 380 | +}) ?? DEFAULT_BROWSER_SNAPSHOT_TIMEOUT_MS; |
373 | 381 | const snapshotQuery = { |
374 | 382 | ...(format ? { format } : {}), |
375 | 383 | targetId, |
|