@useknockout/node 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +69 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +69 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var path = require('path');
|
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
var DEFAULT_BASE_URL = "https://useknockout--api.modal.run";
|
|
10
|
-
var SDK_VERSION = "0.0.
|
|
10
|
+
var SDK_VERSION = "0.0.7";
|
|
11
11
|
var KnockoutError = class _KnockoutError extends Error {
|
|
12
12
|
status;
|
|
13
13
|
code;
|
|
@@ -53,6 +53,34 @@ var Knockout = class {
|
|
|
53
53
|
if (!res.ok) throw new KnockoutError(res.status, body);
|
|
54
54
|
return JSON.parse(body);
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Public usage counter — total images processed all-time, today, and a 7-day breakdown.
|
|
58
|
+
* Use for landing-page social proof. Eventually consistent across containers.
|
|
59
|
+
*/
|
|
60
|
+
async stats() {
|
|
61
|
+
const res = await this.request("GET", "/stats");
|
|
62
|
+
const body = await res.text();
|
|
63
|
+
if (!res.ok) throw new KnockoutError(res.status, body);
|
|
64
|
+
return JSON.parse(body);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Predict latency + cost for an endpoint and image size without doing any GPU work.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const est = await client.estimate({ endpoint: "remove", width: 1024, height: 1024 });
|
|
71
|
+
*/
|
|
72
|
+
async estimate(input) {
|
|
73
|
+
const res = await this.request("POST", "/estimate", {
|
|
74
|
+
headers: { "Content-Type": "application/json" },
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
endpoint: input.endpoint,
|
|
77
|
+
width: input.width,
|
|
78
|
+
height: input.height
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
82
|
+
return await res.json();
|
|
83
|
+
}
|
|
56
84
|
/**
|
|
57
85
|
* Remove the background from an image, returning the cleaned PNG/WebP bytes.
|
|
58
86
|
*
|
|
@@ -252,6 +280,46 @@ var Knockout = class {
|
|
|
252
280
|
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
253
281
|
return Buffer.from(await res.arrayBuffer());
|
|
254
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* LinkedIn-ready headshot preset — bg removal + portrait crop + center face + bg color or blur.
|
|
285
|
+
*
|
|
286
|
+
* @example Solid bg
|
|
287
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgColor: "#0A0A0A" });
|
|
288
|
+
*
|
|
289
|
+
* @example Blurred original as bg
|
|
290
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgBlur: true, blurRadius: 24 });
|
|
291
|
+
*/
|
|
292
|
+
async headshot(input) {
|
|
293
|
+
const format = input.format ?? "jpg";
|
|
294
|
+
const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });
|
|
295
|
+
const form = new FormData();
|
|
296
|
+
form.append("file", blob, filename);
|
|
297
|
+
if (input.bgColor) form.append("bg_color", input.bgColor);
|
|
298
|
+
if (input.bgBlur !== void 0) form.append("bg_blur", input.bgBlur ? "true" : "false");
|
|
299
|
+
if (input.blurRadius !== void 0) form.append("blur_radius", String(input.blurRadius));
|
|
300
|
+
if (input.aspect) form.append("aspect", input.aspect);
|
|
301
|
+
if (input.padding !== void 0) form.append("padding", String(input.padding));
|
|
302
|
+
if (input.headTopRatio !== void 0) form.append("head_top_ratio", String(input.headTopRatio));
|
|
303
|
+
form.append("format", format);
|
|
304
|
+
const res = await this.request("POST", "/headshot", { body: form });
|
|
305
|
+
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
306
|
+
return Buffer.from(await res.arrayBuffer());
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Fast low-res preview cutout (~80ms warm). Skips pymatting refinement and downscales
|
|
310
|
+
* input to `maxDim` (default 512px on the long edge). Use for UX progress indicators.
|
|
311
|
+
*/
|
|
312
|
+
async preview(input) {
|
|
313
|
+
const format = input.format ?? "png";
|
|
314
|
+
const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });
|
|
315
|
+
const form = new FormData();
|
|
316
|
+
form.append("file", blob, filename);
|
|
317
|
+
form.append("max_dim", String(input.maxDim ?? 512));
|
|
318
|
+
form.append("format", format);
|
|
319
|
+
const res = await this.request("POST", "/preview", { body: form });
|
|
320
|
+
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
321
|
+
return Buffer.from(await res.arrayBuffer());
|
|
322
|
+
}
|
|
255
323
|
/**
|
|
256
324
|
* Remove the background from up to 10 remote image URLs in a single call.
|
|
257
325
|
*
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["readFile","basename"],"mappings":";;;;;;;;AAeO,IAAM,gBAAA,GAAmB;AAChC,IAAM,WAAA,GAAc,OAAA;AAyJb,IAAM,aAAA,GAAN,MAAM,cAAA,SAAsB,KAAA,CAAM;AAAA,EACvB,MAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EAEhB,WAAA,CAAY,QAAgB,IAAA,EAAc;AACxC,IAAA,MAAM,IAAA,GAAO,cAAA,CAAc,QAAA,CAAS,MAAM,CAAA;AAC1C,IAAA,KAAA,CAAM,sBAAsB,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,GAAA,EAAM,IAAA,IAAQ,SAAS,CAAA,CAAE,CAAA;AACpE,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA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AA,CAAK,CAAC,IAAI,UAAA,CAAW,IAAI,CAAC,CAAC,CAAA;AAAA,MACrC;AAAA,KACF;AAAA,EACF;AACA,EAAA,MAAM,IAAI,UAAU,qFAAqF,CAAA;AAC3G;AAEA,SAAS,cAAc,IAAA,EAAiE;AACtF,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,EAAU,OAAOC,aAAA,CAAS,IAAI,CAAA,IAAK,OAAA;AACvD,EAAA,OAAO,OAAA;AACT;AAEA,IAAO,aAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * @useknockout/node — official TypeScript / Node.js client for the useknockout API.\n *\n * Quick start:\n *\n * import { Knockout } from \"@useknockout/node\";\n *\n * const client = new Knockout({ token: process.env.KNOCKOUT_TOKEN! });\n * const png = await client.remove({ file: \"./input.jpg\" }); // Buffer of PNG bytes\n * await writeFile(\"out.png\", png);\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\n\nexport const DEFAULT_BASE_URL = \"https://useknockout--api.modal.run\";\nconst SDK_VERSION = \"0.0.6\";\n\nexport type OutputFormat = \"png\" | \"webp\";\nexport type OpaqueFormat = \"png\" | \"webp\" | \"jpg\";\n\ntype FileInput = string | Buffer | Blob | ArrayBuffer | Uint8Array;\n\nexport interface KnockoutOptions {\n /** API bearer token. Required unless your self-hosted instance has no auth. */\n token?: string;\n /** Override the API base URL. Defaults to the hosted endpoint. */\n baseUrl?: string;\n /** Per-request timeout in milliseconds. Default 60_000. */\n timeoutMs?: number;\n /** Custom fetch (useful for edge runtimes / polyfills). Defaults to global fetch. */\n fetch?: typeof fetch;\n}\n\nexport interface RemoveInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface RemoveUrlInput {\n /** Remote URL of the image to process. */\n url: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface ReplaceBgInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the foreground image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Hex color for the new background. Default \"#FFFFFF\". Ignored if `bgUrl` is set. */\n bgColor?: string;\n /** Remote URL of an image to use as the new background. Takes precedence over `bgColor`. */\n bgUrl?: string;\n /** Output format. \"jpg\" is smallest. Default \"png\". */\n format?: OpaqueFormat;\n}\n\nexport interface BatchInput {\n /** Array of local paths / buffers / blobs. Up to 10. */\n files: Array<string | Buffer | Blob | ArrayBuffer | Uint8Array>;\n /** Optional filenames aligned to `files`. */\n filenames?: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchUrlInput {\n /** Remote URLs to process. Up to 10. */\n urls: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchResultItem {\n filename?: string;\n url?: string;\n success: boolean;\n format?: OutputFormat;\n size_bytes?: number;\n data_base64?: string;\n error?: string;\n}\n\nexport interface BatchResponse {\n count: number;\n format: OutputFormat;\n results: BatchResultItem[];\n}\n\nexport interface MaskInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface SmartCropInput {\n file: FileInput;\n filename?: string;\n /** Padding around the subject bbox, in pixels. Default 24. */\n padding?: number;\n /** Return transparent cutout (true) or cropped region from original (false). Default true. */\n transparent?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface ShadowInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n bgUrl?: string;\n shadowColor?: string;\n shadowOffsetX?: number;\n shadowOffsetY?: number;\n shadowBlur?: number;\n shadowOpacity?: number;\n format?: OpaqueFormat;\n}\n\nexport interface StickerInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#FFFFFF\". */\n strokeColor?: string;\n /** Outline width in pixels. Default 20. */\n strokeWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface OutlineInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#000000\". */\n outlineColor?: string;\n /** Outline width in pixels. Default 4. */\n outlineWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface StudioShotInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n /** e.g. \"1:1\", \"4:5\", \"16:9\". Default \"1:1\". */\n aspect?: string;\n padding?: number;\n shadow?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface CompareInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface HealthResponse {\n status: string;\n model: string;\n}\n\n/**\n * Error thrown when the API returns a non-2xx response.\n */\nexport class KnockoutError extends Error {\n public readonly status: number;\n public readonly code: \"auth\" | \"rate_limit\" | \"bad_request\" | \"payload_too_large\" | \"server\" | \"unknown\";\n public readonly body: string;\n\n constructor(status: number, body: string) {\n const code = KnockoutError.classify(status);\n super(`Knockout API error ${status} (${code}): ${body || \"no body\"}`);\n this.name = \"KnockoutError\";\n this.status = status;\n this.code = code;\n this.body = body;\n }\n\n private static classify(status: number): KnockoutError[\"code\"] {\n if (status === 401 || status === 403) return \"auth\";\n if (status === 429) return \"rate_limit\";\n if (status === 413) return \"payload_too_large\";\n if (status >= 400 && status < 500) return \"bad_request\";\n if (status >= 500) return \"server\";\n return \"unknown\";\n }\n}\n\n/**\n * useknockout API client.\n *\n * All methods return a `Buffer` (Node) of the processed image bytes.\n * Use `.toString(\"base64\")` or `writeFile(path, buf)` to persist.\n */\nexport class Knockout {\n private readonly baseUrl: string;\n private readonly token: string | undefined;\n private readonly timeoutMs: number;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: KnockoutOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.token = options.token;\n this.timeoutMs = options.timeoutMs ?? 60_000;\n const fetchRef = options.fetch ?? globalThis.fetch;\n if (!fetchRef) {\n throw new Error(\n \"Global fetch is unavailable. Provide `options.fetch` or use Node 18+.\"\n );\n }\n this.fetchImpl = fetchRef.bind(globalThis);\n }\n\n /** Hit GET /health — no auth required. */\n async health(): Promise<HealthResponse> {\n const res = await this.request(\"GET\", \"/health\");\n const body = await res.text();\n if (!res.ok) throw new KnockoutError(res.status, body);\n return JSON.parse(body) as HealthResponse;\n }\n\n /**\n * Remove the background from an image, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.remove({ file: \"./input.jpg\" });\n */\n async remove(input: RemoveInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob(input);\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const res = await this.request(\"POST\", `/remove?format=${format}`, {\n body: form,\n });\n\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from a remote URL, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.removeUrl({ url: \"https://example.com/cat.jpg\" });\n */\n async removeUrl(input: RemoveUrlInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const res = await this.request(\"POST\", \"/remove-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ url: input.url, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Replace the background with a solid color or a remote image.\n *\n * @example Solid color\n * const jpg = await client.replaceBackground({ file: \"./cat.jpg\", bgColor: \"#FF5733\", format: \"jpg\" });\n *\n * @example Remote image as new background\n * const png = await client.replaceBackground({\n * file: \"./cat.jpg\",\n * bgUrl: \"https://example.com/beach.jpg\",\n * });\n */\n async replaceBackground(input: ReplaceBgInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const params = new URLSearchParams({ format });\n if (input.bgUrl) params.set(\"bg_url\", input.bgUrl);\n if (input.bgColor) params.set(\"bg_color\", input.bgColor);\n\n const res = await this.request(\"POST\", `/replace-bg?${params.toString()}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 images in a single call.\n * Returns a JSON object with base64-encoded result bytes per image.\n *\n * @example\n * const batch = await client.removeBatch({\n * files: [\"./a.jpg\", \"./b.jpg\", \"./c.jpg\"],\n * format: \"png\",\n * });\n * for (const r of batch.results) {\n * if (r.success) await writeFile(r.filename!, Buffer.from(r.data_base64!, \"base64\"));\n * }\n */\n async removeBatch(input: BatchInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.files.length === 0) throw new Error(\"At least one file required\");\n if (input.files.length > 10) throw new Error(\"Max 10 files per batch\");\n\n const form = new FormData();\n for (let i = 0; i < input.files.length; i++) {\n const name = input.filenames?.[i];\n const { blob, filename } = await toBlob({ file: input.files[i]!, filename: name });\n form.append(\"files\", blob, filename);\n }\n\n const res = await this.request(\"POST\", `/remove-batch?format=${format}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n /**\n * Return only the alpha mask as a grayscale PNG/WebP.\n * Useful when chaining into your own compositing pipeline.\n */\n async mask(input: MaskInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/mask\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Auto-crop to the subject's tight bounding box with configurable padding.\n * Returns either a transparent cutout or a cropped region from the original image.\n */\n async smartCrop(input: SmartCropInput): Promise<Buffer> {\n const transparent = input.transparent ?? true;\n const format: OpaqueFormat =\n (input.format as OpaqueFormat | undefined) ?? (transparent ? \"png\" : \"jpg\");\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"padding\", String(input.padding ?? 24));\n form.append(\"transparent\", transparent ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/smart-crop\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Composite subject onto a new background with a configurable drop shadow.\n */\n async shadow(input: ShadowInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.bgUrl) form.append(\"bg_url\", input.bgUrl);\n if (input.shadowColor) form.append(\"shadow_color\", input.shadowColor);\n if (input.shadowOffsetX !== undefined) form.append(\"shadow_offset_x\", String(input.shadowOffsetX));\n if (input.shadowOffsetY !== undefined) form.append(\"shadow_offset_y\", String(input.shadowOffsetY));\n if (input.shadowBlur !== undefined) form.append(\"shadow_blur\", String(input.shadowBlur));\n if (input.shadowOpacity !== undefined) form.append(\"shadow_opacity\", String(input.shadowOpacity));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/shadow\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Sticker style — subject with a thick outline on transparent background.\n * Perfect for WhatsApp / iMessage / Telegram stickers.\n */\n async sticker(input: StickerInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.strokeColor) form.append(\"stroke_color\", input.strokeColor);\n if (input.strokeWidth !== undefined) form.append(\"stroke_width\", String(input.strokeWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/sticker\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Subject on transparent background with a thin configurable outline.\n */\n async outline(input: OutlineInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.outlineColor) form.append(\"outline_color\", input.outlineColor);\n if (input.outlineWidth !== undefined) form.append(\"outline_width\", String(input.outlineWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/outline\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * E-commerce preset — cutout + tight crop + centered + optional shadow on a standard aspect canvas.\n */\n async studioShot(input: StudioShotInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"jpg\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.aspect) form.append(\"aspect\", input.aspect);\n if (input.padding !== undefined) form.append(\"padding\", String(input.padding));\n if (input.shadow !== undefined) form.append(\"shadow\", input.shadow ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/studio-shot\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Before/after side-by-side preview — original on left, transparent cutout (on a checkerboard) on right.\n */\n async compare(input: CompareInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/compare\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 remote image URLs in a single call.\n *\n * @example\n * const batch = await client.removeBatchUrl({\n * urls: [\"https://a.jpg\", \"https://b.jpg\"],\n * });\n */\n async removeBatchUrl(input: BatchUrlInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.urls.length === 0) throw new Error(\"At least one URL required\");\n if (input.urls.length > 10) throw new Error(\"Max 10 URLs per batch\");\n\n const res = await this.request(\"POST\", \"/remove-batch-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ urls: input.urls, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n private async request(\n method: \"GET\" | \"POST\",\n path: string,\n init: { headers?: Record<string, string>; body?: BodyInit } = {}\n ): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n \"User-Agent\": `useknockout-node/${SDK_VERSION}`,\n ...(init.headers ?? {}),\n };\n if (this.token) headers[\"Authorization\"] = `Bearer ${this.token}`;\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n try {\n return await this.fetchImpl(url, {\n method,\n headers,\n body: init.body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\nasync function toBlob(\n input: { file: string | Buffer | Blob | ArrayBuffer | Uint8Array; filename?: string }\n): Promise<{ blob: Blob; filename: string }> {\n const { file } = input;\n const filename = input.filename ?? inferFilename(file);\n\n if (typeof file === \"string\") {\n const data = await readFile(file);\n return { blob: new Blob([new Uint8Array(data)]), filename };\n }\n if (file instanceof Blob) {\n return { blob: file, filename };\n }\n if (file instanceof ArrayBuffer) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (file instanceof Uint8Array) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (Buffer.isBuffer(file)) {\n return {\n blob: new Blob([new Uint8Array(file)]),\n filename,\n };\n }\n throw new TypeError(\"Unsupported `file` input. Provide a path, Buffer, Blob, ArrayBuffer, or Uint8Array.\");\n}\n\nfunction inferFilename(file: string | Buffer | Blob | ArrayBuffer | Uint8Array): string {\n if (typeof file === \"string\") return basename(file) || \"image\";\n return \"image\";\n}\n\nexport default Knockout;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["readFile","basename"],"mappings":";;;;;;;;AAeO,IAAM,gBAAA,GAAmB;AAChC,IAAM,WAAA,GAAc,OAAA;AAiNb,IAAM,aAAA,GAAN,MAAM,cAAA,SAAsB,KAAA,CAAM;AAAA,EACvB,MAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EAEhB,WAAA,CAAY,QAAgB,IAAA,EAAc;AACxC,IAAA,MAAM,IAAA,GAAO,cAAA,CAAc,QAAA,CAAS,MAAM,CAAA;AAC1C,IAAA,KAAA,CAAM,sBAAsB,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,GAAA,EAAM,IAAA,IAAQ,SAAS,CAAA,CAAE,CAAA;AACpE,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA,EAEA,OAAe,SAAS,MAAA,EAAuC;AAC7D,IAAA,IAAI,MAAA,KAAW,GAAA,IAAO,MAAA,KAAW,GAAA,EAAK,OAAO,MAAA;AAC7C,IAAA,IAAI,MAAA,KAAW,KAAK,OAAO,YAAA;AAC3B,IAAA,IAAI,MAAA,KAAW,KAAK,OAAO,mBAAA;AAC3B,IAAA,IAAI,MAAA,IAAU,GAAA,IAAO,MAAA,GAAS,GAAA,EAAK,OAAO,aAAA;AAC1C,IAAA,IAAI,MAAA,IAAU,KAAK,OAAO,QAAA;AAC1B,IAAA,OAAO,SAAA;AAAA,EACT;AACF;AAQO,IAAM,WAAN,MAAe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,IAAA,EAAM,IAAI,IAAA,CAAK,CAAC,IAAI,UAAA,CAAW,IAAI,CAAC,CAAC,CAAA,EAAG,QAAA,EAAS;AAAA,EAC5D;AACA,EAAA,IAAI,gBAAgB,UAAA,EAAY;AAC9B,IAAA,OAAO,EAAE,IAAA,EAAM,IAAI,IAAA,CAAK,CAAC,IAAI,UAAA,CAAW,IAAI,CAAC,CAAC,CAAA,EAAG,QAAA,EAAS;AAAA,EAC5D;AACA,EAAA,IAAI,MAAA,CAAO,QAAA,CAAS,IAAI,CAAA,EAAG;AACzB,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,IAAI,IAAA,CAAK,CAAC,IAAI,UAAA,CAAW,IAAI,CAAC,CAAC,CAAA;AAAA,MACrC;AAAA,KACF;AAAA,EACF;AACA,EAAA,MAAM,IAAI,UAAU,qFAAqF,CAAA;AAC3G;AAEA,SAAS,cAAc,IAAA,EAAiE;AACtF,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,EAAU,OAAOC,aAAA,CAAS,IAAI,CAAA,IAAK,OAAA;AACvD,EAAA,OAAO,OAAA;AACT;AAEA,IAAO,aAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * @useknockout/node — official TypeScript / Node.js client for the useknockout API.\n *\n * Quick start:\n *\n * import { Knockout } from \"@useknockout/node\";\n *\n * const client = new Knockout({ token: process.env.KNOCKOUT_TOKEN! });\n * const png = await client.remove({ file: \"./input.jpg\" }); // Buffer of PNG bytes\n * await writeFile(\"out.png\", png);\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\n\nexport const DEFAULT_BASE_URL = \"https://useknockout--api.modal.run\";\nconst SDK_VERSION = \"0.0.7\";\n\nexport type OutputFormat = \"png\" | \"webp\";\nexport type OpaqueFormat = \"png\" | \"webp\" | \"jpg\";\n\ntype FileInput = string | Buffer | Blob | ArrayBuffer | Uint8Array;\n\nexport interface KnockoutOptions {\n /** API bearer token. Required unless your self-hosted instance has no auth. */\n token?: string;\n /** Override the API base URL. Defaults to the hosted endpoint. */\n baseUrl?: string;\n /** Per-request timeout in milliseconds. Default 60_000. */\n timeoutMs?: number;\n /** Custom fetch (useful for edge runtimes / polyfills). Defaults to global fetch. */\n fetch?: typeof fetch;\n}\n\nexport interface RemoveInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface RemoveUrlInput {\n /** Remote URL of the image to process. */\n url: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface ReplaceBgInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the foreground image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Hex color for the new background. Default \"#FFFFFF\". Ignored if `bgUrl` is set. */\n bgColor?: string;\n /** Remote URL of an image to use as the new background. Takes precedence over `bgColor`. */\n bgUrl?: string;\n /** Output format. \"jpg\" is smallest. Default \"png\". */\n format?: OpaqueFormat;\n}\n\nexport interface BatchInput {\n /** Array of local paths / buffers / blobs. Up to 10. */\n files: Array<string | Buffer | Blob | ArrayBuffer | Uint8Array>;\n /** Optional filenames aligned to `files`. */\n filenames?: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchUrlInput {\n /** Remote URLs to process. Up to 10. */\n urls: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchResultItem {\n filename?: string;\n url?: string;\n success: boolean;\n format?: OutputFormat;\n size_bytes?: number;\n data_base64?: string;\n error?: string;\n}\n\nexport interface BatchResponse {\n count: number;\n format: OutputFormat;\n results: BatchResultItem[];\n}\n\nexport interface MaskInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface SmartCropInput {\n file: FileInput;\n filename?: string;\n /** Padding around the subject bbox, in pixels. Default 24. */\n padding?: number;\n /** Return transparent cutout (true) or cropped region from original (false). Default true. */\n transparent?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface ShadowInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n bgUrl?: string;\n shadowColor?: string;\n shadowOffsetX?: number;\n shadowOffsetY?: number;\n shadowBlur?: number;\n shadowOpacity?: number;\n format?: OpaqueFormat;\n}\n\nexport interface StickerInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#FFFFFF\". */\n strokeColor?: string;\n /** Outline width in pixels. Default 20. */\n strokeWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface OutlineInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#000000\". */\n outlineColor?: string;\n /** Outline width in pixels. Default 4. */\n outlineWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface StudioShotInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n /** e.g. \"1:1\", \"4:5\", \"16:9\". Default \"1:1\". */\n aspect?: string;\n padding?: number;\n shadow?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface CompareInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface HeadshotInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the background. Default \"#FFFFFF\". Ignored if `bgBlur` is true. */\n bgColor?: string;\n /** Use a blurred copy of the original image as the background. Default false. */\n bgBlur?: boolean;\n /** Gaussian blur radius for the background when `bgBlur` is true. Default 20. */\n blurRadius?: number;\n /** Output aspect \"W:H\". Default \"4:5\" (portrait). */\n aspect?: string;\n /** Padding around the subject bbox, in pixels. Default 64. */\n padding?: number;\n /** Vertical headroom as a ratio of canvas height (0–0.5). Default 0.18. */\n headTopRatio?: number;\n format?: OpaqueFormat;\n}\n\nexport interface PreviewInput {\n file: FileInput;\n filename?: string;\n /** Long-edge cap in pixels (64–1024). Default 512. */\n maxDim?: number;\n format?: OutputFormat;\n}\n\nexport interface EstimateInput {\n /** Endpoint name without leading slash, e.g. \"remove\" or \"headshot\". */\n endpoint: string;\n width: number;\n height: number;\n}\n\nexport interface EstimateResponse {\n endpoint: string;\n image_pixels: number;\n est_latency_ms_warm: number;\n est_latency_ms_cold: number;\n est_cost_usd: number;\n free_during_beta: boolean;\n note: string;\n}\n\nexport interface StatsDay {\n date: string;\n count: number;\n}\n\nexport interface StatsResponse {\n total_processed: number;\n today: number;\n last_7_days: StatsDay[];\n error?: string;\n detail?: string;\n}\n\nexport interface HealthResponse {\n status: string;\n model: string;\n}\n\n/**\n * Error thrown when the API returns a non-2xx response.\n */\nexport class KnockoutError extends Error {\n public readonly status: number;\n public readonly code: \"auth\" | \"rate_limit\" | \"bad_request\" | \"payload_too_large\" | \"server\" | \"unknown\";\n public readonly body: string;\n\n constructor(status: number, body: string) {\n const code = KnockoutError.classify(status);\n super(`Knockout API error ${status} (${code}): ${body || \"no body\"}`);\n this.name = \"KnockoutError\";\n this.status = status;\n this.code = code;\n this.body = body;\n }\n\n private static classify(status: number): KnockoutError[\"code\"] {\n if (status === 401 || status === 403) return \"auth\";\n if (status === 429) return \"rate_limit\";\n if (status === 413) return \"payload_too_large\";\n if (status >= 400 && status < 500) return \"bad_request\";\n if (status >= 500) return \"server\";\n return \"unknown\";\n }\n}\n\n/**\n * useknockout API client.\n *\n * All methods return a `Buffer` (Node) of the processed image bytes.\n * Use `.toString(\"base64\")` or `writeFile(path, buf)` to persist.\n */\nexport class Knockout {\n private readonly baseUrl: string;\n private readonly token: string | undefined;\n private readonly timeoutMs: number;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: KnockoutOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.token = options.token;\n this.timeoutMs = options.timeoutMs ?? 60_000;\n const fetchRef = options.fetch ?? globalThis.fetch;\n if (!fetchRef) {\n throw new Error(\n \"Global fetch is unavailable. Provide `options.fetch` or use Node 18+.\"\n );\n }\n this.fetchImpl = fetchRef.bind(globalThis);\n }\n\n /** Hit GET /health — no auth required. */\n async health(): Promise<HealthResponse> {\n const res = await this.request(\"GET\", \"/health\");\n const body = await res.text();\n if (!res.ok) throw new KnockoutError(res.status, body);\n return JSON.parse(body) as HealthResponse;\n }\n\n /**\n * Public usage counter — total images processed all-time, today, and a 7-day breakdown.\n * Use for landing-page social proof. Eventually consistent across containers.\n */\n async stats(): Promise<StatsResponse> {\n const res = await this.request(\"GET\", \"/stats\");\n const body = await res.text();\n if (!res.ok) throw new KnockoutError(res.status, body);\n return JSON.parse(body) as StatsResponse;\n }\n\n /**\n * Predict latency + cost for an endpoint and image size without doing any GPU work.\n *\n * @example\n * const est = await client.estimate({ endpoint: \"remove\", width: 1024, height: 1024 });\n */\n async estimate(input: EstimateInput): Promise<EstimateResponse> {\n const res = await this.request(\"POST\", \"/estimate\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n endpoint: input.endpoint,\n width: input.width,\n height: input.height,\n }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as EstimateResponse;\n }\n\n /**\n * Remove the background from an image, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.remove({ file: \"./input.jpg\" });\n */\n async remove(input: RemoveInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob(input);\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const res = await this.request(\"POST\", `/remove?format=${format}`, {\n body: form,\n });\n\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from a remote URL, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.removeUrl({ url: \"https://example.com/cat.jpg\" });\n */\n async removeUrl(input: RemoveUrlInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const res = await this.request(\"POST\", \"/remove-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ url: input.url, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Replace the background with a solid color or a remote image.\n *\n * @example Solid color\n * const jpg = await client.replaceBackground({ file: \"./cat.jpg\", bgColor: \"#FF5733\", format: \"jpg\" });\n *\n * @example Remote image as new background\n * const png = await client.replaceBackground({\n * file: \"./cat.jpg\",\n * bgUrl: \"https://example.com/beach.jpg\",\n * });\n */\n async replaceBackground(input: ReplaceBgInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const params = new URLSearchParams({ format });\n if (input.bgUrl) params.set(\"bg_url\", input.bgUrl);\n if (input.bgColor) params.set(\"bg_color\", input.bgColor);\n\n const res = await this.request(\"POST\", `/replace-bg?${params.toString()}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 images in a single call.\n * Returns a JSON object with base64-encoded result bytes per image.\n *\n * @example\n * const batch = await client.removeBatch({\n * files: [\"./a.jpg\", \"./b.jpg\", \"./c.jpg\"],\n * format: \"png\",\n * });\n * for (const r of batch.results) {\n * if (r.success) await writeFile(r.filename!, Buffer.from(r.data_base64!, \"base64\"));\n * }\n */\n async removeBatch(input: BatchInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.files.length === 0) throw new Error(\"At least one file required\");\n if (input.files.length > 10) throw new Error(\"Max 10 files per batch\");\n\n const form = new FormData();\n for (let i = 0; i < input.files.length; i++) {\n const name = input.filenames?.[i];\n const { blob, filename } = await toBlob({ file: input.files[i]!, filename: name });\n form.append(\"files\", blob, filename);\n }\n\n const res = await this.request(\"POST\", `/remove-batch?format=${format}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n /**\n * Return only the alpha mask as a grayscale PNG/WebP.\n * Useful when chaining into your own compositing pipeline.\n */\n async mask(input: MaskInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/mask\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Auto-crop to the subject's tight bounding box with configurable padding.\n * Returns either a transparent cutout or a cropped region from the original image.\n */\n async smartCrop(input: SmartCropInput): Promise<Buffer> {\n const transparent = input.transparent ?? true;\n const format: OpaqueFormat =\n (input.format as OpaqueFormat | undefined) ?? (transparent ? \"png\" : \"jpg\");\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"padding\", String(input.padding ?? 24));\n form.append(\"transparent\", transparent ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/smart-crop\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Composite subject onto a new background with a configurable drop shadow.\n */\n async shadow(input: ShadowInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.bgUrl) form.append(\"bg_url\", input.bgUrl);\n if (input.shadowColor) form.append(\"shadow_color\", input.shadowColor);\n if (input.shadowOffsetX !== undefined) form.append(\"shadow_offset_x\", String(input.shadowOffsetX));\n if (input.shadowOffsetY !== undefined) form.append(\"shadow_offset_y\", String(input.shadowOffsetY));\n if (input.shadowBlur !== undefined) form.append(\"shadow_blur\", String(input.shadowBlur));\n if (input.shadowOpacity !== undefined) form.append(\"shadow_opacity\", String(input.shadowOpacity));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/shadow\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Sticker style — subject with a thick outline on transparent background.\n * Perfect for WhatsApp / iMessage / Telegram stickers.\n */\n async sticker(input: StickerInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.strokeColor) form.append(\"stroke_color\", input.strokeColor);\n if (input.strokeWidth !== undefined) form.append(\"stroke_width\", String(input.strokeWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/sticker\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Subject on transparent background with a thin configurable outline.\n */\n async outline(input: OutlineInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.outlineColor) form.append(\"outline_color\", input.outlineColor);\n if (input.outlineWidth !== undefined) form.append(\"outline_width\", String(input.outlineWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/outline\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * E-commerce preset — cutout + tight crop + centered + optional shadow on a standard aspect canvas.\n */\n async studioShot(input: StudioShotInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"jpg\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.aspect) form.append(\"aspect\", input.aspect);\n if (input.padding !== undefined) form.append(\"padding\", String(input.padding));\n if (input.shadow !== undefined) form.append(\"shadow\", input.shadow ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/studio-shot\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Before/after side-by-side preview — original on left, transparent cutout (on a checkerboard) on right.\n */\n async compare(input: CompareInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/compare\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * LinkedIn-ready headshot preset — bg removal + portrait crop + center face + bg color or blur.\n *\n * @example Solid bg\n * const jpg = await client.headshot({ file: \"./photo.jpg\", bgColor: \"#0A0A0A\" });\n *\n * @example Blurred original as bg\n * const jpg = await client.headshot({ file: \"./photo.jpg\", bgBlur: true, blurRadius: 24 });\n */\n async headshot(input: HeadshotInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"jpg\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.bgBlur !== undefined) form.append(\"bg_blur\", input.bgBlur ? \"true\" : \"false\");\n if (input.blurRadius !== undefined) form.append(\"blur_radius\", String(input.blurRadius));\n if (input.aspect) form.append(\"aspect\", input.aspect);\n if (input.padding !== undefined) form.append(\"padding\", String(input.padding));\n if (input.headTopRatio !== undefined) form.append(\"head_top_ratio\", String(input.headTopRatio));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/headshot\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Fast low-res preview cutout (~80ms warm). Skips pymatting refinement and downscales\n * input to `maxDim` (default 512px on the long edge). Use for UX progress indicators.\n */\n async preview(input: PreviewInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"max_dim\", String(input.maxDim ?? 512));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/preview\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 remote image URLs in a single call.\n *\n * @example\n * const batch = await client.removeBatchUrl({\n * urls: [\"https://a.jpg\", \"https://b.jpg\"],\n * });\n */\n async removeBatchUrl(input: BatchUrlInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.urls.length === 0) throw new Error(\"At least one URL required\");\n if (input.urls.length > 10) throw new Error(\"Max 10 URLs per batch\");\n\n const res = await this.request(\"POST\", \"/remove-batch-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ urls: input.urls, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n private async request(\n method: \"GET\" | \"POST\",\n path: string,\n init: { headers?: Record<string, string>; body?: BodyInit } = {}\n ): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n \"User-Agent\": `useknockout-node/${SDK_VERSION}`,\n ...(init.headers ?? {}),\n };\n if (this.token) headers[\"Authorization\"] = `Bearer ${this.token}`;\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n try {\n return await this.fetchImpl(url, {\n method,\n headers,\n body: init.body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\nasync function toBlob(\n input: { file: string | Buffer | Blob | ArrayBuffer | Uint8Array; filename?: string }\n): Promise<{ blob: Blob; filename: string }> {\n const { file } = input;\n const filename = input.filename ?? inferFilename(file);\n\n if (typeof file === \"string\") {\n const data = await readFile(file);\n return { blob: new Blob([new Uint8Array(data)]), filename };\n }\n if (file instanceof Blob) {\n return { blob: file, filename };\n }\n if (file instanceof ArrayBuffer) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (file instanceof Uint8Array) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (Buffer.isBuffer(file)) {\n return {\n blob: new Blob([new Uint8Array(file)]),\n filename,\n };\n }\n throw new TypeError(\"Unsupported `file` input. Provide a path, Buffer, Blob, ArrayBuffer, or Uint8Array.\");\n}\n\nfunction inferFilename(file: string | Buffer | Blob | ArrayBuffer | Uint8Array): string {\n if (typeof file === \"string\") return basename(file) || \"image\";\n return \"image\";\n}\n\nexport default Knockout;\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -136,6 +136,56 @@ interface CompareInput {
|
|
|
136
136
|
filename?: string;
|
|
137
137
|
format?: OutputFormat;
|
|
138
138
|
}
|
|
139
|
+
interface HeadshotInput {
|
|
140
|
+
file: FileInput;
|
|
141
|
+
filename?: string;
|
|
142
|
+
/** Hex color for the background. Default "#FFFFFF". Ignored if `bgBlur` is true. */
|
|
143
|
+
bgColor?: string;
|
|
144
|
+
/** Use a blurred copy of the original image as the background. Default false. */
|
|
145
|
+
bgBlur?: boolean;
|
|
146
|
+
/** Gaussian blur radius for the background when `bgBlur` is true. Default 20. */
|
|
147
|
+
blurRadius?: number;
|
|
148
|
+
/** Output aspect "W:H". Default "4:5" (portrait). */
|
|
149
|
+
aspect?: string;
|
|
150
|
+
/** Padding around the subject bbox, in pixels. Default 64. */
|
|
151
|
+
padding?: number;
|
|
152
|
+
/** Vertical headroom as a ratio of canvas height (0–0.5). Default 0.18. */
|
|
153
|
+
headTopRatio?: number;
|
|
154
|
+
format?: OpaqueFormat;
|
|
155
|
+
}
|
|
156
|
+
interface PreviewInput {
|
|
157
|
+
file: FileInput;
|
|
158
|
+
filename?: string;
|
|
159
|
+
/** Long-edge cap in pixels (64–1024). Default 512. */
|
|
160
|
+
maxDim?: number;
|
|
161
|
+
format?: OutputFormat;
|
|
162
|
+
}
|
|
163
|
+
interface EstimateInput {
|
|
164
|
+
/** Endpoint name without leading slash, e.g. "remove" or "headshot". */
|
|
165
|
+
endpoint: string;
|
|
166
|
+
width: number;
|
|
167
|
+
height: number;
|
|
168
|
+
}
|
|
169
|
+
interface EstimateResponse {
|
|
170
|
+
endpoint: string;
|
|
171
|
+
image_pixels: number;
|
|
172
|
+
est_latency_ms_warm: number;
|
|
173
|
+
est_latency_ms_cold: number;
|
|
174
|
+
est_cost_usd: number;
|
|
175
|
+
free_during_beta: boolean;
|
|
176
|
+
note: string;
|
|
177
|
+
}
|
|
178
|
+
interface StatsDay {
|
|
179
|
+
date: string;
|
|
180
|
+
count: number;
|
|
181
|
+
}
|
|
182
|
+
interface StatsResponse {
|
|
183
|
+
total_processed: number;
|
|
184
|
+
today: number;
|
|
185
|
+
last_7_days: StatsDay[];
|
|
186
|
+
error?: string;
|
|
187
|
+
detail?: string;
|
|
188
|
+
}
|
|
139
189
|
interface HealthResponse {
|
|
140
190
|
status: string;
|
|
141
191
|
model: string;
|
|
@@ -164,6 +214,18 @@ declare class Knockout {
|
|
|
164
214
|
constructor(options?: KnockoutOptions);
|
|
165
215
|
/** Hit GET /health — no auth required. */
|
|
166
216
|
health(): Promise<HealthResponse>;
|
|
217
|
+
/**
|
|
218
|
+
* Public usage counter — total images processed all-time, today, and a 7-day breakdown.
|
|
219
|
+
* Use for landing-page social proof. Eventually consistent across containers.
|
|
220
|
+
*/
|
|
221
|
+
stats(): Promise<StatsResponse>;
|
|
222
|
+
/**
|
|
223
|
+
* Predict latency + cost for an endpoint and image size without doing any GPU work.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* const est = await client.estimate({ endpoint: "remove", width: 1024, height: 1024 });
|
|
227
|
+
*/
|
|
228
|
+
estimate(input: EstimateInput): Promise<EstimateResponse>;
|
|
167
229
|
/**
|
|
168
230
|
* Remove the background from an image, returning the cleaned PNG/WebP bytes.
|
|
169
231
|
*
|
|
@@ -236,6 +298,21 @@ declare class Knockout {
|
|
|
236
298
|
* Before/after side-by-side preview — original on left, transparent cutout (on a checkerboard) on right.
|
|
237
299
|
*/
|
|
238
300
|
compare(input: CompareInput): Promise<Buffer>;
|
|
301
|
+
/**
|
|
302
|
+
* LinkedIn-ready headshot preset — bg removal + portrait crop + center face + bg color or blur.
|
|
303
|
+
*
|
|
304
|
+
* @example Solid bg
|
|
305
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgColor: "#0A0A0A" });
|
|
306
|
+
*
|
|
307
|
+
* @example Blurred original as bg
|
|
308
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgBlur: true, blurRadius: 24 });
|
|
309
|
+
*/
|
|
310
|
+
headshot(input: HeadshotInput): Promise<Buffer>;
|
|
311
|
+
/**
|
|
312
|
+
* Fast low-res preview cutout (~80ms warm). Skips pymatting refinement and downscales
|
|
313
|
+
* input to `maxDim` (default 512px on the long edge). Use for UX progress indicators.
|
|
314
|
+
*/
|
|
315
|
+
preview(input: PreviewInput): Promise<Buffer>;
|
|
239
316
|
/**
|
|
240
317
|
* Remove the background from up to 10 remote image URLs in a single call.
|
|
241
318
|
*
|
|
@@ -248,4 +325,4 @@ declare class Knockout {
|
|
|
248
325
|
private request;
|
|
249
326
|
}
|
|
250
327
|
|
|
251
|
-
export { type BatchInput, type BatchResponse, type BatchResultItem, type BatchUrlInput, type CompareInput, DEFAULT_BASE_URL, type HealthResponse, Knockout, KnockoutError, type KnockoutOptions, type MaskInput, type OpaqueFormat, type OutlineInput, type OutputFormat, type RemoveInput, type RemoveUrlInput, type ReplaceBgInput, type ShadowInput, type SmartCropInput, type StickerInput, type StudioShotInput, Knockout as default };
|
|
328
|
+
export { type BatchInput, type BatchResponse, type BatchResultItem, type BatchUrlInput, type CompareInput, DEFAULT_BASE_URL, type EstimateInput, type EstimateResponse, type HeadshotInput, type HealthResponse, Knockout, KnockoutError, type KnockoutOptions, type MaskInput, type OpaqueFormat, type OutlineInput, type OutputFormat, type PreviewInput, type RemoveInput, type RemoveUrlInput, type ReplaceBgInput, type ShadowInput, type SmartCropInput, type StatsDay, type StatsResponse, type StickerInput, type StudioShotInput, Knockout as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -136,6 +136,56 @@ interface CompareInput {
|
|
|
136
136
|
filename?: string;
|
|
137
137
|
format?: OutputFormat;
|
|
138
138
|
}
|
|
139
|
+
interface HeadshotInput {
|
|
140
|
+
file: FileInput;
|
|
141
|
+
filename?: string;
|
|
142
|
+
/** Hex color for the background. Default "#FFFFFF". Ignored if `bgBlur` is true. */
|
|
143
|
+
bgColor?: string;
|
|
144
|
+
/** Use a blurred copy of the original image as the background. Default false. */
|
|
145
|
+
bgBlur?: boolean;
|
|
146
|
+
/** Gaussian blur radius for the background when `bgBlur` is true. Default 20. */
|
|
147
|
+
blurRadius?: number;
|
|
148
|
+
/** Output aspect "W:H". Default "4:5" (portrait). */
|
|
149
|
+
aspect?: string;
|
|
150
|
+
/** Padding around the subject bbox, in pixels. Default 64. */
|
|
151
|
+
padding?: number;
|
|
152
|
+
/** Vertical headroom as a ratio of canvas height (0–0.5). Default 0.18. */
|
|
153
|
+
headTopRatio?: number;
|
|
154
|
+
format?: OpaqueFormat;
|
|
155
|
+
}
|
|
156
|
+
interface PreviewInput {
|
|
157
|
+
file: FileInput;
|
|
158
|
+
filename?: string;
|
|
159
|
+
/** Long-edge cap in pixels (64–1024). Default 512. */
|
|
160
|
+
maxDim?: number;
|
|
161
|
+
format?: OutputFormat;
|
|
162
|
+
}
|
|
163
|
+
interface EstimateInput {
|
|
164
|
+
/** Endpoint name without leading slash, e.g. "remove" or "headshot". */
|
|
165
|
+
endpoint: string;
|
|
166
|
+
width: number;
|
|
167
|
+
height: number;
|
|
168
|
+
}
|
|
169
|
+
interface EstimateResponse {
|
|
170
|
+
endpoint: string;
|
|
171
|
+
image_pixels: number;
|
|
172
|
+
est_latency_ms_warm: number;
|
|
173
|
+
est_latency_ms_cold: number;
|
|
174
|
+
est_cost_usd: number;
|
|
175
|
+
free_during_beta: boolean;
|
|
176
|
+
note: string;
|
|
177
|
+
}
|
|
178
|
+
interface StatsDay {
|
|
179
|
+
date: string;
|
|
180
|
+
count: number;
|
|
181
|
+
}
|
|
182
|
+
interface StatsResponse {
|
|
183
|
+
total_processed: number;
|
|
184
|
+
today: number;
|
|
185
|
+
last_7_days: StatsDay[];
|
|
186
|
+
error?: string;
|
|
187
|
+
detail?: string;
|
|
188
|
+
}
|
|
139
189
|
interface HealthResponse {
|
|
140
190
|
status: string;
|
|
141
191
|
model: string;
|
|
@@ -164,6 +214,18 @@ declare class Knockout {
|
|
|
164
214
|
constructor(options?: KnockoutOptions);
|
|
165
215
|
/** Hit GET /health — no auth required. */
|
|
166
216
|
health(): Promise<HealthResponse>;
|
|
217
|
+
/**
|
|
218
|
+
* Public usage counter — total images processed all-time, today, and a 7-day breakdown.
|
|
219
|
+
* Use for landing-page social proof. Eventually consistent across containers.
|
|
220
|
+
*/
|
|
221
|
+
stats(): Promise<StatsResponse>;
|
|
222
|
+
/**
|
|
223
|
+
* Predict latency + cost for an endpoint and image size without doing any GPU work.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* const est = await client.estimate({ endpoint: "remove", width: 1024, height: 1024 });
|
|
227
|
+
*/
|
|
228
|
+
estimate(input: EstimateInput): Promise<EstimateResponse>;
|
|
167
229
|
/**
|
|
168
230
|
* Remove the background from an image, returning the cleaned PNG/WebP bytes.
|
|
169
231
|
*
|
|
@@ -236,6 +298,21 @@ declare class Knockout {
|
|
|
236
298
|
* Before/after side-by-side preview — original on left, transparent cutout (on a checkerboard) on right.
|
|
237
299
|
*/
|
|
238
300
|
compare(input: CompareInput): Promise<Buffer>;
|
|
301
|
+
/**
|
|
302
|
+
* LinkedIn-ready headshot preset — bg removal + portrait crop + center face + bg color or blur.
|
|
303
|
+
*
|
|
304
|
+
* @example Solid bg
|
|
305
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgColor: "#0A0A0A" });
|
|
306
|
+
*
|
|
307
|
+
* @example Blurred original as bg
|
|
308
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgBlur: true, blurRadius: 24 });
|
|
309
|
+
*/
|
|
310
|
+
headshot(input: HeadshotInput): Promise<Buffer>;
|
|
311
|
+
/**
|
|
312
|
+
* Fast low-res preview cutout (~80ms warm). Skips pymatting refinement and downscales
|
|
313
|
+
* input to `maxDim` (default 512px on the long edge). Use for UX progress indicators.
|
|
314
|
+
*/
|
|
315
|
+
preview(input: PreviewInput): Promise<Buffer>;
|
|
239
316
|
/**
|
|
240
317
|
* Remove the background from up to 10 remote image URLs in a single call.
|
|
241
318
|
*
|
|
@@ -248,4 +325,4 @@ declare class Knockout {
|
|
|
248
325
|
private request;
|
|
249
326
|
}
|
|
250
327
|
|
|
251
|
-
export { type BatchInput, type BatchResponse, type BatchResultItem, type BatchUrlInput, type CompareInput, DEFAULT_BASE_URL, type HealthResponse, Knockout, KnockoutError, type KnockoutOptions, type MaskInput, type OpaqueFormat, type OutlineInput, type OutputFormat, type RemoveInput, type RemoveUrlInput, type ReplaceBgInput, type ShadowInput, type SmartCropInput, type StickerInput, type StudioShotInput, Knockout as default };
|
|
328
|
+
export { type BatchInput, type BatchResponse, type BatchResultItem, type BatchUrlInput, type CompareInput, DEFAULT_BASE_URL, type EstimateInput, type EstimateResponse, type HeadshotInput, type HealthResponse, Knockout, KnockoutError, type KnockoutOptions, type MaskInput, type OpaqueFormat, type OutlineInput, type OutputFormat, type PreviewInput, type RemoveInput, type RemoveUrlInput, type ReplaceBgInput, type ShadowInput, type SmartCropInput, type StatsDay, type StatsResponse, type StickerInput, type StudioShotInput, Knockout as default };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { basename } from 'path';
|
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
var DEFAULT_BASE_URL = "https://useknockout--api.modal.run";
|
|
6
|
-
var SDK_VERSION = "0.0.
|
|
6
|
+
var SDK_VERSION = "0.0.7";
|
|
7
7
|
var KnockoutError = class _KnockoutError extends Error {
|
|
8
8
|
status;
|
|
9
9
|
code;
|
|
@@ -49,6 +49,34 @@ var Knockout = class {
|
|
|
49
49
|
if (!res.ok) throw new KnockoutError(res.status, body);
|
|
50
50
|
return JSON.parse(body);
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Public usage counter — total images processed all-time, today, and a 7-day breakdown.
|
|
54
|
+
* Use for landing-page social proof. Eventually consistent across containers.
|
|
55
|
+
*/
|
|
56
|
+
async stats() {
|
|
57
|
+
const res = await this.request("GET", "/stats");
|
|
58
|
+
const body = await res.text();
|
|
59
|
+
if (!res.ok) throw new KnockoutError(res.status, body);
|
|
60
|
+
return JSON.parse(body);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Predict latency + cost for an endpoint and image size without doing any GPU work.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const est = await client.estimate({ endpoint: "remove", width: 1024, height: 1024 });
|
|
67
|
+
*/
|
|
68
|
+
async estimate(input) {
|
|
69
|
+
const res = await this.request("POST", "/estimate", {
|
|
70
|
+
headers: { "Content-Type": "application/json" },
|
|
71
|
+
body: JSON.stringify({
|
|
72
|
+
endpoint: input.endpoint,
|
|
73
|
+
width: input.width,
|
|
74
|
+
height: input.height
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
78
|
+
return await res.json();
|
|
79
|
+
}
|
|
52
80
|
/**
|
|
53
81
|
* Remove the background from an image, returning the cleaned PNG/WebP bytes.
|
|
54
82
|
*
|
|
@@ -248,6 +276,46 @@ var Knockout = class {
|
|
|
248
276
|
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
249
277
|
return Buffer.from(await res.arrayBuffer());
|
|
250
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* LinkedIn-ready headshot preset — bg removal + portrait crop + center face + bg color or blur.
|
|
281
|
+
*
|
|
282
|
+
* @example Solid bg
|
|
283
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgColor: "#0A0A0A" });
|
|
284
|
+
*
|
|
285
|
+
* @example Blurred original as bg
|
|
286
|
+
* const jpg = await client.headshot({ file: "./photo.jpg", bgBlur: true, blurRadius: 24 });
|
|
287
|
+
*/
|
|
288
|
+
async headshot(input) {
|
|
289
|
+
const format = input.format ?? "jpg";
|
|
290
|
+
const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });
|
|
291
|
+
const form = new FormData();
|
|
292
|
+
form.append("file", blob, filename);
|
|
293
|
+
if (input.bgColor) form.append("bg_color", input.bgColor);
|
|
294
|
+
if (input.bgBlur !== void 0) form.append("bg_blur", input.bgBlur ? "true" : "false");
|
|
295
|
+
if (input.blurRadius !== void 0) form.append("blur_radius", String(input.blurRadius));
|
|
296
|
+
if (input.aspect) form.append("aspect", input.aspect);
|
|
297
|
+
if (input.padding !== void 0) form.append("padding", String(input.padding));
|
|
298
|
+
if (input.headTopRatio !== void 0) form.append("head_top_ratio", String(input.headTopRatio));
|
|
299
|
+
form.append("format", format);
|
|
300
|
+
const res = await this.request("POST", "/headshot", { body: form });
|
|
301
|
+
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
302
|
+
return Buffer.from(await res.arrayBuffer());
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Fast low-res preview cutout (~80ms warm). Skips pymatting refinement and downscales
|
|
306
|
+
* input to `maxDim` (default 512px on the long edge). Use for UX progress indicators.
|
|
307
|
+
*/
|
|
308
|
+
async preview(input) {
|
|
309
|
+
const format = input.format ?? "png";
|
|
310
|
+
const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });
|
|
311
|
+
const form = new FormData();
|
|
312
|
+
form.append("file", blob, filename);
|
|
313
|
+
form.append("max_dim", String(input.maxDim ?? 512));
|
|
314
|
+
form.append("format", format);
|
|
315
|
+
const res = await this.request("POST", "/preview", { body: form });
|
|
316
|
+
if (!res.ok) throw new KnockoutError(res.status, await res.text());
|
|
317
|
+
return Buffer.from(await res.arrayBuffer());
|
|
318
|
+
}
|
|
251
319
|
/**
|
|
252
320
|
* Remove the background from up to 10 remote image URLs in a single call.
|
|
253
321
|
*
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAeO,IAAM,gBAAA,GAAmB;AAChC,IAAM,WAAA,GAAc,OAAA;AAyJb,IAAM,aAAA,GAAN,MAAM,cAAA,SAAsB,KAAA,CAAM;AAAA,EACvB,MAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EAEhB,WAAA,CAAY,QAAgB,IAAA,EAAc;AACxC,IAAA,MAAM,IAAA,GAAO,cAAA,CAAc,QAAA,CAAS,MAAM,CAAA;AAC1C,IAAA,KAAA,CAAM,sBAAsB,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,GAAA,EAAM,IAAA,IAAQ,SAAS,CAAA,CAAE,CAAA;AACpE,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA,EAEA,OAAe,SAAS,MAAA,EAAuC;AAC7D,IAAA,IAAI,MAAA,KAAW,GAAA,IAAO,MAAA,KAAW,GAAA,EAAK,OAAO,MAAA;AAC7C,IAAA,IAAI,MAAA,KAAW,KAAK,OAAO,YAAA;AAC3B,IAAA,IAAI,MAAA,KAAW,KAAK,OAAO,mBAAA;AAC3B,IAAA,IAAI,MAAA,IAAU,GAAA,IAAO,MAAA,GAAS,GAAA,EAAK,OAAO,aAAA;AAC1C,IAAA,IAAI,MAAA,IAAU,KAAK,OA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.\n *\n * Quick start:\n *\n * import { Knockout } from \"@useknockout/node\";\n *\n * const client = new Knockout({ token: process.env.KNOCKOUT_TOKEN! });\n * const png = await client.remove({ file: \"./input.jpg\" }); // Buffer of PNG bytes\n * await writeFile(\"out.png\", png);\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\n\nexport const DEFAULT_BASE_URL = \"https://useknockout--api.modal.run\";\nconst SDK_VERSION = \"0.0.6\";\n\nexport type OutputFormat = \"png\" | \"webp\";\nexport type OpaqueFormat = \"png\" | \"webp\" | \"jpg\";\n\ntype FileInput = string | Buffer | Blob | ArrayBuffer | Uint8Array;\n\nexport interface KnockoutOptions {\n /** API bearer token. Required unless your self-hosted instance has no auth. */\n token?: string;\n /** Override the API base URL. Defaults to the hosted endpoint. */\n baseUrl?: string;\n /** Per-request timeout in milliseconds. Default 60_000. */\n timeoutMs?: number;\n /** Custom fetch (useful for edge runtimes / polyfills). Defaults to global fetch. */\n fetch?: typeof fetch;\n}\n\nexport interface RemoveInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface RemoveUrlInput {\n /** Remote URL of the image to process. */\n url: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface ReplaceBgInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the foreground image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Hex color for the new background. Default \"#FFFFFF\". Ignored if `bgUrl` is set. */\n bgColor?: string;\n /** Remote URL of an image to use as the new background. Takes precedence over `bgColor`. */\n bgUrl?: string;\n /** Output format. \"jpg\" is smallest. Default \"png\". */\n format?: OpaqueFormat;\n}\n\nexport interface BatchInput {\n /** Array of local paths / buffers / blobs. Up to 10. */\n files: Array<string | Buffer | Blob | ArrayBuffer | Uint8Array>;\n /** Optional filenames aligned to `files`. */\n filenames?: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchUrlInput {\n /** Remote URLs to process. Up to 10. */\n urls: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchResultItem {\n filename?: string;\n url?: string;\n success: boolean;\n format?: OutputFormat;\n size_bytes?: number;\n data_base64?: string;\n error?: string;\n}\n\nexport interface BatchResponse {\n count: number;\n format: OutputFormat;\n results: BatchResultItem[];\n}\n\nexport interface MaskInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface SmartCropInput {\n file: FileInput;\n filename?: string;\n /** Padding around the subject bbox, in pixels. Default 24. */\n padding?: number;\n /** Return transparent cutout (true) or cropped region from original (false). Default true. */\n transparent?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface ShadowInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n bgUrl?: string;\n shadowColor?: string;\n shadowOffsetX?: number;\n shadowOffsetY?: number;\n shadowBlur?: number;\n shadowOpacity?: number;\n format?: OpaqueFormat;\n}\n\nexport interface StickerInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#FFFFFF\". */\n strokeColor?: string;\n /** Outline width in pixels. Default 20. */\n strokeWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface OutlineInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#000000\". */\n outlineColor?: string;\n /** Outline width in pixels. Default 4. */\n outlineWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface StudioShotInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n /** e.g. \"1:1\", \"4:5\", \"16:9\". Default \"1:1\". */\n aspect?: string;\n padding?: number;\n shadow?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface CompareInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface HealthResponse {\n status: string;\n model: string;\n}\n\n/**\n * Error thrown when the API returns a non-2xx response.\n */\nexport class KnockoutError extends Error {\n public readonly status: number;\n public readonly code: \"auth\" | \"rate_limit\" | \"bad_request\" | \"payload_too_large\" | \"server\" | \"unknown\";\n public readonly body: string;\n\n constructor(status: number, body: string) {\n const code = KnockoutError.classify(status);\n super(`Knockout API error ${status} (${code}): ${body || \"no body\"}`);\n this.name = \"KnockoutError\";\n this.status = status;\n this.code = code;\n this.body = body;\n }\n\n private static classify(status: number): KnockoutError[\"code\"] {\n if (status === 401 || status === 403) return \"auth\";\n if (status === 429) return \"rate_limit\";\n if (status === 413) return \"payload_too_large\";\n if (status >= 400 && status < 500) return \"bad_request\";\n if (status >= 500) return \"server\";\n return \"unknown\";\n }\n}\n\n/**\n * useknockout API client.\n *\n * All methods return a `Buffer` (Node) of the processed image bytes.\n * Use `.toString(\"base64\")` or `writeFile(path, buf)` to persist.\n */\nexport class Knockout {\n private readonly baseUrl: string;\n private readonly token: string | undefined;\n private readonly timeoutMs: number;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: KnockoutOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.token = options.token;\n this.timeoutMs = options.timeoutMs ?? 60_000;\n const fetchRef = options.fetch ?? globalThis.fetch;\n if (!fetchRef) {\n throw new Error(\n \"Global fetch is unavailable. Provide `options.fetch` or use Node 18+.\"\n );\n }\n this.fetchImpl = fetchRef.bind(globalThis);\n }\n\n /** Hit GET /health — no auth required. */\n async health(): Promise<HealthResponse> {\n const res = await this.request(\"GET\", \"/health\");\n const body = await res.text();\n if (!res.ok) throw new KnockoutError(res.status, body);\n return JSON.parse(body) as HealthResponse;\n }\n\n /**\n * Remove the background from an image, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.remove({ file: \"./input.jpg\" });\n */\n async remove(input: RemoveInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob(input);\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const res = await this.request(\"POST\", `/remove?format=${format}`, {\n body: form,\n });\n\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from a remote URL, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.removeUrl({ url: \"https://example.com/cat.jpg\" });\n */\n async removeUrl(input: RemoveUrlInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const res = await this.request(\"POST\", \"/remove-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ url: input.url, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Replace the background with a solid color or a remote image.\n *\n * @example Solid color\n * const jpg = await client.replaceBackground({ file: \"./cat.jpg\", bgColor: \"#FF5733\", format: \"jpg\" });\n *\n * @example Remote image as new background\n * const png = await client.replaceBackground({\n * file: \"./cat.jpg\",\n * bgUrl: \"https://example.com/beach.jpg\",\n * });\n */\n async replaceBackground(input: ReplaceBgInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const params = new URLSearchParams({ format });\n if (input.bgUrl) params.set(\"bg_url\", input.bgUrl);\n if (input.bgColor) params.set(\"bg_color\", input.bgColor);\n\n const res = await this.request(\"POST\", `/replace-bg?${params.toString()}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 images in a single call.\n * Returns a JSON object with base64-encoded result bytes per image.\n *\n * @example\n * const batch = await client.removeBatch({\n * files: [\"./a.jpg\", \"./b.jpg\", \"./c.jpg\"],\n * format: \"png\",\n * });\n * for (const r of batch.results) {\n * if (r.success) await writeFile(r.filename!, Buffer.from(r.data_base64!, \"base64\"));\n * }\n */\n async removeBatch(input: BatchInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.files.length === 0) throw new Error(\"At least one file required\");\n if (input.files.length > 10) throw new Error(\"Max 10 files per batch\");\n\n const form = new FormData();\n for (let i = 0; i < input.files.length; i++) {\n const name = input.filenames?.[i];\n const { blob, filename } = await toBlob({ file: input.files[i]!, filename: name });\n form.append(\"files\", blob, filename);\n }\n\n const res = await this.request(\"POST\", `/remove-batch?format=${format}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n /**\n * Return only the alpha mask as a grayscale PNG/WebP.\n * Useful when chaining into your own compositing pipeline.\n */\n async mask(input: MaskInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/mask\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Auto-crop to the subject's tight bounding box with configurable padding.\n * Returns either a transparent cutout or a cropped region from the original image.\n */\n async smartCrop(input: SmartCropInput): Promise<Buffer> {\n const transparent = input.transparent ?? true;\n const format: OpaqueFormat =\n (input.format as OpaqueFormat | undefined) ?? (transparent ? \"png\" : \"jpg\");\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"padding\", String(input.padding ?? 24));\n form.append(\"transparent\", transparent ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/smart-crop\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Composite subject onto a new background with a configurable drop shadow.\n */\n async shadow(input: ShadowInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.bgUrl) form.append(\"bg_url\", input.bgUrl);\n if (input.shadowColor) form.append(\"shadow_color\", input.shadowColor);\n if (input.shadowOffsetX !== undefined) form.append(\"shadow_offset_x\", String(input.shadowOffsetX));\n if (input.shadowOffsetY !== undefined) form.append(\"shadow_offset_y\", String(input.shadowOffsetY));\n if (input.shadowBlur !== undefined) form.append(\"shadow_blur\", String(input.shadowBlur));\n if (input.shadowOpacity !== undefined) form.append(\"shadow_opacity\", String(input.shadowOpacity));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/shadow\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Sticker style — subject with a thick outline on transparent background.\n * Perfect for WhatsApp / iMessage / Telegram stickers.\n */\n async sticker(input: StickerInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.strokeColor) form.append(\"stroke_color\", input.strokeColor);\n if (input.strokeWidth !== undefined) form.append(\"stroke_width\", String(input.strokeWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/sticker\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Subject on transparent background with a thin configurable outline.\n */\n async outline(input: OutlineInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.outlineColor) form.append(\"outline_color\", input.outlineColor);\n if (input.outlineWidth !== undefined) form.append(\"outline_width\", String(input.outlineWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/outline\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * E-commerce preset — cutout + tight crop + centered + optional shadow on a standard aspect canvas.\n */\n async studioShot(input: StudioShotInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"jpg\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.aspect) form.append(\"aspect\", input.aspect);\n if (input.padding !== undefined) form.append(\"padding\", String(input.padding));\n if (input.shadow !== undefined) form.append(\"shadow\", input.shadow ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/studio-shot\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Before/after side-by-side preview — original on left, transparent cutout (on a checkerboard) on right.\n */\n async compare(input: CompareInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/compare\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 remote image URLs in a single call.\n *\n * @example\n * const batch = await client.removeBatchUrl({\n * urls: [\"https://a.jpg\", \"https://b.jpg\"],\n * });\n */\n async removeBatchUrl(input: BatchUrlInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.urls.length === 0) throw new Error(\"At least one URL required\");\n if (input.urls.length > 10) throw new Error(\"Max 10 URLs per batch\");\n\n const res = await this.request(\"POST\", \"/remove-batch-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ urls: input.urls, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n private async request(\n method: \"GET\" | \"POST\",\n path: string,\n init: { headers?: Record<string, string>; body?: BodyInit } = {}\n ): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n \"User-Agent\": `useknockout-node/${SDK_VERSION}`,\n ...(init.headers ?? {}),\n };\n if (this.token) headers[\"Authorization\"] = `Bearer ${this.token}`;\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n try {\n return await this.fetchImpl(url, {\n method,\n headers,\n body: init.body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\nasync function toBlob(\n input: { file: string | Buffer | Blob | ArrayBuffer | Uint8Array; filename?: string }\n): Promise<{ blob: Blob; filename: string }> {\n const { file } = input;\n const filename = input.filename ?? inferFilename(file);\n\n if (typeof file === \"string\") {\n const data = await readFile(file);\n return { blob: new Blob([new Uint8Array(data)]), filename };\n }\n if (file instanceof Blob) {\n return { blob: file, filename };\n }\n if (file instanceof ArrayBuffer) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (file instanceof Uint8Array) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (Buffer.isBuffer(file)) {\n return {\n blob: new Blob([new Uint8Array(file)]),\n filename,\n };\n }\n throw new TypeError(\"Unsupported `file` input. Provide a path, Buffer, Blob, ArrayBuffer, or Uint8Array.\");\n}\n\nfunction inferFilename(file: string | Buffer | Blob | ArrayBuffer | Uint8Array): string {\n if (typeof file === \"string\") return basename(file) || \"image\";\n return \"image\";\n}\n\nexport default Knockout;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAeO,IAAM,gBAAA,GAAmB;AAChC,IAAM,WAAA,GAAc,OAAA;AAiNb,IAAM,aAAA,GAAN,MAAM,cAAA,SAAsB,KAAA,CAAM;AAAA,EACvB,MAAA;AAAA,EACA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,CAAK,CAAC,IAAI,UAAA,CAAW,IAAI,CAAC,CAAC,CAAA;AAAA,MACrC;AAAA,KACF;AAAA,EACF;AACA,EAAA,MAAM,IAAI,UAAU,qFAAqF,CAAA;AAC3G;AAEA,SAAS,cAAc,IAAA,EAAiE;AACtF,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,EAAU,OAAO,QAAA,CAAS,IAAI,CAAA,IAAK,OAAA;AACvD,EAAA,OAAO,OAAA;AACT;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["/**\n * @useknockout/node — official TypeScript / Node.js client for the useknockout API.\n *\n * Quick start:\n *\n * import { Knockout } from \"@useknockout/node\";\n *\n * const client = new Knockout({ token: process.env.KNOCKOUT_TOKEN! });\n * const png = await client.remove({ file: \"./input.jpg\" }); // Buffer of PNG bytes\n * await writeFile(\"out.png\", png);\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\n\nexport const DEFAULT_BASE_URL = \"https://useknockout--api.modal.run\";\nconst SDK_VERSION = \"0.0.7\";\n\nexport type OutputFormat = \"png\" | \"webp\";\nexport type OpaqueFormat = \"png\" | \"webp\" | \"jpg\";\n\ntype FileInput = string | Buffer | Blob | ArrayBuffer | Uint8Array;\n\nexport interface KnockoutOptions {\n /** API bearer token. Required unless your self-hosted instance has no auth. */\n token?: string;\n /** Override the API base URL. Defaults to the hosted endpoint. */\n baseUrl?: string;\n /** Per-request timeout in milliseconds. Default 60_000. */\n timeoutMs?: number;\n /** Custom fetch (useful for edge runtimes / polyfills). Defaults to global fetch. */\n fetch?: typeof fetch;\n}\n\nexport interface RemoveInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface RemoveUrlInput {\n /** Remote URL of the image to process. */\n url: string;\n /** Output format. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface ReplaceBgInput {\n /** Local file path, Buffer, Blob, or ArrayBuffer of the foreground image. */\n file: string | Buffer | Blob | ArrayBuffer | Uint8Array;\n /** Optional filename — inferred from path when `file` is a string. */\n filename?: string;\n /** Hex color for the new background. Default \"#FFFFFF\". Ignored if `bgUrl` is set. */\n bgColor?: string;\n /** Remote URL of an image to use as the new background. Takes precedence over `bgColor`. */\n bgUrl?: string;\n /** Output format. \"jpg\" is smallest. Default \"png\". */\n format?: OpaqueFormat;\n}\n\nexport interface BatchInput {\n /** Array of local paths / buffers / blobs. Up to 10. */\n files: Array<string | Buffer | Blob | ArrayBuffer | Uint8Array>;\n /** Optional filenames aligned to `files`. */\n filenames?: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchUrlInput {\n /** Remote URLs to process. Up to 10. */\n urls: string[];\n /** Output format for each image. Default \"png\". */\n format?: OutputFormat;\n}\n\nexport interface BatchResultItem {\n filename?: string;\n url?: string;\n success: boolean;\n format?: OutputFormat;\n size_bytes?: number;\n data_base64?: string;\n error?: string;\n}\n\nexport interface BatchResponse {\n count: number;\n format: OutputFormat;\n results: BatchResultItem[];\n}\n\nexport interface MaskInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface SmartCropInput {\n file: FileInput;\n filename?: string;\n /** Padding around the subject bbox, in pixels. Default 24. */\n padding?: number;\n /** Return transparent cutout (true) or cropped region from original (false). Default true. */\n transparent?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface ShadowInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n bgUrl?: string;\n shadowColor?: string;\n shadowOffsetX?: number;\n shadowOffsetY?: number;\n shadowBlur?: number;\n shadowOpacity?: number;\n format?: OpaqueFormat;\n}\n\nexport interface StickerInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#FFFFFF\". */\n strokeColor?: string;\n /** Outline width in pixels. Default 20. */\n strokeWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface OutlineInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the outline. Default \"#000000\". */\n outlineColor?: string;\n /** Outline width in pixels. Default 4. */\n outlineWidth?: number;\n format?: OutputFormat;\n}\n\nexport interface StudioShotInput {\n file: FileInput;\n filename?: string;\n bgColor?: string;\n /** e.g. \"1:1\", \"4:5\", \"16:9\". Default \"1:1\". */\n aspect?: string;\n padding?: number;\n shadow?: boolean;\n format?: OpaqueFormat;\n}\n\nexport interface CompareInput {\n file: FileInput;\n filename?: string;\n format?: OutputFormat;\n}\n\nexport interface HeadshotInput {\n file: FileInput;\n filename?: string;\n /** Hex color for the background. Default \"#FFFFFF\". Ignored if `bgBlur` is true. */\n bgColor?: string;\n /** Use a blurred copy of the original image as the background. Default false. */\n bgBlur?: boolean;\n /** Gaussian blur radius for the background when `bgBlur` is true. Default 20. */\n blurRadius?: number;\n /** Output aspect \"W:H\". Default \"4:5\" (portrait). */\n aspect?: string;\n /** Padding around the subject bbox, in pixels. Default 64. */\n padding?: number;\n /** Vertical headroom as a ratio of canvas height (0–0.5). Default 0.18. */\n headTopRatio?: number;\n format?: OpaqueFormat;\n}\n\nexport interface PreviewInput {\n file: FileInput;\n filename?: string;\n /** Long-edge cap in pixels (64–1024). Default 512. */\n maxDim?: number;\n format?: OutputFormat;\n}\n\nexport interface EstimateInput {\n /** Endpoint name without leading slash, e.g. \"remove\" or \"headshot\". */\n endpoint: string;\n width: number;\n height: number;\n}\n\nexport interface EstimateResponse {\n endpoint: string;\n image_pixels: number;\n est_latency_ms_warm: number;\n est_latency_ms_cold: number;\n est_cost_usd: number;\n free_during_beta: boolean;\n note: string;\n}\n\nexport interface StatsDay {\n date: string;\n count: number;\n}\n\nexport interface StatsResponse {\n total_processed: number;\n today: number;\n last_7_days: StatsDay[];\n error?: string;\n detail?: string;\n}\n\nexport interface HealthResponse {\n status: string;\n model: string;\n}\n\n/**\n * Error thrown when the API returns a non-2xx response.\n */\nexport class KnockoutError extends Error {\n public readonly status: number;\n public readonly code: \"auth\" | \"rate_limit\" | \"bad_request\" | \"payload_too_large\" | \"server\" | \"unknown\";\n public readonly body: string;\n\n constructor(status: number, body: string) {\n const code = KnockoutError.classify(status);\n super(`Knockout API error ${status} (${code}): ${body || \"no body\"}`);\n this.name = \"KnockoutError\";\n this.status = status;\n this.code = code;\n this.body = body;\n }\n\n private static classify(status: number): KnockoutError[\"code\"] {\n if (status === 401 || status === 403) return \"auth\";\n if (status === 429) return \"rate_limit\";\n if (status === 413) return \"payload_too_large\";\n if (status >= 400 && status < 500) return \"bad_request\";\n if (status >= 500) return \"server\";\n return \"unknown\";\n }\n}\n\n/**\n * useknockout API client.\n *\n * All methods return a `Buffer` (Node) of the processed image bytes.\n * Use `.toString(\"base64\")` or `writeFile(path, buf)` to persist.\n */\nexport class Knockout {\n private readonly baseUrl: string;\n private readonly token: string | undefined;\n private readonly timeoutMs: number;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: KnockoutOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.token = options.token;\n this.timeoutMs = options.timeoutMs ?? 60_000;\n const fetchRef = options.fetch ?? globalThis.fetch;\n if (!fetchRef) {\n throw new Error(\n \"Global fetch is unavailable. Provide `options.fetch` or use Node 18+.\"\n );\n }\n this.fetchImpl = fetchRef.bind(globalThis);\n }\n\n /** Hit GET /health — no auth required. */\n async health(): Promise<HealthResponse> {\n const res = await this.request(\"GET\", \"/health\");\n const body = await res.text();\n if (!res.ok) throw new KnockoutError(res.status, body);\n return JSON.parse(body) as HealthResponse;\n }\n\n /**\n * Public usage counter — total images processed all-time, today, and a 7-day breakdown.\n * Use for landing-page social proof. Eventually consistent across containers.\n */\n async stats(): Promise<StatsResponse> {\n const res = await this.request(\"GET\", \"/stats\");\n const body = await res.text();\n if (!res.ok) throw new KnockoutError(res.status, body);\n return JSON.parse(body) as StatsResponse;\n }\n\n /**\n * Predict latency + cost for an endpoint and image size without doing any GPU work.\n *\n * @example\n * const est = await client.estimate({ endpoint: \"remove\", width: 1024, height: 1024 });\n */\n async estimate(input: EstimateInput): Promise<EstimateResponse> {\n const res = await this.request(\"POST\", \"/estimate\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n endpoint: input.endpoint,\n width: input.width,\n height: input.height,\n }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as EstimateResponse;\n }\n\n /**\n * Remove the background from an image, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.remove({ file: \"./input.jpg\" });\n */\n async remove(input: RemoveInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob(input);\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const res = await this.request(\"POST\", `/remove?format=${format}`, {\n body: form,\n });\n\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from a remote URL, returning the cleaned PNG/WebP bytes.\n *\n * @example\n * const png = await client.removeUrl({ url: \"https://example.com/cat.jpg\" });\n */\n async removeUrl(input: RemoveUrlInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const res = await this.request(\"POST\", \"/remove-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ url: input.url, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Replace the background with a solid color or a remote image.\n *\n * @example Solid color\n * const jpg = await client.replaceBackground({ file: \"./cat.jpg\", bgColor: \"#FF5733\", format: \"jpg\" });\n *\n * @example Remote image as new background\n * const png = await client.replaceBackground({\n * file: \"./cat.jpg\",\n * bgUrl: \"https://example.com/beach.jpg\",\n * });\n */\n async replaceBackground(input: ReplaceBgInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n\n const form = new FormData();\n form.append(\"file\", blob, filename);\n\n const params = new URLSearchParams({ format });\n if (input.bgUrl) params.set(\"bg_url\", input.bgUrl);\n if (input.bgColor) params.set(\"bg_color\", input.bgColor);\n\n const res = await this.request(\"POST\", `/replace-bg?${params.toString()}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 images in a single call.\n * Returns a JSON object with base64-encoded result bytes per image.\n *\n * @example\n * const batch = await client.removeBatch({\n * files: [\"./a.jpg\", \"./b.jpg\", \"./c.jpg\"],\n * format: \"png\",\n * });\n * for (const r of batch.results) {\n * if (r.success) await writeFile(r.filename!, Buffer.from(r.data_base64!, \"base64\"));\n * }\n */\n async removeBatch(input: BatchInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.files.length === 0) throw new Error(\"At least one file required\");\n if (input.files.length > 10) throw new Error(\"Max 10 files per batch\");\n\n const form = new FormData();\n for (let i = 0; i < input.files.length; i++) {\n const name = input.filenames?.[i];\n const { blob, filename } = await toBlob({ file: input.files[i]!, filename: name });\n form.append(\"files\", blob, filename);\n }\n\n const res = await this.request(\"POST\", `/remove-batch?format=${format}`, {\n body: form,\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n /**\n * Return only the alpha mask as a grayscale PNG/WebP.\n * Useful when chaining into your own compositing pipeline.\n */\n async mask(input: MaskInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/mask\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Auto-crop to the subject's tight bounding box with configurable padding.\n * Returns either a transparent cutout or a cropped region from the original image.\n */\n async smartCrop(input: SmartCropInput): Promise<Buffer> {\n const transparent = input.transparent ?? true;\n const format: OpaqueFormat =\n (input.format as OpaqueFormat | undefined) ?? (transparent ? \"png\" : \"jpg\");\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"padding\", String(input.padding ?? 24));\n form.append(\"transparent\", transparent ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/smart-crop\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Composite subject onto a new background with a configurable drop shadow.\n */\n async shadow(input: ShadowInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.bgUrl) form.append(\"bg_url\", input.bgUrl);\n if (input.shadowColor) form.append(\"shadow_color\", input.shadowColor);\n if (input.shadowOffsetX !== undefined) form.append(\"shadow_offset_x\", String(input.shadowOffsetX));\n if (input.shadowOffsetY !== undefined) form.append(\"shadow_offset_y\", String(input.shadowOffsetY));\n if (input.shadowBlur !== undefined) form.append(\"shadow_blur\", String(input.shadowBlur));\n if (input.shadowOpacity !== undefined) form.append(\"shadow_opacity\", String(input.shadowOpacity));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/shadow\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Sticker style — subject with a thick outline on transparent background.\n * Perfect for WhatsApp / iMessage / Telegram stickers.\n */\n async sticker(input: StickerInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.strokeColor) form.append(\"stroke_color\", input.strokeColor);\n if (input.strokeWidth !== undefined) form.append(\"stroke_width\", String(input.strokeWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/sticker\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Subject on transparent background with a thin configurable outline.\n */\n async outline(input: OutlineInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.outlineColor) form.append(\"outline_color\", input.outlineColor);\n if (input.outlineWidth !== undefined) form.append(\"outline_width\", String(input.outlineWidth));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/outline\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * E-commerce preset — cutout + tight crop + centered + optional shadow on a standard aspect canvas.\n */\n async studioShot(input: StudioShotInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"jpg\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.aspect) form.append(\"aspect\", input.aspect);\n if (input.padding !== undefined) form.append(\"padding\", String(input.padding));\n if (input.shadow !== undefined) form.append(\"shadow\", input.shadow ? \"true\" : \"false\");\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/studio-shot\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Before/after side-by-side preview — original on left, transparent cutout (on a checkerboard) on right.\n */\n async compare(input: CompareInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/compare\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * LinkedIn-ready headshot preset — bg removal + portrait crop + center face + bg color or blur.\n *\n * @example Solid bg\n * const jpg = await client.headshot({ file: \"./photo.jpg\", bgColor: \"#0A0A0A\" });\n *\n * @example Blurred original as bg\n * const jpg = await client.headshot({ file: \"./photo.jpg\", bgBlur: true, blurRadius: 24 });\n */\n async headshot(input: HeadshotInput): Promise<Buffer> {\n const format: OpaqueFormat = input.format ?? \"jpg\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n if (input.bgColor) form.append(\"bg_color\", input.bgColor);\n if (input.bgBlur !== undefined) form.append(\"bg_blur\", input.bgBlur ? \"true\" : \"false\");\n if (input.blurRadius !== undefined) form.append(\"blur_radius\", String(input.blurRadius));\n if (input.aspect) form.append(\"aspect\", input.aspect);\n if (input.padding !== undefined) form.append(\"padding\", String(input.padding));\n if (input.headTopRatio !== undefined) form.append(\"head_top_ratio\", String(input.headTopRatio));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/headshot\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Fast low-res preview cutout (~80ms warm). Skips pymatting refinement and downscales\n * input to `maxDim` (default 512px on the long edge). Use for UX progress indicators.\n */\n async preview(input: PreviewInput): Promise<Buffer> {\n const format: OutputFormat = input.format ?? \"png\";\n const { blob, filename } = await toBlob({ file: input.file, filename: input.filename });\n const form = new FormData();\n form.append(\"file\", blob, filename);\n form.append(\"max_dim\", String(input.maxDim ?? 512));\n form.append(\"format\", format);\n const res = await this.request(\"POST\", \"/preview\", { body: form });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return Buffer.from(await res.arrayBuffer());\n }\n\n /**\n * Remove the background from up to 10 remote image URLs in a single call.\n *\n * @example\n * const batch = await client.removeBatchUrl({\n * urls: [\"https://a.jpg\", \"https://b.jpg\"],\n * });\n */\n async removeBatchUrl(input: BatchUrlInput): Promise<BatchResponse> {\n const format: OutputFormat = input.format ?? \"png\";\n if (input.urls.length === 0) throw new Error(\"At least one URL required\");\n if (input.urls.length > 10) throw new Error(\"Max 10 URLs per batch\");\n\n const res = await this.request(\"POST\", \"/remove-batch-url\", {\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ urls: input.urls, format }),\n });\n if (!res.ok) throw new KnockoutError(res.status, await res.text());\n return (await res.json()) as BatchResponse;\n }\n\n private async request(\n method: \"GET\" | \"POST\",\n path: string,\n init: { headers?: Record<string, string>; body?: BodyInit } = {}\n ): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n const headers: Record<string, string> = {\n \"User-Agent\": `useknockout-node/${SDK_VERSION}`,\n ...(init.headers ?? {}),\n };\n if (this.token) headers[\"Authorization\"] = `Bearer ${this.token}`;\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n try {\n return await this.fetchImpl(url, {\n method,\n headers,\n body: init.body,\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\nasync function toBlob(\n input: { file: string | Buffer | Blob | ArrayBuffer | Uint8Array; filename?: string }\n): Promise<{ blob: Blob; filename: string }> {\n const { file } = input;\n const filename = input.filename ?? inferFilename(file);\n\n if (typeof file === \"string\") {\n const data = await readFile(file);\n return { blob: new Blob([new Uint8Array(data)]), filename };\n }\n if (file instanceof Blob) {\n return { blob: file, filename };\n }\n if (file instanceof ArrayBuffer) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (file instanceof Uint8Array) {\n return { blob: new Blob([new Uint8Array(file)]), filename };\n }\n if (Buffer.isBuffer(file)) {\n return {\n blob: new Blob([new Uint8Array(file)]),\n filename,\n };\n }\n throw new TypeError(\"Unsupported `file` input. Provide a path, Buffer, Blob, ArrayBuffer, or Uint8Array.\");\n}\n\nfunction inferFilename(file: string | Buffer | Blob | ArrayBuffer | Uint8Array): string {\n if (typeof file === \"string\") return basename(file) || \"image\";\n return \"image\";\n}\n\nexport default Knockout;\n"]}
|