0a3d1875f7
Avoid non-null assertions in tool and doctor code by preserving narrowed locals through each use site. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import type { LookAtArgs } from "./types"
|
|
|
|
export interface LookAtArgsWithAlias extends LookAtArgs {
|
|
path?: string
|
|
}
|
|
|
|
export function normalizeArgs(args: LookAtArgsWithAlias): LookAtArgs {
|
|
return {
|
|
file_path: args.file_path ?? args.path,
|
|
image_data: args.image_data,
|
|
goal: args.goal ?? "",
|
|
}
|
|
}
|
|
|
|
export function validateArgs(args: LookAtArgs): string | null {
|
|
const filePath = args.file_path
|
|
const hasFilePath = Boolean(filePath && filePath.length > 0)
|
|
const hasImageData = Boolean(args.image_data && args.image_data.length > 0)
|
|
|
|
if (filePath && /^https?:\/\//i.test(filePath)) {
|
|
return "Error: Remote URLs are not supported for file_path. Download the file first or use a local path."
|
|
}
|
|
if (!hasFilePath && !hasImageData) {
|
|
return `Error: Must provide either 'file_path' or 'image_data'. Usage:
|
|
- look_at(file_path="/path/to/file", goal="what to extract")
|
|
- look_at(image_data="base64_encoded_data", goal="what to extract")`
|
|
}
|
|
if (hasFilePath && hasImageData) {
|
|
return "Error: Provide only one of 'file_path' or 'image_data', not both."
|
|
}
|
|
if (!args.goal) {
|
|
return "Error: Missing required parameter 'goal'. Usage: look_at(file_path=\"/path/to/file\", goal=\"what to extract\")"
|
|
}
|
|
return null
|
|
}
|