diff --git a/src/validate/interfaces.ts b/src/validate/interfaces.ts index 649b778..b11474f 100644 --- a/src/validate/interfaces.ts +++ b/src/validate/interfaces.ts @@ -1,4 +1,5 @@ -export interface EmailValidationResponse { +import { BaseResponse } from "../../types"; +export interface EmailValidationResponse extends BaseResponse { email: string; disposable: boolean; role_account: boolean; @@ -9,8 +10,7 @@ export interface EmailValidationResponse { valid: boolean; } -export interface NSFWValidationResponse { - success: boolean; +export interface NSFWValidationResponse extends BaseResponse { nsfw: boolean; nudity: boolean; gore: boolean; @@ -24,8 +24,7 @@ export interface ProfanityParams { censor_replacement?: string; } -export interface ProfanityValidationResponse { - success: boolean; +export interface ProfanityValidationResponse extends BaseResponse { message: string; clean_text: string; profanities: { @@ -41,8 +40,7 @@ export interface SpellCheckParams { language_code?: string; } -export interface SpellCheckValidationResponse { - success: boolean; +export interface SpellCheckValidationResponse extends BaseResponse { misspellings_found: boolean; misspellings: Array<{ word: string; @@ -54,16 +52,14 @@ export interface SpellCheckValidationResponse { auto_correct_text: string; } -export interface SpamCheckValidationResponse { - success: boolean; +export interface SpamCheckValidationResponse extends BaseResponse { check: { is_spam: boolean; score: number; }; } -export interface SpamCheckValidationArrayResponse { - success: boolean; +export interface SpamCheckValidationArrayResponse extends BaseResponse { check: { is_spam: boolean; score: number; diff --git a/src/vision/interfaces.ts b/src/vision/interfaces.ts index aba7b4b..bafb807 100644 --- a/src/vision/interfaces.ts +++ b/src/vision/interfaces.ts @@ -1,3 +1,5 @@ +import { BaseResponse } from "../../types"; + export type VOCRParams = { prompt?: string | string[]; url?: string; @@ -5,28 +7,8 @@ export type VOCRParams = { page_range?: Array; }; -interface Bounds { - top_left: { - x: number; - y: number; - }; - top_right: { - x: number; - y: number; - }; - bottom_left: { - x: number; - y: number; - }; - bottom_right: { - x: number; - y: number; - }; -} - -export interface VOCRResponse { - success: boolean; - context: string; +export interface VOCRResponse extends BaseResponse { + context: string | Record; width: number; height: number; tags: string[]; @@ -53,9 +35,10 @@ export type ObjectDetectionParams = { features?: ("object_detection" | "gui")[]; annotated_image?: boolean; return_type?: "url" | "base64"; + return_masks: }; -export interface ObjectDetectionResponse { +export interface ObjectDetectionResponse extends BaseResponse { // Optional annotated image - included only if annotated_image=true and objects/gui_elements exist annotated_image?: string; // URL or base64 string depending on return_type @@ -90,3 +73,22 @@ interface Point { x: number; y: number; } + +interface Bounds { + top_left: { + x: number; + y: number; + }; + top_right: { + x: number; + y: number; + }; + bottom_left: { + x: number; + y: number; + }; + bottom_right: { + x: number; + y: number; + }; +} diff --git a/src/web/interfaces/deep_research.ts b/src/web/interfaces/deep_research.ts index 8d69030..0357ff2 100644 --- a/src/web/interfaces/deep_research.ts +++ b/src/web/interfaces/deep_research.ts @@ -1,3 +1,4 @@ +import { BaseResponse } from "../../../types"; // Input parameters interface for reference export interface DeepResearchParams { query: string; @@ -10,8 +11,7 @@ export interface DeepResearchParams { target_output_tokens?: number; } -export interface DeepResearchResponse { - success: boolean; +export interface DeepResearchResponse extends BaseResponse { query: string; results: string; sources: SearchResult[]; diff --git a/src/web/interfaces/html_to_any.ts b/src/web/interfaces/html_to_any.ts index 1750250..641d760 100644 --- a/src/web/interfaces/html_to_any.ts +++ b/src/web/interfaces/html_to_any.ts @@ -1,3 +1,5 @@ +import { BaseResponse } from "../../../types"; + export interface HTMLAnyParams { html?: string; url?: string; @@ -21,3 +23,22 @@ export interface HTMLAnyParams { }; return_type?: "url" | "binary" | "base64"; } + +// response for "url" and "base64" return types (both return url string) +export interface HTMLAnyURLResponse extends BaseResponse { + url: string; +} + +export interface HTMLAnyBinaryResponse extends Response { + // binary response doesn't have structure +} + +export interface HTMLAnyURLParams extends Omit { + return_type: "url" | "base64"; +} + +export interface HTMLAnyBinaryParams extends Omit { + return_type: "binary"; +} + +export type HTMLAnyResponse = HTMLAnyURLResponse | HTMLAnyBinaryResponse; diff --git a/src/web/interfaces/scrape.ts b/src/web/interfaces/scrape.ts index 91acf9a..f65d8c7 100644 --- a/src/web/interfaces/scrape.ts +++ b/src/web/interfaces/scrape.ts @@ -1,4 +1,5 @@ -export interface CookieParameter { +import { BaseResponse } from "../../../types"; +interface CookieParameter { name: string; value: string; url?: string; @@ -49,20 +50,19 @@ export interface BaseAIScrapeParams { features?: Array<"meta" | "link"> | null; } -export interface AIScrapeParamsWithSelector extends BaseAIScrapeParams { +interface AIScrapeParamsWithSelector extends BaseAIScrapeParams { selectors: Array; element_prompts?: string[]; } -export interface AIScrapeParamsWithPrompts extends BaseAIScrapeParams { +interface AIScrapeParamsWithPrompts extends BaseAIScrapeParams { selectors?: Array; element_prompts?: string[]; } export type AIScrapeParams = AIScrapeParamsWithSelector | AIScrapeParamsWithPrompts; -export interface AIScrapeResponse { - success: boolean; +export interface AIScrapeResponse extends BaseResponse { data: Array<{ key: string; selector: string; diff --git a/src/web/interfaces/search.ts b/src/web/interfaces/search.ts index e8fdd8e..4254088 100644 --- a/src/web/interfaces/search.ts +++ b/src/web/interfaces/search.ts @@ -1,3 +1,4 @@ +import { BaseResponse } from "../../../types"; export interface SearchParams { query: string; spell_check?: boolean; @@ -23,8 +24,7 @@ interface RelatedIndex { is_safe?: boolean; } -export interface SearchResponse { - success: boolean; +export interface SearchResponse extends BaseResponse { query: string; ai_overview?: string; spell_fixed: boolean; @@ -72,7 +72,6 @@ export interface SearchResponse { }[]; } -export interface SuggestionResponse { - success: boolean; +export interface SuggestionResponse extends BaseResponse { suggestions: string[]; } diff --git a/src/web/web.ts b/src/web/web.ts index ca54599..47881d5 100644 --- a/src/web/web.ts +++ b/src/web/web.ts @@ -1,7 +1,7 @@ import { respToFileChoice } from "../helpers"; import { RequestClient } from "../request"; import { DeepResearchParams, DeepResearchResponse } from "./interfaces/deep_research"; -import { HTMLAnyParams } from "./interfaces/html_to_any"; +import { HTMLAnyParams, HTMLAnyURLResponse, HTMLAnyBinaryResponse, HTMLAnyURLParams, HTMLAnyBinaryParams } from "./interfaces/html_to_any"; import { AIScrapeParams, AIScrapeResponse } from "./interfaces/scrape"; import { SearchParams, SearchResponse, SuggestionResponse } from "./interfaces/search"; class Web { @@ -11,10 +11,17 @@ class Web { return await this.client.fetchJSS("/ai/scrape", "POST", params); }; - html_to_any = async (params: HTMLAnyParams) => { - const resp = await this.client.fetchJSS("/web/html_to_any", "POST", params); - return respToFileChoice(resp); - }; + // Simplified function overloads + html_to_any(params: HTMLAnyURLParams): Promise; + html_to_any(params: HTMLAnyBinaryParams): Promise; + html_to_any(params: HTMLAnyParams): Promise; + async html_to_any(params: HTMLAnyParams): Promise { + if (params.return_type === "binary") { + return (await this.client.fetchJSS("/web/html_to_any", "POST", params)) as HTMLAnyBinaryResponse; + } + // For both "url" and "base64", return the same structure with url property + return (await this.client.fetchJSS("/web/html_to_any", "POST", params)) as HTMLAnyURLResponse; + } deep_research = async (params: DeepResearchParams): Promise => { return await this.client.fetchJSS("/web/deep_research", "POST", params);