diff --git a/src/audio/audio.ts b/src/audio/audio.ts index 2bdb8fa..46f81f7 100644 --- a/src/audio/audio.ts +++ b/src/audio/audio.ts @@ -1,11 +1,14 @@ import { RequestClient } from "../request"; import { createFileUploadFormData } from "../utils"; -import { SpeechToTextParams, SpeechToTextResponse } from "./interfaces"; +import { SpeechToTextParams, SpeechToTextSyncResponse, SpeechToTextWebhookResponse } from "./interfaces"; class Audio { constructor(private readonly client: RequestClient) {} - speech_to_text(params: SpeechToTextParams): Promise; - speech_to_text(file: Blob | Buffer, params?: Omit): Promise; - async speech_to_text(params: SpeechToTextParams | Blob | Buffer, options?: SpeechToTextParams): Promise { + speech_to_text(params: SpeechToTextParams): Promise; + speech_to_text(file: Blob | Buffer, params?: Omit): Promise; + async speech_to_text( + params: SpeechToTextParams | Blob | Buffer, + options?: SpeechToTextParams + ): Promise { if (params instanceof Blob || params instanceof Buffer) { const formData = createFileUploadFormData(params, options); return await this.client.fetchJSS("/ai/transcribe", "POST", formData); diff --git a/src/audio/interfaces.ts b/src/audio/interfaces.ts index 128cf18..90dd79c 100644 --- a/src/audio/interfaces.ts +++ b/src/audio/interfaces.ts @@ -11,16 +11,13 @@ export interface SpeechToTextParams { chunk_duration?: number; } -export interface SpeechToTextResponse extends BaseResponse { +export interface SpeechToTextSyncResponse extends BaseResponse { text: string; chunks: Array<{ timestamp: number[]; text: string; }>; - status?: "processing" | "error"; - id?: string; speakers?: { - // available when by_speaker is true speaker: string; timestamp: number[]; text: string; diff --git a/src/core.ts b/src/core.ts index 3f3965e..bc5b23e 100644 --- a/src/core.ts +++ b/src/core.ts @@ -29,7 +29,6 @@ export const JigsawStack = (config?: BaseConfig) => { }; return { - fetch: client.fetchJSS, sentiment: general.sentiment, translate: general.translate, image_generation: general.image_generation, diff --git a/src/general/index.ts b/src/general/index.ts index 8dc3f18..56fc0b3 100644 --- a/src/general/index.ts +++ b/src/general/index.ts @@ -5,11 +5,13 @@ import { createFileUploadFormData } from "../utils"; import { EmbeddingParams, EmbeddingResponse, + ImageGenerationParams, PredictionParams, PredictionResponse, SentimentResponse, SummaryParams, SummaryResponse, + TextToSQLParams, TextToSQLResponse, TranslateImageParams, TranslateParams, @@ -50,33 +52,12 @@ class General { return await this.client.fetchJSS("/ai/sentiment", "POST", params); }; - image_generation = async (params: { - prompt: string; - aspect_ratio?: "1:1" | "16:9" | "21:9" | "3:2" | "2:3" | "4:5" | "5:4" | "3:4" | "4:3" | "9:16" | "9:21"; - width?: number; - height?: number; - steps?: number; - output_format?: "png" | "svg"; - return_type?: "url" | "binary" | "base64"; - advance_config?: { - negative_prompt?: string; - guidance?: number; - seed?: number; - }; - url?: string; - file_store_key?: string; - }) => { + image_generation = async (params: ImageGenerationParams) => { const resp = await this.client.fetchJSS("/ai/image_generation", "POST", params); - return respToFileChoice(resp); }; - text_to_sql = async (params: { - prompt: string; - sql_schema?: string; - file_store_key?: string; - database?: "postgresql" | "mysql" | "sqlite"; - }): Promise => { + text_to_sql = async (params: TextToSQLParams): Promise => { return await this.client.fetchJSS("/ai/sql", "POST", params); }; diff --git a/src/general/interfaces.ts b/src/general/interfaces.ts index cacee57..dcaade3 100644 --- a/src/general/interfaces.ts +++ b/src/general/interfaces.ts @@ -1,5 +1,33 @@ import { BaseResponse } from "../../types"; +export type TextToSQLParams = { + prompt: string; + database?: "postgresql" | "mysql" | "sqlite"; + sql_schema?: string; + file_store_key?: string; +}; + +export interface ImageGenerationParams { + prompt: string; + aspect_ratio?: "1:1" | "16:9" | "21:9" | "3:2" | "2:3" | "4:5" | "5:4" | "3:4" | "4:3" | "9:16" | "9:21"; + width?: number; + height?: number; + steps?: number; + output_format?: "png" | "svg"; + return_type?: "url" | "binary" | "base64"; + advance_config?: { + negative_prompt?: string; + guidance?: number; + seed?: number; + }; + url?: string; + file_store_key?: string; +} + +export interface ImageGenerationResponse extends BaseResponse { + url: string; +} + export interface SentimentResponse extends BaseResponse { sentiment: { emotion: string; @@ -24,12 +52,11 @@ export interface TranslateParams { text: string | string[]; } -export interface TranslateImageParams { - target_language: string; +export type TranslateImageParams = { url?: string; - file_store_key?: string; + target_language: string; return_type?: "url" | "binary" | "base64"; -} +}; export interface SpeechToTextResponse extends BaseResponse { text: string; diff --git a/src/helpers.ts b/src/helpers.ts index e7cd89b..a08e3c6 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,4 +1,10 @@ -export const respToFileChoice = (resp) => { +export const respToFileChoice = ( + resp: Response +): { + blob: () => Promise; + buffer: () => Promise; + file: (filename: string, options?: FilePropertyBag) => Promise; +} => { if (!(resp instanceof Response)) { return resp; } diff --git a/src/vercel-ai-toolkit.ts b/src/vercel-ai-toolkit.ts index cd03e16..813e6e0 100644 --- a/src/vercel-ai-toolkit.ts +++ b/src/vercel-ai-toolkit.ts @@ -89,18 +89,11 @@ export class JigsawStackToolSet { target_language: z.string().describe('Target language code (e.g., "en", "es", "fr")'), }), execute: async ({ url, file_store_key, target_language }) => { - await this.jigsawStack.translate.image({ + return await this.jigsawStack.translate.image({ url, - file_store_key, target_language, + return_type: "url", }); - - return { - success: true, - message: `Successfully translated image to ${target_language}`, - target_language, - note: "Image has been translated. Use jigsawStack.translate.image() directly to get the binary data.", - }; }, }), @@ -250,8 +243,8 @@ export class JigsawStackToolSet { return await this.jigsawStack.vision.vocr({ prompt, url, - file_store_key, page_range, + file_store_key, }); }, }), @@ -264,8 +257,8 @@ export class JigsawStackToolSet { }), execute: async ({ url, file_store_key }) => { return await this.jigsawStack.vision.object_detection({ - url, file_store_key, + return_type: "url", }); }, }), diff --git a/src/vision/interfaces.ts b/src/vision/interfaces.ts index 63b5516..aba7b4b 100644 --- a/src/vision/interfaces.ts +++ b/src/vision/interfaces.ts @@ -1,9 +1,9 @@ -export interface VOCRParams { +export type VOCRParams = { prompt?: string | string[]; url?: string; file_store_key?: string; page_range?: Array; -} +}; interface Bounds { top_left: { @@ -46,14 +46,14 @@ export interface VOCRResponse { page_range?: Array; // only available when page_range is specified } -export interface ObjectDetectionParams { +export type ObjectDetectionParams = { url?: string; file_store_key?: string; prompts?: string[]; features?: ("object_detection" | "gui")[]; annotated_image?: boolean; return_type?: "url" | "base64"; -} +}; export interface ObjectDetectionResponse { // Optional annotated image - included only if annotated_image=true and objects/gui_elements exist @@ -73,6 +73,7 @@ interface GuiElement { interface DetectedObject { bounds: BoundingBox; + label: string; mask?: string; // URL or base64 string depending on return_type - only present for some objects }