yzsd-image 1.0.2 → 1.0.4
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 +3 -3
- package/dist/index.js +35 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ YZSD AI 图片生成 MCP 服务器。通过 Model Context Protocol 使用 AI 生
|
|
|
22
22
|
"yzsd-image": {
|
|
23
23
|
"type": "stdio",
|
|
24
24
|
"command": "npx",
|
|
25
|
-
"args": ["-y", "yzsd-image"],
|
|
25
|
+
"args": ["-y", "yzsd-image@latest"],
|
|
26
26
|
"env": {
|
|
27
27
|
"YZSD_API_KEY": "your-api-key-here"
|
|
28
28
|
}
|
|
@@ -70,7 +70,7 @@ npm install -g yzsd-image
|
|
|
70
70
|
"yzsd-image": {
|
|
71
71
|
"type": "stdio",
|
|
72
72
|
"command": "npx",
|
|
73
|
-
"args": ["-y", "yzsd-image"],
|
|
73
|
+
"args": ["-y", "yzsd-image@latest"],
|
|
74
74
|
"env": {
|
|
75
75
|
"YZSD_API_KEY": "your-api-key-here"
|
|
76
76
|
}
|
|
@@ -88,7 +88,7 @@ npm install -g yzsd-image
|
|
|
88
88
|
"yzsd-image": {
|
|
89
89
|
"type": "stdio",
|
|
90
90
|
"command": "npx",
|
|
91
|
-
"args": ["-y", "yzsd-image"],
|
|
91
|
+
"args": ["-y", "yzsd-image@latest"],
|
|
92
92
|
"env": {
|
|
93
93
|
"YZSD_API_KEY": "your-api-key-here"
|
|
94
94
|
}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import axios from "axios";
|
|
|
6
6
|
import * as fs from "fs/promises";
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
const API_BASE_URL = "https://token.1001xr.asia:8443";
|
|
9
|
+
const MODEL_PATH = "/v1beta/models/gemini-3-pro-image-preview:generateContent";
|
|
9
10
|
const VALID_ASPECT_RATIOS = [
|
|
10
11
|
"1:1", "16:9", "9:16", "4:3", "3:4",
|
|
11
12
|
"3:2", "2:3", "21:9", "5:4", "4:5"
|
|
@@ -139,18 +140,24 @@ class YZSDImageServer {
|
|
|
139
140
|
if (!VALID_SIZES.includes(size)) {
|
|
140
141
|
throw new Error(`Invalid size. Must be one of: ${VALID_SIZES.join(", ")}`);
|
|
141
142
|
}
|
|
142
|
-
const
|
|
143
|
-
prompt,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
const payload = {
|
|
144
|
+
contents: [{ parts: [{ text: prompt }] }],
|
|
145
|
+
generationConfig: {
|
|
146
|
+
responseModalities: ["IMAGE"],
|
|
147
|
+
imageConfig: {
|
|
148
|
+
aspectRatio: aspectRatio,
|
|
149
|
+
image_size: size,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
const response = await axios.post(`${API_BASE_URL}${MODEL_PATH}`, payload, {
|
|
147
154
|
headers: {
|
|
148
155
|
"Authorization": `Bearer ${key}`,
|
|
149
156
|
"Content-Type": "application/json",
|
|
150
157
|
},
|
|
151
158
|
timeout: size === "4K" ? 120000 : size === "2K" ? 60000 : 30000,
|
|
152
159
|
});
|
|
153
|
-
const imageData = response.data.
|
|
160
|
+
const imageData = response.data.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;
|
|
154
161
|
if (!imageData) {
|
|
155
162
|
throw new Error("No image data in response");
|
|
156
163
|
}
|
|
@@ -175,18 +182,34 @@ class YZSDImageServer {
|
|
|
175
182
|
}
|
|
176
183
|
const imageBuffer = await fs.readFile(inputPath);
|
|
177
184
|
const base64Image = imageBuffer.toString("base64");
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
185
|
+
const mimeType = inputPath.toLowerCase().endsWith('.png') ? 'image/png' : 'image/jpeg';
|
|
186
|
+
const payload = {
|
|
187
|
+
contents: [{
|
|
188
|
+
parts: [
|
|
189
|
+
{
|
|
190
|
+
inlineData: {
|
|
191
|
+
mimeType: mimeType,
|
|
192
|
+
data: base64Image,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
{ text: prompt },
|
|
196
|
+
],
|
|
197
|
+
}],
|
|
198
|
+
generationConfig: {
|
|
199
|
+
responseModalities: ["IMAGE"],
|
|
200
|
+
imageConfig: {
|
|
201
|
+
aspectRatio: aspectRatio,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
const response = await axios.post(`${API_BASE_URL}${MODEL_PATH}`, payload, {
|
|
183
206
|
headers: {
|
|
184
207
|
"Authorization": `Bearer ${key}`,
|
|
185
208
|
"Content-Type": "application/json",
|
|
186
209
|
},
|
|
187
210
|
timeout: 120000,
|
|
188
211
|
});
|
|
189
|
-
const imageData = response.data.
|
|
212
|
+
const imageData = response.data.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;
|
|
190
213
|
if (!imageData) {
|
|
191
214
|
throw new Error("No image data in response");
|
|
192
215
|
}
|