call-ai 0.18.19-dev → 0.18.23-dev
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/image.js +66 -97
- package/image.js.map +1 -1
- package/package.json +3 -9
- package/types.d.ts +1 -0
package/image.js
CHANGED
|
@@ -1,111 +1,80 @@
|
|
|
1
1
|
import { callAiFetch, joinUrlParts } from "./utils.js";
|
|
2
2
|
import { callAiEnv } from "./env.js";
|
|
3
|
-
import { PACKAGE_VERSION } from "./version.js";
|
|
4
3
|
export async function imageGen(prompt, options = {}) {
|
|
5
|
-
const { model = "gpt-image-1", apiKey = callAiEnv.CALLAI_API_KEY,
|
|
4
|
+
const { model = "gpt-image-1", apiKey = callAiEnv.CALLAI_API_KEY, size = "1024x1024" } = options;
|
|
6
5
|
if (!apiKey) {
|
|
7
6
|
throw new Error("API key is required for image generation. Provide via options.apiKey or set window.CALLAI_API_KEY");
|
|
8
7
|
}
|
|
9
|
-
if (debug) {
|
|
10
|
-
console.log(`[imageGen:${PACKAGE_VERSION}] Generating image with prompt: ${prompt.substring(0, 50)}...`);
|
|
11
|
-
console.log(`[imageGen:${PACKAGE_VERSION}] Using model: ${model}`);
|
|
12
|
-
}
|
|
13
8
|
const customOrigin = options.imgUrl || callAiEnv.CALLAI_IMG_URL;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
console.log(`[imageGen:${PACKAGE_VERSION}] Raw response:`, responseText.substring(0, 500) + "...");
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const result = JSON.parse(responseText);
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
catch (parseError) {
|
|
49
|
-
if (debug) {
|
|
50
|
-
console.error(`[imageGen:${PACKAGE_VERSION}] JSON Parse Error:`, parseError);
|
|
51
|
-
console.error(`[imageGen:${PACKAGE_VERSION}] Response text length:`, responseText.length);
|
|
52
|
-
console.error(`[imageGen:${PACKAGE_VERSION}] Response sample:`, responseText.substring(0, 1000));
|
|
53
|
-
}
|
|
54
|
-
throw new Error(`Failed to parse JSON response: ${parseError instanceof Error ? parseError.message : "Unknown error"}`);
|
|
55
|
-
}
|
|
9
|
+
if (!options.images || options.images.length === 0) {
|
|
10
|
+
const generateEndpoint = options.endpoint || joinUrlParts(customOrigin || callAiEnv.def.CALLAI_CHAT_URL, "/api/openai-image/generate");
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw new Error("API key is required for image generation (simple)");
|
|
13
|
+
}
|
|
14
|
+
const headers = new Headers({
|
|
15
|
+
Authorization: `Bearer ${apiKey}`,
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
});
|
|
18
|
+
const response = await callAiFetch(options)(generateEndpoint, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers,
|
|
21
|
+
body: JSON.stringify({
|
|
22
|
+
model,
|
|
23
|
+
prompt,
|
|
24
|
+
size,
|
|
25
|
+
...(options.quality && { quality: options.quality }),
|
|
26
|
+
...(options.style && { style: options.style }),
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
const errorData = await response.text();
|
|
31
|
+
throw new Error(`Image generation failed: ${response.status} ${response.statusText} - ${errorData}`);
|
|
32
|
+
}
|
|
33
|
+
const responseText = await response.text();
|
|
34
|
+
try {
|
|
35
|
+
const result = JSON.parse(responseText);
|
|
36
|
+
return result;
|
|
56
37
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
formData.append("model", model);
|
|
60
|
-
formData.append("prompt", prompt);
|
|
61
|
-
options.images.forEach((image, index) => {
|
|
62
|
-
formData.append(`image_${index}`, image);
|
|
63
|
-
});
|
|
64
|
-
formData.append("size", size);
|
|
65
|
-
if (options.quality)
|
|
66
|
-
formData.append("quality", options.quality);
|
|
67
|
-
if (options.style)
|
|
68
|
-
formData.append("style", options.style);
|
|
69
|
-
const origin = customOrigin || callAiEnv.def.CALLAI_CHAT_URL;
|
|
70
|
-
const editEndpoint = joinUrlParts(origin, "/api/openai-image/edit");
|
|
71
|
-
if (!apiKey) {
|
|
72
|
-
throw new Error("API key is required for image generation (edit)");
|
|
73
|
-
}
|
|
74
|
-
const headers = new Headers({
|
|
75
|
-
Authorization: `Bearer ${apiKey}`,
|
|
76
|
-
});
|
|
77
|
-
const response = await callAiFetch(options)(editEndpoint, {
|
|
78
|
-
method: "POST",
|
|
79
|
-
headers,
|
|
80
|
-
body: formData,
|
|
81
|
-
});
|
|
82
|
-
if (!response.ok) {
|
|
83
|
-
const errorData = await response.text();
|
|
84
|
-
throw new Error(`Image editing failed: ${response.status} ${response.statusText} - ${errorData}`);
|
|
85
|
-
}
|
|
86
|
-
const responseText = await response.text();
|
|
87
|
-
if (debug) {
|
|
88
|
-
console.log(`[imageGen:${PACKAGE_VERSION}] Raw response:`, responseText.substring(0, 500) + "...");
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
const result = JSON.parse(responseText);
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
catch (parseError) {
|
|
95
|
-
if (debug) {
|
|
96
|
-
console.error(`[imageGen:${PACKAGE_VERSION}] JSON Parse Error:`, parseError);
|
|
97
|
-
console.error(`[imageGen:${PACKAGE_VERSION}] Response text length:`, responseText.length);
|
|
98
|
-
console.error(`[imageGen:${PACKAGE_VERSION}] Response sample:`, responseText.substring(0, 1000));
|
|
99
|
-
}
|
|
100
|
-
throw new Error(`Failed to parse JSON response: ${parseError instanceof Error ? parseError.message : "Unknown error"}`);
|
|
101
|
-
}
|
|
38
|
+
catch (parseError) {
|
|
39
|
+
throw new Error(`Failed to parse JSON response: ${parseError instanceof Error ? parseError.message : "Unknown error"}`);
|
|
102
40
|
}
|
|
103
41
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
42
|
+
else {
|
|
43
|
+
const formData = new FormData();
|
|
44
|
+
formData.append("model", model);
|
|
45
|
+
formData.append("prompt", prompt);
|
|
46
|
+
options.images.forEach((image, index) => {
|
|
47
|
+
formData.append(`image_${index}`, image);
|
|
48
|
+
});
|
|
49
|
+
formData.append("size", size);
|
|
50
|
+
if (options.quality)
|
|
51
|
+
formData.append("quality", options.quality);
|
|
52
|
+
if (options.style)
|
|
53
|
+
formData.append("style", options.style);
|
|
54
|
+
const editEndpoint = options.endpoint || joinUrlParts(customOrigin || callAiEnv.def.CALLAI_CHAT_URL, "/api/openai-image/edit");
|
|
55
|
+
if (!apiKey) {
|
|
56
|
+
throw new Error("API key is required for image generation (edit)");
|
|
57
|
+
}
|
|
58
|
+
const headers = new Headers({
|
|
59
|
+
Authorization: `Bearer ${apiKey}`,
|
|
60
|
+
});
|
|
61
|
+
const response = await callAiFetch(options)(editEndpoint, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers,
|
|
64
|
+
body: formData,
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const errorData = await response.text();
|
|
68
|
+
throw new Error(`Image editing failed: ${response.status} ${response.statusText} - ${errorData}`);
|
|
69
|
+
}
|
|
70
|
+
const responseText = await response.text();
|
|
71
|
+
try {
|
|
72
|
+
const result = JSON.parse(responseText);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
catch (parseError) {
|
|
76
|
+
throw new Error(`Failed to parse JSON response: ${parseError instanceof Error ? parseError.message : "Unknown error"}`);
|
|
107
77
|
}
|
|
108
|
-
throw error;
|
|
109
78
|
}
|
|
110
79
|
}
|
|
111
80
|
//# sourceMappingURL=image.js.map
|
package/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../jsr/image.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../jsr/image.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAQrC,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,OAAO,GAAoB,EAAE,EAA0B;IACpG,MAAM,EAAE,KAAK,GAAG,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC,cAAc,EAAE,IAAI,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAEjG,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,mGAAmG,CAAC,CAAC;IACvH,CAAC;IAGD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,cAAc,CAAC;IAGhE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAGnD,MAAM,gBAAgB,GACpB,OAAO,CAAC,QAAQ,IAAI,YAAY,CAAC,YAAY,IAAI,SAAS,CAAC,GAAG,CAAC,eAAe,EAAE,4BAA4B,CAAC,CAAC;QAEhH,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QAGD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;YAC1B,aAAa,EAAE,UAAU,MAAM,EAAE;YACjC,cAAc,EAAE,kBAAkB;SACnC,CAAC,CAAC;QAE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I,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACxC,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,kCAAkC,UAAU,YAAY,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;QAC1H,CAAC;IACH,CAAC;AAAA,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "call-ai",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.23-dev",
|
|
4
4
|
"description": "Lightweight library for making AI API calls with streaming support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -25,18 +25,12 @@
|
|
|
25
25
|
"Meno Abels"
|
|
26
26
|
],
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@fireproof/core-cli": "^0.23.15",
|
|
30
|
-
"@types/node": "^24.9.1",
|
|
31
|
-
"@vitest/browser-playwright": "^4.0.10",
|
|
32
|
-
"typescript": "^5.9.3"
|
|
33
|
-
},
|
|
34
28
|
"engines": {
|
|
35
29
|
"node": ">=20.0.0"
|
|
36
30
|
},
|
|
37
31
|
"dependencies": {
|
|
38
|
-
"@adviser/cement": "
|
|
39
|
-
"@fireproof/core-runtime": "
|
|
32
|
+
"@adviser/cement": "0.5.2",
|
|
33
|
+
"@fireproof/core-runtime": "0.24.0"
|
|
40
34
|
},
|
|
41
35
|
"scripts": {
|
|
42
36
|
"build": "core-cli tsc"
|