aimakeall-mcp 0.3.0 → 0.4.0
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 +1 -1
- package/lib/cloud-tools.mjs +110 -7
- package/lib/config.mjs +1 -1
- package/lib/media-store.mjs +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/cloud-tools.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
fileToDataUrl,
|
|
15
15
|
fileToImagePayload,
|
|
16
16
|
guessMimeType,
|
|
17
|
+
saveExportBuffer,
|
|
17
18
|
saveMediaBuffer,
|
|
18
19
|
savePayloadHandle,
|
|
19
20
|
SERVER_JSON_BODY_LIMIT_BYTES,
|
|
@@ -46,6 +47,26 @@ function decodeHeaderValue(value) {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
// 상품 이미지 URL 클라이언트 가드 — 서버가 1차 필터하지만 이 코드는 사용자 PC 에서
|
|
51
|
+
// 돌므로, 악성 페이지가 심은 내부망 URL(127.0.0.1:9876 컴패니언 등) fetch 를 이중 차단.
|
|
52
|
+
function isSafePublicImageUrl(rawUrl) {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = new URL(String(rawUrl || ""));
|
|
55
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
|
|
56
|
+
const host = parsed.hostname.toLowerCase();
|
|
57
|
+
if (!host || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal")) return false;
|
|
58
|
+
if (host.includes(":") || host.startsWith("[")) return false; // IPv6 리터럴은 스킵 (이미지 CDN 에 불필요)
|
|
59
|
+
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(host)) {
|
|
60
|
+
const [a, b] = host.split(".").map(Number);
|
|
61
|
+
if (a === 0 || a === 10 || a === 127 || (a === 100 && b >= 64 && b <= 127) || (a === 169 && b === 254)
|
|
62
|
+
|| (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || a >= 224) return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
49
70
|
// 실측 mp3 길이(초) — 파싱 실패 시에만 CBR-128 근사로 폴백.
|
|
50
71
|
function audioDurationSecFromFile(filePath) {
|
|
51
72
|
try {
|
|
@@ -165,6 +186,83 @@ export function registerCloudTools(server, config, api) {
|
|
|
165
186
|
}),
|
|
166
187
|
);
|
|
167
188
|
|
|
189
|
+
server.tool(
|
|
190
|
+
"research_product",
|
|
191
|
+
"상품 링크로 리뷰 기반 시장조사를 합니다: 구매자 불만 TOP3(근거 리뷰 인용)·첫 3초 후킹 패턴·경쟁 광고 공백·핵심 USP·금지 표현. 결과의 planBrief는 plan_commerce_video의 researchBrief로, productImagePaths는 productImagePaths로 그대로 이어가세요. 사이트가 서버 접근을 차단하면(fetchBlocked 안내) 에이전트가 직접 상품 페이지·리뷰를 읽어 pageText/reviewsText로 다시 호출하세요.",
|
|
192
|
+
{
|
|
193
|
+
productUrl: z.string().optional().describe("상품 페이지 URL (아마존·쇼핑몰 등)"),
|
|
194
|
+
productName: z.string().optional().describe("상품명 (URL 없이 텍스트만 넘길 때)"),
|
|
195
|
+
pageText: z.string().optional().describe("에이전트가 직접 읽은 상품 페이지 텍스트 (봇 차단 폴백)"),
|
|
196
|
+
reviewsText: z.string().optional().describe("에이전트가 수집한 구매 후기 텍스트 (봇 차단 폴백)"),
|
|
197
|
+
downloadImages: z.boolean().optional().describe("기본 true — 상품 이미지를 로컬 저장해 plan_commerce_video용 경로 반환"),
|
|
198
|
+
},
|
|
199
|
+
wrapCloudHandler(config, async ({ productUrl = "", productName = "", pageText = "", reviewsText = "", downloadImages = true }) => {
|
|
200
|
+
if (!productUrl.trim() && !pageText.trim() && !reviewsText.trim()) {
|
|
201
|
+
return textResult("productUrl 또는 pageText/reviewsText 중 하나는 필요합니다.", { isError: true });
|
|
202
|
+
}
|
|
203
|
+
const payload = await api.request("/api/tracker/commerce/product-research", {
|
|
204
|
+
body: { pageText, productName, reviewsText, url: productUrl },
|
|
205
|
+
method: "POST",
|
|
206
|
+
timeoutMs: 120_000,
|
|
207
|
+
});
|
|
208
|
+
if (!payload?.ok) {
|
|
209
|
+
return textResult(
|
|
210
|
+
`리서치 자료를 얻지 못했습니다: ${payload?.error || "자료 없음"}\n${payload?.guidance || ""}`,
|
|
211
|
+
{ isError: true },
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
const productImagePaths = [];
|
|
215
|
+
if (downloadImages) {
|
|
216
|
+
const EXT_BY_SUBTYPE = { jpeg: "jpg", jpg: "jpg", png: "png", webp: "webp" };
|
|
217
|
+
for (const imageUrl of (Array.isArray(payload?.product?.imageUrls) ? payload.product.imageUrls : []).slice(0, 5)) {
|
|
218
|
+
if (!isSafePublicImageUrl(imageUrl)) continue;
|
|
219
|
+
try {
|
|
220
|
+
// redirect 미추적 — CDN 이 내부 주소로 리다이렉트시키는 우회 차단.
|
|
221
|
+
const res = await fetch(imageUrl, { redirect: "manual", signal: AbortSignal.timeout(30_000) });
|
|
222
|
+
if (!res.ok) continue;
|
|
223
|
+
const contentType = String(res.headers.get("content-type") || "").toLowerCase();
|
|
224
|
+
const subtype = contentType.startsWith("image/") ? contentType.slice(6).split(";")[0].trim() : "";
|
|
225
|
+
const ext = EXT_BY_SUBTYPE[subtype];
|
|
226
|
+
if (!ext) continue; // 이미지가 아니거나(HTML/SVG 등) 미지원 포맷
|
|
227
|
+
// 스트리밍 캡 — 전체 버퍼링 전에 8MB 에서 중단.
|
|
228
|
+
const parts = [];
|
|
229
|
+
let received = 0;
|
|
230
|
+
let tooLarge = false;
|
|
231
|
+
for await (const chunk of res.body) {
|
|
232
|
+
const piece = Buffer.from(chunk);
|
|
233
|
+
received += piece.length;
|
|
234
|
+
if (received > 8 * 1024 * 1024) {
|
|
235
|
+
tooLarge = true;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
parts.push(piece);
|
|
239
|
+
}
|
|
240
|
+
if (tooLarge || !received) continue;
|
|
241
|
+
const saved = saveMediaBuffer(config.stateDir, `product-${productImagePaths.length + 1}.${ext}`, Buffer.concat(parts));
|
|
242
|
+
productImagePaths.push(saved.filePath);
|
|
243
|
+
} catch {
|
|
244
|
+
// 이미지 한 장 실패는 무시
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return jsonResult({
|
|
249
|
+
fetchBlocked: payload?.fetchBlocked || false,
|
|
250
|
+
next: productImagePaths.length
|
|
251
|
+
? "plan_commerce_video에 productImagePaths와 researchBrief(planBrief)를 그대로 넘기세요."
|
|
252
|
+
: "상품 이미지를 확보하지 못했습니다 — 에이전트가 상품 사진을 로컬에 저장해 그 경로로 plan_commerce_video를 호출하세요 (researchBrief는 planBrief 사용).",
|
|
253
|
+
planBrief: payload?.planBrief,
|
|
254
|
+
product: {
|
|
255
|
+
imageCount: (Array.isArray(payload?.product?.imageUrls) ? payload.product.imageUrls : []).length,
|
|
256
|
+
name: payload?.product?.name,
|
|
257
|
+
price: payload?.product?.price,
|
|
258
|
+
reviewCount: payload?.product?.reviewCount,
|
|
259
|
+
},
|
|
260
|
+
productImagePaths,
|
|
261
|
+
research: payload?.research,
|
|
262
|
+
});
|
|
263
|
+
}),
|
|
264
|
+
);
|
|
265
|
+
|
|
168
266
|
server.tool(
|
|
169
267
|
"plan_commerce_video",
|
|
170
268
|
"제품 홍보 영상 기획을 생성합니다. 제품 사진 파일 경로가 최소 1장 필요합니다 (이 PC의 로컬 경로).",
|
|
@@ -177,8 +275,9 @@ export function registerCloudTools(server, config, api) {
|
|
|
177
275
|
tone: z.string().optional().describe("기본 '자동 추천'"),
|
|
178
276
|
categoryId: z.string().optional().describe("기본 ecommerce"),
|
|
179
277
|
sceneCount: z.number().int().min(1).max(12).optional().describe("기본 6"),
|
|
278
|
+
researchBrief: z.string().optional().describe("research_product 결과의 planBrief — 불만·후킹·경쟁공백이 기획에 반영됨"),
|
|
180
279
|
},
|
|
181
|
-
wrapCloudHandler(config, async ({ productName, productImagePaths, modelImagePath = "", description = "", targetCustomer = "", tone = "자동 추천", categoryId = "ecommerce", sceneCount = 6 }) => {
|
|
280
|
+
wrapCloudHandler(config, async ({ productName, productImagePaths, modelImagePath = "", description = "", targetCustomer = "", tone = "자동 추천", categoryId = "ecommerce", sceneCount = 6, researchBrief = "" }) => {
|
|
182
281
|
// 확장자 검증(임의 파일 업로드 차단) + 합산 크기 예산(서버 413 사전 차단).
|
|
183
282
|
for (const filePath of productImagePaths) assertAllowedInputFile(filePath, ALLOWED_IMAGE_EXTS, { kind: "이미지" });
|
|
184
283
|
if (modelImagePath) assertAllowedInputFile(modelImagePath, ALLOWED_IMAGE_EXTS, { kind: "모델 이미지" });
|
|
@@ -192,6 +291,7 @@ export function registerCloudTools(server, config, api) {
|
|
|
192
291
|
operationId: createUsageEventId("commerce-plan"),
|
|
193
292
|
productImages: productImagePaths.map((filePath) => fileToImagePayload(filePath)),
|
|
194
293
|
productName,
|
|
294
|
+
researchBrief,
|
|
195
295
|
sceneCount,
|
|
196
296
|
selectedCharacters: [],
|
|
197
297
|
skillOverride: null,
|
|
@@ -1252,30 +1352,33 @@ export function registerCloudTools(server, config, api) {
|
|
|
1252
1352
|
for (const image of Array.isArray(result.lifestyleImages) ? result.lifestyleImages : []) {
|
|
1253
1353
|
const url = String(image?.url || "");
|
|
1254
1354
|
if (!url) continue;
|
|
1355
|
+
// HTML 이 실제로 참조하는 컷만 받는다 — 조립에서 빠진 컷을 받아 저장하면
|
|
1356
|
+
// 정리되지 않는 exports/ 에 고아 파일이 영구히 쌓인다.
|
|
1357
|
+
const escaped = escapeHtml(url);
|
|
1358
|
+
if (!html.includes(url) && !html.includes(escaped)) continue;
|
|
1255
1359
|
try {
|
|
1256
1360
|
const res = await fetch(url, { signal: AbortSignal.timeout(60_000) });
|
|
1257
1361
|
if (!res.ok) continue;
|
|
1258
1362
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
1259
1363
|
const ext = String(res.headers.get("content-type") || "").includes("png") ? "png" : "jpg";
|
|
1260
|
-
const saved =
|
|
1364
|
+
const saved = saveExportBuffer(config.stateDir, `pdp-image-${image?.idx ?? savedImages.length + 1}.${ext}`, buf);
|
|
1261
1365
|
// HTML 은 같은 디렉터리에 저장되므로 상대경로 치환으로 자립형 유지.
|
|
1262
1366
|
const local = `./${path.basename(saved.filePath)}`;
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
if (html !== before) savedImages.push(saved.filePath);
|
|
1367
|
+
html = html.split(url).join(local).split(escaped).join(local);
|
|
1368
|
+
savedImages.push(saved.filePath);
|
|
1266
1369
|
} catch {
|
|
1267
1370
|
// 다운로드 실패한 컷은 원격 URL 유지
|
|
1268
1371
|
}
|
|
1269
1372
|
}
|
|
1270
1373
|
}
|
|
1271
|
-
const savedHtml =
|
|
1374
|
+
const savedHtml = saveExportBuffer(config.stateDir, "pdp.html", Buffer.from(html, "utf8"), { contentType: "text/html" });
|
|
1272
1375
|
return jsonResult({
|
|
1273
1376
|
analysis: trimAnalysis(result.analysis),
|
|
1274
1377
|
heroHeadline: result?.copy?.heroHeadline,
|
|
1275
1378
|
htmlPath: savedHtml.filePath,
|
|
1276
1379
|
imageCount: (Array.isArray(result.lifestyleImages) ? result.lifestyleImages : []).filter((image) => image?.url).length,
|
|
1277
1380
|
localImages: savedImages.length,
|
|
1278
|
-
note: "htmlPath와 로컬
|
|
1381
|
+
note: "htmlPath와 로컬 이미지는 자동 정리되지 않는 exports 폴더에 저장됩니다. 옮길 때는 같은 폴더의 이미지들과 함께 이동하세요(상대경로 참조).",
|
|
1279
1382
|
tagline: result?.copy?.tagline,
|
|
1280
1383
|
});
|
|
1281
1384
|
}),
|
package/lib/config.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { homedir } from "node:os";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
4
|
// 프록시 버전 — 서버가 X-AImakeAll-MCP-Version 으로 하한을 강제(426)할 수 있다.
|
|
5
|
-
export const MCP_PROXY_VERSION = "0.
|
|
5
|
+
export const MCP_PROXY_VERSION = "0.4.0";
|
|
6
6
|
|
|
7
7
|
export const DEFAULT_API_BASE = "https://aimakeall.com";
|
|
8
8
|
export const DEFAULT_COMPANION_URL = "http://127.0.0.1:9876";
|
package/lib/media-store.mjs
CHANGED
|
@@ -114,6 +114,17 @@ export function readPayloadHandle(filePath, { stateDir = "" } = {}) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
// 보존 기간이 지난 스테이징 미디어 정리 — 숨김 디렉터리에 GB 단위로 쌓이는 것 방지.
|
|
117
|
+
// 최종 산출물(PDP HTML 등)용 보존 디렉터리 — pruneOldMedia(48h TTL)는 media/ 만
|
|
118
|
+
// 정리하므로 exports/ 는 자동 삭제되지 않는다.
|
|
119
|
+
export function saveExportBuffer(stateDir, name, buffer, { contentType = "" } = {}) {
|
|
120
|
+
const dir = path.join(stateDir, "exports");
|
|
121
|
+
mkdirSync(dir, { recursive: true });
|
|
122
|
+
const safeName = sanitizeOutputFilename(name, "export");
|
|
123
|
+
const filePath = path.join(dir, `${Date.now()}-${randomUUID().slice(0, 8)}-${safeName}`);
|
|
124
|
+
writeFileSync(filePath, buffer, { flag: "wx", mode: 0o600 });
|
|
125
|
+
return { bytes: buffer.length, contentType, filePath };
|
|
126
|
+
}
|
|
127
|
+
|
|
117
128
|
export function pruneOldMedia(stateDir, { now = Date.now() } = {}) {
|
|
118
129
|
const dir = mediaDir(stateDir);
|
|
119
130
|
let removed = 0;
|