Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/validate/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface EmailValidationResponse {
import { BaseResponse } from "../../types";
export interface EmailValidationResponse extends BaseResponse {
email: string;
disposable: boolean;
role_account: boolean;
Expand All @@ -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;
Expand All @@ -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: {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
48 changes: 25 additions & 23 deletions src/vision/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
import { BaseResponse } from "../../types";

export type VOCRParams = {
prompt?: string | string[];
url?: string;
file_store_key?: string;
page_range?: Array<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;
};
}

export interface VOCRResponse {
success: boolean;
context: string;
export interface VOCRResponse extends BaseResponse {
context: string | Record<string, string[]>;
width: number;
height: number;
tags: string[];
Expand All @@ -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

Expand Down Expand Up @@ -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;
};
}
4 changes: 2 additions & 2 deletions src/web/interfaces/deep_research.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BaseResponse } from "../../../types";
// Input parameters interface for reference
export interface DeepResearchParams {
query: string;
Expand All @@ -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[];
Expand Down
21 changes: 21 additions & 0 deletions src/web/interfaces/html_to_any.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BaseResponse } from "../../../types";

export interface HTMLAnyParams {
html?: string;
url?: string;
Expand All @@ -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<HTMLAnyParams, "return_type"> {
return_type: "url" | "base64";
}

export interface HTMLAnyBinaryParams extends Omit<HTMLAnyParams, "return_type"> {
return_type: "binary";
}

export type HTMLAnyResponse = HTMLAnyURLResponse | HTMLAnyBinaryResponse;
10 changes: 5 additions & 5 deletions src/web/interfaces/scrape.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface CookieParameter {
import { BaseResponse } from "../../../types";
interface CookieParameter {
name: string;
value: string;
url?: string;
Expand Down Expand Up @@ -49,20 +50,19 @@ export interface BaseAIScrapeParams {
features?: Array<"meta" | "link"> | null;
}

export interface AIScrapeParamsWithSelector extends BaseAIScrapeParams {
interface AIScrapeParamsWithSelector extends BaseAIScrapeParams {
selectors: Array<string>;
element_prompts?: string[];
}

export interface AIScrapeParamsWithPrompts extends BaseAIScrapeParams {
interface AIScrapeParamsWithPrompts extends BaseAIScrapeParams {
selectors?: Array<string>;
element_prompts?: string[];
}

export type AIScrapeParams = AIScrapeParamsWithSelector | AIScrapeParamsWithPrompts;

export interface AIScrapeResponse {
success: boolean;
export interface AIScrapeResponse extends BaseResponse {
data: Array<{
key: string;
selector: string;
Expand Down
7 changes: 3 additions & 4 deletions src/web/interfaces/search.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BaseResponse } from "../../../types";
export interface SearchParams {
query: string;
spell_check?: boolean;
Expand All @@ -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;
Expand Down Expand Up @@ -72,7 +72,6 @@ export interface SearchResponse {
}[];
}

export interface SuggestionResponse {
success: boolean;
export interface SuggestionResponse extends BaseResponse {
suggestions: string[];
}
17 changes: 12 additions & 5 deletions src/web/web.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<HTMLAnyURLResponse>;
html_to_any(params: HTMLAnyBinaryParams): Promise<HTMLAnyBinaryResponse>;
html_to_any(params: HTMLAnyParams): Promise<HTMLAnyURLResponse | HTMLAnyBinaryResponse>;
async html_to_any(params: HTMLAnyParams): Promise<HTMLAnyURLResponse | HTMLAnyBinaryResponse> {
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<DeepResearchResponse> => {
return await this.client.fetchJSS("/web/deep_research", "POST", params);
Expand Down
Loading