yzsd-image 1.0.2 → 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.
Files changed (2) hide show
  1. package/dist/index.js +35 -12
  2. package/package.json +1 -1
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 response = await axios.post(`${API_BASE_URL}/v1/images/generate`, {
143
- prompt,
144
- aspect_ratio: aspectRatio,
145
- size,
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.image || response.data.data?.[0]?.b64_json;
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 response = await axios.post(`${API_BASE_URL}/v1/images/edit`, {
179
- image: base64Image,
180
- prompt,
181
- aspect_ratio: aspectRatio,
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.image || response.data.data?.[0]?.b64_json;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yzsd-image",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "YZSD AI 图片生成 MCP 服务器 - 支持文生图和图生图编辑",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",