From e3476725e614b45c65609fba6eda1fb0cfdc4ea3 Mon Sep 17 00:00:00 2001 From: Win Cheng Date: Mon, 25 Aug 2025 17:26:36 -0700 Subject: [PATCH 1/5] global headers done --- src/request.ts | 4 ++-- types.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/request.ts b/src/request.ts index 2eb9672..ab708bc 100644 --- a/src/request.ts +++ b/src/request.ts @@ -17,7 +17,7 @@ export class RequestClient { [key: string]: string; } ) => { - const disableRequestLogging = this.config?.disableRequestLogging; + // const disableRequestLogging = this.config?.disableRequestLogging; const isFileUpload = body instanceof Blob || body instanceof Buffer; searchParams = searchParams ? removeUndefinedProperties(searchParams) : undefined; @@ -25,8 +25,8 @@ export class RequestClient { const _headers = { "x-api-key": this.config?.apiKey, "Content-Type": isFileUpload ? "application/octet-stream" : "application/json", + ...this.config?.headers, ...headers, - ["x-jigsaw-no-request-log"]: disableRequestLogging && "true", }; const _body = isFileUpload ? body : JSON.stringify(body); diff --git a/types.ts b/types.ts index be27fa1..4cfb82a 100644 --- a/types.ts +++ b/types.ts @@ -11,5 +11,5 @@ export interface BaseResponse { export interface BaseConfig { apiKey?: string; baseURL?: string; - disableRequestLogging?: boolean; // Controls how requests are logged. Default is false. + headers?: Record; // Additional headers to be sent with the request. } From 9f9cf07cbe8bec57b9c4d2d1344af242108a8f78 Mon Sep 17 00:00:00 2001 From: Win Cheng Date: Mon, 25 Aug 2025 17:37:47 -0700 Subject: [PATCH 2/5] tested and works --- .gitignore | 1 + test.ts | 16 ---------------- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 test.ts diff --git a/.gitignore b/.gitignore index 5a38a0b..d3ddc9f 100644 --- a/.gitignore +++ b/.gitignore @@ -130,6 +130,7 @@ dist .pnp.* test.js +test.ts .DS_Store diff --git a/test.ts b/test.ts deleted file mode 100644 index 14e860d..0000000 --- a/test.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { createJigsawStackClient } from "./tests/test-helpers"; - -const client = createJigsawStackClient(); - -const result = await client.classification.text({ - dataset: [ - { type: "text" as const, value: "This is a great product! I love it." }, - { type: "text" as const, value: "This is a great product! I hate it." }, - ], - labels: [ - { key: "positive", type: "text" as const, value: "positive sentiment" }, - { key: "negative", type: "text" as const, value: "negative sentiment" }, - ], -}); - -console.log(result); From 53221ae54ff5f1738e19342f0c0d2bfc2445ddb3 Mon Sep 17 00:00:00 2001 From: Vineet Agarwal <91052168+VineeTagarwaL-code@users.noreply.github.com> Date: Wed, 27 Aug 2025 05:41:34 +0530 Subject: [PATCH 3/5] Update request.ts --- src/request.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/request.ts b/src/request.ts index 332b321..38bf703 100644 --- a/src/request.ts +++ b/src/request.ts @@ -18,7 +18,6 @@ export class RequestClient { [key: string]: string; } ) => { - // const disableRequestLogging = this.config?.disableRequestLogging; const isFileUpload = body instanceof Blob || body instanceof Buffer; const isFormData = body instanceof FormData; From 182f98863d188c643c17e134aeb75011b447cbde Mon Sep 17 00:00:00 2001 From: Win Cheng Date: Wed, 27 Aug 2025 10:14:31 -0700 Subject: [PATCH 4/5] updated the test now should be consistent --- src/core.ts | 15 +++++++++------ src/request.ts | 2 +- tests/test-helpers.ts | 39 ++------------------------------------- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/src/core.ts b/src/core.ts index bc5b23e..fedd4cc 100644 --- a/src/core.ts +++ b/src/core.ts @@ -7,6 +7,7 @@ import { File } from "./store/file"; import Validate from "./validate"; import Vision from "./vision/vision"; import Web from "./web/web"; +import Classification from "./classification/index"; export const JigsawStack = (config?: BaseConfig) => { const _apiKey = config?.apiKey || process?.env?.JIGSAWSTACK_API_KEY; @@ -27,6 +28,7 @@ export const JigsawStack = (config?: BaseConfig) => { retrieve: file.retrieve, delete: file.delete, }; + const classification = new Classification(client); return { sentiment: general.sentiment, @@ -38,16 +40,17 @@ export const JigsawStack = (config?: BaseConfig) => { embedding: general.embedding, audio, vision: { - vocr: vision.vocr, - object_detection: vision.object_detection, + vocr: vision.vocr.bind(vision), + object_detection: vision.object_detection.bind(vision), }, web: { - ai_scrape: web.ai_scrape, - html_to_any: web.html_to_any, - search: web.search, - search_suggestions: web.search_suggestions, + ai_scrape: web.ai_scrape.bind(web), + html_to_any: web.html_to_any.bind(web), + search: web.search.bind(web), + search_suggestions: web.search_suggestions.bind(web), }, store, validate, + classification, }; }; diff --git a/src/request.ts b/src/request.ts index 38bf703..8839085 100644 --- a/src/request.ts +++ b/src/request.ts @@ -25,7 +25,7 @@ export class RequestClient { const _headers = { "x-api-key": this.config?.apiKey, - "Content-Type": isFileUpload ? "application/octet-stream" : "application/json", + ...(!isFormData && { "Content-Type": isFileUpload ? "application/octet-stream" : "application/json" }), ...this.config?.headers, ...headers, }; diff --git a/tests/test-helpers.ts b/tests/test-helpers.ts index 6452f66..fb6c1aa 100644 --- a/tests/test-helpers.ts +++ b/tests/test-helpers.ts @@ -1,11 +1,5 @@ // tests/test-helpers.ts - Fix the client structure -import Audio from "../src/audio/audio"; -import Classification from "../src/classification/index"; -import General from "../src/general/index"; -import { RequestClient } from "../src/request"; -import Validate from "../src/validate/index"; -import Vision from "../src/vision/vision"; -import Web from "../src/web/web"; +import { JigsawStack } from "jigsawstack"; export function createJigsawStackClient() { const apiKey = process.env.JIGSAWSTACK_API_KEY; @@ -14,36 +8,7 @@ export function createJigsawStackClient() { throw new Error("JIGSAWSTACK_API_KEY environment variable is required for testing"); } - const client = new RequestClient({ apiKey }); - - return { - // General APIs - sentiment: (params: any) => new General(client).sentiment(params), - translate: { - text: (params: any) => new General(client).translate.text(params), - image: (params: any) => new General(client).translate.image(params), - }, - summary: (params: any) => new General(client).summary(params), - embedding: (params: any) => new General(client).embedding(params), - text_to_sql: (params: any) => new General(client).text_to_sql(params), - prediction: (params: any) => new General(client).prediction(params), - image_generation: (params: any) => new General(client).image_generation(params), - - // Audio APIs - audio: new Audio(client), - - // Vision APIs - vision: new Vision(client), - - // Web APIs - Include both web scraping AND search - web: new Web(client), - - // Classification APIs - classification: new Classification(client), - - // Validation APIs - validate: new Validate(client), - }; + return JigsawStack({ apiKey }); } export function expectSuccess(result: any): void { From 09d6b8d2914f20a1a6efd1241f737909bc4b225f Mon Sep 17 00:00:00 2001 From: Win Cheng Date: Wed, 27 Aug 2025 10:16:29 -0700 Subject: [PATCH 5/5] linting --- src/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.ts b/src/core.ts index fedd4cc..436e507 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,13 +1,13 @@ import "isomorphic-fetch"; import { BaseConfig } from "../types"; import AudioApis from "./audio/audio"; +import Classification from "./classification/index"; import General from "./general"; import { RequestClient } from "./request"; import { File } from "./store/file"; import Validate from "./validate"; import Vision from "./vision/vision"; import Web from "./web/web"; -import Classification from "./classification/index"; export const JigsawStack = (config?: BaseConfig) => { const _apiKey = config?.apiKey || process?.env?.JIGSAWSTACK_API_KEY;