modelscope-image-mcp 1.0.1 → 1.0.2
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/package.json +1 -1
- package/server.js +16 -4
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -125,7 +125,17 @@ async function waitTask(taskId, timeoutMs = TASK_TIMEOUT_MS) {
|
|
|
125
125
|
throw new Error(`任务超时(${Math.round(timeoutMs / 1000)}s),可调大 MODELSCOPE_TIMEOUT_MS`);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
/** 把模型 ID 压成适合做文件名的短标识:black-forest-labs/FLUX.1-Krea-dev -> flux-1-krea-dev */
|
|
129
|
+
function modelSlug(model) {
|
|
130
|
+
return String(model)
|
|
131
|
+
.split("/")
|
|
132
|
+
.pop()
|
|
133
|
+
.toLowerCase()
|
|
134
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
135
|
+
.replace(/^-+|-+$/g, "");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function downloadImage(url, dir, tag = "") {
|
|
129
139
|
const res = await fetch(url);
|
|
130
140
|
if (!res.ok) throw new Error(`下载图片失败:HTTP ${res.status} ${url}`);
|
|
131
141
|
|
|
@@ -140,7 +150,8 @@ async function downloadImage(url, dir) {
|
|
|
140
150
|
/* 忽略,用默认后缀 */
|
|
141
151
|
}
|
|
142
152
|
|
|
143
|
-
const
|
|
153
|
+
const prefix = tag ? `ms-${tag}` : "ms";
|
|
154
|
+
const file = path.join(dir, `${prefix}-${timestamp()}-${Math.floor(Math.random() * 1e4)}${ext}`);
|
|
144
155
|
await fs.promises.writeFile(file, buf);
|
|
145
156
|
return file;
|
|
146
157
|
}
|
|
@@ -177,9 +188,10 @@ async function runGeneration({ model, prompt, negativePrompt, size, seed, image,
|
|
|
177
188
|
const urls = (Array.isArray(raw) ? raw : [raw]).filter(Boolean);
|
|
178
189
|
|
|
179
190
|
const dir = outputDir || OUTPUT_DIR;
|
|
191
|
+
const tag = modelSlug(model);
|
|
180
192
|
const files = [];
|
|
181
193
|
for (const url of urls) {
|
|
182
|
-
files.push(await downloadImage(url, dir));
|
|
194
|
+
files.push(await downloadImage(url, dir, tag));
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
return { taskId, files, urls, model };
|
|
@@ -330,7 +342,7 @@ async function handleMessage(msg) {
|
|
|
330
342
|
reply(id, {
|
|
331
343
|
protocolVersion: params?.protocolVersion || "2024-11-05",
|
|
332
344
|
capabilities: { tools: {} },
|
|
333
|
-
serverInfo: { name: "modelscope-image-mcp", version: "1.0.
|
|
345
|
+
serverInfo: { name: "modelscope-image-mcp", version: "1.0.2" },
|
|
334
346
|
});
|
|
335
347
|
return;
|
|
336
348
|
|