aimakeall-mcp 0.2.0 → 0.3.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/api-client.mjs +73 -1
- package/lib/cloud-tools.mjs +281 -0
- package/lib/config.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/api-client.mjs
CHANGED
|
@@ -139,5 +139,77 @@ export function createApiClient({ apiBase, pat }) {
|
|
|
139
139
|
return payload;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
// SSE(text/event-stream) 라우트 — `data: {json}` 프레임을 순서대로 파싱한다.
|
|
143
|
+
// 서버는 게이트(인증/플랜/기계정책) 실패는 SSE 이전 일반 JSON 으로, 그 이후의
|
|
144
|
+
// 실패는 HTTP 200 스트림 안 {type:"error"} 프레임으로 보낸다. 둘 다 예외로 변환.
|
|
145
|
+
async function requestSse(pathName, { body, timeoutMs = DEFAULT_TIMEOUT_MS, onEvent } = {}) {
|
|
146
|
+
const response = await fetch(`${apiBase}${pathName}`, {
|
|
147
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: `Bearer ${pat}`,
|
|
150
|
+
"X-AImakeAll-MCP-Version": MCP_PROXY_VERSION,
|
|
151
|
+
...(body !== undefined ? { "Content-Type": "application/json" } : {}),
|
|
152
|
+
},
|
|
153
|
+
method: "POST",
|
|
154
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
155
|
+
});
|
|
156
|
+
const contentType = String(response.headers.get("content-type") || "");
|
|
157
|
+
if (!contentType.includes("text/event-stream")) {
|
|
158
|
+
const text = await response.text();
|
|
159
|
+
let payload = null;
|
|
160
|
+
try {
|
|
161
|
+
payload = text ? JSON.parse(text) : null;
|
|
162
|
+
} catch {
|
|
163
|
+
payload = null;
|
|
164
|
+
}
|
|
165
|
+
throw new AimakeallApiError(describeApiFailure(response.status, payload), {
|
|
166
|
+
errorCode: String(payload?.error || ""),
|
|
167
|
+
retryAfterSeconds: Number(payload?.retryAfterSeconds) || 0,
|
|
168
|
+
status: response.status,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const events = [];
|
|
172
|
+
let result = null;
|
|
173
|
+
let buffer = "";
|
|
174
|
+
const decoder = new TextDecoder();
|
|
175
|
+
try {
|
|
176
|
+
for await (const chunk of response.body) {
|
|
177
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
178
|
+
let frameEnd;
|
|
179
|
+
while ((frameEnd = buffer.indexOf("\n\n")) >= 0) {
|
|
180
|
+
const frame = buffer.slice(0, frameEnd);
|
|
181
|
+
buffer = buffer.slice(frameEnd + 2);
|
|
182
|
+
for (const line of frame.split("\n")) {
|
|
183
|
+
if (!line.startsWith("data:")) continue;
|
|
184
|
+
let payload = null;
|
|
185
|
+
try {
|
|
186
|
+
payload = JSON.parse(line.slice(5).trim());
|
|
187
|
+
} catch {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!payload || typeof payload !== "object") continue;
|
|
191
|
+
if (payload.type === "error") {
|
|
192
|
+
throw new AimakeallApiError(String(payload.message || payload.error || "스트리밍 생성 중 오류가 발생했습니다."), {
|
|
193
|
+
errorCode: "SSE_ERROR",
|
|
194
|
+
status: 200,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
events.push(payload);
|
|
198
|
+
if (payload.type === "result") result = payload.result;
|
|
199
|
+
onEvent?.(payload);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (error instanceof AimakeallApiError) throw error;
|
|
205
|
+
// 스트림 중단(idle timeout·네트워크) — 서버에서는 생성이 계속 완료·과금됐을 수 있다.
|
|
206
|
+
throw new AimakeallApiError(
|
|
207
|
+
"스트리밍 수신이 중단되었습니다. 서버에서는 생성이 계속 완료되어 과금됐을 수 있으니, 무작정 재시도하지 말고 계정 사용량/결과를 먼저 확인하세요.",
|
|
208
|
+
{ errorCode: "SSE_INTERRUPTED", status: 0 },
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return { events, result };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return { request, requestBinary, requestSse, requestStreamUpload };
|
|
143
215
|
}
|
package/lib/cloud-tools.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
encodedDataUrlBytes,
|
|
14
14
|
fileToDataUrl,
|
|
15
15
|
fileToImagePayload,
|
|
16
|
+
guessMimeType,
|
|
16
17
|
saveMediaBuffer,
|
|
17
18
|
savePayloadHandle,
|
|
18
19
|
SERVER_JSON_BODY_LIMIT_BYTES,
|
|
@@ -999,4 +1000,284 @@ export function registerCloudTools(server, config, api) {
|
|
|
999
1000
|
return jsonResult({ count: voices.length, provider, voices });
|
|
1000
1001
|
}),
|
|
1001
1002
|
);
|
|
1003
|
+
|
|
1004
|
+
// ── 인플루언서(소울) 스튜디오 ────────────────────────────────────────────────
|
|
1005
|
+
server.tool(
|
|
1006
|
+
"create_influencer_character",
|
|
1007
|
+
"참조 사진으로 인플루언서(소울) 캐릭터를 학습 등록합니다. 학습 비용 $2.50(1회성) — 실패 시 자동 재시도 금지(중복 과금). 등록 후 influencer_character_status로 completed까지 10초 간격 폴링하세요 (수 분 소요).",
|
|
1008
|
+
{
|
|
1009
|
+
name: z.string().min(1).describe("캐릭터 이름"),
|
|
1010
|
+
photoPaths: z.array(z.string()).min(5).max(18).describe("동일 인물 사진 로컬 경로 5~18장 (jpg/png/webp)"),
|
|
1011
|
+
},
|
|
1012
|
+
wrapCloudHandler(config, async ({ name, photoPaths }) => {
|
|
1013
|
+
for (const filePath of photoPaths) assertAllowedInputFile(filePath, ALLOWED_IMAGE_EXTS, { kind: "참조 사진" });
|
|
1014
|
+
const publicUrls = [];
|
|
1015
|
+
// 업로드 URL 발급은 사진 수만큼 쓰기 슬롯(20/분)을 쓰므로, 분당 한도에 걸리면
|
|
1016
|
+
// retryAfterSeconds 만큼 대기 후 이어서 진행한다(발급된 URL 은 보존).
|
|
1017
|
+
const issueUploadUrl = async (mime) => {
|
|
1018
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
1019
|
+
try {
|
|
1020
|
+
return await api.request("/api/tracker/higgsfield/files/generate-upload-url", {
|
|
1021
|
+
body: { content_type: mime },
|
|
1022
|
+
method: "POST",
|
|
1023
|
+
timeoutMs: 30_000,
|
|
1024
|
+
});
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
if (error instanceof AimakeallApiError && error.errorCode === "MACHINE_RATE_LIMITED" && attempt < 3) {
|
|
1027
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(1, error.retryAfterSeconds || 10) * 1000));
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
throw error;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
// presigned PUT(직접) — 컴패니언 불필요.
|
|
1035
|
+
for (const filePath of photoPaths) {
|
|
1036
|
+
const mime = guessMimeType(filePath, "image/jpeg");
|
|
1037
|
+
const issued = await issueUploadUrl(mime);
|
|
1038
|
+
const uploadUrl = String(issued?.upload_url || "");
|
|
1039
|
+
const publicUrl = String(issued?.public_url || "");
|
|
1040
|
+
if (!uploadUrl || !publicUrl) {
|
|
1041
|
+
return textResult("업로드 URL 발급에 실패했습니다. Higgsfield API 키 연결을 확인하세요.", { isError: true });
|
|
1042
|
+
}
|
|
1043
|
+
const put = await fetch(uploadUrl, {
|
|
1044
|
+
body: readFileSync(filePath),
|
|
1045
|
+
headers: { "Content-Type": mime },
|
|
1046
|
+
method: "PUT",
|
|
1047
|
+
signal: AbortSignal.timeout(120_000),
|
|
1048
|
+
});
|
|
1049
|
+
if (!put.ok) {
|
|
1050
|
+
return textResult(`사진 업로드 실패 (HTTP ${put.status}): ${path.basename(filePath)}`, { isError: true });
|
|
1051
|
+
}
|
|
1052
|
+
publicUrls.push(publicUrl);
|
|
1053
|
+
}
|
|
1054
|
+
let payload;
|
|
1055
|
+
try {
|
|
1056
|
+
// 서버의 업스트림 창(90s)보다 길게 잡아, 클라이언트가 먼저 끊어 "성공했는데
|
|
1057
|
+
// 실패로 오인 → 재시도 → 중복 과금($2.50)" 되는 상황을 방지한다.
|
|
1058
|
+
payload = await api.request("/api/tracker/higgsfield/v1/custom-references", {
|
|
1059
|
+
body: { input_images: publicUrls.map((url) => ({ image_url: url, type: "image_url" })), name },
|
|
1060
|
+
method: "POST",
|
|
1061
|
+
timeoutMs: 120_000,
|
|
1062
|
+
});
|
|
1063
|
+
} catch (error) {
|
|
1064
|
+
const reason = String(error?.message || error);
|
|
1065
|
+
return textResult(
|
|
1066
|
+
`캐릭터 학습 등록 요청이 실패했습니다: ${reason}\n재시도 전에 반드시 list_influencer_characters로 캐릭터가 이미 생성됐는지 확인하세요 — 생성돼 있다면 재시도는 중복 과금($2.50)입니다.`,
|
|
1067
|
+
{ isError: true },
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
const referenceId = String(payload?.id || payload?.reference_id || "");
|
|
1071
|
+
if (!referenceId) return textResult("캐릭터 학습 등록 응답에 ID가 없습니다. list_influencer_characters로 생성 여부를 확인하세요.", { isError: true });
|
|
1072
|
+
return jsonResult({
|
|
1073
|
+
costUsd: payload?.costUsd,
|
|
1074
|
+
next: "influencer_character_status를 10초 간격으로 폴링해 completed를 기다리세요. 이 호출을 재시도하면 중복 과금됩니다.",
|
|
1075
|
+
photoCount: publicUrls.length,
|
|
1076
|
+
referenceId,
|
|
1077
|
+
status: payload?.status,
|
|
1078
|
+
});
|
|
1079
|
+
}),
|
|
1080
|
+
);
|
|
1081
|
+
|
|
1082
|
+
server.tool(
|
|
1083
|
+
"influencer_character_status",
|
|
1084
|
+
"소울 캐릭터 학습 상태를 조회합니다 (terminal: completed | failed).",
|
|
1085
|
+
{ referenceId: z.string().min(1) },
|
|
1086
|
+
wrapCloudHandler(config, async ({ referenceId }) => {
|
|
1087
|
+
const payload = await api.request(`/api/tracker/higgsfield/v1/custom-references/${encodeURIComponent(referenceId)}`, {
|
|
1088
|
+
method: "GET",
|
|
1089
|
+
timeoutMs: 30_000,
|
|
1090
|
+
});
|
|
1091
|
+
return jsonResult({
|
|
1092
|
+
name: payload?.name,
|
|
1093
|
+
referenceId,
|
|
1094
|
+
status: payload?.status,
|
|
1095
|
+
thumbnailUrl: payload?.thumbnail_url,
|
|
1096
|
+
});
|
|
1097
|
+
}),
|
|
1098
|
+
);
|
|
1099
|
+
|
|
1100
|
+
server.tool(
|
|
1101
|
+
"list_influencer_characters",
|
|
1102
|
+
"등록된 소울 캐릭터 목록을 조회합니다. (machine 토큰은 서버 경유로 만든 캐릭터만 상세 조회·생성에 사용 가능)",
|
|
1103
|
+
{ page: z.number().int().min(1).optional().describe("기본 1") },
|
|
1104
|
+
wrapCloudHandler(config, async ({ page = 1 }) => {
|
|
1105
|
+
const payload = await api.request(`/api/tracker/higgsfield/v1/custom-references/list?page=${page}&page_size=50`, {
|
|
1106
|
+
method: "GET",
|
|
1107
|
+
timeoutMs: 30_000,
|
|
1108
|
+
});
|
|
1109
|
+
return jsonResult({
|
|
1110
|
+
characters: (Array.isArray(payload?.items) ? payload.items : []).map((item) => ({
|
|
1111
|
+
id: item?.id,
|
|
1112
|
+
name: item?.name,
|
|
1113
|
+
status: item?.status,
|
|
1114
|
+
})),
|
|
1115
|
+
page,
|
|
1116
|
+
totalPages: payload?.total_pages,
|
|
1117
|
+
});
|
|
1118
|
+
}),
|
|
1119
|
+
);
|
|
1120
|
+
|
|
1121
|
+
server.tool(
|
|
1122
|
+
"suggest_influencer_prompts",
|
|
1123
|
+
"소울 이미지용 연출·프롬프트 10종을 추천받습니다. 반환 prompt는 부정규칙까지 완성형이므로 generate_influencer_image에 그대로 쓰세요.",
|
|
1124
|
+
{
|
|
1125
|
+
gender: z.enum(["여자", "남자"]),
|
|
1126
|
+
ageRange: z.enum(["10대", "20대", "30대", "40대", "50대", "60대"]),
|
|
1127
|
+
keyword: z.string().min(1).describe("장면 키워드 (예: 카페에서 책 읽는 모습)"),
|
|
1128
|
+
},
|
|
1129
|
+
wrapCloudHandler(config, async ({ gender, ageRange, keyword }) => {
|
|
1130
|
+
const { events } = await api.requestSse("/api/tracker/gemini/soul-prompts", {
|
|
1131
|
+
body: { ageRange, gender, imageModel: "soul", keyword },
|
|
1132
|
+
timeoutMs: 180_000,
|
|
1133
|
+
});
|
|
1134
|
+
const items = events
|
|
1135
|
+
.filter((event) => event?.type === "item" && event.item)
|
|
1136
|
+
.map((event) => ({ directing: event.item.directing, id: event.item.id, prompt: event.item.prompt }));
|
|
1137
|
+
if (!items.length) return textResult("프롬프트 추천 결과가 비어 있습니다.", { isError: true });
|
|
1138
|
+
return jsonResult({ count: items.length, items });
|
|
1139
|
+
}),
|
|
1140
|
+
);
|
|
1141
|
+
|
|
1142
|
+
server.tool(
|
|
1143
|
+
"generate_influencer_image",
|
|
1144
|
+
"학습 완료(completed)된 소울 캐릭터로 인플루언서 이미지를 생성합니다 (720p $0.094/장, 1080p $0.19/장). 반환 requestId를 influencer_image_status로 폴링하세요 (~30초).",
|
|
1145
|
+
{
|
|
1146
|
+
prompt: z.string().min(1).describe("영문 프롬프트 (suggest_influencer_prompts 결과 그대로 권장)"),
|
|
1147
|
+
referenceId: z.string().min(1).describe("completed 상태의 캐릭터 referenceId"),
|
|
1148
|
+
aspectRatio: z.enum(["9:16", "16:9", "4:3", "3:4", "1:1", "2:3", "3:2"]).optional().describe("기본 4:3"),
|
|
1149
|
+
resolution: z.enum(["720p", "1080p"]).optional().describe("기본 720p"),
|
|
1150
|
+
imageReferenceUrl: z.string().optional().describe("구도/씬 참조 이미지 URL (선택)"),
|
|
1151
|
+
seed: z.number().int().optional().describe("재현용 시드 (선택)"),
|
|
1152
|
+
},
|
|
1153
|
+
wrapCloudHandler(config, async ({ prompt, referenceId, aspectRatio = "4:3", resolution = "720p", imageReferenceUrl = "", seed }) => {
|
|
1154
|
+
const payload = await api.request("/api/tracker/higgsfield/higgsfield-ai/soul/character", {
|
|
1155
|
+
body: {
|
|
1156
|
+
aspect_ratio: aspectRatio,
|
|
1157
|
+
batch_size: 1,
|
|
1158
|
+
custom_reference_id: referenceId,
|
|
1159
|
+
custom_reference_strength: 1,
|
|
1160
|
+
enhance_prompt: false,
|
|
1161
|
+
...(imageReferenceUrl ? { image_reference_url: imageReferenceUrl } : {}),
|
|
1162
|
+
prompt,
|
|
1163
|
+
resolution,
|
|
1164
|
+
...(seed !== undefined ? { seed } : {}),
|
|
1165
|
+
},
|
|
1166
|
+
method: "POST",
|
|
1167
|
+
timeoutMs: 60_000,
|
|
1168
|
+
});
|
|
1169
|
+
const requestId = String(payload?.request_id || payload?.id || "");
|
|
1170
|
+
if (!requestId) return textResult("이미지 생성 요청 응답에 request_id가 없습니다.", { isError: true });
|
|
1171
|
+
return jsonResult({ costUsd: payload?.costUsd, requestId, status: payload?.status });
|
|
1172
|
+
}),
|
|
1173
|
+
);
|
|
1174
|
+
|
|
1175
|
+
server.tool(
|
|
1176
|
+
"influencer_image_status",
|
|
1177
|
+
"소울 이미지 생성 상태를 조회합니다 (terminal: completed | failed | nsfw | canceled). 결과 이미지는 만료 없는 공개 URL입니다.",
|
|
1178
|
+
{ requestId: z.string().min(1) },
|
|
1179
|
+
wrapCloudHandler(config, async ({ requestId }) => {
|
|
1180
|
+
const payload = await api.request(`/api/tracker/higgsfield/requests/${encodeURIComponent(requestId)}/status`, {
|
|
1181
|
+
method: "GET",
|
|
1182
|
+
timeoutMs: 30_000,
|
|
1183
|
+
});
|
|
1184
|
+
return jsonResult({
|
|
1185
|
+
error: payload?.error || payload?.message || undefined,
|
|
1186
|
+
imageUrls: (Array.isArray(payload?.images) ? payload.images : []).map((image) => image?.url).filter(Boolean),
|
|
1187
|
+
progress: payload?.progress,
|
|
1188
|
+
requestId,
|
|
1189
|
+
status: payload?.status,
|
|
1190
|
+
});
|
|
1191
|
+
}),
|
|
1192
|
+
);
|
|
1193
|
+
|
|
1194
|
+
// ── 상세페이지(PDP) ─────────────────────────────────────────────────────────
|
|
1195
|
+
server.tool(
|
|
1196
|
+
"generate_pdp",
|
|
1197
|
+
"상품 사진으로 상세페이지(PDP) HTML을 생성합니다. 분석→카피→라이프스타일 컷 8장→조립까지 서버가 한 번에 처리하며 3~6분 걸립니다. 결과는 HTML 파일 경로로 반환됩니다 (Pro 스튜디오 기능).",
|
|
1198
|
+
{
|
|
1199
|
+
productName: z.string().min(1).describe("상품명"),
|
|
1200
|
+
productImagePaths: z.array(z.string()).min(2).max(5).describe("상품 사진 로컬 경로 2~5장 (첫 장이 메인)"),
|
|
1201
|
+
modelImagePath: z.string().optional().describe("모델 사진 로컬 경로 (선택 — 사용 장면 컷 레퍼런스)"),
|
|
1202
|
+
description: z.string().optional().describe("부가 설명"),
|
|
1203
|
+
targetCustomer: z.string().optional(),
|
|
1204
|
+
priceRange: z.enum(["~1만원", "1~5만원", "5~10만원", "10~30만원", "30~100만원", "100만원~"]).optional(),
|
|
1205
|
+
coreUsp: z.string().optional().describe("핵심 USP — 한 줄씩 줄바꿈 구분"),
|
|
1206
|
+
tone: z.enum(["자동 추천", "프리미엄·럭셔리", "친근·일상적", "전문적·신뢰", "감성·스토리", "트렌디·MZ"]).optional().describe("기본 자동 추천"),
|
|
1207
|
+
usePersonaReviews: z.boolean().optional().describe("기본 false. true면 한국인 페르소나 후기 5건으로 대체 (+30초)"),
|
|
1208
|
+
downloadImages: z.boolean().optional().describe("기본 true — 라이프스타일 컷을 로컬 저장하고 HTML src를 로컬 경로로 재작성(원격 URL 만료 대비)"),
|
|
1209
|
+
},
|
|
1210
|
+
wrapCloudHandler(config, async ({
|
|
1211
|
+
productName,
|
|
1212
|
+
productImagePaths,
|
|
1213
|
+
modelImagePath = "",
|
|
1214
|
+
description = "",
|
|
1215
|
+
targetCustomer = "",
|
|
1216
|
+
priceRange = "",
|
|
1217
|
+
coreUsp = "",
|
|
1218
|
+
tone = "자동 추천",
|
|
1219
|
+
usePersonaReviews = false,
|
|
1220
|
+
downloadImages = true,
|
|
1221
|
+
}) => {
|
|
1222
|
+
for (const filePath of productImagePaths) assertAllowedInputFile(filePath, ALLOWED_IMAGE_EXTS, { kind: "상품 사진" });
|
|
1223
|
+
if (modelImagePath) assertAllowedInputFile(modelImagePath, ALLOWED_IMAGE_EXTS, { kind: "모델 사진" });
|
|
1224
|
+
assertEncodedBudget([...productImagePaths, modelImagePath], { context: "상품/모델 사진" });
|
|
1225
|
+
|
|
1226
|
+
const { result } = await api.requestSse("/api/tracker/pdp/generate", {
|
|
1227
|
+
body: {
|
|
1228
|
+
coreUsp,
|
|
1229
|
+
description,
|
|
1230
|
+
modelImage: modelImagePath ? fileToImagePayload(modelImagePath) : null,
|
|
1231
|
+
priceRange,
|
|
1232
|
+
productImages: productImagePaths.map((filePath) => fileToImagePayload(filePath)),
|
|
1233
|
+
productName,
|
|
1234
|
+
targetCustomer,
|
|
1235
|
+
tone,
|
|
1236
|
+
usePersonaReviews,
|
|
1237
|
+
},
|
|
1238
|
+
timeoutMs: 900_000,
|
|
1239
|
+
});
|
|
1240
|
+
if (!result?.html) return textResult("PDP 생성 결과가 비어 있습니다. 잠시 후 다시 시도하세요.", { isError: true });
|
|
1241
|
+
|
|
1242
|
+
let html = String(result.html);
|
|
1243
|
+
const savedImages = [];
|
|
1244
|
+
if (downloadImages) {
|
|
1245
|
+
// 렌더러가 URL 을 HTML 이스케이프(&→& 등)해 넣었을 수 있으므로 두 형태 모두 치환.
|
|
1246
|
+
const escapeHtml = (value) => value
|
|
1247
|
+
.replaceAll("&", "&")
|
|
1248
|
+
.replaceAll("<", "<")
|
|
1249
|
+
.replaceAll(">", ">")
|
|
1250
|
+
.replaceAll('"', """)
|
|
1251
|
+
.replaceAll("'", "'");
|
|
1252
|
+
for (const image of Array.isArray(result.lifestyleImages) ? result.lifestyleImages : []) {
|
|
1253
|
+
const url = String(image?.url || "");
|
|
1254
|
+
if (!url) continue;
|
|
1255
|
+
try {
|
|
1256
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(60_000) });
|
|
1257
|
+
if (!res.ok) continue;
|
|
1258
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
1259
|
+
const ext = String(res.headers.get("content-type") || "").includes("png") ? "png" : "jpg";
|
|
1260
|
+
const saved = saveMediaBuffer(config.stateDir, `pdp-image-${image?.idx ?? savedImages.length + 1}.${ext}`, buf);
|
|
1261
|
+
// HTML 은 같은 디렉터리에 저장되므로 상대경로 치환으로 자립형 유지.
|
|
1262
|
+
const local = `./${path.basename(saved.filePath)}`;
|
|
1263
|
+
const before = html;
|
|
1264
|
+
html = html.split(url).join(local).split(escapeHtml(url)).join(local);
|
|
1265
|
+
if (html !== before) savedImages.push(saved.filePath);
|
|
1266
|
+
} catch {
|
|
1267
|
+
// 다운로드 실패한 컷은 원격 URL 유지
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
const savedHtml = saveMediaBuffer(config.stateDir, "pdp.html", Buffer.from(html, "utf8"), { contentType: "text/html" });
|
|
1272
|
+
return jsonResult({
|
|
1273
|
+
analysis: trimAnalysis(result.analysis),
|
|
1274
|
+
heroHeadline: result?.copy?.heroHeadline,
|
|
1275
|
+
htmlPath: savedHtml.filePath,
|
|
1276
|
+
imageCount: (Array.isArray(result.lifestyleImages) ? result.lifestyleImages : []).filter((image) => image?.url).length,
|
|
1277
|
+
localImages: savedImages.length,
|
|
1278
|
+
note: "htmlPath와 로컬 이미지들은 48시간 뒤 자동 정리되는 스테이징 폴더에 있습니다. 보존하려면 같은 폴더의 이미지들과 함께 원하는 위치로 복사하세요.",
|
|
1279
|
+
tagline: result?.copy?.tagline,
|
|
1280
|
+
});
|
|
1281
|
+
}),
|
|
1282
|
+
);
|
|
1002
1283
|
}
|
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.3.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";
|