@aicats/sdk 1.0.0 → 1.0.3
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 +34 -13
- package/dist/index.d.mts +19 -4
- package/dist/index.d.ts +19 -4
- package/dist/index.js +30 -4
- package/dist/index.mjs +30 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,26 +30,39 @@ Get a random AI-generated cat image.
|
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
const blob = await AiCats.random({
|
|
33
|
-
size: Size.Medium,
|
|
34
|
-
theme: Theme.Xmas
|
|
33
|
+
size: Size.Medium, // Image size (default: Large)
|
|
34
|
+
theme: Theme.Xmas, // Optional theme
|
|
35
|
+
responseType: 'blob' // 'blob' | 'arrayBuffer' | 'base64' | 'dataUrl'
|
|
35
36
|
});
|
|
37
|
+
|
|
38
|
+
// Get as base64
|
|
39
|
+
const base64 = await AiCats.random({ responseType: 'base64' });
|
|
40
|
+
|
|
41
|
+
// Get as data URL (for direct use in img.src)
|
|
42
|
+
const dataUrl = await AiCats.random({ responseType: 'dataUrl' });
|
|
36
43
|
```
|
|
37
44
|
|
|
38
|
-
### `AiCats.getById(id,
|
|
45
|
+
### `AiCats.getById(id, options?)`
|
|
39
46
|
Get a specific cat image by ID.
|
|
40
47
|
|
|
41
48
|
```typescript
|
|
42
|
-
const blob = await AiCats.getById('
|
|
49
|
+
const blob = await AiCats.getById('669de24a-1da1-4fcd-84b1-9e55a43a0e0e', { size: Size.Small });
|
|
50
|
+
|
|
51
|
+
// Get as base64
|
|
52
|
+
const base64 = await AiCats.getById('669de24a-1da1-4fcd-84b1-9e55a43a0e0e', { responseType: 'base64' });
|
|
53
|
+
|
|
54
|
+
// Get as data URL
|
|
55
|
+
const dataUrl = await AiCats.getById('669de24a-1da1-4fcd-84b1-9e55a43a0e0e', { responseType: 'dataUrl' });
|
|
43
56
|
```
|
|
44
57
|
|
|
45
58
|
### `AiCats.getInfo(id)`
|
|
46
59
|
Get detailed information about a cat image.
|
|
47
60
|
|
|
48
61
|
```typescript
|
|
49
|
-
const info = await AiCats.getInfo('
|
|
50
|
-
console.log(info.prompt); // "
|
|
51
|
-
console.log(info.theme); // "
|
|
52
|
-
console.log(info.dateCreated); //
|
|
62
|
+
const info = await AiCats.getInfo('669de24a-1da1-4fcd-84b1-9e55a43a0e0e');
|
|
63
|
+
console.log(info.prompt); // "In a futuristic space observatory..."
|
|
64
|
+
console.log(info.theme); // "Default"
|
|
65
|
+
console.log(info.dateCreated); // 1724534067586
|
|
53
66
|
```
|
|
54
67
|
|
|
55
68
|
### `AiCats.search(options?)`
|
|
@@ -57,10 +70,10 @@ Search for cat images.
|
|
|
57
70
|
|
|
58
71
|
```typescript
|
|
59
72
|
const results = await AiCats.search({
|
|
60
|
-
query: '
|
|
61
|
-
limit: 20,
|
|
62
|
-
theme: Theme.Halloween
|
|
63
|
-
descending: true
|
|
73
|
+
query: 'rainbow', // Search text
|
|
74
|
+
limit: 20, // Max results (1-100)
|
|
75
|
+
theme: Theme.Halloween, // Filter by theme
|
|
76
|
+
descending: true // Newest first
|
|
64
77
|
});
|
|
65
78
|
|
|
66
79
|
for (const cat of results) {
|
|
@@ -72,7 +85,7 @@ for (const cat of results) {
|
|
|
72
85
|
Find cats similar to a given cat.
|
|
73
86
|
|
|
74
87
|
```typescript
|
|
75
|
-
const similar = await AiCats.getSimilar('
|
|
88
|
+
const similar = await AiCats.getSimilar('669de24a-1da1-4fcd-84b1-9e55a43a0e0e', { limit: 5 });
|
|
76
89
|
```
|
|
77
90
|
|
|
78
91
|
### `AiCats.getThemes()`
|
|
@@ -93,6 +106,14 @@ const halloweenCount = await AiCats.getCount(Theme.Halloween);
|
|
|
93
106
|
|
|
94
107
|
## Types
|
|
95
108
|
|
|
109
|
+
### ResponseType
|
|
110
|
+
```typescript
|
|
111
|
+
'blob' // Blob object (default)
|
|
112
|
+
'arrayBuffer' // ArrayBuffer
|
|
113
|
+
'base64' // Base64 encoded string
|
|
114
|
+
'dataUrl' // Data URL (data:image/jpeg;base64,...)
|
|
115
|
+
```
|
|
116
|
+
|
|
96
117
|
### Size
|
|
97
118
|
```typescript
|
|
98
119
|
Size.Large // 1024x1024 (default)
|
package/dist/index.d.mts
CHANGED
|
@@ -38,6 +38,8 @@ declare enum Theme {
|
|
|
38
38
|
interface CatInfo {
|
|
39
39
|
/** Unique identifier for the cat image */
|
|
40
40
|
id: string;
|
|
41
|
+
/** URL to access the cat image */
|
|
42
|
+
url: string;
|
|
41
43
|
/** Unix timestamp when the image was created */
|
|
42
44
|
dateCreated: number;
|
|
43
45
|
/** The AI prompt used to generate this cat image */
|
|
@@ -66,12 +68,18 @@ declare enum Size {
|
|
|
66
68
|
Micro = "16"
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
/** Response type for image requests */
|
|
72
|
+
type ResponseType = 'blob' | 'arrayBuffer' | 'base64' | 'dataUrl';
|
|
73
|
+
/** Image response based on responseType */
|
|
74
|
+
type ImageResponse<T extends ResponseType = 'blob'> = T extends 'blob' ? Blob : T extends 'arrayBuffer' ? ArrayBuffer : T extends 'base64' ? string : T extends 'dataUrl' ? string : Blob;
|
|
69
75
|
/** Options for getting a random cat */
|
|
70
|
-
interface RandomCatOptions {
|
|
76
|
+
interface RandomCatOptions<T extends ResponseType = 'blob'> {
|
|
71
77
|
/** Image size (default: Large) */
|
|
72
78
|
size?: Size;
|
|
73
79
|
/** Theme of the cat image */
|
|
74
80
|
theme?: Theme;
|
|
81
|
+
/** Response format (default: blob) */
|
|
82
|
+
responseType?: T;
|
|
75
83
|
}
|
|
76
84
|
/** Options for searching cats */
|
|
77
85
|
interface SearchOptions {
|
|
@@ -95,15 +103,22 @@ interface SimilarOptions {
|
|
|
95
103
|
/** Image size in results */
|
|
96
104
|
size?: Size;
|
|
97
105
|
}
|
|
106
|
+
/** Options for getting a cat by ID */
|
|
107
|
+
interface GetByIdOptions<T extends ResponseType = 'blob'> {
|
|
108
|
+
/** Image size (default: Large) */
|
|
109
|
+
size?: Size;
|
|
110
|
+
/** Response format (default: blob) */
|
|
111
|
+
responseType?: T;
|
|
112
|
+
}
|
|
98
113
|
|
|
99
114
|
declare const AiCats: {
|
|
100
|
-
random: (options?: RandomCatOptions) => Promise<
|
|
101
|
-
getById: (id: string,
|
|
115
|
+
random: <T extends ResponseType = "blob">(options?: RandomCatOptions<T>) => Promise<ImageResponse<T>>;
|
|
116
|
+
getById: <T extends ResponseType = "blob">(id: string, options?: GetByIdOptions<T>) => Promise<ImageResponse<T>>;
|
|
102
117
|
getInfo: (id: string) => Promise<CatInfo>;
|
|
103
118
|
search: (options?: SearchOptions) => Promise<SearchResult[]>;
|
|
104
119
|
getSimilar: (id: string, options?: SimilarOptions) => Promise<SearchResult[]>;
|
|
105
120
|
getSearchCompletion: (options?: SearchOptions) => Promise<string>;
|
|
106
|
-
getThemes: () => Promise<
|
|
121
|
+
getThemes: () => Promise<Theme[]>;
|
|
107
122
|
getCount: (theme?: Theme) => Promise<number>;
|
|
108
123
|
};
|
|
109
124
|
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ declare enum Theme {
|
|
|
38
38
|
interface CatInfo {
|
|
39
39
|
/** Unique identifier for the cat image */
|
|
40
40
|
id: string;
|
|
41
|
+
/** URL to access the cat image */
|
|
42
|
+
url: string;
|
|
41
43
|
/** Unix timestamp when the image was created */
|
|
42
44
|
dateCreated: number;
|
|
43
45
|
/** The AI prompt used to generate this cat image */
|
|
@@ -66,12 +68,18 @@ declare enum Size {
|
|
|
66
68
|
Micro = "16"
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
/** Response type for image requests */
|
|
72
|
+
type ResponseType = 'blob' | 'arrayBuffer' | 'base64' | 'dataUrl';
|
|
73
|
+
/** Image response based on responseType */
|
|
74
|
+
type ImageResponse<T extends ResponseType = 'blob'> = T extends 'blob' ? Blob : T extends 'arrayBuffer' ? ArrayBuffer : T extends 'base64' ? string : T extends 'dataUrl' ? string : Blob;
|
|
69
75
|
/** Options for getting a random cat */
|
|
70
|
-
interface RandomCatOptions {
|
|
76
|
+
interface RandomCatOptions<T extends ResponseType = 'blob'> {
|
|
71
77
|
/** Image size (default: Large) */
|
|
72
78
|
size?: Size;
|
|
73
79
|
/** Theme of the cat image */
|
|
74
80
|
theme?: Theme;
|
|
81
|
+
/** Response format (default: blob) */
|
|
82
|
+
responseType?: T;
|
|
75
83
|
}
|
|
76
84
|
/** Options for searching cats */
|
|
77
85
|
interface SearchOptions {
|
|
@@ -95,15 +103,22 @@ interface SimilarOptions {
|
|
|
95
103
|
/** Image size in results */
|
|
96
104
|
size?: Size;
|
|
97
105
|
}
|
|
106
|
+
/** Options for getting a cat by ID */
|
|
107
|
+
interface GetByIdOptions<T extends ResponseType = 'blob'> {
|
|
108
|
+
/** Image size (default: Large) */
|
|
109
|
+
size?: Size;
|
|
110
|
+
/** Response format (default: blob) */
|
|
111
|
+
responseType?: T;
|
|
112
|
+
}
|
|
98
113
|
|
|
99
114
|
declare const AiCats: {
|
|
100
|
-
random: (options?: RandomCatOptions) => Promise<
|
|
101
|
-
getById: (id: string,
|
|
115
|
+
random: <T extends ResponseType = "blob">(options?: RandomCatOptions<T>) => Promise<ImageResponse<T>>;
|
|
116
|
+
getById: <T extends ResponseType = "blob">(id: string, options?: GetByIdOptions<T>) => Promise<ImageResponse<T>>;
|
|
102
117
|
getInfo: (id: string) => Promise<CatInfo>;
|
|
103
118
|
search: (options?: SearchOptions) => Promise<SearchResult[]>;
|
|
104
119
|
getSimilar: (id: string, options?: SimilarOptions) => Promise<SearchResult[]>;
|
|
105
120
|
getSearchCompletion: (options?: SearchOptions) => Promise<string>;
|
|
106
|
-
getThemes: () => Promise<
|
|
121
|
+
getThemes: () => Promise<Theme[]>;
|
|
107
122
|
getCount: (theme?: Theme) => Promise<number>;
|
|
108
123
|
};
|
|
109
124
|
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,31 @@ var Theme = /* @__PURE__ */ ((Theme2) => {
|
|
|
54
54
|
|
|
55
55
|
// src/api/v1.api.ts
|
|
56
56
|
var ApiUrl = "https://api.ai-cats.net/v1";
|
|
57
|
+
async function toResponseType(buffer, type = "blob") {
|
|
58
|
+
switch (type) {
|
|
59
|
+
case "arrayBuffer":
|
|
60
|
+
return buffer;
|
|
61
|
+
case "base64": {
|
|
62
|
+
const bytes = new Uint8Array(buffer);
|
|
63
|
+
let binary = "";
|
|
64
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
65
|
+
binary += String.fromCharCode(bytes[i]);
|
|
66
|
+
}
|
|
67
|
+
return btoa(binary);
|
|
68
|
+
}
|
|
69
|
+
case "dataUrl": {
|
|
70
|
+
const bytes = new Uint8Array(buffer);
|
|
71
|
+
let binary = "";
|
|
72
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
73
|
+
binary += String.fromCharCode(bytes[i]);
|
|
74
|
+
}
|
|
75
|
+
return `data:image/jpeg;base64,${btoa(binary)}`;
|
|
76
|
+
}
|
|
77
|
+
case "blob":
|
|
78
|
+
default:
|
|
79
|
+
return new Blob([buffer], { type: "image/jpeg" });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
57
82
|
async function random(options) {
|
|
58
83
|
const params = new URLSearchParams();
|
|
59
84
|
if (options?.size) params.set("size", options.size);
|
|
@@ -64,15 +89,16 @@ async function random(options) {
|
|
|
64
89
|
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
65
90
|
}
|
|
66
91
|
const buffer = await response.arrayBuffer();
|
|
67
|
-
return
|
|
92
|
+
return toResponseType(buffer, options?.responseType ?? "blob");
|
|
68
93
|
}
|
|
69
|
-
async function getById(id,
|
|
94
|
+
async function getById(id, options) {
|
|
95
|
+
const size = options?.size ?? "1024" /* Large */;
|
|
70
96
|
const response = await fetch(`${ApiUrl}/cat/${id}?size=${size}`);
|
|
71
97
|
if (!response.ok) {
|
|
72
98
|
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
73
99
|
}
|
|
74
100
|
const buffer = await response.arrayBuffer();
|
|
75
|
-
return
|
|
101
|
+
return toResponseType(buffer, options?.responseType ?? "blob");
|
|
76
102
|
}
|
|
77
103
|
async function getInfo(id) {
|
|
78
104
|
const response = await fetch(`${ApiUrl}/cat/info/${id}`);
|
|
@@ -124,7 +150,7 @@ async function getSearchCompletion(options = {}) {
|
|
|
124
150
|
return data.completion;
|
|
125
151
|
}
|
|
126
152
|
async function getThemes() {
|
|
127
|
-
const response = await fetch(`${ApiUrl}/cat/
|
|
153
|
+
const response = await fetch(`${ApiUrl}/cat/theme-list`);
|
|
128
154
|
if (!response.ok) {
|
|
129
155
|
throw new Error(`Error fetching themes: ${response.statusText}`);
|
|
130
156
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -26,6 +26,31 @@ var Theme = /* @__PURE__ */ ((Theme2) => {
|
|
|
26
26
|
|
|
27
27
|
// src/api/v1.api.ts
|
|
28
28
|
var ApiUrl = "https://api.ai-cats.net/v1";
|
|
29
|
+
async function toResponseType(buffer, type = "blob") {
|
|
30
|
+
switch (type) {
|
|
31
|
+
case "arrayBuffer":
|
|
32
|
+
return buffer;
|
|
33
|
+
case "base64": {
|
|
34
|
+
const bytes = new Uint8Array(buffer);
|
|
35
|
+
let binary = "";
|
|
36
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
37
|
+
binary += String.fromCharCode(bytes[i]);
|
|
38
|
+
}
|
|
39
|
+
return btoa(binary);
|
|
40
|
+
}
|
|
41
|
+
case "dataUrl": {
|
|
42
|
+
const bytes = new Uint8Array(buffer);
|
|
43
|
+
let binary = "";
|
|
44
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
45
|
+
binary += String.fromCharCode(bytes[i]);
|
|
46
|
+
}
|
|
47
|
+
return `data:image/jpeg;base64,${btoa(binary)}`;
|
|
48
|
+
}
|
|
49
|
+
case "blob":
|
|
50
|
+
default:
|
|
51
|
+
return new Blob([buffer], { type: "image/jpeg" });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
29
54
|
async function random(options) {
|
|
30
55
|
const params = new URLSearchParams();
|
|
31
56
|
if (options?.size) params.set("size", options.size);
|
|
@@ -36,15 +61,16 @@ async function random(options) {
|
|
|
36
61
|
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
37
62
|
}
|
|
38
63
|
const buffer = await response.arrayBuffer();
|
|
39
|
-
return
|
|
64
|
+
return toResponseType(buffer, options?.responseType ?? "blob");
|
|
40
65
|
}
|
|
41
|
-
async function getById(id,
|
|
66
|
+
async function getById(id, options) {
|
|
67
|
+
const size = options?.size ?? "1024" /* Large */;
|
|
42
68
|
const response = await fetch(`${ApiUrl}/cat/${id}?size=${size}`);
|
|
43
69
|
if (!response.ok) {
|
|
44
70
|
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
45
71
|
}
|
|
46
72
|
const buffer = await response.arrayBuffer();
|
|
47
|
-
return
|
|
73
|
+
return toResponseType(buffer, options?.responseType ?? "blob");
|
|
48
74
|
}
|
|
49
75
|
async function getInfo(id) {
|
|
50
76
|
const response = await fetch(`${ApiUrl}/cat/info/${id}`);
|
|
@@ -96,7 +122,7 @@ async function getSearchCompletion(options = {}) {
|
|
|
96
122
|
return data.completion;
|
|
97
123
|
}
|
|
98
124
|
async function getThemes() {
|
|
99
|
-
const response = await fetch(`${ApiUrl}/cat/
|
|
125
|
+
const response = await fetch(`${ApiUrl}/cat/theme-list`);
|
|
100
126
|
if (!response.ok) {
|
|
101
127
|
throw new Error(`Error fetching themes: ${response.statusText}`);
|
|
102
128
|
}
|