@coreviz/sdk 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @coreviz/sdk
2
2
 
3
- CoreViz SDK - A JavaScript/Node.js interface for CoreViz's Vision AI APIs.
3
+ The official JavaScript/TypeScript SDK for CoreViz's Vision AI APIs. Easily integrate powerful image analysis and manipulation features into your applications.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,17 +8,111 @@ CoreViz SDK - A JavaScript/Node.js interface for CoreViz's Vision AI APIs.
8
8
  npm install @coreviz/sdk
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Configuration
12
12
 
13
- ```js
14
- const coreviz = require('@coreviz/sdk');
15
- coreviz();
13
+ To use the AI features, you need a CoreViz API key.
14
+ Set the `COREVIZ_API_KEY` environment variable in your project.
15
+
16
+ ```bash
17
+ export COREVIZ_API_KEY=your_api_key_here
16
18
  ```
17
19
 
18
- ## Development
20
+ ## API Reference
21
+
22
+ ### `describe(image)`
23
+
24
+ Generates a detailed text description of an image.
25
+
26
+ **Parameters:**
27
+ - `image` (string): The image to describe. Can be a base64 string or a URL.
19
28
 
20
- This is currently a placeholder package. The actual API functionality will be implemented soon.
29
+ **Returns:**
30
+ - `Promise<string>`: A text description of the image.
31
+
32
+ **Example:**
33
+
34
+ ```typescript
35
+ import { describe } from '@coreviz/sdk';
36
+
37
+ const description = await describe('https://example.com/image.jpg');
38
+ console.log(description);
39
+ ```
40
+
41
+ ### `tag(image, options)`
42
+
43
+ Analyzes an image and returns relevant tags or classifications based on a prompt.
44
+
45
+ **Parameters:**
46
+ - `image` (string): The image to analyze. Can be a base64 string or a URL.
47
+ - `options` (object):
48
+ - `prompt` (string): The context or question to guide the tagging (e.g., "What objects are in this image?").
49
+ - `options` (string[], optional): A specific list of tags to choose from.
50
+ - `multiple` (boolean, optional): Whether to allow multiple tags (default: `true`).
51
+
52
+ **Returns:**
53
+ - `Promise<TagResponse>`: An object containing:
54
+ - `tags` (string[]): The list of identified tags.
55
+ - `raw` (unknown): The raw API response.
56
+
57
+ **Example:**
58
+
59
+ ```typescript
60
+ import { tag } from '@coreviz/sdk';
61
+
62
+ const result = await tag('base64_image_string...', {
63
+ prompt: "Is this indoor or outdoor?",
64
+ options: ["indoor", "outdoor"],
65
+ multiple: false
66
+ });
67
+ console.log(result.tags); // ["indoor"]
68
+ ```
69
+
70
+ ### `edit(image, options)`
71
+
72
+ Modifies an image based on a text prompt using generative AI.
73
+
74
+ **Parameters:**
75
+ - `image` (string): The image to edit. Can be a base64 string or a URL.
76
+ - `options` (object):
77
+ - `prompt` (string): Description of the desired edit.
78
+ - `aspectRatio` (string, optional): Target aspect ratio (`'match_input_image'`, `'1:1'`, `'16:9'`, `'9:16'`, `'4:3'`, `'3:4'`).
79
+ - `outputFormat` (string, optional): `'jpg'` or `'png'`.
80
+ - `model` (string, optional): The model to use (default: `'flux-kontext-max'`).
81
+
82
+ **Returns:**
83
+ - `Promise<string>`: The edited image as a base64 string or URL.
84
+
85
+ **Example:**
86
+
87
+ ```typescript
88
+ import { edit } from '@coreviz/sdk';
89
+
90
+ const editedImage = await edit('https://example.com/photo.jpg', {
91
+ prompt: "Make it look like a painting",
92
+ aspectRatio: "1:1"
93
+ });
94
+ ```
95
+
96
+ ### `resize(input, maxWidth?, maxHeight?)`
97
+
98
+ Utility function to resize images client-side or server-side before processing.
99
+
100
+ **Parameters:**
101
+ - `input` (string | File): The image to resize.
102
+ - `maxWidth` (number, optional): Maximum width (default: 1920).
103
+ - `maxHeight` (number, optional): Maximum height (default: 1080).
104
+
105
+ **Returns:**
106
+ - `Promise<string>`: The resized image as a base64 string.
107
+
108
+ **Example:**
109
+
110
+ ```typescript
111
+ import { resize } from '@coreviz/sdk';
112
+
113
+ const resized = await resize(myFileObject, 800, 600);
114
+ ```
21
115
 
22
116
  ## License
23
117
 
24
- MIT
118
+ MIT
@@ -1 +1,5 @@
1
- export declare function describe(image: string): Promise<string | undefined>;
1
+ export interface DescribeOptions {
2
+ token?: string;
3
+ apiKey?: string;
4
+ }
5
+ export declare function describe(image: string, options?: DescribeOptions): Promise<string | undefined>;
package/dist/describe.js CHANGED
@@ -2,15 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.describe = describe;
4
4
  const resize_1 = require("./resize");
5
- async function describe(image) {
5
+ async function describe(image, options) {
6
6
  try {
7
7
  const resizedImage = await (0, resize_1.resize)(image);
8
+ const headers = {
9
+ 'Content-Type': 'application/json',
10
+ };
11
+ if (options?.token) {
12
+ headers['Authorization'] = `Bearer ${options.token}`;
13
+ }
14
+ else {
15
+ headers['x-api-key'] = options?.apiKey || process.env.COREVIZ_API_KEY || "";
16
+ }
8
17
  const response = await fetch(`https://lab.coreviz.io/api/ai/describe`, {
9
18
  method: 'POST',
10
- headers: {
11
- 'x-api-key': process.env.COREVIZ_API_KEY || "",
12
- 'Content-Type': 'application/json',
13
- },
19
+ headers,
14
20
  body: JSON.stringify({ image: resizedImage }),
15
21
  });
16
22
  if (!response.ok) {
package/dist/edit.d.ts CHANGED
@@ -3,5 +3,7 @@ export interface EditOptions {
3
3
  aspectRatio?: 'match_input_image' | '1:1' | '16:9' | '9:16' | '4:3' | '3:4';
4
4
  outputFormat?: 'jpg' | 'png';
5
5
  model?: 'flux-kontext-max' | 'google/nano-banana' | 'seedream-4';
6
+ token?: string;
7
+ apiKey?: string;
6
8
  }
7
9
  export declare function edit(image: string, options: EditOptions): Promise<string | undefined>;
package/dist/edit.js CHANGED
@@ -5,12 +5,18 @@ const resize_1 = require("./resize");
5
5
  async function edit(image, options) {
6
6
  try {
7
7
  const resizedImage = await (0, resize_1.resize)(image);
8
+ const headers = {
9
+ 'Content-Type': 'application/json',
10
+ };
11
+ if (options.token) {
12
+ headers['Authorization'] = `Bearer ${options.token}`;
13
+ }
14
+ else {
15
+ headers['x-api-key'] = options.apiKey || process.env.COREVIZ_API_KEY || "";
16
+ }
8
17
  const response = await fetch(`https://lab.coreviz.io/api/ai/edit`, {
9
18
  method: 'POST',
10
- headers: {
11
- 'x-api-key': process.env.COREVIZ_API_KEY || "",
12
- 'Content-Type': 'application/json',
13
- },
19
+ headers,
14
20
  body: JSON.stringify({
15
21
  image: resizedImage,
16
22
  prompt: options.prompt,
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { describe } from './describe';
1
+ import { describe, DescribeOptions } from './describe';
2
2
  import { resize } from './resize';
3
3
  import { edit, EditOptions } from './edit';
4
4
  import { tag, TagOptions, TagResponse } from './tag';
5
5
  export { describe, resize, edit, tag };
6
- export type { EditOptions, TagOptions, TagResponse };
6
+ export type { EditOptions, TagOptions, TagResponse, DescribeOptions };
package/dist/tag.d.ts CHANGED
@@ -2,6 +2,8 @@ export interface TagOptions {
2
2
  prompt: string;
3
3
  options?: string[];
4
4
  multiple?: boolean;
5
+ token?: string;
6
+ apiKey?: string;
5
7
  }
6
8
  export interface TagResponse {
7
9
  tags: string[];
package/dist/tag.js CHANGED
@@ -5,12 +5,18 @@ const resize_1 = require("./resize");
5
5
  async function tag(image, options) {
6
6
  try {
7
7
  const resizedImage = await (0, resize_1.resize)(image);
8
+ const headers = {
9
+ 'Content-Type': 'application/json',
10
+ };
11
+ if (options.token) {
12
+ headers['Authorization'] = `Bearer ${options.token}`;
13
+ }
14
+ else {
15
+ headers['x-api-key'] = options.apiKey || process.env.COREVIZ_API_KEY || "";
16
+ }
8
17
  const response = await fetch("https://lab.coreviz.io/api/ai/tag", {
9
18
  method: 'POST',
10
- headers: {
11
- 'x-api-key': process.env.COREVIZ_API_KEY || "",
12
- 'Content-Type': 'application/json',
13
- },
19
+ headers,
14
20
  body: JSON.stringify({
15
21
  image: resizedImage,
16
22
  prompt: options.prompt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreviz/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CoreViz SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,4 +34,4 @@
34
34
  "dependencies": {
35
35
  "sharp": "^0.34.5"
36
36
  }
37
- }
37
+ }