Compare commits
No commits in common. "main" and "codex/98k-image-resolution-20261116" have entirely different histories.
main
...
codex/98k-
@ -40,11 +40,6 @@ EMAIL_VERIFICATION_SECRET=
|
|||||||
# Optional scheduled job protection.
|
# Optional scheduled job protection.
|
||||||
CRON_SECRET=
|
CRON_SECRET=
|
||||||
|
|
||||||
# Canvas feedback: server-side project credentials for the shared notification center.
|
|
||||||
YYD_NOTIFICATION_CENTER_URL=https://sc.jiansun.vip/notification-center
|
|
||||||
YYD_NOTIFICATION_CENTER_PROJECT_CODE=
|
|
||||||
YYD_NOTIFICATION_CENTER_PROJECT_SECRET=
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Database
|
# Database
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|||||||
@ -23,21 +23,6 @@ import { AntigravityBackground } from "@/components/antigravity-background";
|
|||||||
import { createClientLogger } from "@/lib/observability/client-logger";
|
import { createClientLogger } from "@/lib/observability/client-logger";
|
||||||
|
|
||||||
const logger = createClientLogger("auth-login");
|
const logger = createClientLogger("auth-login");
|
||||||
|
|
||||||
function getSafeLoginCallbackUrl() {
|
|
||||||
const { origin, search } = window.location;
|
|
||||||
const callbackUrl = new URLSearchParams(search).get("callbackUrl");
|
|
||||||
if (!callbackUrl?.startsWith("/")) return "/";
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { origin: targetOrigin, pathname, search, hash } = new URL(callbackUrl, origin);
|
|
||||||
if (targetOrigin !== origin || pathname.startsWith("//")) return "/";
|
|
||||||
return pathname + search + hash;
|
|
||||||
} catch {
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [isSuccessful, setIsSuccessful] = useState(false);
|
const [isSuccessful, setIsSuccessful] = useState(false);
|
||||||
@ -85,7 +70,7 @@ export default function Page() {
|
|||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
if (data?.valid === true && data?.userType !== "guest") {
|
if (data?.valid === true && data?.userType !== "guest") {
|
||||||
window.location.replace(getSafeLoginCallbackUrl());
|
window.location.replace("/");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setIsCheckingExistingSession(false);
|
setIsCheckingExistingSession(false);
|
||||||
@ -105,7 +90,6 @@ export default function Page() {
|
|||||||
const completeDingTalkLogin = useCallback(async (token: string) => {
|
const completeDingTalkLogin = useCallback(async (token: string) => {
|
||||||
logger.debug("[DingTalk] Completing login with token", { hasToken: Boolean(token) });
|
logger.debug("[DingTalk] Completing login with token", { hasToken: Boolean(token) });
|
||||||
setIsHandlingToken(true);
|
setIsHandlingToken(true);
|
||||||
const callbackUrl = getSafeLoginCallbackUrl();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 获取 CSRF token
|
// 获取 CSRF token
|
||||||
@ -118,12 +102,11 @@ export default function Page() {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
"X-Auth-Return-Redirect": "1",
|
|
||||||
},
|
},
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
csrfToken,
|
csrfToken,
|
||||||
token,
|
token,
|
||||||
callbackUrl,
|
callbackUrl: "/",
|
||||||
}),
|
}),
|
||||||
credentials: "include", // 重要:确保 cookie 被发送和接收
|
credentials: "include", // 重要:确保 cookie 被发送和接收
|
||||||
});
|
});
|
||||||
@ -151,12 +134,12 @@ export default function Page() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (session && session.user) {
|
if (session && session.user) {
|
||||||
logger.debug("[DingTalk] Session validated, redirecting...");
|
logger.debug("[DingTalk] Session validated, redirecting to home...");
|
||||||
setIsSuccessful(true);
|
setIsSuccessful(true);
|
||||||
// 使用 replace 而不是 href,避免在历史记录中留下登录页
|
// 使用 replace 而不是 href,避免在历史记录中留下登录页
|
||||||
// 增加短暂延迟确保 cookie 完全同步
|
// 增加短暂延迟确保 cookie 完全同步
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.replace(callbackUrl);
|
window.location.replace("/");
|
||||||
}, 200);
|
}, 200);
|
||||||
} else {
|
} else {
|
||||||
logger.error("[DingTalk] Session not created after login");
|
logger.error("[DingTalk] Session not created after login");
|
||||||
@ -191,7 +174,7 @@ export default function Page() {
|
|||||||
// 使用 replace 而不是 href,避免在历史记录中留下登录页
|
// 使用 replace 而不是 href,避免在历史记录中留下登录页
|
||||||
// 增加短暂延迟确保 cookie 完全同步
|
// 增加短暂延迟确保 cookie 完全同步
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.replace(callbackUrl);
|
window.location.replace(result.url || "/");
|
||||||
}, 200);
|
}, 200);
|
||||||
} else {
|
} else {
|
||||||
logger.error("[DingTalk] Session not created");
|
logger.error("[DingTalk] Session not created");
|
||||||
@ -315,7 +298,7 @@ export default function Page() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await signIn("google", { redirectTo: getSafeLoginCallbackUrl() });
|
await signIn("google", { callbackUrl: "/" });
|
||||||
};
|
};
|
||||||
|
|
||||||
// 检查 URL 中是否有钉钉 Token(页面加载时自动登录)
|
// 检查 URL 中是否有钉钉 Token(页面加载时自动登录)
|
||||||
@ -382,14 +365,13 @@ export default function Page() {
|
|||||||
description: "提交的信息校验失败",
|
description: "提交的信息校验失败",
|
||||||
});
|
});
|
||||||
} else if (state.status === "success") {
|
} else if (state.status === "success") {
|
||||||
const callbackUrl = getSafeLoginCallbackUrl();
|
toast({ type: "success", description: "登录成功,正在进入首页" });
|
||||||
toast({ type: "success", description: "登录成功,正在跳转" });
|
|
||||||
setIsSuccessful(true);
|
setIsSuccessful(true);
|
||||||
loginRedirectTimerRef.current = window.setTimeout(() => {
|
loginRedirectTimerRef.current = window.setTimeout(() => {
|
||||||
window.location.replace(callbackUrl);
|
window.location.replace("/");
|
||||||
}, 120);
|
}, 120);
|
||||||
loginRedirectFallbackTimerRef.current = window.setTimeout(() => {
|
loginRedirectFallbackTimerRef.current = window.setTimeout(() => {
|
||||||
window.location.assign(callbackUrl);
|
window.location.assign("/");
|
||||||
}, 1600);
|
}, 1600);
|
||||||
}
|
}
|
||||||
}, [state.status]);
|
}, [state.status]);
|
||||||
@ -411,6 +393,23 @@ export default function Page() {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const getSafeLoginCallbackUrl = () => {
|
||||||
|
if (typeof window === "undefined") return "/";
|
||||||
|
|
||||||
|
const callbackUrl = new URLSearchParams(window.location.search).get(
|
||||||
|
"callbackUrl",
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
callbackUrl &&
|
||||||
|
callbackUrl.startsWith("/") &&
|
||||||
|
!callbackUrl.startsWith("//")
|
||||||
|
) {
|
||||||
|
return callbackUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "/";
|
||||||
|
};
|
||||||
|
|
||||||
const buildDingTalkLoginUrl = (orgName?: string) => {
|
const buildDingTalkLoginUrl = (orgName?: string) => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
if (orgName) params.set("org", orgName);
|
if (orgName) params.set("org", orgName);
|
||||||
|
|||||||
@ -623,7 +623,7 @@ async function resolveReplacementProductIdentityProfile(params: {
|
|||||||
system:
|
system:
|
||||||
"你是高精度商品结构分析器。多张图片属于同一商品;请跨视角还原唯一结构身份,并明确每个视角最清楚的构件。",
|
"你是高精度商品结构分析器。多张图片属于同一商品;请跨视角还原唯一结构身份,并明确每个视角最清楚的构件。",
|
||||||
temperature: params.planningRuntime.kind === "local_moonshot" ? 1 : 0.1,
|
temperature: params.planningRuntime.kind === "local_moonshot" ? 1 : 0.1,
|
||||||
maxOutputTokens: 1800,
|
maxTokens: 1800,
|
||||||
abortSignal: AbortSignal.timeout(
|
abortSignal: AbortSignal.timeout(
|
||||||
params.planningRuntime.kind === "local_moonshot" ? 90_000 : 60_000,
|
params.planningRuntime.kind === "local_moonshot" ? 90_000 : 60_000,
|
||||||
),
|
),
|
||||||
@ -2376,7 +2376,7 @@ export async function analyzeReplacementReferenceImage(params: {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
maxOutputTokens: 160,
|
maxTokens: 160,
|
||||||
abortSignal: AbortSignal.timeout(45_000),
|
abortSignal: AbortSignal.timeout(45_000),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
@ -2679,7 +2679,7 @@ export async function analyzeReplacementExecutionPlan(params: {
|
|||||||
system:
|
system:
|
||||||
"你是高精度商品详情图场景规划器。你只分析当前参考图本身,负责理解这一屏的场景、机位、主体位置和人物需求,不要臆测或依赖其他输入图片。",
|
"你是高精度商品详情图场景规划器。你只分析当前参考图本身,负责理解这一屏的场景、机位、主体位置和人物需求,不要臆测或依赖其他输入图片。",
|
||||||
temperature: params.planningRuntime.kind === "local_moonshot" ? 1 : 0.1,
|
temperature: params.planningRuntime.kind === "local_moonshot" ? 1 : 0.1,
|
||||||
maxOutputTokens: 1600,
|
maxTokens: 1600,
|
||||||
abortSignal: AbortSignal.timeout(replacementScenePlanningTimeoutMs),
|
abortSignal: AbortSignal.timeout(replacementScenePlanningTimeoutMs),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -264,29 +264,6 @@ export function chatMessagesHaveImageInput(messages: ChatMessage[]) {
|
|||||||
return countChatMessageImageInputs(messages) > 0;
|
return countChatMessageImageInputs(messages) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canUseImageFallback(
|
|
||||||
candidate: { model: any; provider: any },
|
|
||||||
imageParams: { imageSize?: unknown; aspectRatio?: unknown; imageCount?: number },
|
|
||||||
messages: ChatMessage[],
|
|
||||||
balanceBlockedProviders: ReadonlySet<string>,
|
|
||||||
) {
|
|
||||||
if (balanceBlockedProviders.has(candidate.provider?.id)) return false;
|
|
||||||
const config = candidate.model?.imageGenConfig;
|
|
||||||
const size = String(imageParams.imageSize || "").toUpperCase();
|
|
||||||
const ratio = String(imageParams.aspectRatio || "");
|
|
||||||
if (size && Array.isArray(config?.supportedImageSizes) &&
|
|
||||||
!config.supportedImageSizes.includes(size)) return false;
|
|
||||||
if (ratio && ratio !== "auto" && Array.isArray(config?.supportedAspectRatios) &&
|
|
||||||
!config.supportedAspectRatios.includes(ratio)) return false;
|
|
||||||
if (imageParams.imageCount && typeof config?.maxImages === "number" &&
|
|
||||||
imageParams.imageCount > config.maxImages) return false;
|
|
||||||
const referenceCount = countChatMessageImageInputs(messages);
|
|
||||||
if (referenceCount && modelLacksReferenceImageInputSupport(candidate.model, candidate.provider)) return false;
|
|
||||||
if (referenceCount && typeof config?.maxReferenceImages === "number" &&
|
|
||||||
referenceCount > config.maxReferenceImages) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getImageFailoverConvertProvider(providerType?: string | null) {
|
export function getImageFailoverConvertProvider(providerType?: string | null) {
|
||||||
switch (providerType) {
|
switch (providerType) {
|
||||||
case "bfl-image":
|
case "bfl-image":
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
import { saveMessages } from "@/lib/db/queries";
|
import { saveMessages } from "@/lib/db/queries";
|
||||||
import type { ImageGenerationStatusStreamPayload } from "@/lib/canvas/image-generation-status";
|
import type { ImageGenerationStatusStreamPayload } from "@/lib/canvas/image-generation-status";
|
||||||
import { formatRequestFailure, getRequestFailureDetails } from "@/lib/request-error";
|
import { formatRequestFailure, getRequestFailureDetails } from "@/lib/request-error";
|
||||||
import { createLogger } from "@/lib/observability/logger";
|
|
||||||
import { safeWriteStreamChunk, type StreamWriter, writeAssistantTextChunk, writeStructuredDataChunk } from "./stream";
|
import { safeWriteStreamChunk, type StreamWriter, writeAssistantTextChunk, writeStructuredDataChunk } from "./stream";
|
||||||
|
|
||||||
const logger = createLogger("chat.imageGenerationFailure");
|
|
||||||
|
|
||||||
export async function reportImageGenerationFailure(params: {
|
export async function reportImageGenerationFailure(params: {
|
||||||
writer: StreamWriter;
|
writer: StreamWriter;
|
||||||
chatId: string;
|
chatId: string;
|
||||||
@ -15,12 +12,6 @@ export async function reportImageGenerationFailure(params: {
|
|||||||
label: string;
|
label: string;
|
||||||
}) {
|
}) {
|
||||||
const failure = getRequestFailureDetails(params.error, "图片生成失败");
|
const failure = getRequestFailureDetails(params.error, "图片生成失败");
|
||||||
logger.warn("Image request failed", {
|
|
||||||
requestId: params.messageId,
|
|
||||||
userMessageId: params.userMessageId,
|
|
||||||
providerRequestId: (params.error as { providerRequestId?: string } | null)?.providerRequestId,
|
|
||||||
code: failure.code,
|
|
||||||
});
|
|
||||||
const status: ImageGenerationStatusStreamPayload = {
|
const status: ImageGenerationStatusStreamPayload = {
|
||||||
phase: "failed",
|
phase: "failed",
|
||||||
userMessageId: params.userMessageId,
|
userMessageId: params.userMessageId,
|
||||||
|
|||||||
@ -337,7 +337,6 @@ import {
|
|||||||
} from "./_lib/image-media";
|
} from "./_lib/image-media";
|
||||||
import {
|
import {
|
||||||
buildImageFallbackCandidates,
|
buildImageFallbackCandidates,
|
||||||
canUseImageFallback,
|
|
||||||
countChatMessageImageInputs,
|
countChatMessageImageInputs,
|
||||||
generateImageWithFailoverCandidate,
|
generateImageWithFailoverCandidate,
|
||||||
getImageCrossProviderCandidates,
|
getImageCrossProviderCandidates,
|
||||||
@ -9217,11 +9216,8 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
// 🆕 尝试备用模型(支持跨服务商切换)
|
// 🆕 尝试备用模型(支持跨服务商切换)
|
||||||
let fallbackSuccess = false;
|
let fallbackSuccess = false;
|
||||||
const balanceBlockedProviders = new Set<string>();
|
|
||||||
if (isProviderBalanceError(primaryError) && currentModelConfig?.providerId) balanceBlockedProviders.add(currentModelConfig.providerId);
|
|
||||||
const triedFallbackModelIds = new Set<string>();
|
const triedFallbackModelIds = new Set<string>();
|
||||||
for (const candidate of fallbackCandidates) {
|
for (const candidate of fallbackCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, buildMessagesForGemini(), balanceBlockedProviders)) continue;
|
|
||||||
try {
|
try {
|
||||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||||
chatApiLogger.info(`[Chat API] 🔄 Trying fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔄 Trying fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
@ -9243,7 +9239,6 @@ export async function POST(request: Request) {
|
|||||||
chatApiLogger.info(`[Chat API] ✅ Fallback model ${fallbackResult.displayName} succeeded!`);
|
chatApiLogger.info(`[Chat API] ✅ Fallback model ${fallbackResult.displayName} succeeded!`);
|
||||||
break;
|
break;
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
|
||||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||||
@ -9297,7 +9292,6 @@ export async function POST(request: Request) {
|
|||||||
}).filter((candidate) => !triedFallbackModelIds.has(String(candidate.model.id || "")));
|
}).filter((candidate) => !triedFallbackModelIds.has(String(candidate.model.id || "")));
|
||||||
|
|
||||||
for (const candidate of crossProviderCandidates) {
|
for (const candidate of crossProviderCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, buildMessagesForGemini(), balanceBlockedProviders)) continue;
|
|
||||||
try {
|
try {
|
||||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||||
chatApiLogger.info(`[Chat API] 🔁 Gemini cross-provider failover: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔁 Gemini cross-provider failover: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
@ -9320,7 +9314,6 @@ export async function POST(request: Request) {
|
|||||||
chatApiLogger.info(`[Chat API] ✅ Gemini cross-provider fallback model ${fallbackResult.displayName} succeeded!`);
|
chatApiLogger.info(`[Chat API] ✅ Gemini cross-provider fallback model ${fallbackResult.displayName} succeeded!`);
|
||||||
break;
|
break;
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
|
||||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||||
@ -9991,7 +9984,7 @@ export async function POST(request: Request) {
|
|||||||
const balanceBlockedProviders = new Set<string>();
|
const balanceBlockedProviders = new Set<string>();
|
||||||
if (isProviderBalanceError(primaryError) && currentModelEntry?.provider.id) balanceBlockedProviders.add(currentModelEntry.provider.id);
|
if (isProviderBalanceError(primaryError) && currentModelEntry?.provider.id) balanceBlockedProviders.add(currentModelEntry.provider.id);
|
||||||
for (const candidate of fallbackCandidates) {
|
for (const candidate of fallbackCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForAlibaba, balanceBlockedProviders)) continue;
|
if (balanceBlockedProviders.has(candidate.provider.id)) continue;
|
||||||
try {
|
try {
|
||||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||||
chatApiLogger.info(`[Chat API] 🔄 Alibaba fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔄 Alibaba fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
@ -10067,7 +10060,7 @@ export async function POST(request: Request) {
|
|||||||
}).filter((candidate) => !triedFallbackModelIds.has(String(candidate.model.id || "")) && !balanceBlockedProviders.has(candidate.provider.id));
|
}).filter((candidate) => !triedFallbackModelIds.has(String(candidate.model.id || "")) && !balanceBlockedProviders.has(candidate.provider.id));
|
||||||
|
|
||||||
for (const candidate of crossProviderCandidates) {
|
for (const candidate of crossProviderCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForAlibaba, balanceBlockedProviders)) continue;
|
if (balanceBlockedProviders.has(candidate.provider.id)) continue;
|
||||||
try {
|
try {
|
||||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||||
chatApiLogger.info(`[Chat API] 🔁 Cross-provider failover attempt: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔁 Cross-provider failover attempt: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
@ -10455,10 +10448,7 @@ export async function POST(request: Request) {
|
|||||||
throw primaryError;
|
throw primaryError;
|
||||||
}
|
}
|
||||||
let fallbackSuccess = false;
|
let fallbackSuccess = false;
|
||||||
const balanceBlockedProviders = new Set<string>();
|
|
||||||
if (isProviderBalanceError(primaryError) && volcanoModelConfig?.providerId) balanceBlockedProviders.add(volcanoModelConfig.providerId);
|
|
||||||
for (const candidate of fallbackCandidates) {
|
for (const candidate of fallbackCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForVolcano, balanceBlockedProviders)) continue;
|
|
||||||
try {
|
try {
|
||||||
chatApiLogger.info(`[Chat API] 🔄 Volcano fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔄 Volcano fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
const fallbackResult = await generateImageWithFailoverCandidate({
|
const fallbackResult = await generateImageWithFailoverCandidate({
|
||||||
@ -10480,7 +10470,6 @@ export async function POST(request: Request) {
|
|||||||
chatApiLogger.info(`[Chat API] ✅ Volcano fallback model ${fallbackResult.displayName} succeeded!`);
|
chatApiLogger.info(`[Chat API] ✅ Volcano fallback model ${fallbackResult.displayName} succeeded!`);
|
||||||
break;
|
break;
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
|
||||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||||
@ -10516,7 +10505,6 @@ export async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const candidate of crossProviderCandidates) {
|
for (const candidate of crossProviderCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForVolcano, balanceBlockedProviders)) continue;
|
|
||||||
try {
|
try {
|
||||||
chatApiLogger.info(`[Chat API] 🔁 Volcano cross-provider failover attempt: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔁 Volcano cross-provider failover attempt: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
if (
|
if (
|
||||||
@ -10597,7 +10585,6 @@ export async function POST(request: Request) {
|
|||||||
chatApiLogger.info(`[Chat API] ✅ Volcano cross-provider failover succeeded: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] ✅ Volcano cross-provider failover succeeded: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
break;
|
break;
|
||||||
} catch (crossError) {
|
} catch (crossError) {
|
||||||
if (isProviderBalanceError(crossError)) balanceBlockedProviders.add(candidate.provider.id);
|
|
||||||
const crossErrorMessage = normalizeFailoverErrorMessage(crossError);
|
const crossErrorMessage = normalizeFailoverErrorMessage(crossError);
|
||||||
if (shouldCooldownImageFallbackModel(crossErrorMessage)) {
|
if (shouldCooldownImageFallbackModel(crossErrorMessage)) {
|
||||||
setImageFallbackModelCooldown(candidate.model.id, crossErrorMessage);
|
setImageFallbackModelCooldown(candidate.model.id, crossErrorMessage);
|
||||||
@ -11341,10 +11328,7 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let fallbackSuccess = false;
|
let fallbackSuccess = false;
|
||||||
const balanceBlockedProviders = new Set<string>();
|
|
||||||
if (isProviderBalanceError(primaryError) && currentModelConfig?.providerId) balanceBlockedProviders.add(currentModelConfig.providerId);
|
|
||||||
for (const candidate of fallbackCandidates) {
|
for (const candidate of fallbackCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForCrossProvider, balanceBlockedProviders)) continue;
|
|
||||||
try {
|
try {
|
||||||
chatApiLogger.info(`[Chat API] 🔄 OpenAI-compatible fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔄 OpenAI-compatible fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
const shouldUseOpenAICompatFallback =
|
const shouldUseOpenAICompatFallback =
|
||||||
@ -11386,7 +11370,6 @@ export async function POST(request: Request) {
|
|||||||
chatApiLogger.info(`[Chat API] ✅ OpenAI-compatible fallback model ${candidate.model.displayName} succeeded!`);
|
chatApiLogger.info(`[Chat API] ✅ OpenAI-compatible fallback model ${candidate.model.displayName} succeeded!`);
|
||||||
break;
|
break;
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
|
||||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||||
@ -11423,7 +11406,6 @@ export async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const candidate of crossProviderCandidates) {
|
for (const candidate of crossProviderCandidates) {
|
||||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForCrossProvider, balanceBlockedProviders)) continue;
|
|
||||||
try {
|
try {
|
||||||
chatApiLogger.info(`[Chat API] 🔁 OpenAI-compatible cross-provider failover: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] 🔁 OpenAI-compatible cross-provider failover: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
if (
|
if (
|
||||||
@ -11507,7 +11489,6 @@ export async function POST(request: Request) {
|
|||||||
chatApiLogger.info(`[Chat API] ✅ OpenAI-compatible cross-provider failover succeeded: ${candidate.model.displayName} (${candidate.provider.type})`);
|
chatApiLogger.info(`[Chat API] ✅ OpenAI-compatible cross-provider failover succeeded: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||||
break;
|
break;
|
||||||
} catch (crossError) {
|
} catch (crossError) {
|
||||||
if (isProviderBalanceError(crossError)) balanceBlockedProviders.add(candidate.provider.id);
|
|
||||||
const crossErrorMessage = normalizeFailoverErrorMessage(crossError);
|
const crossErrorMessage = normalizeFailoverErrorMessage(crossError);
|
||||||
if (shouldCooldownImageFallbackModel(crossErrorMessage)) {
|
if (shouldCooldownImageFallbackModel(crossErrorMessage)) {
|
||||||
setImageFallbackModelCooldown(candidate.model.id, crossErrorMessage);
|
setImageFallbackModelCooldown(candidate.model.id, crossErrorMessage);
|
||||||
|
|||||||
@ -450,7 +450,7 @@ async function analyzeFunctionalShowcaseImage(params: {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
maxOutputTokens: 120,
|
maxTokens: 120,
|
||||||
abortSignal: AbortSignal.timeout(25_000),
|
abortSignal: AbortSignal.timeout(25_000),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@ export async function GET(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const failure = task.status === "failed" ? getRequestFailureDetails(task.error) : undefined;
|
const failure = task.status === "failed" ? getRequestFailureDetails(task.error) : undefined;
|
||||||
return NextResponse.json({ success: true, task: { ...task, failure, error: failure ? formatRequestFailure(failure, task.requestId) : task.error } });
|
return NextResponse.json({ success: true, task: { ...task, failure, error: failure ? formatRequestFailure(failure, task.id) : task.error } });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
|
|||||||
@ -1,92 +0,0 @@
|
|||||||
import { after, NextResponse } from "next/server";
|
|
||||||
import { z, ZodError } from "zod";
|
|
||||||
import { auth } from "@/app/(auth)/auth";
|
|
||||||
import { CanvasFeedbackError, collectCanvasFeedbackContext } from "@/lib/canvas/feedback-context";
|
|
||||||
import { feedbackCommandSchema } from "@/lib/canvas/feedback-contract";
|
|
||||||
import {
|
|
||||||
deliverCanvasFeedback,
|
|
||||||
feedbackReceipt,
|
|
||||||
findCanvasFeedback,
|
|
||||||
refreshCanvasFeedback,
|
|
||||||
saveCanvasFeedback,
|
|
||||||
} from "@/lib/canvas/feedback-store";
|
|
||||||
|
|
||||||
export const runtime = "nodejs";
|
|
||||||
export const dynamic = "force-dynamic";
|
|
||||||
const response = (data: unknown, status = 200) =>
|
|
||||||
NextResponse.json(data, { status, headers: { "Cache-Control": "no-store" } });
|
|
||||||
function failure(error: unknown) {
|
|
||||||
if (error instanceof CanvasFeedbackError) return response({ error: error.message }, error.status);
|
|
||||||
if (error instanceof ZodError || error instanceof SyntaxError)
|
|
||||||
return response({ error: "反馈资料格式不正确,请重新打开问题反馈后重试。" }, 400);
|
|
||||||
console.error("[Canvas feedback] request failed", {
|
|
||||||
errorType: error instanceof Error ? error.name : "unknown",
|
|
||||||
});
|
|
||||||
return response({ error: "反馈暂未保存成功,请保留问题说明,稍后重试。" }, 503);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
||||||
try {
|
|
||||||
const session = await auth();
|
|
||||||
if (!session?.user?.id) return response({ error: "登录已过期,请登录后发送反馈。" }, 401);
|
|
||||||
const projectId = z
|
|
||||||
.string()
|
|
||||||
.uuid()
|
|
||||||
.parse((await params).id);
|
|
||||||
const raw = await request.text();
|
|
||||||
if (new TextEncoder().encode(raw).byteLength > 262144)
|
|
||||||
return response({ error: "反馈资料过大,请减少补充说明后重试。" }, 413);
|
|
||||||
const command = feedbackCommandSchema.parse(JSON.parse(raw));
|
|
||||||
if (command.action === "submit") {
|
|
||||||
const existing = await findCanvasFeedback(command.id);
|
|
||||||
if (existing) {
|
|
||||||
if (existing.userId !== session.user.id || existing.projectId !== projectId)
|
|
||||||
throw new CanvasFeedbackError("反馈编号不可用", 409);
|
|
||||||
return response({ feedback: feedbackReceipt(await refreshCanvasFeedback(existing)) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const context = await collectCanvasFeedbackContext(
|
|
||||||
session.user.id,
|
|
||||||
projectId,
|
|
||||||
command.client,
|
|
||||||
command.action === "submit" ? command.selection : null,
|
|
||||||
);
|
|
||||||
if (command.action === "context") return response({ context });
|
|
||||||
const selected = context.requests.find((item) => item.key === command.selection) || null;
|
|
||||||
const row = await saveCanvasFeedback({
|
|
||||||
id: command.id,
|
|
||||||
userId: session.user.id,
|
|
||||||
description: command.description,
|
|
||||||
appUrl: process.env.NEXT_PUBLIC_APP_URL || new URL(request.url).origin,
|
|
||||||
snapshot: {
|
|
||||||
reporter: context.reporter,
|
|
||||||
project: context.project,
|
|
||||||
request: selected,
|
|
||||||
client: command.client,
|
|
||||||
userAgent: (request.headers.get("user-agent") || "").slice(0, 512),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
after(() => deliverCanvasFeedback(row.id));
|
|
||||||
return response({ feedback: feedbackReceipt(row) }, 202);
|
|
||||||
} catch (error) {
|
|
||||||
return failure(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
||||||
try {
|
|
||||||
const session = await auth();
|
|
||||||
if (!session?.user?.id) return response({ error: "登录已过期,请登录后查看反馈状态。" }, 401);
|
|
||||||
const projectId = z
|
|
||||||
.string()
|
|
||||||
.uuid()
|
|
||||||
.parse((await params).id);
|
|
||||||
const id = z.string().uuid().parse(new URL(request.url).searchParams.get("feedbackId"));
|
|
||||||
const row = await findCanvasFeedback(id);
|
|
||||||
if (!row || row.userId !== session.user.id || row.projectId !== projectId)
|
|
||||||
throw new CanvasFeedbackError("反馈记录不存在", 404);
|
|
||||||
return response({ feedback: feedbackReceipt(await refreshCanvasFeedback(row)) });
|
|
||||||
} catch (error) {
|
|
||||||
return failure(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1804,7 +1804,7 @@ async function runDualDirectorPlanPreflight(params: {
|
|||||||
? "You are both an art director and a marketing director for high-conversion e-commerce detail pages. Output JSON only."
|
? "You are both an art director and a marketing director for high-conversion e-commerce detail pages. Output JSON only."
|
||||||
: "你同时扮演高转化电商详情页的平面设计总监与营销总监。仅输出JSON。",
|
: "你同时扮演高转化电商详情页的平面设计总监与营销总监。仅输出JSON。",
|
||||||
temperature: params.isLocalMoonshot ? 1 : 0.1,
|
temperature: params.isLocalMoonshot ? 1 : 0.1,
|
||||||
maxOutputTokens: 2000,
|
maxTokens: 2000,
|
||||||
...(params.kimiOptions || {}),
|
...(params.kimiOptions || {}),
|
||||||
}, params.timeoutMs || DETAIL_PLAN_PREFLIGHT_TIMEOUT_MS);
|
}, params.timeoutMs || DETAIL_PLAN_PREFLIGHT_TIMEOUT_MS);
|
||||||
|
|
||||||
@ -2040,7 +2040,7 @@ export async function POST(request: Request) {
|
|||||||
kimiDetailProfile: plannerKimiOptions.headers
|
kimiDetailProfile: plannerKimiOptions.headers
|
||||||
? {
|
? {
|
||||||
thinking: plannerKimiOptions.headers["x-detail-agent-kimi-thinking"],
|
thinking: plannerKimiOptions.headers["x-detail-agent-kimi-thinking"],
|
||||||
maxOutputTokens: plannerKimiOptions.maxOutputTokens,
|
maxTokens: plannerKimiOptions.maxTokens,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
});
|
});
|
||||||
@ -2177,7 +2177,7 @@ export async function POST(request: Request) {
|
|||||||
`{"summary":"简述","globalStyle":{"designLanguage":"一句话风格方向","typography":{"fontFamily":"字体家族","title":"主标题规范","subtitle":"副标题规范","body":"正文规范"},"layout":{"grid":"栅格","safeArea":"安全区","rhythm":"留白节奏"},"palette":"配色规范"},"screens":[{"index":1,"screenType":"B","objective":"本屏目标","title":"首屏示例:甩甩杆,自拍不手抖(6-20字)","subtitle":"一句副标题","copy":"正文文案","layoutNote":"排版说明","useModel":false,"modelReason":"是否需要人物及原因","bundleShowcase":false,"bundleReason":"是否为搭配展示页及原因","fabe":{"b":"利益","f":"特征","a":"优势","e":"证据"},"visualPrompt":"用于生图的完整提示词,必须包含790x1300与统一字体排版"}],"dslV2Screens":[{"version":"detail-ui-dsl/v2","screenIndex":1,"layoutVariant":"hero-left-panel","region":{"x":0.06,"y":0.05,"width":0.88,"height":0.46},"nodes":[{"kind":"panel","id":"hero-panel","variant":"glass","tone":"light","direction":"column","gap":18,"children":[{"kind":"badge","id":"screen-badge","icon":"sparkle","text":"核心升级","tone":"primary"},{"kind":"heading","id":"hero-title","text":"护腰椅,久坐不腰酸","level":1,"emphasis":"hero"},{"kind":"body","id":"hero-subtitle","text":"在家里加班,也能护腰/舒适","emphasis":"strong"}]}]}]}`,
|
`{"summary":"简述","globalStyle":{"designLanguage":"一句话风格方向","typography":{"fontFamily":"字体家族","title":"主标题规范","subtitle":"副标题规范","body":"正文规范"},"layout":{"grid":"栅格","safeArea":"安全区","rhythm":"留白节奏"},"palette":"配色规范"},"screens":[{"index":1,"screenType":"B","objective":"本屏目标","title":"首屏示例:甩甩杆,自拍不手抖(6-20字)","subtitle":"一句副标题","copy":"正文文案","layoutNote":"排版说明","useModel":false,"modelReason":"是否需要人物及原因","bundleShowcase":false,"bundleReason":"是否为搭配展示页及原因","fabe":{"b":"利益","f":"特征","a":"优势","e":"证据"},"visualPrompt":"用于生图的完整提示词,必须包含790x1300与统一字体排版"}],"dslV2Screens":[{"version":"detail-ui-dsl/v2","screenIndex":1,"layoutVariant":"hero-left-panel","region":{"x":0.06,"y":0.05,"width":0.88,"height":0.46},"nodes":[{"kind":"panel","id":"hero-panel","variant":"glass","tone":"light","direction":"column","gap":18,"children":[{"kind":"badge","id":"screen-badge","icon":"sparkle","text":"核心升级","tone":"primary"},{"kind":"heading","id":"hero-title","text":"护腰椅,久坐不腰酸","level":1,"emphasis":"hero"},{"kind":"body","id":"hero-subtitle","text":"在家里加班,也能护腰/舒适","emphasis":"strong"}]}]}]}`,
|
||||||
temperature: 0.25,
|
temperature: 0.25,
|
||||||
...(localDetailAgentResolved ? { temperature: 1 } : {}),
|
...(localDetailAgentResolved ? { temperature: 1 } : {}),
|
||||||
maxOutputTokens: 1800,
|
maxTokens: 1800,
|
||||||
...plannerKimiOptions,
|
...plannerKimiOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -323,7 +323,7 @@ export async function POST(request: Request) {
|
|||||||
kimiDetailProfile: reviewKimiOptions.headers
|
kimiDetailProfile: reviewKimiOptions.headers
|
||||||
? {
|
? {
|
||||||
thinking: reviewKimiOptions.headers["x-detail-agent-kimi-thinking"],
|
thinking: reviewKimiOptions.headers["x-detail-agent-kimi-thinking"],
|
||||||
maxOutputTokens: reviewKimiOptions.maxOutputTokens,
|
maxTokens: reviewKimiOptions.maxTokens,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
});
|
});
|
||||||
@ -438,7 +438,7 @@ export async function POST(request: Request) {
|
|||||||
? "You are both an Art Director and a Marketing Director for high-conversion e-commerce detail pages. Evaluate with strict professional standards and output JSON only."
|
? "You are both an Art Director and a Marketing Director for high-conversion e-commerce detail pages. Evaluate with strict professional standards and output JSON only."
|
||||||
: "你同时是高转化电商详情页的平面设计总监与营销总监。按严格专业标准评估,仅输出JSON。",
|
: "你同时是高转化电商详情页的平面设计总监与营销总监。按严格专业标准评估,仅输出JSON。",
|
||||||
temperature: localDetailAgentResolved ? 1 : 0.1,
|
temperature: localDetailAgentResolved ? 1 : 0.1,
|
||||||
maxOutputTokens: 800,
|
maxTokens: 800,
|
||||||
...reviewKimiOptions,
|
...reviewKimiOptions,
|
||||||
} as any);
|
} as any);
|
||||||
text = String(result?.text || "");
|
text = String(result?.text || "");
|
||||||
|
|||||||
@ -114,7 +114,7 @@ export async function POST(request: NextRequest) {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
temperature: 0.2,
|
temperature: 0.2,
|
||||||
maxOutputTokens: 1200,
|
maxTokens: 1200,
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
@ -11406,7 +11406,6 @@ export default function CanvasEditorLegacyPage({
|
|||||||
setPanelMode("fileList");
|
setPanelMode("fileList");
|
||||||
}}
|
}}
|
||||||
projectTitle={projectTitle}
|
projectTitle={projectTitle}
|
||||||
projectId={id}
|
|
||||||
rightInset={panelOcclusionRight}
|
rightInset={panelOcclusionRight}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -1,110 +0,0 @@
|
|||||||
import { notFound, redirect } from "next/navigation";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { auth } from "@/app/(auth)/auth";
|
|
||||||
import { feedbackReceipt, findCanvasFeedback } from "@/lib/canvas/feedback-store";
|
|
||||||
import { formatFeedbackTime } from "@/lib/canvas/feedback-contract";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
|
||||||
|
|
||||||
export default async function CanvasFeedbackPage({ params }: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id } = await params;
|
|
||||||
if (!z.string().uuid().safeParse(id).success) notFound();
|
|
||||||
const session = await auth();
|
|
||||||
if (!session?.user?.id || session.user.type === "guest") {
|
|
||||||
const query = new URLSearchParams({ callbackUrl: `/feedback/${id}` });
|
|
||||||
redirect(`/login?${query}`);
|
|
||||||
}
|
|
||||||
const feedback = await findCanvasFeedback(id);
|
|
||||||
if (!feedback || (feedback.userId !== session.user.id && session.user.type !== "admin"))
|
|
||||||
notFound();
|
|
||||||
const { reporter, project, request, client, userAgent } = feedback.snapshot;
|
|
||||||
const fields = [
|
|
||||||
["反馈编号", feedback.id],
|
|
||||||
["反馈人", `${reporter.name} · ${reporter.email} · ${reporter.department || "未登记部门"}`],
|
|
||||||
["用户编号", reporter.id],
|
|
||||||
["反馈时间", formatFeedbackTime(feedback.createdAt.toISOString())],
|
|
||||||
["画布", `${project.title}(${project.id})`],
|
|
||||||
["对话编号", client.chatId || "未打开对话"],
|
|
||||||
["请求号", request?.requestId || "尚未获取"],
|
|
||||||
["任务或消息编号", request?.id || "未关联"],
|
|
||||||
["请求时间", request?.createdAt ? formatFeedbackTime(request.createdAt) : "未记录"],
|
|
||||||
["状态与模型", `${request?.status || "页面问题"} / ${request?.model || "未记录"}`],
|
|
||||||
[
|
|
||||||
"处理耗时",
|
|
||||||
request?.durationMs != null
|
|
||||||
? `${(request.durationMs / 1000).toFixed(1)} 秒`
|
|
||||||
: "未记录或尚未结束",
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"资料来源",
|
|
||||||
request?.evidence === "browser"
|
|
||||||
? "浏览器当前对话,服务端尚无对应消息记录"
|
|
||||||
: "服务端记录及浏览器当前页面",
|
|
||||||
],
|
|
||||||
["页面版本", client.pageVersion],
|
|
||||||
["浏览器", userAgent],
|
|
||||||
[
|
|
||||||
"窗口与网络",
|
|
||||||
`${client.viewport.width} × ${client.viewport.height} · ${client.online ? "在线" : "离线"}`,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return (
|
|
||||||
<main className="mx-auto max-w-3xl space-y-6 px-6 py-8 text-foreground">
|
|
||||||
<h1 className="text-2xl font-semibold">画布问题反馈</h1>
|
|
||||||
<p className="text-sm text-muted-foreground">{feedbackReceipt(feedback).message}</p>
|
|
||||||
<dl className="space-y-3">
|
|
||||||
{fields.map(([label, value]) => (
|
|
||||||
<div key={label} className="grid gap-1 text-sm sm:grid-cols-[8rem_1fr]">
|
|
||||||
<dt className="text-muted-foreground">{label}</dt>
|
|
||||||
<dd className="whitespace-pre-wrap break-words">{value}</dd>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</dl>
|
|
||||||
{[
|
|
||||||
["用户说明", feedback.description || "未补充说明"],
|
|
||||||
["请求内容", request?.prompt || "未关联具体请求"],
|
|
||||||
["错误信息", request?.error || client.errors.join("\n") || "未记录明确错误"],
|
|
||||||
].map(([label, value]) => (
|
|
||||||
<section key={label} className="space-y-2">
|
|
||||||
<h2 className="text-base font-medium">{label}</h2>
|
|
||||||
<p className="whitespace-pre-wrap break-words rounded-lg bg-muted p-4 text-sm">{value}</p>
|
|
||||||
</section>
|
|
||||||
))}
|
|
||||||
{request?.parameters && Object.keys(request.parameters).length > 0 && (
|
|
||||||
<section className="space-y-2">
|
|
||||||
<h2 className="text-base font-medium">请求参数</h2>
|
|
||||||
<pre className="overflow-auto whitespace-pre-wrap break-all rounded-lg bg-muted p-4 text-sm">
|
|
||||||
{JSON.stringify(request.parameters, null, 2)}
|
|
||||||
</pre>
|
|
||||||
</section>
|
|
||||||
)}
|
|
||||||
{client.nodes.length > 0 && (
|
|
||||||
<details className="text-sm">
|
|
||||||
<summary className="cursor-pointer">相关画布节点</summary>
|
|
||||||
<pre className="mt-3 overflow-auto whitespace-pre-wrap break-all">
|
|
||||||
{JSON.stringify(client.nodes, null, 2)}
|
|
||||||
</pre>
|
|
||||||
</details>
|
|
||||||
)}
|
|
||||||
<details className="text-sm">
|
|
||||||
<summary className="cursor-pointer">当前对话上下文</summary>
|
|
||||||
<div className="mt-4 space-y-4">
|
|
||||||
{client.messages.map((item) => (
|
|
||||||
<div key={item.id} className="space-y-1">
|
|
||||||
<p className="text-muted-foreground">
|
|
||||||
{item.role === "user" ? "用户" : "助手"} · {item.id}
|
|
||||||
</p>
|
|
||||||
<p className="whitespace-pre-wrap break-words">{item.text}</p>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
<a
|
|
||||||
className="inline-block text-sm underline underline-offset-4"
|
|
||||||
href={`/canvas/${project.id}`}
|
|
||||||
>
|
|
||||||
打开相关画布
|
|
||||||
</a>
|
|
||||||
</main>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,6 +1,4 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { CANVAS_FEEDBACK_CONTEXT_EVENT, feedbackMessages, type FeedbackCaptureEvent } from "@/lib/canvas/feedback-client";
|
|
||||||
import { CanvasFeedbackDialog } from "./CanvasFeedbackDialog";
|
|
||||||
|
|
||||||
import { advancePastAtomicRanges, scanMarkdownImageStreaming } from "@/lib/canvas/markdown-image-streaming";
|
import { advancePastAtomicRanges, scanMarkdownImageStreaming } from "@/lib/canvas/markdown-image-streaming";
|
||||||
import { useChat } from "@ai-sdk/react";
|
import { useChat } from "@ai-sdk/react";
|
||||||
@ -4431,15 +4429,6 @@ export function CanvasChatPanel({
|
|||||||
|
|
||||||
// 获取纯 UUID(去掉 canvas- 前缀)用于 API 调用
|
// 获取纯 UUID(去掉 canvas- 前缀)用于 API 调用
|
||||||
const rawChatId = toRawCanvasChatId(activeChatId);
|
const rawChatId = toRawCanvasChatId(activeChatId);
|
||||||
useEffect(() => {
|
|
||||||
const collectFeedback = (event: Event) => {
|
|
||||||
const detail = (event as FeedbackCaptureEvent).detail;
|
|
||||||
if (detail.projectId !== canvasId) return;
|
|
||||||
detail.receive({ chatId: rawChatId, messages: feedbackMessages(activeMessagesRef.current) });
|
|
||||||
};
|
|
||||||
window.addEventListener(CANVAS_FEEDBACK_CONTEXT_EVENT, collectFeedback);
|
|
||||||
return () => window.removeEventListener(CANVAS_FEEDBACK_CONTEXT_EVENT, collectFeedback);
|
|
||||||
}, [canvasId, rawChatId]);
|
|
||||||
const buildHistoryMessagesUrl = useCallback(
|
const buildHistoryMessagesUrl = useCallback(
|
||||||
(targetRawChatId: string, options?: { cacheBust?: boolean }) => {
|
(targetRawChatId: string, options?: { cacheBust?: boolean }) => {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
@ -15898,9 +15887,6 @@ export function CanvasChatPanel({
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex shrink-0 items-center">
|
<div className="flex shrink-0 items-center">
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<div className={isVideoWorkspace ? "" : "sm:hidden"}>
|
|
||||||
<CanvasFeedbackDialog projectId={canvasId} />
|
|
||||||
</div>
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
|
|||||||
@ -1,363 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { Bug } from "lucide-react";
|
|
||||||
import { useEffect, useRef, useState } from "react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import { captureFeedbackChat } from "@/lib/canvas/feedback-client";
|
|
||||||
import { useCanvasStore } from "@/store/canvas";
|
|
||||||
import {
|
|
||||||
feedbackCommandSchema,
|
|
||||||
formatFeedbackTime,
|
|
||||||
type FeedbackClient,
|
|
||||||
type FeedbackContext,
|
|
||||||
type FeedbackReceipt,
|
|
||||||
} from "@/lib/canvas/feedback-contract";
|
|
||||||
|
|
||||||
type Submission = Extract<ReturnType<typeof feedbackCommandSchema.parse>, { action: "submit" }>;
|
|
||||||
const terminal = (value: string) => ["sent", "unread", "read", "failed"].includes(value);
|
|
||||||
const fieldClass =
|
|
||||||
"w-full rounded-lg border border-input bg-background px-3 py-2 text-sm text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring";
|
|
||||||
|
|
||||||
export function CanvasFeedbackDialog({ projectId }: { projectId: string }) {
|
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const [context, setContext] = useState<FeedbackContext | null>(null);
|
|
||||||
const [selection, setSelection] = useState<string | null>(null);
|
|
||||||
const [description, setDescription] = useState("");
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [sending, setSending] = useState(false);
|
|
||||||
const [sealed, setSealed] = useState(false);
|
|
||||||
const [error, setError] = useState("");
|
|
||||||
const [receipt, setReceipt] = useState<FeedbackReceipt | null>(null);
|
|
||||||
const captured = useRef<FeedbackClient | null>(null);
|
|
||||||
const submission = useRef<Submission | null>(null);
|
|
||||||
const errors = useRef<string[]>([]);
|
|
||||||
const submitLock = useRef(false);
|
|
||||||
const endpoint = `/api/canvas/${projectId}/feedback`;
|
|
||||||
const storageKey = `canvas-feedback:${projectId}`;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const rememberError = (event: ErrorEvent) => {
|
|
||||||
errors.current = [
|
|
||||||
...errors.current,
|
|
||||||
String(event.message || "页面脚本错误").slice(0, 2000),
|
|
||||||
].slice(-5);
|
|
||||||
};
|
|
||||||
window.addEventListener("error", rememberError);
|
|
||||||
return () => window.removeEventListener("error", rememberError);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open || receipt) return;
|
|
||||||
const controller = new AbortController();
|
|
||||||
try {
|
|
||||||
const raw = sessionStorage.getItem(storageKey);
|
|
||||||
if (raw && !submission.current) {
|
|
||||||
const command = feedbackCommandSchema.parse(JSON.parse(raw));
|
|
||||||
if (command.action === "submit") {
|
|
||||||
submission.current = command;
|
|
||||||
captured.current = command.client;
|
|
||||||
setSealed(true);
|
|
||||||
setDescription(command.description);
|
|
||||||
setSelection(command.selection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
/* An unavailable local draft does not prevent a new feedback report. */
|
|
||||||
}
|
|
||||||
if (submission.current) {
|
|
||||||
void fetch(`${endpoint}?feedbackId=${submission.current.id}`, {
|
|
||||||
cache: "no-store",
|
|
||||||
signal: controller.signal,
|
|
||||||
})
|
|
||||||
.then(async (response) => {
|
|
||||||
const data = await response.json();
|
|
||||||
if (response.ok) setReceipt(data.feedback);
|
|
||||||
else if (response.status !== 404)
|
|
||||||
setError(data.error || "暂时无法确认反馈状态,请重试提交同一条反馈。");
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
if (!controller.signal.aborted) setError("暂时无法确认反馈状态,可重试提交同一条反馈。");
|
|
||||||
});
|
|
||||||
return () => controller.abort();
|
|
||||||
}
|
|
||||||
const canvas = useCanvasStore.getState();
|
|
||||||
const selectedIds = new Set(canvas.selectedNodeIds);
|
|
||||||
const nodes = [...canvas.nodes]
|
|
||||||
.sort((a, b) => Number(selectedIds.has(b.id)) - Number(selectedIds.has(a.id)))
|
|
||||||
.slice(0, 20);
|
|
||||||
const client: FeedbackClient = {
|
|
||||||
...captureFeedbackChat(projectId),
|
|
||||||
capturedAt: new Date().toISOString(),
|
|
||||||
pageVersion: process.env.NEXT_PUBLIC_APP_RELEASE || "development",
|
|
||||||
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
||||||
online: navigator.onLine,
|
|
||||||
errors: [...errors.current],
|
|
||||||
nodes: nodes.map((node) => {
|
|
||||||
const data = node.data as unknown as Record<string, unknown>;
|
|
||||||
const metadata = data.metadata as Record<string, unknown> | undefined;
|
|
||||||
return {
|
|
||||||
id: node.id.slice(0, 180),
|
|
||||||
type: node.type.slice(0, 64),
|
|
||||||
title: String(data.title || "").slice(0, 256),
|
|
||||||
status: String(data.status || "").slice(0, 64),
|
|
||||||
taskId: String(metadata?.taskId || "").slice(0, 180),
|
|
||||||
width: node.size?.width,
|
|
||||||
height: node.size?.height,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
captured.current = client;
|
|
||||||
setLoading(true);
|
|
||||||
setError("");
|
|
||||||
void fetch(endpoint, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ action: "context", client }),
|
|
||||||
signal: controller.signal,
|
|
||||||
})
|
|
||||||
.then(async (response) => {
|
|
||||||
const data = await response.json();
|
|
||||||
if (!response.ok) throw new Error(data.error || "排查资料暂时加载失败,请重新打开反馈。");
|
|
||||||
setContext(data.context);
|
|
||||||
setSelection(data.context.requests[0]?.key || null);
|
|
||||||
})
|
|
||||||
.catch((failure) => {
|
|
||||||
if (!controller.signal.aborted)
|
|
||||||
setError(failure.message || "排查资料暂时加载失败,请重新打开反馈。");
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (!controller.signal.aborted) setLoading(false);
|
|
||||||
});
|
|
||||||
return () => controller.abort();
|
|
||||||
}, [open, endpoint, projectId, receipt, storageKey]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open || !receipt || terminal(receipt.status)) return;
|
|
||||||
const controller = new AbortController();
|
|
||||||
let timer: ReturnType<typeof setTimeout>;
|
|
||||||
const poll = async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${endpoint}?feedbackId=${receipt.id}`, {
|
|
||||||
cache: "no-store",
|
|
||||||
signal: controller.signal,
|
|
||||||
});
|
|
||||||
const data = await response.json();
|
|
||||||
if (response.ok && !controller.signal.aborted) {
|
|
||||||
setReceipt(data.feedback);
|
|
||||||
setError("");
|
|
||||||
} else if (!controller.signal.aborted)
|
|
||||||
setError(data.error || "暂时无法刷新通知状态,已保存的反馈会继续处理。");
|
|
||||||
} catch {
|
|
||||||
if (!controller.signal.aborted)
|
|
||||||
setError("网络暂时不可用,已保存的反馈会继续处理,请勿重复提交。");
|
|
||||||
}
|
|
||||||
if (!controller.signal.aborted) timer = setTimeout(poll, 4000);
|
|
||||||
};
|
|
||||||
timer = setTimeout(poll, 1500);
|
|
||||||
return () => {
|
|
||||||
controller.abort();
|
|
||||||
clearTimeout(timer);
|
|
||||||
};
|
|
||||||
}, [open, receipt?.id, receipt?.status, endpoint]);
|
|
||||||
|
|
||||||
const send = async () => {
|
|
||||||
if (submitLock.current || receipt) return;
|
|
||||||
if (!submission.current) {
|
|
||||||
if (!captured.current || !context) return;
|
|
||||||
submission.current = {
|
|
||||||
action: "submit",
|
|
||||||
id: crypto.randomUUID(),
|
|
||||||
description,
|
|
||||||
selection,
|
|
||||||
client: captured.current,
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
sessionStorage.setItem(storageKey, JSON.stringify(submission.current));
|
|
||||||
} catch {
|
|
||||||
/* In-memory retries still retain this report's id. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
submitLock.current = true;
|
|
||||||
setSending(true);
|
|
||||||
setSealed(true);
|
|
||||||
setError("");
|
|
||||||
try {
|
|
||||||
const response = await fetch(endpoint, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify(submission.current),
|
|
||||||
signal: AbortSignal.timeout(20000),
|
|
||||||
});
|
|
||||||
const data = await response.json();
|
|
||||||
if (!response.ok) {
|
|
||||||
if (response.status === 400 || response.status === 409 || response.status === 413) {
|
|
||||||
submission.current = null;
|
|
||||||
sessionStorage.removeItem(storageKey);
|
|
||||||
setSealed(false);
|
|
||||||
}
|
|
||||||
throw new Error(data.error || "暂时无法确认反馈是否保存,请重试提交同一条反馈。");
|
|
||||||
}
|
|
||||||
setReceipt(data.feedback);
|
|
||||||
} catch (failure) {
|
|
||||||
setError(
|
|
||||||
failure instanceof Error && failure.name !== "TimeoutError"
|
|
||||||
? failure.message
|
|
||||||
: "提交连接超时。请重试提交同一条反馈,系统会核对原编号,避免重复通知。",
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
submitLock.current = false;
|
|
||||||
setSending(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const startAnother = () => {
|
|
||||||
submission.current = null;
|
|
||||||
captured.current = null;
|
|
||||||
sessionStorage.removeItem(storageKey);
|
|
||||||
setContext(null);
|
|
||||||
setDescription("");
|
|
||||||
setSelection(null);
|
|
||||||
setError("");
|
|
||||||
setSealed(false);
|
|
||||||
setReceipt(null);
|
|
||||||
};
|
|
||||||
const selected = context?.requests.find((item) => item.key === selection);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
|
||||||
<DialogTrigger asChild>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="ml-2 inline-flex shrink-0 items-center gap-2 rounded-lg px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
|
|
||||||
aria-label="问题反馈"
|
|
||||||
>
|
|
||||||
<Bug className="size-4" aria-hidden="true" />
|
|
||||||
<span className="hidden sm:inline">问题反馈</span>
|
|
||||||
</button>
|
|
||||||
</DialogTrigger>
|
|
||||||
<DialogContent
|
|
||||||
className="max-h-[85dvh] overflow-y-auto sm:max-w-xl"
|
|
||||||
aria-busy={loading || sending}
|
|
||||||
>
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>问题反馈</DialogTitle>
|
|
||||||
<DialogDescription className="text-pretty">
|
|
||||||
自动附上当前画布、用户和相关请求资料。你可以补充问题现象,发送给魔礼红。
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
{receipt ? (
|
|
||||||
<div className="space-y-3 py-2" role="status" aria-live="polite">
|
|
||||||
<p className="text-sm">{receipt.message}</p>
|
|
||||||
<p className="break-all text-sm text-muted-foreground">反馈编号:{receipt.id}</p>
|
|
||||||
<a
|
|
||||||
href={`/feedback/${receipt.id}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
className="inline-block text-sm underline underline-offset-4"
|
|
||||||
>
|
|
||||||
查看已保存的完整反馈
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="space-y-4">
|
|
||||||
{loading ? (
|
|
||||||
<p role="status" className="py-4 text-sm text-muted-foreground">
|
|
||||||
正在整理排查资料…
|
|
||||||
</p>
|
|
||||||
) : context ? (
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{context.reporter.name} · {context.project.title}
|
|
||||||
</p>
|
|
||||||
) : null}
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label htmlFor="canvas-feedback-request" className="text-sm font-medium">
|
|
||||||
关联请求
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
id="canvas-feedback-request"
|
|
||||||
className={fieldClass}
|
|
||||||
value={selection || ""}
|
|
||||||
disabled={sealed || loading}
|
|
||||||
onChange={(event) => setSelection(event.target.value || null)}
|
|
||||||
>
|
|
||||||
<option value="">页面或画布问题,不关联具体请求</option>
|
|
||||||
{context?.requests.map((item) => (
|
|
||||||
<option key={item.key} value={item.key}>
|
|
||||||
{item.createdAt ? formatFeedbackTime(item.createdAt) : "时间未记录"} ·{" "}
|
|
||||||
{item.prompt.slice(0, 45)}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
{selected && (
|
|
||||||
<div className="space-y-2 rounded-lg bg-muted p-3 text-sm">
|
|
||||||
<p>
|
|
||||||
请求号:
|
|
||||||
<span className="break-all">
|
|
||||||
{selected.requestId || "尚未获取,将附上消息编号"}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
<p className="max-h-28 overflow-y-auto whitespace-pre-wrap break-words text-muted-foreground">
|
|
||||||
{selected.prompt}
|
|
||||||
</p>
|
|
||||||
{selected.error && (
|
|
||||||
<p className="whitespace-pre-wrap break-words">{selected.error}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label htmlFor="canvas-feedback-description" className="text-sm font-medium">
|
|
||||||
补充说明 <span className="font-normal text-muted-foreground">(选填)</span>
|
|
||||||
</label>
|
|
||||||
<textarea
|
|
||||||
id="canvas-feedback-description"
|
|
||||||
rows={4}
|
|
||||||
maxLength={2000}
|
|
||||||
className={`${fieldClass} resize-y`}
|
|
||||||
value={description}
|
|
||||||
disabled={sealed}
|
|
||||||
onChange={(event) => setDescription(event.target.value)}
|
|
||||||
placeholder="例如:点击预览后一直加载,等待约 30 秒仍无法查看。"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
将附上相关请求内容、任务状态、页面版本及已记录的错误;本次反馈不会重新执行任务。
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{error && (
|
|
||||||
<p role="alert" className="whitespace-pre-wrap text-sm text-destructive">
|
|
||||||
{error}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
<DialogFooter className="gap-2 sm:space-x-0">
|
|
||||||
<Button type="button" variant="outline" onClick={() => setOpen(false)}>
|
|
||||||
{receipt ? "返回画布" : "取消"}
|
|
||||||
</Button>
|
|
||||||
{receipt ? (
|
|
||||||
<Button type="button" variant="outline" onClick={startAnother}>
|
|
||||||
反馈另一个问题
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
onClick={() => void send()}
|
|
||||||
disabled={sending || loading || (!context && !submission.current)}
|
|
||||||
>
|
|
||||||
{sending ? "正在发送…" : sealed ? "重试提交同一反馈" : "发送给魔礼红"}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,14 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { ReferenceIcon } from "@/components/lovart/reference-icon";
|
import { ReferenceIcon } from "@/components/lovart/reference-icon";
|
||||||
import { CanvasFeedbackDialog } from "./CanvasFeedbackDialog";
|
|
||||||
|
|
||||||
type CanvasSurfaceHeaderProps = {
|
type CanvasSurfaceHeaderProps = {
|
||||||
onAddImage: () => void;
|
onAddImage: () => void;
|
||||||
onHome: () => void;
|
onHome: () => void;
|
||||||
onOpenFiles: () => void;
|
onOpenFiles: () => void;
|
||||||
projectTitle: string;
|
projectTitle: string;
|
||||||
projectId: string;
|
|
||||||
rightInset: number;
|
rightInset: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,7 +18,6 @@ export function CanvasSurfaceHeader({
|
|||||||
onHome,
|
onHome,
|
||||||
onOpenFiles,
|
onOpenFiles,
|
||||||
projectTitle,
|
projectTitle,
|
||||||
projectId,
|
|
||||||
rightInset,
|
rightInset,
|
||||||
}: CanvasSurfaceHeaderProps) {
|
}: CanvasSurfaceHeaderProps) {
|
||||||
return (
|
return (
|
||||||
@ -74,7 +71,6 @@ export function CanvasSurfaceHeader({
|
|||||||
<ReferenceIcon name="plus" size={16} />
|
<ReferenceIcon name="plus" size={16} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<CanvasFeedbackDialog projectId={projectId} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
import { fetchUploadWithRetry } from "@/lib/client/upload-with-retry";
|
import { fetchUploadWithRetry } from "@/lib/client/upload-with-retry";
|
||||||
import { useCanvasGroupRuns } from "@/hooks/use-canvas-group-runs";
|
import { useCanvasGroupRuns } from "@/hooks/use-canvas-group-runs";
|
||||||
import { hasRecoverableCanvasTask } from "@/lib/video-canvas/task-recovery";
|
import { hasRecoverableCanvasTask } from "@/lib/video-canvas/task-recovery";
|
||||||
import { restoreTextResourceContent } from "@/lib/video-canvas/text-resource";
|
|
||||||
import { GroupStoryboardPreview } from "./GroupStoryboardPreview";
|
import { GroupStoryboardPreview } from "./GroupStoryboardPreview";
|
||||||
import { CanvasGroupToolbar } from "./CanvasGroupToolbar";
|
import { CanvasGroupToolbar } from "./CanvasGroupToolbar";
|
||||||
import { isCanvasGroup, groupMembers, makeCanvasGroup, ungroupCanvasNodes, moveCanvasSelection, layoutCanvasGroup, migrateLegacyGroups, exportCanvasGroup, instantiateCanvasGroup, groupBounds, assignGroupMembers } from "@/lib/video-canvas/groups";
|
import { isCanvasGroup, groupMembers, makeCanvasGroup, ungroupCanvasNodes, moveCanvasSelection, layoutCanvasGroup, migrateLegacyGroups, exportCanvasGroup, instantiateCanvasGroup, groupBounds, assignGroupMembers } from "@/lib/video-canvas/groups";
|
||||||
@ -4146,7 +4145,7 @@ function normalizeTextResourceNode(node: CloneNode, fallbackIndex: number): Clon
|
|||||||
draftValues: {
|
draftValues: {
|
||||||
...(node.draftValues || {}),
|
...(node.draftValues || {}),
|
||||||
action: "TEXT_RESOURCE",
|
action: "TEXT_RESOURCE",
|
||||||
content: restoreTextResourceContent(node.draftValues),
|
content: Array.isArray(node.draftValues?.content) ? node.draftValues?.content : [],
|
||||||
nodeType: "text",
|
nodeType: "text",
|
||||||
scriptRole: "resource",
|
scriptRole: "resource",
|
||||||
viewMode: undefined,
|
viewMode: undefined,
|
||||||
@ -15627,8 +15626,7 @@ function VideoTargetModuleComposer({
|
|||||||
const ratio = supported.ratios.length && !supported.ratios.includes(normalizeVideoRatioValue(current.ratio)) ? supported.ratios[0] : current.ratio;
|
const ratio = supported.ratios.length && !supported.ratios.includes(normalizeVideoRatioValue(current.ratio)) ? supported.ratios[0] : current.ratio;
|
||||||
const executableResolutions = supported.resolutions.filter(value => ["480p", "720p", "1080p"].includes(value.toLowerCase()));
|
const executableResolutions = supported.resolutions.filter(value => ["480p", "720p", "1080p"].includes(value.toLowerCase()));
|
||||||
const resolution = executableResolutions.length && !executableResolutions.includes(normalizeVideoResolutionValue(current.resolution)) ? executableResolutions[0].toUpperCase() : current.resolution;
|
const resolution = executableResolutions.length && !executableResolutions.includes(normalizeVideoResolutionValue(current.resolution)) ? executableResolutions[0].toUpperCase() : current.resolution;
|
||||||
const durations = getCanvasVideoParameters(target, activeMode, resolution || "720P").durations;
|
const duration = supported.durations.length && !supported.durations.includes(normalizeVideoDurationValue(current.duration)) ? `${supported.durations[0]}s` : current.duration;
|
||||||
const duration = durations.length && !durations.includes(normalizeVideoDurationValue(current.duration)) ? `${durations[0]}s` : current.duration;
|
|
||||||
const audio = supported.supportsAudio ? current.audio : "关闭";
|
const audio = supported.supportsAudio ? current.audio : "关闭";
|
||||||
return ratio === current.ratio && resolution === current.resolution && duration === current.duration && audio === current.audio ? current : {...current, ratio, resolution, duration, audio};
|
return ratio === current.ratio && resolution === current.resolution && duration === current.duration && audio === current.audio ? current : {...current, ratio, resolution, duration, audio};
|
||||||
});
|
});
|
||||||
@ -17931,7 +17929,7 @@ function VideoParameterEditor({
|
|||||||
const candidates = filterCanvasModels(modelOptions, audioRequired ? "audio-video" : "video", mode);
|
const candidates = filterCanvasModels(modelOptions, audioRequired ? "audio-video" : "video", mode);
|
||||||
const model = candidates.find(item => item.id === settings.model || item.modelId === settings.model) ||
|
const model = candidates.find(item => item.id === settings.model || item.modelId === settings.model) ||
|
||||||
(!normalizeModelRef(settings.model) || settings.model === "auto" ? candidates[0] : undefined);
|
(!normalizeModelRef(settings.model) || settings.model === "auto" ? candidates[0] : undefined);
|
||||||
const options = getCanvasVideoParameters(model, mode, settings.resolution || "720P");
|
const options = getCanvasVideoParameters(model, mode);
|
||||||
const executableResolutions = options.resolutions.filter(value => ["480p", "720p", "1080p"].includes(value.toLowerCase())).map(value => value.toUpperCase());
|
const executableResolutions = options.resolutions.filter(value => ["480p", "720p", "1080p"].includes(value.toLowerCase())).map(value => value.toUpperCase());
|
||||||
const durationIndex = Math.max(0, options.durations.indexOf(normalizeVideoDurationValue(settings.duration)));
|
const durationIndex = Math.max(0, options.durations.indexOf(normalizeVideoDurationValue(settings.duration)));
|
||||||
return (
|
return (
|
||||||
@ -20841,18 +20839,8 @@ function PresetMediaCanvasNode({
|
|||||||
</div>
|
</div>
|
||||||
) : mediaType === "audio" ? (
|
) : mediaType === "audio" ? (
|
||||||
<div className="relative h-[calc(100%-32px)]">
|
<div className="relative h-[calc(100%-32px)]">
|
||||||
{isGenerating || isGenerationFailed ? (
|
<OfficialAudioCard durationSeconds={getDraftNumber(node, "durationSeconds", 3)} mediaUrl={mediaUrl} selected={selected} />
|
||||||
<GenerationPendingPreview
|
{!generated ? (
|
||||||
errorMessage={getDraftString(node, "generationError")}
|
|
||||||
onCancel={onCancelGeneration}
|
|
||||||
progress={getDraftNumber(node, "generationProgress", 0)}
|
|
||||||
status={generationStatus}
|
|
||||||
statusLabel={getDraftString(node, "pendingLabel") || "生成中"}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<OfficialAudioCard durationSeconds={getDraftNumber(node, "durationSeconds", 0)} mediaUrl={mediaUrl} selected={selected} />
|
|
||||||
)}
|
|
||||||
{!generated && !isGenerating && !isGenerationFailed ? (
|
|
||||||
<button
|
<button
|
||||||
aria-label={mediaUrl ? "替换音频" : "上传音频"}
|
aria-label={mediaUrl ? "替换音频" : "上传音频"}
|
||||||
className="absolute right-3 top-3 flex h-9 w-9 items-center justify-center rounded-[8px] bg-black/56 text-white/90"
|
className="absolute right-3 top-3 flex h-9 w-9 items-center justify-center rounded-[8px] bg-black/56 text-white/90"
|
||||||
@ -21398,14 +21386,12 @@ function GenerationPendingPreview({
|
|||||||
previewUrl,
|
previewUrl,
|
||||||
progress,
|
progress,
|
||||||
status,
|
status,
|
||||||
statusLabel,
|
|
||||||
}: {
|
}: {
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
previewUrl?: string;
|
previewUrl?: string;
|
||||||
progress: number;
|
progress: number;
|
||||||
status: string;
|
status: string;
|
||||||
statusLabel?: string;
|
|
||||||
}) {
|
}) {
|
||||||
const displayProgress = Math.max(2, Math.min(99, Math.round(progress)));
|
const displayProgress = Math.max(2, Math.min(99, Math.round(progress)));
|
||||||
const failed = status === "failed";
|
const failed = status === "failed";
|
||||||
@ -21451,7 +21437,7 @@ function GenerationPendingPreview({
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<span>{statusLabel || `生成中 ${displayProgress}%...`}</span>
|
<span>生成中 {displayProgress}%...</span>
|
||||||
<button
|
<button
|
||||||
className="font-medium text-white/42 transition hover:text-white/80"
|
className="font-medium text-white/42 transition hover:text-white/80"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
@ -21479,7 +21465,11 @@ function PureTextResourceCanvasNode({
|
|||||||
onTextResourceChange: (content: string) => void;
|
onTextResourceChange: (content: string) => void;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
}) {
|
}) {
|
||||||
const textContent = restoreTextResourceContent(node.draftValues)[0] || "";
|
const contentValues = node.draftValues?.content;
|
||||||
|
const textContent =
|
||||||
|
Array.isArray(contentValues) && typeof contentValues[0] === "string"
|
||||||
|
? contentValues[0]
|
||||||
|
: "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full w-full">
|
<div className="h-full w-full">
|
||||||
|
|||||||
@ -1663,10 +1663,6 @@ export function ImageNode({
|
|||||||
}, [publicModelAliasConfig.worldModels]);
|
}, [publicModelAliasConfig.worldModels]);
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const [isProcessing, setIsProcessing] = useState(false);
|
const [isProcessing, setIsProcessing] = useState(false);
|
||||||
const [toolbarFailure, setToolbarFailure] = useState<{
|
|
||||||
imageUrl: string;
|
|
||||||
message: string;
|
|
||||||
} | null>(null);
|
|
||||||
const [isCreatingDetachedResultNode, setIsCreatingDetachedResultNode] =
|
const [isCreatingDetachedResultNode, setIsCreatingDetachedResultNode] =
|
||||||
useState(false);
|
useState(false);
|
||||||
const [imageAdjustPanelOpen, setImageAdjustPanelOpen] = useState(false);
|
const [imageAdjustPanelOpen, setImageAdjustPanelOpen] = useState(false);
|
||||||
@ -4683,7 +4679,6 @@ export function ImageNode({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setIsCreatingDetachedResultNode(false);
|
setIsCreatingDetachedResultNode(false);
|
||||||
setToolbarFailure(null);
|
|
||||||
setIsProcessing(true);
|
setIsProcessing(true);
|
||||||
const actionName = "框选抠图";
|
const actionName = "框选抠图";
|
||||||
|
|
||||||
@ -4701,10 +4696,8 @@ export function ImageNode({
|
|||||||
await runCanvasRemoteOperation(() => executeCanvasToolbarCapability(command));
|
await runCanvasRemoteOperation(() => executeCanvasToolbarCapability(command));
|
||||||
toast.success(`${actionName}完成`);
|
toast.success(`${actionName}完成`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setToolbarFailure({
|
console.error("框选抠图失败:", error);
|
||||||
imageUrl: data.src,
|
toast.error(error instanceof Error ? error.message : `${actionName}失败`);
|
||||||
message: error instanceof Error ? error.message : `${actionName}失败`,
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsCreatingDetachedResultNode(false);
|
setIsCreatingDetachedResultNode(false);
|
||||||
setIsProcessing(false);
|
setIsProcessing(false);
|
||||||
@ -6658,7 +6651,6 @@ export function ImageNode({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setIsCreatingDetachedResultNode(false);
|
setIsCreatingDetachedResultNode(false);
|
||||||
setToolbarFailure(null);
|
|
||||||
setIsProcessing(true);
|
setIsProcessing(true);
|
||||||
try {
|
try {
|
||||||
const command = createCanvasCapabilityClientCommand({
|
const command = createCanvasCapabilityClientCommand({
|
||||||
@ -6670,10 +6662,9 @@ export function ImageNode({
|
|||||||
await runCanvasRemoteOperation(() => executeCanvasToolbarCapability(command));
|
await runCanvasRemoteOperation(() => executeCanvasToolbarCapability(command));
|
||||||
toast.success(`${capability.title}完成`);
|
toast.success(`${capability.title}完成`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setToolbarFailure({
|
const message =
|
||||||
imageUrl: data.src,
|
error instanceof Error ? error.message : `${capability.title}失败`;
|
||||||
message: error instanceof Error ? error.message : `${capability.title}失败`,
|
toast.error(message);
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsCreatingDetachedResultNode(false);
|
setIsCreatingDetachedResultNode(false);
|
||||||
setIsProcessing(false);
|
setIsProcessing(false);
|
||||||
@ -9435,29 +9426,6 @@ export function ImageNode({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isProcessing && toolbarFailure && toolbarFailure.imageUrl === data.src && (
|
|
||||||
<div
|
|
||||||
className="absolute inset-x-2 bottom-2 z-20 flex max-h-[70%] items-start gap-2 overflow-auto rounded-lg border border-red-200 bg-white px-3 py-2 text-xs text-red-800 shadow-sm dark:border-red-900 dark:bg-zinc-900 dark:text-red-200"
|
|
||||||
data-canvas-no-drag="true"
|
|
||||||
onPointerDown={(event) => event.stopPropagation()}
|
|
||||||
>
|
|
||||||
<p className="min-w-0 flex-1 select-text whitespace-pre-wrap break-words" role="alert">
|
|
||||||
{toolbarFailure.message}
|
|
||||||
</p>
|
|
||||||
<button
|
|
||||||
aria-label="关闭任务提示"
|
|
||||||
className="shrink-0 rounded p-1 hover:bg-red-100 dark:hover:bg-red-950"
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
setToolbarFailure(null);
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
<X className="h-3 w-3" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* 工具栏使用 Portal 渲染到 body,避免被裁剪 */}
|
{/* 工具栏使用 Portal 渲染到 body,避免被裁剪 */}
|
||||||
|
|
||||||
{/* 悬浮时的更多操作按钮 (右上角) */}
|
{/* 悬浮时的更多操作按钮 (右上角) */}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ChevronDown, ChevronUp, Link2, Scan, SlidersHorizontal, Sparkles } from "lucide-react";
|
import { ChevronDown, ChevronUp, Link2, Scan, SlidersHorizontal, Sparkles } from "lucide-react";
|
||||||
import { getGrsaiGptImageOutputSize } from "@/lib/ai/grsai-gpt-image-sizes";
|
import { getGrsaiGptImageOutputSize } from "@/lib/ai/grsai-gpt-image-sizes";
|
||||||
import { getVip98kQualityOptions, resolveVip98kImageTaskSize, type Vip98kTaskInvocation } from "@/lib/ai/vip98k-task-invocation";
|
import { resolveVip98kImageTaskSize } from "@/lib/ai/vip98k-task-invocation";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
@ -268,17 +268,6 @@ export function ImageParamsBar({
|
|||||||
availableAspectRatioOptions[0]?.value ||
|
availableAspectRatioOptions[0]?.value ||
|
||||||
"1:1";
|
"1:1";
|
||||||
|
|
||||||
const declaredQualityOptions = providerType === "vip98k"
|
|
||||||
? getVip98kQualityOptions((imageGenConfig?.vip98k?.invocation as Vip98kTaskInvocation | undefined)?.inputSchema)
|
|
||||||
: undefined;
|
|
||||||
const qualityOptions = ([
|
|
||||||
{ label: "自动", value: "auto" },
|
|
||||||
{ label: "高", value: "high" },
|
|
||||||
{ label: "中", value: "medium" },
|
|
||||||
{ label: "低", value: "low" },
|
|
||||||
] as const).filter(option => declaredQualityOptions === undefined ||
|
|
||||||
(declaredQualityOptions.length ? declaredQualityOptions.includes(option.value) : option.value === "auto"));
|
|
||||||
|
|
||||||
const clampParamsByProvider = (raw: ImageGenerationParams): ImageGenerationParams => {
|
const clampParamsByProvider = (raw: ImageGenerationParams): ImageGenerationParams => {
|
||||||
const options = getImageCountOptions();
|
const options = getImageCountOptions();
|
||||||
const fallbackCount = options[0] ?? 1;
|
const fallbackCount = options[0] ?? 1;
|
||||||
@ -297,7 +286,6 @@ export function ImageParamsBar({
|
|||||||
aspectRatio,
|
aspectRatio,
|
||||||
imageSize,
|
imageSize,
|
||||||
imageCount,
|
imageCount,
|
||||||
quality: qualityOptions.some(option => option.value === raw.quality) ? raw.quality : qualityOptions[0]?.value || "auto",
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -334,6 +322,12 @@ export function ImageParamsBar({
|
|||||||
...buildBaseParams(initialParams),
|
...buildBaseParams(initialParams),
|
||||||
});
|
});
|
||||||
const [minimalParamsOpen, setMinimalParamsOpen] = useState(false);
|
const [minimalParamsOpen, setMinimalParamsOpen] = useState(false);
|
||||||
|
const qualityOptions = [
|
||||||
|
{ label: "自动", value: "auto" },
|
||||||
|
{ label: "高", value: "high" },
|
||||||
|
{ label: "中", value: "medium" },
|
||||||
|
{ label: "低", value: "low" },
|
||||||
|
] as const;
|
||||||
const qualityLabel =
|
const qualityLabel =
|
||||||
qualityOptions.find((option) => option.value === params.quality)?.label || "中";
|
qualityOptions.find((option) => option.value === params.quality)?.label || "中";
|
||||||
|
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
# 画布问题反馈
|
|
||||||
|
|
||||||
画布顶部提供“问题反馈”;小窗口及视频画布在对话顶部提供入口。用户确认关联请求、补充说明后发送。反馈不调用画布保存或生成接口。
|
|
||||||
|
|
||||||
## 资料与权限
|
|
||||||
|
|
||||||
- 用户身份由登录会话及服务端用户表确定;收件人固定为准确花名“魔礼红”。
|
|
||||||
- 请求按当前用户、画布及对话查询。图片任务通过当前对话请求号或画布节点任务号关联,不查询账号下任意最近任务。
|
|
||||||
- 服务端只读取任务表,不调用带恢复、执行或状态变更副作用的任务查询接口。
|
|
||||||
- 自动采集当前对话最近 12 条公开消息(文字总量最多 48,000 字符)、最多 20 个节点的编号、尺寸及任务号,以及页面版本、窗口、网络和最近脚本错误。截图、图片二进制、内部提示词、Cookie 和认证头不采集。
|
|
||||||
- 用户可以切换关联请求或选择页面问题。尚未持久化的消息标记为浏览器来源;缺少请求号时保留消息或任务编号,不推测编号。
|
|
||||||
- 完整反馈保存在 `CanvasFeedback`;通知正文为限长摘要,按钮打开 `/feedback/{id}`。详情仅反馈本人及平台管理员可读。画布删除后反馈仍可查看,账号删除会级联删除其反馈。
|
|
||||||
|
|
||||||
## 提交和投递
|
|
||||||
|
|
||||||
- 浏览器在首次提交时固定反馈 UUID 和请求内容,在当前标签页保留提交资料。重复点击、响应丢失后的重试和刷新恢复均沿用原 UUID。
|
|
||||||
- 服务端按 UUID 插入一次,持久化的通知内容保持不变。通知中心幂等键为 `canvas-feedback:{id}:v1`;每次 HTTP 请求生成新 nonce。
|
|
||||||
- 保存成功后异步提交通知。节点运行时每分钟继续处理尚未入队的反馈,最多尝试 5 次;连接异常、5xx 和 429 按 1、5、15、30 分钟间隔重试,其他明确拒绝停止重试。
|
|
||||||
- 反馈与调度时间统一为 UTC;首次调度显式写入应用时间,数据库默认值也使用 UTC。普通画布能力的默认创建时间按数据库时区转换,视频队列显式写入的 UTC 时间保持原值。
|
|
||||||
- 通知中心返回投递 ID 后只查询该单,不重新发送。中心负责实际投递及其重试;`DELIVERY_OUTCOME_UNKNOWN` 不自动补发。
|
|
||||||
- `pending`(本地保存)、`accepted`(中心受理)、`sent/unread/read`(钉钉接受或阅读)、`failed` 分别显示,不把受理当作送达。
|
|
||||||
|
|
||||||
## 服务端配置
|
|
||||||
|
|
||||||
```dotenv
|
|
||||||
YYD_NOTIFICATION_CENTER_URL=https://sc.jiansun.vip/notification-center
|
|
||||||
YYD_NOTIFICATION_CENTER_PROJECT_CODE=
|
|
||||||
YYD_NOTIFICATION_CENTER_PROJECT_SECRET=
|
|
||||||
```
|
|
||||||
|
|
||||||
项目代码及密钥使用通知中心分配值,仅配置到服务端。消息签名沿用通知中心 HMAC 契约,签名路径不含公网 `/notification-center` 前缀。
|
|
||||||
|
|
||||||
上线前先备份生产环境配置,并单独执行 `0105_add_canvas_feedback.sql` 和 `0106_canvas_feedback_utc_defaults.sql`;迁移仅涉及反馈表及其默认值,不修改任务、画布、计费或原通知表。应用发布仍使用既有构建机直传流程。回滚应用可保留新增表,尚未入队的反馈在恢复新版后继续处理。
|
|
||||||
|
|
||||||
## 验证
|
|
||||||
|
|
||||||
`tests/routes/canvas-feedback.test.ts` 覆盖错误与原消息关联、固定收件人及摘要长度、受理状态、签名和重试边界;`tests/e2e/canvas-issue-feedback.test.ts` 覆盖自动采集、重复点击、丢失响应后刷新恢复和窄屏操作。
|
|
||||||
|
|
||||||
生产验收使用维护者自己的独立测试画布及已失败的测试记录,不提交模型任务。核对反馈与通知各只有一条、原任务 attempts 不变;查询通知中心最终状态,并核对完整反馈页面权限。
|
|
||||||
@ -1,175 +0,0 @@
|
|||||||
# 生效模型参数核对(2026-11-16)
|
|
||||||
|
|
||||||
核对对象为模型和所属上游同时启用的 76 条配置,包括隐藏但仍可被功能调用的模型。依据生产配置快照、实际请求构建代码、98K 当前账户公布的接口契约以及阿里云、AtlasCloud、Anthropic 官方资料。
|
|
||||||
|
|
||||||
## 修复范围
|
|
||||||
|
|
||||||
| 问题 | 影响与处理 |
|
|
||||||
| --- | --- |
|
|
||||||
| 图片尺寸与比例 | 删除仅允许正方形的错误约束;有独立比例与清晰度字段时按上游契约组合,固定 2K/4K 模型使用对应档位。 |
|
|
||||||
| 请求路线 | 显式选定的标准接口优先于通用任务示例,保留路线与参数约束的对应关系。 |
|
|
||||||
| 参考图数量 | 读取嵌套约束并采用当前实际调用接口的上限,GPT Image 2 的上限由 16 校正为 14。 |
|
|
||||||
| 图片质量与负面提示词 | 质量和负面提示词只写入一个有效位置;固定质量模型不再发送旧的其他档位,页面只提供接口接受的质量选项。 |
|
|
||||||
| 可选生成控制 | 修复水印、提示词扩展、随机种子、尾帧和固定镜头的已支持字段漏传,保留 false 和 0 的原值;上游未声明的字段不发送。 |
|
|
||||||
| 视频时长 | Veo 使用当前接口的 duration 字段;Minimax 的 1080p 时长选项限制在接口允许范围内。 |
|
|
||||||
| 文字输出长度 | AI SDK 调用统一使用 maxOutputTokens,原生厂商接口保留各自标准字段。 |
|
|
||||||
| Claude 采样参数 | 对固定采样协议移除 temperature、top_p、top_k,保留工具调用和输出长度。Haiku 5.5 已实测。 |
|
|
||||||
| 世界生成分类 | world-generation 的类型及任务调用配置按现有世界生成接口校正,避免作为聊天模型使用。 |
|
|
||||||
| 聊天生图备用模型 | 按原请求的清晰度、比例、张数和参考图数量筛选,不把 1K/4K 请求传给固定 2K 模型;额度不足时跳过同一账户的其他模型。 |
|
|
||||||
| 额度错误与请求追踪 | 98K 的英文可用额度不足归类为服务商余额/额度问题,保留上游请求号并关联网页请求号。 |
|
|
||||||
|
|
||||||
## 验证
|
|
||||||
|
|
||||||
- 图片、视频、音频及工具参数组成 12,135 个离线请求用例,采用实际请求构建函数,并核对当前接口约束与字段值。
|
|
||||||
- 阿里云图片另外覆盖 80 个尺寸、数量、参考图、随机种子和开关组合;7 个 AtlasCloud 三维模型按各自 OpenAPI 请求规范核对。
|
|
||||||
- 19 个聊天/文字模型捕获官方 SDK 生成的请求,覆盖输出长度、采样、停止词以及适用的图片和工具调用。13 个 98K 模型同时通过当前路线契约校验;其余 6 个根据接入代码和 SDK 请求核对。
|
|
||||||
- 自动回归 118 项通过,TypeScript 检查通过。
|
|
||||||
- 聊天回退与失败提示另通过 49 项针对性回归,覆盖固定清晰度、比例、张数、参考图上限、同账户额度隔离、未知结果不重提,以及网页提示和历史记录一致。
|
|
||||||
- 独立实测:Nano Banana 2 带参考图生成 16:9 图片,返回 1376×768 PNG;固定 4K 编辑返回 4096×4096 JPEG;Claude Haiku 5.5 返回有效工具调用。两张图片均完成七牛保存和下载验证。每项只有一次提交。
|
|
||||||
|
|
||||||
## 生效模型清单
|
|
||||||
|
|
||||||
| 模型 | 上游 | 本次核对 |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| `grok-4.7` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `gpt-image-2` | 98K | 126 组请求字段与接口约束 |
|
|
||||||
| `gpt-image-2-vip` | 98K | 360 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-2` | 98K | 90 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-pro` | 98K | 90 组请求字段与接口约束 |
|
|
||||||
| `gpt-image-2.5` | 98K | 30 组请求字段与接口约束 |
|
|
||||||
| `gpt-image-2.5-flare` | 98K | 288 组请求字段与接口约束 |
|
|
||||||
| `ocr` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `gpt-image-2.5-sunburst` | 98K | 504 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-2-2k-cl` | 98K | 12 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-2-4k-cl` | 98K | 12 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-2-cl` | 98K | 12 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-pro-4k-vip` | 98K | 12 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-pro-cl` | 98K | 12 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-pro-vip` | 98K | 12 组请求字段与接口约束 |
|
|
||||||
| `doubao-seedream-5-0-pro` | 98K | 240 组请求字段与接口约束 |
|
|
||||||
| `flux-2-pro` | 98K | 48 组请求字段与接口约束 |
|
|
||||||
| `gpt-image-2.6` | 98K | 84 组请求字段与接口约束 |
|
|
||||||
| `gpt-image-2.6-flare` | 98K | 360 组请求字段与接口约束 |
|
|
||||||
| `gpt-image-2.6-sunburst` | 98K | 36 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-2-plus` | 98K | 360 组请求字段与接口约束 |
|
|
||||||
| `nano-banana-pro-plus` | 98K | 360 组请求字段与接口约束 |
|
|
||||||
| `qwen-image-3.0` | 98K | 48 组请求字段与接口约束 |
|
|
||||||
| `qwen-image-3.0-pro` | 98K | 48 组请求字段与接口约束 |
|
|
||||||
| `minimax-h3` | 98K | 320 组请求字段与接口约束 |
|
|
||||||
| `veo-3.1-fast` | 98K | 16 组请求字段与接口约束 |
|
|
||||||
| `seedance-2.5` | 98K | 1296 组请求字段与接口约束 |
|
|
||||||
| `seedance-2.5-image-to-video` | 98K | 1458 组请求字段与接口约束 |
|
|
||||||
| `seedance-2.5-reference-to-video` | 98K | 1458 组请求字段与接口约束 |
|
|
||||||
| `seedance-2.5-text-to-video` | 98K | 1134 组请求字段与接口约束 |
|
|
||||||
| `gemini-omni-1.1-flash-preview` | 98K | 8 组请求字段与接口约束 |
|
|
||||||
| `grok-imagine-video` | 98K | 2500 组请求字段与接口约束 |
|
|
||||||
| `grok-imagine-video-1.5` | 98K | 750 组请求字段与接口约束 |
|
|
||||||
| `gemini-3.8-flash` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `gpt-6-astra` | 98K | SDK 请求、输出长度、采样、停止词 |
|
|
||||||
| `gpt-6-sol` | 98K | SDK 请求、输出长度、采样、停止词 |
|
|
||||||
| `gpt-6.1-sol` | 98K | SDK 请求、输出长度、采样、停止词 |
|
|
||||||
| `world-generation` | 98K | 世界生成类型、任务提交与结果查询配置 |
|
|
||||||
| `claude-haiku-5-5` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `claude-sonnet-4-6` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `image-expansion` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `gem-3.1-tts` | 98K | 4 组请求字段与接口约束 |
|
|
||||||
| `mimo-v2.5-asr` | 98K | 1 组请求字段与接口约束 |
|
|
||||||
| `mimo-v2.5-tts` | 98K | 1 组请求字段与接口约束 |
|
|
||||||
| `mimo-v2.5-tts-voiceclone` | 98K | 1 组请求字段与接口约束 |
|
|
||||||
| `mimo-v2.5-tts-voicedesign` | 98K | 1 组请求字段与接口约束 |
|
|
||||||
| `music-2.5` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `music-2.5+` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `speech-2.8-hd` | 98K | 6 组请求字段与接口约束 |
|
|
||||||
| `speech-2.8-turbo` | 98K | 6 组请求字段与接口约束 |
|
|
||||||
| `suno-v4.5` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `suno-v6` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `suno-v5` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `suno-v5-5` | 98K | 3 组请求字段与接口约束 |
|
|
||||||
| `claude-fable-5-1` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `claude-opus-5-5` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `claude-sonnet-5-5` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `gemini-4-argon` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `grok-4.5` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `grok-4.6` | 98K | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `tripo-h3.1/image-to-3d` | AtlasCloud | 提示词/参考图、三维输出参数及官方 OpenAPI |
|
|
||||||
| `tripo-h3.1/text-to-3d` | AtlasCloud | 提示词/参考图、三维输出参数及官方 OpenAPI |
|
|
||||||
| `tencent/hunyuan3d-pro/text-to-3d` | AtlasCloud | 提示词/参考图、三维输出参数及官方 OpenAPI |
|
|
||||||
| `tencent/hunyuan3d-pro/image-to-3d` | AtlasCloud | 提示词/参考图、三维输出参数及官方 OpenAPI |
|
|
||||||
| `tencent/hunyuan3d-rapid/text-to-3d` | AtlasCloud | 提示词/参考图、三维输出参数及官方 OpenAPI |
|
|
||||||
| `tencent/hunyuan3d-rapid/image-to-3d` | AtlasCloud | 提示词/参考图、三维输出参数及官方 OpenAPI |
|
|
||||||
| `bytedance/seed3d-v2.0/image-to-3d` | AtlasCloud | 提示词/参考图、三维输出参数及官方 OpenAPI |
|
|
||||||
| `qwen-image-3.0` | 阿里云图片 | 80 组图片参数及原生请求字段 |
|
|
||||||
| `qwen3-vl-plus` | 阿里云 | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `qwen3.8-max` | 阿里云 | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `qwen3.8-omni-flash` | 阿里云 | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `qwen3-tts-instruct-flash` | 阿里云 | 官方语音请求、音色、语言与指令 |
|
|
||||||
| `qwen3-tts-flash` | 阿里云 | 官方语音请求、音色、语言与指令 |
|
|
||||||
| `deepseek-flash` | 自定义标准接口 | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `agnes-1.5-flash` | 自定义标准接口 | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
| `agnes-2.0-flash` | 自定义标准接口 | SDK 请求、输出长度、采样、停止词、视觉及工具调用 |
|
|
||||||
|
|
||||||
## 线上核对
|
|
||||||
|
|
||||||
11 月 16 日 15:14–15:23(新加坡时间)98K 只读核查确认账户可用余额不足以预留生成费用,相关拒绝未派发上游;相同的额度错误及备用模型规格不匹配在本轮发布激活前已出现,与网页是否刷新无关。15:43 确认充值到账,“风骚”账号 15:34–15:44 已有 6 笔成功新图片记录,包含 1K 和 4K 请求;历史失败请求未重放。
|
|
||||||
|
|
||||||
32 条模型参数配置已更新并回读核对。聊天回退与额度提示修复已上线,公开入口与正式进程版本一致;切换在旧进程工作归零后完成,未修改历史任务状态。
|
|
||||||
|
|
||||||
场景融合的无效视频首选项已清除,恢复为“不指定首选”,与原先实际采用的图片候选池一致;其余设置保持不变。该配置即时生效,无需重启服务。
|
|
||||||
|
|
||||||
## 当日需求收尾
|
|
||||||
|
|
||||||
| 需求 | 核对结果 |
|
|
||||||
| --- | --- |
|
|
||||||
| 下载慢与图片归档 | 原图七牛直连、准备及转换状态、取消自动转传回生产机的修复已上线。16:21 归档完成数持续增加,队列中的新图片正在保存或更新画布引用,没有新的失败记录。 |
|
|
||||||
| 旧 BananaImage 入口 | 旧供应商与五个旧模型已停用、隐藏;98K 对应入口保留。线上回读与网页列表一致。 |
|
|
||||||
| 后台历史缺图 | 11 月 13 日有 108 张涉及 24 位用户的原图未成功归档;上游文件 404、七牛及本地缓存无副本。Relay 隔离核验三个备份后找回 10 张的原请求号,其余 98 张没有匹配的保留响应,原文件恢复数为 0;未重新生成。 |
|
|
||||||
| 98K 缺失模型接入 | 本次原定的 48 个型号已开放 40 个:对话 5、图片 15、视频 7、语音及音乐 13。剩余 8 个仍受上游型号授权或能力限制。 |
|
|
||||||
| 六款 CL/VIP 参考图编辑 | 六款已完成独立参考图生成、尺寸及七牛保存验证并上线;网页已核对六款均可选择,已移除“仅文生图”标记。 |
|
|
||||||
| “风骚”首次规格错误 | 4K 尺寸映射修复已上线,独立参考图结果为 4096×4096;网页选择固定 4K 型号时自动切换到 4K,参数面板只提供该型号支持的选项。 |
|
|
||||||
| 全部生效模型参数核对 | 已覆盖当时生效的 76 条模型记录,修复与配置调整已上线,包含分辨率、比例、数量、参考图、质量、采样、视频时长等字段。 |
|
|
||||||
| “风骚”再次报错 | 已确认额度不足引发不兼容备用模型回退,非旧网页引起;额度识别、同供应商回退阻止及规格筛选已上线。充值后该账号已有新的成功结果,旧请求未重放。 |
|
|
||||||
|
|
||||||
### 网页操作验收
|
|
||||||
|
|
||||||
- 在独立图片测试画布核对模型列表及固定 4K 参数。测试画布:`97aca1be-6bdb-485e-945e-00cc21691d84`。
|
|
||||||
- 在独立音频测试画布选择 `mimo-v2.5-tts`,提交中文短句一次,19.42 秒完成;WAV 文件保存至七牛,网页显示约 4 秒并播放到结尾。任务记录为成功、尝试一次。测试画布:`8b76a09a-f24f-42ff-9f1e-f3809909dd84`。
|
|
||||||
- 上述测试不等于 40 个新型号的每一种网页流程均完成验收;参考图、视频和其他音频型号的实际调用及存储验证沿用已有独立测试记录。
|
|
||||||
|
|
||||||
17:46 起在 Codex 内置浏览器补充验收,所有操作均在独立测试画布完成:语音识别 6.88 秒返回文字,声音克隆 93.27 秒、声音设计 15.07 秒返回已存入七牛的 WAV,均只提交一次。识别文字存在同音字误差,需要人工校对。
|
|
||||||
|
|
||||||
本轮修复语音识别成功后画布结果为空的问题:新结果采用画布文本结构,已保存的字符串结果也可直接显示和编辑;重复查询不会覆盖人工修改。音频生成节点显示排队、处理中及失败信息,不再以空播放器及默认三秒时长表示未完成任务。相关回归 72 项和 TypeScript 检查通过;内置浏览器独立页面已验证新旧文字显示、中文与尺寸编辑、空格保留及等待/失败状态,修复已上线。
|
|
||||||
|
|
||||||
画布恢复时统一读取字符串和数组格式的文本,保留中文、尺寸及空格;人工编辑和主动清空按画布保存内容显示。恢复与任务相关回归 46 项、TypeScript 检查及内置浏览器的实际恢复组件验收通过。18:53(新加坡时间)在原测试画布完成正式网页验收:旧文字正常读取,中文和 `15mm` 修改保存后刷新仍保留,主动清空保存后刷新保持空白,末尾空格正常保留。
|
|
||||||
|
|
||||||
音乐原任务已成功完成并保存七牛,网页解码时长约 150 秒并可播放。供应商核对确认只受理及扣费一次;本项目工作进程续查一次原任务,没有重新派发。声音克隆与声音设计在内置浏览器均播放到结尾。
|
|
||||||
|
|
||||||
正式运行版本为 `20261116T103955Z-582667dd05a1`,源码提交 `582667dd05a1a629850937aa46b506897998576d`,构建编号 `9nLxMnP463njtm-3FO694`;生产进程目录、构建编号、公开版本接口与发布回执一致。发布等待后台工作结束后再停止旧进程,历史挂起任务记录保持不变。原测试画布仍为五笔成功任务,没有新增生成请求。18:50 复核当日图片归档均已完成,没有等待归档或下载准备积压。
|
|
||||||
|
|
||||||
验收截图:`.qa/production-audio-acceptance.png`。临时本地验收服务已结束,测试画布保留供复核。
|
|
||||||
|
|
||||||
### 剩余上游事项
|
|
||||||
|
|
||||||
| 型号 | 当前阻塞 | 处理方 |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| `gemini-3-pro-image-preview-vip`、`gemini-3.1-flash-image-preview-vip`、`gemini-nano-banana-2.1-vip`、`nano_banana`、`nano_banana_2`、`nano_banana_pro` | 实际账户目录未提供精确型号,原请求返回无执行权限 | ToAPIs 开通对应账户分组型号 |
|
|
||||||
| `gpt-6.1-terra` | 标准工具字段已传递,原响应没有工具调用 | ToAPIs 确认该线路工具调用能力 |
|
|
||||||
| `gem-2.5-tts` | 原异步任务终态服务不可用,已退款并释放预留 | ZZY 恢复该音频服务 |
|
|
||||||
|
|
||||||
以上 8 个仍未开放。Relay 于 16:25 回读确认尚无恢复证据,本轮未新增已知失败的付费探测。
|
|
||||||
|
|
||||||
### 历史原图恢复
|
|
||||||
|
|
||||||
Relay 已只读核验 11 月 13 日 15:13、16:00 以及 11 月 16 日 12:03 的独立备份。10 张可匹配原请求的图片均由 Grsai 同步返回,备份只保留已失效的图片链接,没有原文件或可查询的上游任务号;需要供应商按原型号、受理时间和账号查找原交付记录。其余 98 张没有可匹配的保留响应。此核验未覆盖生产数据、未重新生成图片或产生新的生成扣费。
|
|
||||||
|
|
||||||
## 已知问题与验证边界
|
|
||||||
|
|
||||||
- 生产机可用磁盘约 1.09 GiB,接近发布与批量打包下载的保留线。本轮已回收一个未启用候选副本及一个更早退役版本的构建产物;构建机完整包和源码、当前与最近回滚版本、业务数据均保留。
|
|
||||||
|
|
||||||
- 离线参数核对不等于 76 个模型逐个完成付费生成,也不证明上游持续可用、效果或速度;实际生成验证范围为上述三项。
|
|
||||||
- 自动选模时页面尚未确定最终模型,接入层仍须依据实际选中接口规范化固定参数。模型清单和接口约束会随上游调整,本报告对应本次核对时点。
|
|
||||||
|
|
||||||
## 资料
|
|
||||||
|
|
||||||
- [Anthropic Haiku 5.5 采样参数迁移说明](https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide#remove-sampling-parameters)
|
|
||||||
- [阿里云图片生成及编辑接口](https://www.alibabacloud.com/help/en/model-studio/qwen-image-generation-and-editing-api-reference)
|
|
||||||
- [阿里云语音合成接口](https://www.alibabacloud.com/help/en/model-studio/qwen-tts-api)
|
|
||||||
@ -12,11 +12,6 @@ export function register() {
|
|||||||
void import("@/lib/canvas/image-task-queue")
|
void import("@/lib/canvas/image-task-queue")
|
||||||
.then(({ resumeDetailReplacementBatchTasks }) => resumeDetailReplacementBatchTasks())
|
.then(({ resumeDetailReplacementBatchTasks }) => resumeDetailReplacementBatchTasks())
|
||||||
.catch((error) => console.error("[Detail Replacement Batch] Recovery failed", error));
|
.catch((error) => console.error("[Detail Replacement Batch] Recovery failed", error));
|
||||||
if (process.env.YYD_NOTIFICATION_CENTER_PROJECT_SECRET) {
|
|
||||||
void import("@/lib/canvas/feedback-store")
|
|
||||||
.then(({ runCanvasFeedbackDelivery }) => runCanvasFeedbackDelivery())
|
|
||||||
.catch(() => console.error("[Canvas feedback] notification queue unavailable"));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
setTimeout(recover, 5000).unref?.();
|
setTimeout(recover, 5000).unref?.();
|
||||||
setInterval(recover, 60_000).unref?.();
|
setInterval(recover, 60_000).unref?.();
|
||||||
|
|||||||
@ -185,7 +185,7 @@ async function optimizeWithConfiguredQwenVisionModel(params: {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
maxOutputTokens: 320,
|
maxTokens: 320,
|
||||||
abortSignal: AbortSignal.timeout(30_000),
|
abortSignal: AbortSignal.timeout(30_000),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -124,7 +124,7 @@ async function analyzeWithConfiguredQwenVisionModel(params: {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
maxOutputTokens: 220,
|
maxTokens: 220,
|
||||||
abortSignal: AbortSignal.timeout(25_000),
|
abortSignal: AbortSignal.timeout(25_000),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -1,51 +0,0 @@
|
|||||||
import "server-only";
|
|
||||||
|
|
||||||
import { buildImageProxyUrl } from "@/lib/image-delivery";
|
|
||||||
import { createLogger } from "@/lib/observability/logger";
|
|
||||||
import { archiveImageThroughQiniu } from "@/lib/storage/qiniu-image-archive";
|
|
||||||
|
|
||||||
const logger = createLogger("aos-image-transfer");
|
|
||||||
const imageFormats = ["jpeg", "png", "webp", "tiff"];
|
|
||||||
|
|
||||||
export async function readAosQiniuInput(imageUrl: string) {
|
|
||||||
const cdnOrigin = process.env.NEXT_PUBLIC_CANVAS_CDN_ORIGIN;
|
|
||||||
if (!cdnOrigin) return null;
|
|
||||||
try {
|
|
||||||
const source = new URL(imageUrl);
|
|
||||||
if (source.protocol !== "https:" || source.origin !== new URL(cdnOrigin).origin ||
|
|
||||||
source.username || source.password || source.search || source.hash ||
|
|
||||||
!source.pathname.startsWith("/uploads/")) return null;
|
|
||||||
|
|
||||||
const response = await fetch(`${source.href}?imageInfo`, {
|
|
||||||
cache: "no-store",
|
|
||||||
redirect: "error",
|
|
||||||
signal: AbortSignal.timeout(4000),
|
|
||||||
});
|
|
||||||
if (!response.ok) return null;
|
|
||||||
const info = await response.json();
|
|
||||||
const { width, height, size } = info;
|
|
||||||
if (!["jpeg", "png", "webp"].includes(info.format) ||
|
|
||||||
![width, height, size].every(value => Number.isSafeInteger(value) && value > 0) ||
|
|
||||||
size > 20 * 1024 * 1024) return null;
|
|
||||||
return { url: source.href, width, height, bytes: size } as {
|
|
||||||
url: string; width: number; height: number; bytes: number;
|
|
||||||
};
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function archiveAosResult(imageUrl: unknown, archiveId: string) {
|
|
||||||
if (typeof imageUrl !== "string" || !/^https:\/\//i.test(imageUrl)) return null;
|
|
||||||
try {
|
|
||||||
const image = await archiveImageThroughQiniu(imageUrl, archiveId);
|
|
||||||
if (!image || !imageFormats.some(format => image.contentType === `image/${format}`)) return null;
|
|
||||||
return {
|
|
||||||
original: image.url,
|
|
||||||
thumbnail: buildImageProxyUrl(image.url, { width: 480, format: "webp" }),
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
logger.warn("archive_failed", { archiveId, errorName: error instanceof Error ? error.name : undefined });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1737,7 +1737,7 @@ async function buildExecutionPlanWithAgent(
|
|||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join("\n\n"),
|
.join("\n\n"),
|
||||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.1),
|
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.1),
|
||||||
maxOutputTokens: 420,
|
maxTokens: 420,
|
||||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
@ -1858,7 +1858,7 @@ async function generateAgentConversation(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
temperature: getCompatibleTextGenerationTemperature(visionModelConfig, 0.2),
|
temperature: getCompatibleTextGenerationTemperature(visionModelConfig, 0.2),
|
||||||
maxOutputTokens: 360,
|
maxTokens: 360,
|
||||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
@ -1920,7 +1920,7 @@ async function generateAgentConversation(
|
|||||||
system: systemPrompt,
|
system: systemPrompt,
|
||||||
prompt,
|
prompt,
|
||||||
temperature: getCompatibleTextGenerationTemperature(reasoningModelConfig, 0.35),
|
temperature: getCompatibleTextGenerationTemperature(reasoningModelConfig, 0.35),
|
||||||
maxOutputTokens: 520,
|
maxTokens: 520,
|
||||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
@ -2002,7 +2002,7 @@ async function recommendImageParamsWithAgent(
|
|||||||
- negativePrompt 仅在明显需要避坑时填写。`,
|
- negativePrompt 仅在明显需要避坑时填写。`,
|
||||||
prompt: requestText,
|
prompt: requestText,
|
||||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.15),
|
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.15),
|
||||||
maxOutputTokens: 220,
|
maxTokens: 220,
|
||||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
@ -2095,7 +2095,7 @@ async function recommendVideoPlanWithAgent(
|
|||||||
- 避免抽象空话,必须可执行。`,
|
- 避免抽象空话,必须可执行。`,
|
||||||
prompt,
|
prompt,
|
||||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.2),
|
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.2),
|
||||||
maxOutputTokens: 720,
|
maxTokens: 720,
|
||||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
@ -2175,7 +2175,7 @@ async function refineRouteWithAgent(
|
|||||||
候选模型:
|
候选模型:
|
||||||
${candidatesText}`,
|
${candidatesText}`,
|
||||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.1),
|
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.1),
|
||||||
maxOutputTokens: 120,
|
maxTokens: 120,
|
||||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ export type DetailKimiPurpose = "plan" | "preflight" | "review" | "repair";
|
|||||||
export type DetailKimiGenerateOptions = {
|
export type DetailKimiGenerateOptions = {
|
||||||
temperature?: number;
|
temperature?: number;
|
||||||
topP?: number;
|
topP?: number;
|
||||||
maxOutputTokens?: number;
|
maxTokens?: number;
|
||||||
headers?: Record<string, string>;
|
headers?: Record<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ export function buildDetailKimiGenerateOptions(params: {
|
|||||||
return {
|
return {
|
||||||
temperature: thinking === "enabled" ? 1 : 0.6,
|
temperature: thinking === "enabled" ? 1 : 0.6,
|
||||||
topP: 0.95,
|
topP: 0.95,
|
||||||
maxOutputTokens: getPurposeMaxTokens(params),
|
maxTokens: getPurposeMaxTokens(params),
|
||||||
headers: {
|
headers: {
|
||||||
[DETAIL_KIMI_THINKING_HEADER]: thinking,
|
[DETAIL_KIMI_THINKING_HEADER]: thinking,
|
||||||
[DETAIL_KIMI_PROFILE_HEADER]: `detail-ui-${params.purpose}`,
|
[DETAIL_KIMI_PROFILE_HEADER]: `detail-ui-${params.purpose}`,
|
||||||
|
|||||||
@ -687,7 +687,7 @@ export async function optimizePromptWithLLM(params: {
|
|||||||
system: optimizerSystemPrompt,
|
system: optimizerSystemPrompt,
|
||||||
prompt: finalUserMessage,
|
prompt: finalUserMessage,
|
||||||
temperature: getCompatibleTextGenerationTemperature(selectedOptimizerModel, 0.2),
|
temperature: getCompatibleTextGenerationTemperature(selectedOptimizerModel, 0.2),
|
||||||
maxOutputTokens: 200,
|
maxTokens: 200,
|
||||||
abortSignal: AbortSignal.timeout(12_000),
|
abortSignal: AbortSignal.timeout(12_000),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -153,30 +153,28 @@ export function createVip98kChatModel(params: {
|
|||||||
(!metadata.chatInvocation && invocation.protocol === "anthropic-messages"));
|
(!metadata.chatInvocation && invocation.protocol === "anthropic-messages"));
|
||||||
const resolveModel = async (signal?: AbortSignal) => {
|
const resolveModel = async (signal?: AbortSignal) => {
|
||||||
signal?.throwIfAborted();
|
signal?.throwIfAborted();
|
||||||
if (!needsDiscovery) return { model, contract: invocation };
|
if (!needsDiscovery) return model;
|
||||||
const models = await awaitWithAbort(discoverContracts(root, baseFetch), signal);
|
const models = await awaitWithAbort(discoverContracts(root, baseFetch), signal);
|
||||||
const contract = selectVip98kChatInvocation(models.get(params.modelId));
|
const contract = selectVip98kChatInvocation(models.get(params.modelId));
|
||||||
if (!contract) throw new Error("VIP98K 此模型未公布兼容的对话接口,请核对模型类型和接口配置。");
|
if (!contract) throw new Error("VIP98K 此模型未公布兼容的对话接口,请核对模型类型和接口配置。");
|
||||||
return { model: createModel(contract), contract };
|
return createModel(contract);
|
||||||
};
|
};
|
||||||
const callOptions = (options: LanguageModelV2CallOptions, contract: typeof invocation) =>
|
|
||||||
contract?.omitSampling ? { ...options, temperature: undefined, topP: undefined, topK: undefined } : options;
|
|
||||||
return {
|
return {
|
||||||
specificationVersion: model.specificationVersion,
|
specificationVersion: model.specificationVersion,
|
||||||
provider: model.provider,
|
provider: model.provider,
|
||||||
modelId: model.modelId,
|
modelId: model.modelId,
|
||||||
supportedUrls: model.supportedUrls,
|
supportedUrls: model.supportedUrls,
|
||||||
async doGenerate(options) {
|
async doGenerate(options) {
|
||||||
const active = await resolveModel(options.abortSignal);
|
const activeModel = await resolveModel(options.abortSignal);
|
||||||
const result = await active.model.doGenerate(callOptions(options, active.contract));
|
const result = await activeModel.doGenerate(options);
|
||||||
if (requiresToolCall(options) && !result.content.some((part) => part.type === "tool-call")) throw missingToolError();
|
if (requiresToolCall(options) && !result.content.some((part) => part.type === "tool-call")) throw missingToolError();
|
||||||
if (!result.content.some((part) => part.type === "tool-call" ||
|
if (!result.content.some((part) => part.type === "tool-call" ||
|
||||||
(part.type === "text" && part.text.trim()))) throw emptyResponseError();
|
(part.type === "text" && part.text.trim()))) throw emptyResponseError();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
async doStream(options) {
|
async doStream(options) {
|
||||||
const active = await resolveModel(options.abortSignal);
|
const activeModel = await resolveModel(options.abortSignal);
|
||||||
const result = await active.model.doStream(callOptions(options, active.contract));
|
const result = await activeModel.doStream(options);
|
||||||
let usable = false;
|
let usable = false;
|
||||||
let toolCalled = false;
|
let toolCalled = false;
|
||||||
let failed = false;
|
let failed = false;
|
||||||
|
|||||||
@ -28,8 +28,6 @@ import {
|
|||||||
normalizeVip98kInvocationHeaders,
|
normalizeVip98kInvocationHeaders,
|
||||||
resolveVip98kImageTaskSize,
|
resolveVip98kImageTaskSize,
|
||||||
selectVip98kTaskInvocation,
|
selectVip98kTaskInvocation,
|
||||||
vip98kReferenceLimit,
|
|
||||||
getVip98kQualityOptions,
|
|
||||||
type Vip98kTaskInvocation,
|
type Vip98kTaskInvocation,
|
||||||
} from "@/lib/ai/vip98k-task-invocation";
|
} from "@/lib/ai/vip98k-task-invocation";
|
||||||
import { VIP98K_BASE_URL, normalizeVip98kBaseUrl } from "@/lib/ai/vip98k-models";
|
import { VIP98K_BASE_URL, normalizeVip98kBaseUrl } from "@/lib/ai/vip98k-models";
|
||||||
@ -1317,10 +1315,7 @@ async function submitTask(params: {
|
|||||||
|| [502, 504, 524].includes(response.status)
|
|| [502, 504, 524].includes(response.status)
|
||||||
|| /pending\s+safe\s+reconciliation|request\s+outcome\s+(?:is\s+)?unknown|final\s+outcome\s+could\s+not\s+be\s+confirmed/i.test(errorMessage))
|
|| /pending\s+safe\s+reconciliation|request\s+outcome\s+(?:is\s+)?unknown|final\s+outcome\s+could\s+not\s+be\s+confirmed/i.test(errorMessage))
|
||||||
throw new ProviderTaskUncertainError(`供应商提交结果未确认,可能仍在处理,请勿重复生成:${getUserFacingImageGenerationErrorMessage({ message: errorMessage, status: response.status })} (HTTP ${response.status})`);
|
throw new ProviderTaskUncertainError(`供应商提交结果未确认,可能仍在处理,请勿重复生成:${getUserFacingImageGenerationErrorMessage({ message: errorMessage, status: response.status })} (HTTP ${response.status})`);
|
||||||
throw Object.assign(new Error(`${errorMessage} (HTTP ${response.status})`), {
|
throw new Error(`${errorMessage} (HTTP ${response.status})`);
|
||||||
status: response.status,
|
|
||||||
providerRequestId: response.headers.get("x-request-id"),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error("VIP98K request failed after media readiness retries");
|
throw new Error("VIP98K request failed after media readiness retries");
|
||||||
@ -1579,14 +1574,6 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
|||||||
const imageParams = params.imageParams || {};
|
const imageParams = params.imageParams || {};
|
||||||
const promptTitle = params.prompt.split(/\s+/).slice(0, 8).join(" ").slice(0, 80);
|
const promptTitle = params.prompt.split(/\s+/).slice(0, 8).join(" ").slice(0, 80);
|
||||||
const body: Record<string, unknown> = { ...(invocation?.requestExample || {}) };
|
const body: Record<string, unknown> = { ...(invocation?.requestExample || {}) };
|
||||||
if (toRecord(body.metadata)) body.metadata = { ...toRecord(body.metadata)! };
|
|
||||||
const setField = (key: string, value: unknown) => {
|
|
||||||
const metadata = toRecord(body.metadata);
|
|
||||||
if (metadata && key in metadata) {
|
|
||||||
metadata[key] = value;
|
|
||||||
delete body[key];
|
|
||||||
} else body[key] = value;
|
|
||||||
};
|
|
||||||
if ("model" in body || !invocation) body.model = params.modelId;
|
if ("model" in body || !invocation) body.model = params.modelId;
|
||||||
if ("displayName" in body || !invocation) {
|
if ("displayName" in body || !invocation) {
|
||||||
body.displayName = promptTitle || params.modelId;
|
body.displayName = promptTitle || params.modelId;
|
||||||
@ -1607,15 +1594,22 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
|||||||
const negativePrompt = String(videoParams.negativePrompt || imageParams.negativePrompt || "").trim();
|
const negativePrompt = String(videoParams.negativePrompt || imageParams.negativePrompt || "").trim();
|
||||||
const quality = String(imageParams.quality || "").trim().toLowerCase();
|
const quality = String(imageParams.quality || "").trim().toLowerCase();
|
||||||
const outputConstraintFallbacks: string[] = [];
|
const outputConstraintFallbacks: string[] = [];
|
||||||
const aspectRatioFields = ["ratio", "aspectRatio", "aspect_ratio"].filter((key) =>
|
let hasNativeAspectRatio = false;
|
||||||
invocationSupportsBodyField(invocation, key),
|
|
||||||
);
|
|
||||||
const hasSeparateAspectRatio = Boolean(aspectRatio && aspectRatioFields.length);
|
|
||||||
let hasNativeAspectRatio = hasSeparateAspectRatio;
|
|
||||||
let hasNativeResolution = false;
|
let hasNativeResolution = false;
|
||||||
|
|
||||||
if (aspectRatio) {
|
if (aspectRatio) {
|
||||||
for (const key of aspectRatioFields) body[key] = aspectRatio;
|
if (invocationSupportsBodyField(invocation, "ratio")) {
|
||||||
|
body.ratio = aspectRatio;
|
||||||
|
hasNativeAspectRatio = true;
|
||||||
|
}
|
||||||
|
if (invocationSupportsBodyField(invocation, "aspectRatio")) {
|
||||||
|
body.aspectRatio = aspectRatio;
|
||||||
|
hasNativeAspectRatio = true;
|
||||||
|
}
|
||||||
|
if (invocationSupportsBodyField(invocation, "aspect_ratio")) {
|
||||||
|
body.aspect_ratio = aspectRatio;
|
||||||
|
hasNativeAspectRatio = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (duration && invocationSupportsBodyField(invocation, "duration")) body.duration = duration;
|
if (duration && invocationSupportsBodyField(invocation, "duration")) body.duration = duration;
|
||||||
if (duration && invocationSupportsBodyField(invocation, "duration_seconds")) body.duration_seconds = duration;
|
if (duration && invocationSupportsBodyField(invocation, "duration_seconds")) body.duration_seconds = duration;
|
||||||
@ -1658,31 +1652,11 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (negativePrompt) {
|
if (negativePrompt) {
|
||||||
const key = ["negative_prompt", "negativePrompt"].find(key =>
|
if ("negativePrompt" in body || !invocation) body.negativePrompt = negativePrompt;
|
||||||
invocationSupportsBodyField(invocation, key));
|
if ("negative_prompt" in body || !invocation) body.negative_prompt = negativePrompt;
|
||||||
if (key) {
|
|
||||||
const other = key === "negative_prompt" ? "negativePrompt" : "negative_prompt";
|
|
||||||
delete body[other];
|
|
||||||
if (toRecord(body.metadata)) delete (body.metadata as Record<string, unknown>)[other];
|
|
||||||
setField(key, negativePrompt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (quality && invocationSupportsBodyField(invocation, "quality")) {
|
if (quality && invocationSupportsBodyField(invocation, "quality")) {
|
||||||
const options = getVip98kQualityOptions(invocation?.inputSchema);
|
body.quality = quality;
|
||||||
const effectiveQuality = options?.length === 1 ? options[0] : quality;
|
|
||||||
if (options?.length && !options.includes(effectiveQuality)) throw Error("当前模型不支持所选图片质量,请重新选择");
|
|
||||||
setField("quality", effectiveQuality);
|
|
||||||
}
|
|
||||||
const generationParamAliases = [
|
|
||||||
["seed", "seed"],
|
|
||||||
["watermark", "watermark"],
|
|
||||||
["promptExtend", "prompt_extend"],
|
|
||||||
["cameraFixed", "camera_fixed"],
|
|
||||||
["returnLastFrame", "return_last_frame"],
|
|
||||||
] as const;
|
|
||||||
for (const [sourceKey, targetKey] of generationParamAliases) {
|
|
||||||
const value = params.kind === "video" ? videoParams[sourceKey] : imageParams[sourceKey];
|
|
||||||
if (value !== undefined && invocationSupportsBodyField(invocation, targetKey)) setField(targetKey, value);
|
|
||||||
}
|
}
|
||||||
const imageToolParamAliases = [
|
const imageToolParamAliases = [
|
||||||
["scaleFactor", "scale_factor"],
|
["scaleFactor", "scale_factor"],
|
||||||
@ -1724,8 +1698,9 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
|||||||
delete body.size;
|
delete body.size;
|
||||||
}
|
}
|
||||||
const imageBindingKeys = bindVip98kImages(body, params.imageUrls, invocation?.inputSchema);
|
const imageBindingKeys = bindVip98kImages(body, params.imageUrls, invocation?.inputSchema);
|
||||||
|
const imageProperties = toRecord(invocation?.inputSchema?.properties) || {};
|
||||||
for (const key of imageBindingKeys) {
|
for (const key of imageBindingKeys) {
|
||||||
const limit = vip98kReferenceLimit(invocation?.inputSchema, key);
|
const limit = toRecord(imageProperties[key])?.maxItems;
|
||||||
if (typeof limit === "number" && params.imageUrls.length > limit) throw Error(`当前模型最多支持 ${limit} 张参考图`);
|
if (typeof limit === "number" && params.imageUrls.length > limit) throw Error(`当前模型最多支持 ${limit} 张参考图`);
|
||||||
}
|
}
|
||||||
if (params.imageUrls.length > 0 && !invocation && imageBindingKeys.length === 0) {
|
if (params.imageUrls.length > 0 && !invocation && imageBindingKeys.length === 0) {
|
||||||
@ -1782,42 +1757,16 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
|||||||
const match = String(value).match(/^(\d+)x(\d+)$/);
|
const match = String(value).match(/^(\d+)x(\d+)$/);
|
||||||
return match ? [{ size: value, width: Number(match[1]), height: Number(match[2]) }] : [];
|
return match ? [{ size: value, width: Number(match[1]), height: Number(match[2]) }] : [];
|
||||||
}) : [];
|
}) : [];
|
||||||
const automaticRatioField = ["aspect_ratio", "aspectRatio", "ratio"].find((key) => {
|
|
||||||
const schema = toRecord(props[key]);
|
|
||||||
return (imageParams.aspectRatio === "auto" || body[key] === "auto") &&
|
|
||||||
(schema?.const === "auto" || (Array.isArray(schema?.enum) && schema.enum.includes("auto")));
|
|
||||||
});
|
|
||||||
const selectedRatio = aspectRatio || "1:1";
|
const selectedRatio = aspectRatio || "1:1";
|
||||||
const configuredSizes =
|
if (ratios.includes(selectedRatio)) body.size = selectedRatio;
|
||||||
params.modelConfig.imageGenConfig?.supportedImageSizes ??
|
|
||||||
params.modelConfig.capabilities?.supportedImageSizes;
|
|
||||||
const fixedOneK =
|
|
||||||
resolution === "1K" &&
|
|
||||||
Array.isArray(configuredSizes) &&
|
|
||||||
configuredSizes.length === 1 &&
|
|
||||||
configuredSizes[0] === "1K";
|
|
||||||
if (!aspectRatio && automaticRatioField && hasNativeResolution && sizes?.includes(resolution)) {
|
|
||||||
body[automaticRatioField] = "auto";
|
|
||||||
body.size = resolution;
|
|
||||||
} else if (hasSeparateAspectRatio && fixedOneK && sizes?.includes("auto") && ratios.includes(selectedRatio)) {
|
|
||||||
// A fixed-tier route can use its explicit ratio without a second geometry
|
|
||||||
// constraint. Its published pixel presets may round the nominal ratio.
|
|
||||||
body.size = "auto";
|
|
||||||
} else if (ratios.includes(selectedRatio)) {
|
|
||||||
body.size = selectedRatio;
|
|
||||||
} else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution;
|
|
||||||
else if (pixels.length && (resolution || aspectRatio)) {
|
else if (pixels.length && (resolution || aspectRatio)) {
|
||||||
const [rw, rh] = selectedRatio.split(":").map(Number);
|
const [rw, rh] = selectedRatio.split(":").map(Number);
|
||||||
const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025);
|
const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025);
|
||||||
if (!matching.length && sizes?.includes("auto") && hasNativeAspectRatio && hasNativeResolution) {
|
|
||||||
body.size = "auto";
|
|
||||||
} else {
|
|
||||||
if (!matching.length) throw Error("当前模型不支持所选图片比例");
|
if (!matching.length) throw Error("当前模型不支持所选图片比例");
|
||||||
const area = resolution === "4K" ? 4096 ** 2 : resolution === "2K" ? 2048 ** 2 : 1024 ** 2;
|
const area = resolution === "4K" ? 4096 ** 2 : resolution === "2K" ? 2048 ** 2 : 1024 ** 2;
|
||||||
matching.sort((a, b) => Math.abs(a.width * a.height - area) - Math.abs(b.width * b.height - area));
|
matching.sort((a, b) => Math.abs(a.width * a.height - area) - Math.abs(b.width * b.height - area));
|
||||||
body.size = matching[0].size;
|
body.size = matching[0].size;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (ratios.length || pixels.length) {
|
if (ratios.length || pixels.length) {
|
||||||
const suffix = "\n\n[Output constraints]";
|
const suffix = "\n\n[Output constraints]";
|
||||||
if (typeof body.prompt === "string" && body.prompt.includes(suffix)) body.prompt = body.prompt.split(suffix)[0];
|
if (typeof body.prompt === "string" && body.prompt.includes(suffix)) body.prompt = body.prompt.split(suffix)[0];
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import {
|
|||||||
getSystemSetting,
|
getSystemSetting,
|
||||||
upsertMediaAsset,
|
upsertMediaAsset,
|
||||||
} from "@/lib/db/queries";
|
} from "@/lib/db/queries";
|
||||||
import { archiveAosResult, readAosQiniuInput } from "@/lib/ai/aos-image-transfer";
|
|
||||||
import { executeConfiguredVip98kTask } from "@/lib/ai/vip98k-runtime";
|
import { executeConfiguredVip98kTask } from "@/lib/ai/vip98k-runtime";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { generatedImage } from "@/lib/db/schema";
|
import { generatedImage } from "@/lib/db/schema";
|
||||||
@ -31,21 +30,20 @@ type RmbgConfig = {
|
|||||||
export type ExecuteRmbgJobParams = {
|
export type ExecuteRmbgJobParams = {
|
||||||
requestId?: string;
|
requestId?: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
|
imageBuffer: Buffer;
|
||||||
imageBase64?: string;
|
imageBase64?: string;
|
||||||
includeBase64?: boolean;
|
|
||||||
foregroundType?: "" | "person" | "object" | "stamp";
|
foregroundType?: "" | "person" | "object" | "stamp";
|
||||||
prompt?: string;
|
prompt?: string;
|
||||||
chatId?: string | null;
|
chatId?: string | null;
|
||||||
messageId?: string | null;
|
messageId?: string | null;
|
||||||
skipGallerySave?: boolean;
|
skipGallerySave?: boolean;
|
||||||
|
// 仅当 imageBuffer 与 URL 对应的输入文件一致时提供。
|
||||||
|
inputImageUrl?: string | null;
|
||||||
sourceImageUrl?: string | null;
|
sourceImageUrl?: string | null;
|
||||||
} & (
|
};
|
||||||
| { imageBuffer: Buffer; inputImageUrl?: string | null }
|
|
||||||
| { imageBuffer?: undefined; inputImageUrl: string }
|
|
||||||
);
|
|
||||||
|
|
||||||
export type ExecuteRmbgJobResult = {
|
export type ExecuteRmbgJobResult = {
|
||||||
image_base64?: string;
|
image_base64: string;
|
||||||
thumbnail_url: string;
|
thumbnail_url: string;
|
||||||
original_url: string;
|
original_url: string;
|
||||||
processing_time: number;
|
processing_time: number;
|
||||||
@ -183,15 +181,6 @@ function getAosFriendlyErrorMessage(detail: string): string | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertAosImageResolution(width?: number, height?: number) {
|
|
||||||
if (width && height && (width > AOS_MAX_RESOLUTION || height > AOS_MAX_RESOLUTION)) {
|
|
||||||
throw new RmbgServiceError(
|
|
||||||
`抠图参考图分辨率超限(${width}×${height} 像素),当前 AOS 上游要求宽、高均不超过 ${AOS_MAX_RESOLUTION} 像素。`,
|
|
||||||
400
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function prepareImageForAos(
|
async function prepareImageForAos(
|
||||||
imageBuffer: Buffer
|
imageBuffer: Buffer
|
||||||
): Promise<{ buffer: Buffer; mimeType: string; filename: string }> {
|
): Promise<{ buffer: Buffer; mimeType: string; filename: string }> {
|
||||||
@ -212,7 +201,13 @@ async function prepareImageForAos(
|
|||||||
return { buffer: imageBuffer, mimeType: "application/octet-stream", filename: "image" };
|
return { buffer: imageBuffer, mimeType: "application/octet-stream", filename: "image" };
|
||||||
}
|
}
|
||||||
|
|
||||||
assertAosImageResolution(metadata.width, metadata.height);
|
const { width, height } = metadata;
|
||||||
|
if (width && height && (width > AOS_MAX_RESOLUTION || height > AOS_MAX_RESOLUTION)) {
|
||||||
|
throw new RmbgServiceError(
|
||||||
|
`抠图参考图分辨率超限(${width}×${height} 像素),当前 AOS 上游要求宽、高均不超过 ${AOS_MAX_RESOLUTION} 像素。`,
|
||||||
|
400
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const format = metadata.format || "";
|
const format = metadata.format || "";
|
||||||
if (["gif", "svg", "heif", "avif", "jp2", "jxl"].includes(format)) {
|
if (["gif", "svg", "heif", "avif", "jp2", "jxl"].includes(format)) {
|
||||||
@ -379,42 +374,31 @@ async function processWithPhotoRoom(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function processWithAosSegmentation(
|
async function processWithAosSegmentation(
|
||||||
input: Pick<ExecuteRmbgJobParams, "imageBuffer" | "inputImageUrl" | "includeBase64">,
|
imageBuffer: Buffer,
|
||||||
config: {
|
config: {
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
apiBaseUrl?: string;
|
apiBaseUrl?: string;
|
||||||
foregroundType?: "" | "person" | "object" | "stamp";
|
foregroundType?: "" | "person" | "object" | "stamp";
|
||||||
crop?: 0 | 1;
|
crop?: 0 | 1;
|
||||||
format?: "png" | "jpg";
|
format?: "png" | "jpg";
|
||||||
|
inputImageUrl?: string | null;
|
||||||
requestId?: string;
|
requestId?: string;
|
||||||
}
|
}
|
||||||
): Promise<{
|
): Promise<{ success: boolean; imageBuffer?: Buffer; processing_time?: number; error?: string }> {
|
||||||
success: boolean;
|
|
||||||
imageBuffer?: Buffer;
|
|
||||||
archived?: NonNullable<Awaited<ReturnType<typeof archiveAosResult>>>;
|
|
||||||
processing_time?: number;
|
|
||||||
error?: string;
|
|
||||||
}> {
|
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
const baseUrl = (config.apiBaseUrl || "https://techsz.aoscdn.com").replace(/\/+$/, "");
|
const baseUrl = (config.apiBaseUrl || "https://techsz.aoscdn.com").replace(/\/+$/, "");
|
||||||
const createUrl = `${baseUrl}/api/tasks/visual/segmentation`;
|
const createUrl = `${baseUrl}/api/tasks/visual/segmentation`;
|
||||||
const headers = { "X-API-KEY": config.apiKey };
|
const headers = { "X-API-KEY": config.apiKey };
|
||||||
let stage = "create";
|
let stage = "create";
|
||||||
let providerTaskId: string | undefined;
|
let providerTaskId: string | undefined;
|
||||||
const directInput = !input.imageBuffer && input.inputImageUrl
|
const sourceImage = await prepareImageForAos(imageBuffer);
|
||||||
? await readAosQiniuInput(input.inputImageUrl)
|
|
||||||
: null;
|
|
||||||
if (directInput) assertAosImageResolution(directInput.width, directInput.height);
|
|
||||||
const imageBuffer = input.imageBuffer ?? (directInput ? null : await fetchImageBufferFromUrl(input.inputImageUrl!));
|
|
||||||
const inputBytes = directInput?.bytes ?? imageBuffer!.length;
|
|
||||||
const sourceImage = imageBuffer ? await prepareImageForAos(imageBuffer) : null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const createForm = new FormData();
|
const createForm = new FormData();
|
||||||
let publicSourceUrl = directInput?.url ?? null;
|
let publicSourceUrl: string | null = null;
|
||||||
if (!publicSourceUrl && input.inputImageUrl && inputBytes <= AOS_MAX_URL_INPUT_BYTES) {
|
if (config.inputImageUrl && imageBuffer.length <= AOS_MAX_URL_INPUT_BYTES) {
|
||||||
try {
|
try {
|
||||||
const source = new URL(input.inputImageUrl);
|
const source = new URL(config.inputImageUrl);
|
||||||
const cdn = new URL(process.env.NEXT_PUBLIC_CANVAS_CDN_ORIGIN || "");
|
const cdn = new URL(process.env.NEXT_PUBLIC_CANVAS_CDN_ORIGIN || "");
|
||||||
if (["http:", "https:"].includes(source.protocol) && source.hostname === cdn.hostname) {
|
if (["http:", "https:"].includes(source.protocol) && source.hostname === cdn.hostname) {
|
||||||
publicSourceUrl = source.toString();
|
publicSourceUrl = source.toString();
|
||||||
@ -424,10 +408,10 @@ async function processWithAosSegmentation(
|
|||||||
if (publicSourceUrl) {
|
if (publicSourceUrl) {
|
||||||
createForm.append("image_url", publicSourceUrl);
|
createForm.append("image_url", publicSourceUrl);
|
||||||
} else {
|
} else {
|
||||||
const imageBlob = new Blob([new Uint8Array(sourceImage!.buffer)], {
|
const imageBlob = new Blob([new Uint8Array(sourceImage.buffer)], {
|
||||||
type: sourceImage!.mimeType,
|
type: sourceImage.mimeType,
|
||||||
});
|
});
|
||||||
createForm.append("image_file", imageBlob, sourceImage!.filename);
|
createForm.append("image_file", imageBlob, sourceImage.filename);
|
||||||
}
|
}
|
||||||
createForm.append("sync", "0");
|
createForm.append("sync", "0");
|
||||||
createForm.append("return_type", "1");
|
createForm.append("return_type", "1");
|
||||||
@ -439,7 +423,7 @@ async function processWithAosSegmentation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createStartedAt = Date.now();
|
const createStartedAt = Date.now();
|
||||||
logger.info("aos_task_create_started", { requestId: config.requestId, sourceMode: publicSourceUrl ? "url" : "file", inputBytes, uploadBytes: publicSourceUrl ? 0 : inputBytes });
|
logger.info("aos_task_create_started", { requestId: config.requestId, sourceMode: publicSourceUrl ? "url" : "file", inputBytes: imageBuffer.length, uploadBytes: publicSourceUrl ? 0 : sourceImage.buffer.length });
|
||||||
|
|
||||||
const createResponse = await withTimeout(
|
const createResponse = await withTimeout(
|
||||||
(signal) =>
|
(signal) =>
|
||||||
@ -513,12 +497,6 @@ async function processWithAosSegmentation(
|
|||||||
taskId,
|
taskId,
|
||||||
});
|
});
|
||||||
stage = "download";
|
stage = "download";
|
||||||
if (input.includeBase64 === false) {
|
|
||||||
const archived = await archiveAosResult(imageUrl, `aos-rmbg-${taskId}`);
|
|
||||||
if (archived) {
|
|
||||||
return { success: true, archived, processing_time: (Date.now() - startTime) / 1000 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const imageResponse = await readAosResult(
|
const imageResponse = await readAosResult(
|
||||||
async (signal) => {
|
async (signal) => {
|
||||||
const response = await fetch(imageUrl, {
|
const response = await fetch(imageUrl, {
|
||||||
@ -566,7 +544,7 @@ async function processWithAosSegmentation(
|
|||||||
return { success: false, error: `AOS查询任务超时,结果尚未确认(任务 ${taskId})` };
|
return { success: false, error: `AOS查询任务超时,结果尚未确认(任务 ${taskId})` };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error && error.name === "AbortError") {
|
if (error instanceof Error && error.name === "AbortError") {
|
||||||
logger.warn("aos_request_timeout", { requestId: config.requestId, stage, taskId: providerTaskId, inputBytes });
|
logger.warn("aos_request_timeout", { requestId: config.requestId, stage, taskId: providerTaskId, inputBytes: imageBuffer.length });
|
||||||
const message = stage === "create"
|
const message = stage === "create"
|
||||||
? "AOS创建任务超时(120秒),结果尚未确认"
|
? "AOS创建任务超时(120秒),结果尚未确认"
|
||||||
: stage === "poll"
|
: stage === "poll"
|
||||||
@ -675,10 +653,6 @@ export async function fetchImageBufferFromUrl(imageUrl: string): Promise<Buffer>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function executeRmbgJob(
|
|
||||||
params: ExecuteRmbgJobParams & { includeBase64?: true }
|
|
||||||
): Promise<ExecuteRmbgJobResult & { image_base64: string }>;
|
|
||||||
export function executeRmbgJob(params: ExecuteRmbgJobParams): Promise<ExecuteRmbgJobResult>;
|
|
||||||
export async function executeRmbgJob(
|
export async function executeRmbgJob(
|
||||||
params: ExecuteRmbgJobParams
|
params: ExecuteRmbgJobParams
|
||||||
): Promise<ExecuteRmbgJobResult> {
|
): Promise<ExecuteRmbgJobResult> {
|
||||||
@ -691,12 +665,14 @@ async function runRmbgJob(
|
|||||||
const {
|
const {
|
||||||
requestId = crypto.randomUUID(),
|
requestId = crypto.randomUUID(),
|
||||||
userId,
|
userId,
|
||||||
includeBase64 = true,
|
imageBuffer,
|
||||||
|
imageBase64 = imageBuffer.toString("base64"),
|
||||||
foregroundType,
|
foregroundType,
|
||||||
prompt = "抠图处理",
|
prompt = "抠图处理",
|
||||||
chatId = null,
|
chatId = null,
|
||||||
messageId = null,
|
messageId = null,
|
||||||
skipGallerySave = false,
|
skipGallerySave = false,
|
||||||
|
inputImageUrl = null,
|
||||||
sourceImageUrl = null,
|
sourceImageUrl = null,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
@ -706,21 +682,17 @@ async function runRmbgJob(
|
|||||||
hasChatId: Boolean(chatId),
|
hasChatId: Boolean(chatId),
|
||||||
hasMessageId: Boolean(messageId),
|
hasMessageId: Boolean(messageId),
|
||||||
hasSourceImageUrl: Boolean(sourceImageUrl),
|
hasSourceImageUrl: Boolean(sourceImageUrl),
|
||||||
inputBytes: params.imageBuffer?.length,
|
inputBytes: imageBuffer.length,
|
||||||
provider,
|
provider,
|
||||||
skipGallerySave,
|
skipGallerySave,
|
||||||
});
|
});
|
||||||
|
|
||||||
let resultBuffer: Buffer | undefined;
|
let resultBuffer: Buffer;
|
||||||
let resultBase64: string | undefined;
|
let resultBase64: string;
|
||||||
let archived: NonNullable<Awaited<ReturnType<typeof archiveAosResult>>> | undefined;
|
|
||||||
let processingTime: number;
|
let processingTime: number;
|
||||||
const imageBuffer = provider === "aoscdn"
|
|
||||||
? null
|
|
||||||
: params.imageBuffer ?? await fetchImageBufferFromUrl(params.inputImageUrl!);
|
|
||||||
|
|
||||||
if (provider === "vip98k") {
|
if (provider === "vip98k") {
|
||||||
const result = await processWithVip98k(imageBuffer!);
|
const result = await processWithVip98k(imageBuffer);
|
||||||
if (!result.success || !result.imageBuffer) {
|
if (!result.success || !result.imageBuffer) {
|
||||||
logger.warn("job_provider_failed", {
|
logger.warn("job_provider_failed", {
|
||||||
provider,
|
provider,
|
||||||
@ -729,9 +701,10 @@ async function runRmbgJob(
|
|||||||
throw new RmbgServiceError("抠图处理失败", 500, result.error);
|
throw new RmbgServiceError("抠图处理失败", 500, result.error);
|
||||||
}
|
}
|
||||||
resultBuffer = result.imageBuffer;
|
resultBuffer = result.imageBuffer;
|
||||||
|
resultBase64 = resultBuffer.toString("base64");
|
||||||
processingTime = result.processing_time || 0;
|
processingTime = result.processing_time || 0;
|
||||||
} else if (provider === "photoroom") {
|
} else if (provider === "photoroom") {
|
||||||
const result = await processWithPhotoRoom(imageBuffer!, config.photoroomApiKey!);
|
const result = await processWithPhotoRoom(imageBuffer, config.photoroomApiKey!);
|
||||||
if (!result.success || !result.imageBuffer) {
|
if (!result.success || !result.imageBuffer) {
|
||||||
logger.warn("job_provider_failed", {
|
logger.warn("job_provider_failed", {
|
||||||
provider,
|
provider,
|
||||||
@ -740,18 +713,20 @@ async function runRmbgJob(
|
|||||||
throw new RmbgServiceError("抠图处理失败", 500, result.error);
|
throw new RmbgServiceError("抠图处理失败", 500, result.error);
|
||||||
}
|
}
|
||||||
resultBuffer = result.imageBuffer;
|
resultBuffer = result.imageBuffer;
|
||||||
|
resultBase64 = resultBuffer.toString("base64");
|
||||||
processingTime = result.processing_time || 0;
|
processingTime = result.processing_time || 0;
|
||||||
} else if (provider === "aoscdn") {
|
} else if (provider === "aoscdn") {
|
||||||
const result = await processWithAosSegmentation(params, {
|
const result = await processWithAosSegmentation(imageBuffer, {
|
||||||
apiKey: config.aosApiKey!,
|
apiKey: config.aosApiKey!,
|
||||||
apiBaseUrl: config.aosApiBaseUrl,
|
apiBaseUrl: config.aosApiBaseUrl,
|
||||||
foregroundType: foregroundType ?? config.aosForegroundType ?? "",
|
foregroundType: foregroundType ?? config.aosForegroundType ?? "",
|
||||||
crop: config.aosCrop === 1 ? 1 : 0,
|
crop: config.aosCrop === 1 ? 1 : 0,
|
||||||
format: config.aosFormat === "jpg" ? "jpg" : "png",
|
format: config.aosFormat === "jpg" ? "jpg" : "png",
|
||||||
|
inputImageUrl,
|
||||||
requestId,
|
requestId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result.success || !(result.imageBuffer || result.archived)) {
|
if (!result.success || !result.imageBuffer) {
|
||||||
const detail = result.error || "AOS处理失败";
|
const detail = result.error || "AOS处理失败";
|
||||||
const friendlyMessage = getAosFriendlyErrorMessage(detail);
|
const friendlyMessage = getAosFriendlyErrorMessage(detail);
|
||||||
logger.warn("job_provider_failed", {
|
logger.warn("job_provider_failed", {
|
||||||
@ -767,10 +742,10 @@ async function runRmbgJob(
|
|||||||
}
|
}
|
||||||
|
|
||||||
resultBuffer = result.imageBuffer;
|
resultBuffer = result.imageBuffer;
|
||||||
archived = result.archived;
|
resultBase64 = resultBuffer.toString("base64");
|
||||||
processingTime = result.processing_time || 0;
|
processingTime = result.processing_time || 0;
|
||||||
} else {
|
} else {
|
||||||
const result = await processWithRMBG(params.imageBase64 ?? imageBuffer!.toString("base64"), {
|
const result = await processWithRMBG(imageBase64, {
|
||||||
apiUrl: config.apiUrl!,
|
apiUrl: config.apiUrl!,
|
||||||
apiKey: config.apiKey,
|
apiKey: config.apiKey,
|
||||||
});
|
});
|
||||||
@ -788,8 +763,7 @@ async function runRmbgJob(
|
|||||||
processingTime = result.processing_time || 0;
|
processingTime = result.processing_time || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadResult = archived ?? await uploadBufferToS3(resultBuffer!, "image/png");
|
const uploadResult = await uploadBufferToS3(resultBuffer, "image/png");
|
||||||
resultBase64 = includeBase64 ? resultBase64 ?? resultBuffer!.toString("base64") : undefined;
|
|
||||||
const thumbnailUrl = uploadResult.thumbnail;
|
const thumbnailUrl = uploadResult.thumbnail;
|
||||||
const originalUrl = uploadResult.original;
|
const originalUrl = uploadResult.original;
|
||||||
|
|
||||||
|
|||||||
@ -55,7 +55,7 @@ export async function buildDirectAgentImageAnalysisAnswer(params: {
|
|||||||
"请用中文直接回答,不要复述“根据摘要/根据图片”,也不要输出多余寒暄。",
|
"请用中文直接回答,不要复述“根据摘要/根据图片”,也不要输出多余寒暄。",
|
||||||
].join("\n\n"),
|
].join("\n\n"),
|
||||||
temperature: 0.2,
|
temperature: 0.2,
|
||||||
maxOutputTokens: 320,
|
maxTokens: 320,
|
||||||
abortSignal: AbortSignal.timeout(20_000),
|
abortSignal: AbortSignal.timeout(20_000),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -1624,7 +1624,7 @@ export async function summarizeImageForExecutionReport(params: {
|
|||||||
...(compatibleTemperature !== undefined
|
...(compatibleTemperature !== undefined
|
||||||
? { temperature: compatibleTemperature }
|
? { temperature: compatibleTemperature }
|
||||||
: {}),
|
: {}),
|
||||||
maxOutputTokens: 120,
|
maxTokens: 120,
|
||||||
abortSignal: AbortSignal.timeout(attemptTimeoutMs),
|
abortSignal: AbortSignal.timeout(attemptTimeoutMs),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
@ -2251,7 +2251,7 @@ ${historyText}
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
...(analyzerTemperature !== undefined ? { temperature: analyzerTemperature } : {}),
|
...(analyzerTemperature !== undefined ? { temperature: analyzerTemperature } : {}),
|
||||||
maxOutputTokens: 360,
|
maxTokens: 360,
|
||||||
abortSignal: AbortSignal.timeout(ANALYZER_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(ANALYZER_TIMEOUT_MS),
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
@ -2259,7 +2259,7 @@ ${historyText}
|
|||||||
system: ANALYZER_SYSTEM_PROMPT,
|
system: ANALYZER_SYSTEM_PROMPT,
|
||||||
prompt: userMessage,
|
prompt: userMessage,
|
||||||
...(analyzerTemperature !== undefined ? { temperature: analyzerTemperature } : {}),
|
...(analyzerTemperature !== undefined ? { temperature: analyzerTemperature } : {}),
|
||||||
maxOutputTokens: 300,
|
maxTokens: 300,
|
||||||
abortSignal: AbortSignal.timeout(ANALYZER_TIMEOUT_MS),
|
abortSignal: AbortSignal.timeout(ANALYZER_TIMEOUT_MS),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ export type Vip98kChatInvocation = {
|
|||||||
protocol: "openai-chat" | "openai-responses" | "anthropic-messages";
|
protocol: "openai-chat" | "openai-responses" | "anthropic-messages";
|
||||||
path: "/v1/chat/completions" | "/v1/responses" | "/v1/messages";
|
path: "/v1/chat/completions" | "/v1/responses" | "/v1/messages";
|
||||||
headers: Record<string, string>;
|
headers: Record<string, string>;
|
||||||
omitSampling?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function record(value: unknown): RecordValue | null {
|
function record(value: unknown): RecordValue | null {
|
||||||
@ -57,18 +56,10 @@ export function selectVip98kChatInvocation(value: unknown): Vip98kChatInvocation
|
|||||||
});
|
});
|
||||||
const selected = candidates[0];
|
const selected = candidates[0];
|
||||||
if (!selected) return null;
|
if (!selected) return null;
|
||||||
const selectedRoute = getVip98kInvocationHeaders(selected.headers)["X-Relay-Route-Option"];
|
|
||||||
const schemaSource = candidates.find(candidate => candidate.path === selected.path &&
|
|
||||||
getVip98kInvocationHeaders(candidate.headers)["X-Relay-Route-Option"] === selectedRoute &&
|
|
||||||
(candidate.input_schema || candidate.inputSchema));
|
|
||||||
const properties = record(record(schemaSource?.input_schema || schemaSource?.inputSchema)?.properties);
|
|
||||||
const fixedSampling = selected.omitSampling === true || ["temperature", "top_p"].some(key =>
|
|
||||||
record(properties?.[key])?.const !== undefined);
|
|
||||||
return {
|
return {
|
||||||
protocol: selected.path === "/v1/messages" ? "anthropic-messages" : selected.path === "/v1/responses" ? "openai-responses" : "openai-chat",
|
protocol: selected.path === "/v1/messages" ? "anthropic-messages" : selected.path === "/v1/responses" ? "openai-responses" : "openai-chat",
|
||||||
path: selected.path as Vip98kChatInvocation["path"],
|
path: selected.path as Vip98kChatInvocation["path"],
|
||||||
headers: getVip98kInvocationHeaders(selected.headers),
|
headers: getVip98kInvocationHeaders(selected.headers),
|
||||||
...(fixedSampling ? { omitSampling: true } : {}),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,6 @@ import {
|
|||||||
hasVerifiedVip98kOpenAiImageArrayContract,
|
hasVerifiedVip98kOpenAiImageArrayContract,
|
||||||
normalizeVip98kInvocationHeaders,
|
normalizeVip98kInvocationHeaders,
|
||||||
getVip98kImageBindingKeys,
|
getVip98kImageBindingKeys,
|
||||||
vip98kReferenceLimit,
|
|
||||||
selectVip98kTaskInvocation,
|
|
||||||
} from "@/lib/ai/vip98k-task-invocation";
|
} from "@/lib/ai/vip98k-task-invocation";
|
||||||
import { selectVip98kChatInvocation, vip98kChatSupportsVision } from "./vip98k-chat-contract";
|
import { selectVip98kChatInvocation, vip98kChatSupportsVision } from "./vip98k-chat-contract";
|
||||||
|
|
||||||
@ -570,12 +568,7 @@ function getSupportedImageSizes(model: Vip98kCatalogModel) {
|
|||||||
}
|
}
|
||||||
const primary = toRecord(toRecord(model.invocation?.input_schema)?.properties) || {};
|
const primary = toRecord(toRecord(model.invocation?.input_schema)?.properties) || {};
|
||||||
const resolutionEnum = parseStringArray(toRecord(primary.resolution)?.enum);
|
const resolutionEnum = parseStringArray(toRecord(primary.resolution)?.enum);
|
||||||
if (resolutionEnum.length) return [...new Set(resolutionEnum.map(normalizeImageSize).filter((size): size is string => Boolean(size)))];
|
if (resolutionEnum.length) return resolutionEnum.map(normalizeImageSize).filter((size): size is string => Boolean(size));
|
||||||
// The published tier can include portrait presets with a longer pixel edge.
|
|
||||||
const declaredSizes = getSupportedResolutions(model)
|
|
||||||
.map(normalizeImageSize)
|
|
||||||
.filter((size): size is string => Boolean(size));
|
|
||||||
if (declaredSizes.length) return [...new Set(declaredSizes)];
|
|
||||||
const schemaSizes = getInvocationCandidates(model).flatMap((invocation) => {
|
const schemaSizes = getInvocationCandidates(model).flatMap((invocation) => {
|
||||||
const properties =
|
const properties =
|
||||||
toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
||||||
@ -583,7 +576,7 @@ function getSupportedImageSizes(model: Vip98kCatalogModel) {
|
|||||||
(key) => parseStringArray(toRecord(properties[key])?.enum),
|
(key) => parseStringArray(toRecord(properties[key])?.enum),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
const sizes = schemaSizes
|
const sizes = [...getSupportedResolutions(model), ...schemaSizes]
|
||||||
.map(normalizeImageSize)
|
.map(normalizeImageSize)
|
||||||
.filter((value): value is string => Boolean(value));
|
.filter((value): value is string => Boolean(value));
|
||||||
return sizes.length ? Array.from(new Set(sizes)) : [DEFAULT_IMAGE_SIZE];
|
return sizes.length ? Array.from(new Set(sizes)) : [DEFAULT_IMAGE_SIZE];
|
||||||
@ -759,11 +752,7 @@ function createImagePreset(
|
|||||||
"ratio",
|
"ratio",
|
||||||
"aspect-ratio",
|
"aspect-ratio",
|
||||||
].some((key) => invocationKeys.has(key)) || hasVerifiedVip98kOpenAiImageArrayContract(modelId);
|
].some((key) => invocationKeys.has(key)) || hasVerifiedVip98kOpenAiImageArrayContract(modelId);
|
||||||
const supportsQuality = getInvocationCandidates(model).some(invocation => {
|
const supportsQuality = invocationKeys.has("quality");
|
||||||
const field = toRecord(toRecord(invocation.input_schema)?.properties)?.quality;
|
|
||||||
return field !== false && Boolean(field || invocation.request_example?.quality !== undefined) &&
|
|
||||||
!toRecord(field)?.const;
|
|
||||||
});
|
|
||||||
// Flare repeatedly returns 3:4/4:3 for 4:5/5:4, even with aspect_ratio supplied.
|
// Flare repeatedly returns 3:4/4:3 for 4:5/5:4, even with aspect_ratio supplied.
|
||||||
const declaredRatios = getInvocationCandidates(model).flatMap(invocation => {
|
const declaredRatios = getInvocationCandidates(model).flatMap(invocation => {
|
||||||
const props = toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
const props = toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
||||||
@ -778,17 +767,14 @@ function createImagePreset(
|
|||||||
: []),
|
: []),
|
||||||
...(supportsReferenceImages ? ["image-to-image", "reference-images"] : []),
|
...(supportsReferenceImages ? ["image-to-image", "reference-images"] : []),
|
||||||
];
|
];
|
||||||
const metadata = getVip98kMetadata(model, "image");
|
const declaredReferenceLimits = getInvocationCandidates(model).flatMap(invocation => {
|
||||||
const referenceInvocation = selectVip98kTaskInvocation({
|
const properties = toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
||||||
modelId, kind: "image", imageCount: 1,
|
return ["file_urls", "image", "images", "reference_images"].flatMap(key => {
|
||||||
configuredInvocation: metadata.invocation,
|
const limit = toRecord(properties[key])?.maxItems;
|
||||||
configuredInvocations: metadata.invocations,
|
|
||||||
});
|
|
||||||
const declaredReferenceLimits = getVip98kImageBindingKeys(referenceInvocation).flatMap(key => {
|
|
||||||
const limit = vip98kReferenceLimit(referenceInvocation?.inputSchema, key);
|
|
||||||
return typeof limit === "number" && limit > 0 ? [limit] : [];
|
return typeof limit === "number" && limit > 0 ? [limit] : [];
|
||||||
});
|
});
|
||||||
const maxReferenceImages = declaredReferenceLimits.length ? Math.min(...declaredReferenceLimits) : supportsMultiImageReference
|
});
|
||||||
|
const maxReferenceImages = declaredReferenceLimits.length ? Math.max(...declaredReferenceLimits) : supportsMultiImageReference
|
||||||
? 8
|
? 8
|
||||||
: supportsReferenceImages
|
: supportsReferenceImages
|
||||||
? 1
|
? 1
|
||||||
@ -819,7 +805,7 @@ function createImagePreset(
|
|||||||
supportedAspectRatios,
|
supportedAspectRatios,
|
||||||
supportsMultiImageReference,
|
supportsMultiImageReference,
|
||||||
maxReferenceImages,
|
maxReferenceImages,
|
||||||
vip98k: metadata,
|
vip98k: getVip98kMetadata(model, "image"),
|
||||||
},
|
},
|
||||||
defaultParams: {
|
defaultParams: {
|
||||||
provider: "vip98k",
|
provider: "vip98k",
|
||||||
@ -855,7 +841,7 @@ function createImagePreset(
|
|||||||
},
|
},
|
||||||
enableLoadingPlaceholder: true,
|
enableLoadingPlaceholder: true,
|
||||||
loadingColor: "yellow",
|
loadingColor: "yellow",
|
||||||
vip98k: metadata,
|
vip98k: getVip98kMetadata(model, "image"),
|
||||||
},
|
},
|
||||||
sortOrder: TYPE_SORT_ORDER.image + index,
|
sortOrder: TYPE_SORT_ORDER.image + index,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -316,32 +316,6 @@ function scoreReferenceInvocation(invocation: Vip98kTaskInvocation) {
|
|||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function vip98kReferenceLimit(schema: unknown, key: string): number | undefined {
|
|
||||||
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return;
|
|
||||||
const current = schema as Record<string, any>;
|
|
||||||
const limits: number[] = [];
|
|
||||||
const visitField = (field: any) => {
|
|
||||||
if (!field || typeof field !== "object") return;
|
|
||||||
if (typeof field.maxItems === "number") limits.push(field.maxItems);
|
|
||||||
for (const child of Array.isArray(field.allOf) ? field.allOf : []) visitField(child);
|
|
||||||
};
|
|
||||||
visitField(current.properties?.[key]);
|
|
||||||
for (const child of Array.isArray(current.allOf) ? current.allOf : []) {
|
|
||||||
const limit = vip98kReferenceLimit(child, key);
|
|
||||||
if (limit !== undefined) limits.push(limit);
|
|
||||||
}
|
|
||||||
return limits.length ? Math.min(...limits) : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getVip98kQualityOptions(schema: Record<string, unknown> | null | undefined): string[] | undefined {
|
|
||||||
const field = (schema?.properties as Record<string, unknown> | undefined)?.quality;
|
|
||||||
if (field === false) return [];
|
|
||||||
if (!field || typeof field !== "object") return undefined;
|
|
||||||
const quality = field as Record<string, unknown>;
|
|
||||||
if (typeof quality.const === "string") return [quality.const];
|
|
||||||
return Array.isArray(quality.enum) ? quality.enum.filter((value): value is string => typeof value === "string") : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function encodeVip98kTaskBody(body: Record<string, unknown>, contentType?: string | null): { body: string | FormData; headers: Record<string, string> } {
|
export function encodeVip98kTaskBody(body: Record<string, unknown>, contentType?: string | null): { body: string | FormData; headers: Record<string, string> } {
|
||||||
if (contentType?.split(";", 1)[0].trim() !== "multipart/form-data") {
|
if (contentType?.split(";", 1)[0].trim() !== "multipart/form-data") {
|
||||||
return { body: JSON.stringify(body), headers: { "Content-Type": contentType || "application/json" } };
|
return { body: JSON.stringify(body), headers: { "Content-Type": contentType || "application/json" } };
|
||||||
@ -382,22 +356,14 @@ export function selectVip98kTaskInvocation(params: {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ((params.imageCount || 0) > 0) {
|
if ((params.imageCount || 0) > 0) {
|
||||||
const references = candidates.filter(invocationSupportsVip98kImages);
|
const referenceInvocation = candidates
|
||||||
const routedReferences = references.filter(candidate =>
|
.filter(invocationSupportsVip98kImages)
|
||||||
getVip98kInvocationHeaders(candidate.headers)["X-Relay-Route-Option"]);
|
|
||||||
const referenceInvocation = (routedReferences.length ? routedReferences : references)
|
|
||||||
.sort((a, b) => scoreReferenceInvocation(b) - scoreReferenceInvocation(a))[0];
|
.sort((a, b) => scoreReferenceInvocation(b) - scoreReferenceInvocation(a))[0];
|
||||||
if (referenceInvocation) {
|
if (referenceInvocation) {
|
||||||
return resolveVip98kTaskInvocation(params.modelId, referenceInvocation);
|
return resolveVip98kTaskInvocation(params.modelId, referenceInvocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.configuredInvocation &&
|
|
||||||
getVip98kInvocationHeaders(params.configuredInvocation.headers)["X-Relay-Route-Option"] &&
|
|
||||||
!params.configuredInvocation.path.includes(":generateContent")) {
|
|
||||||
return resolveVip98kTaskInvocation(params.modelId, params.configuredInvocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.kind === "image" && !params.imageCount) {
|
if (params.kind === "image" && !params.imageCount) {
|
||||||
const textImageTask = candidates.find(candidate => {
|
const textImageTask = candidates.find(candidate => {
|
||||||
const properties = candidate.inputSchema?.properties as Record<string, unknown> | undefined;
|
const properties = candidate.inputSchema?.properties as Record<string, unknown> | undefined;
|
||||||
@ -483,6 +449,7 @@ function createVerifiedOpenAiImageInvocation(modelId: string) {
|
|||||||
|
|
||||||
function addVerifiedOpenAiImageFields(
|
function addVerifiedOpenAiImageFields(
|
||||||
invocation: Vip98kTaskInvocation,
|
invocation: Vip98kTaskInvocation,
|
||||||
|
modelId: string,
|
||||||
): Vip98kTaskInvocation {
|
): Vip98kTaskInvocation {
|
||||||
const inputSchema = invocation.inputSchema || {};
|
const inputSchema = invocation.inputSchema || {};
|
||||||
const properties =
|
const properties =
|
||||||
@ -501,8 +468,16 @@ function addVerifiedOpenAiImageFields(
|
|||||||
...inputSchema,
|
...inputSchema,
|
||||||
properties: {
|
properties: {
|
||||||
...properties,
|
...properties,
|
||||||
image: properties.image ?? { items: { type: "string" }, type: "array" },
|
image: { items: { type: "string" }, type: "array" },
|
||||||
aspect_ratio: properties.aspect_ratio ?? { type: "string" },
|
aspect_ratio: { type: "string" },
|
||||||
|
...(hasVerifiedVip98kGptImage25ResolutionTiers(modelId)
|
||||||
|
? {
|
||||||
|
size: {
|
||||||
|
enum: ["1024x1024", "2048x2048", "2880x2880"],
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -524,7 +499,7 @@ export function resolveVip98kTaskInvocation(
|
|||||||
invocationTargetsModel(configuredInvocation, normalizedModelId)
|
invocationTargetsModel(configuredInvocation, normalizedModelId)
|
||||||
? configuredInvocation
|
? configuredInvocation
|
||||||
: createVerifiedOpenAiImageInvocation(modelId);
|
: createVerifiedOpenAiImageInvocation(modelId);
|
||||||
return addVerifiedOpenAiImageFields(invocation);
|
return addVerifiedOpenAiImageFields(invocation, normalizedModelId);
|
||||||
}
|
}
|
||||||
const processingRequest = KNOWN_IMAGE_PROCESSING_TOOL_REQUESTS[normalizedModelId];
|
const processingRequest = KNOWN_IMAGE_PROCESSING_TOOL_REQUESTS[normalizedModelId];
|
||||||
if (processingRequest) {
|
if (processingRequest) {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { executeLayerSplitJob } from "@/lib/ai/layer-split/service";
|
|||||||
import { executeResizeJob } from "@/lib/ai/resize/service";
|
import { executeResizeJob } from "@/lib/ai/resize/service";
|
||||||
import {
|
import {
|
||||||
executeRmbgJob,
|
executeRmbgJob,
|
||||||
|
fetchImageBufferFromUrl,
|
||||||
RmbgServiceError,
|
RmbgServiceError,
|
||||||
} from "@/lib/ai/rmbg/service";
|
} from "@/lib/ai/rmbg/service";
|
||||||
import type { CanvasCapabilityClientCommand } from "@/lib/canvas/capabilities/client-command";
|
import type { CanvasCapabilityClientCommand } from "@/lib/canvas/capabilities/client-command";
|
||||||
@ -125,11 +126,12 @@ async function executeForTarget(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (command.capabilityId === "image.remove_background") {
|
if (command.capabilityId === "image.remove_background") {
|
||||||
|
const imageBuffer = await fetchImageBufferFromUrl(target.sourceImageUrl);
|
||||||
const result = await executeRmbgJob({
|
const result = await executeRmbgJob({
|
||||||
requestId: command.requestId,
|
requestId: command.requestId,
|
||||||
userId: params.userId,
|
userId: params.userId,
|
||||||
|
imageBuffer,
|
||||||
inputImageUrl: target.sourceImageUrl,
|
inputImageUrl: target.sourceImageUrl,
|
||||||
includeBase64: false,
|
|
||||||
sourceImageUrl: target.sourceImageUrl,
|
sourceImageUrl: target.sourceImageUrl,
|
||||||
prompt: prompt || "抠图处理",
|
prompt: prompt || "抠图处理",
|
||||||
skipGallerySave: false,
|
skipGallerySave: false,
|
||||||
@ -255,12 +257,10 @@ async function executeForTarget(
|
|||||||
imageUrl: target.sourceImageUrl,
|
imageUrl: target.sourceImageUrl,
|
||||||
prompt: prompt || "图像增强处理",
|
prompt: prompt || "图像增强处理",
|
||||||
scaleFactor: asFiniteNumber(command.args.scaleFactor),
|
scaleFactor: asFiniteNumber(command.args.scaleFactor),
|
||||||
includeBase64: false,
|
|
||||||
},
|
},
|
||||||
pollingParams: {
|
pollingParams: {
|
||||||
prompt: prompt || "图像增强处理",
|
prompt: prompt || "图像增强处理",
|
||||||
sourceImageUrl: target.sourceImageUrl,
|
sourceImageUrl: target.sourceImageUrl,
|
||||||
includeBase64: "false",
|
|
||||||
},
|
},
|
||||||
timeoutMs: 10 * 60 * 1000,
|
timeoutMs: 10 * 60 * 1000,
|
||||||
headers: getCookieHeaders(params.requestHeaders),
|
headers: getCookieHeaders(params.requestHeaders),
|
||||||
|
|||||||
@ -1,36 +1,6 @@
|
|||||||
export const AOS_ENHANCE_RESULT_TIMEOUT_MS = 30_000;
|
// Polling is bounded by elapsed time, including network waits. Terminal provider failures
|
||||||
|
// must escape immediately instead of being converted into a perpetual pending response.
|
||||||
export class EnhanceTerminalError extends Error {}
|
export class EnhanceTerminalError extends Error {}
|
||||||
|
|
||||||
export async function readCompletedEnhanceImage(
|
|
||||||
data: { image?: unknown; image_base64?: unknown },
|
|
||||||
fetcher: typeof fetch = fetch,
|
|
||||||
): Promise<{ buffer: Buffer; mimeType: string }> {
|
|
||||||
try {
|
|
||||||
const image = data.image_base64 || data.image;
|
|
||||||
if (typeof image !== "string" || !image) throw new Error("处理结果缺少图片");
|
|
||||||
let buffer: Buffer;
|
|
||||||
if (/^https?:\/\//i.test(image)) {
|
|
||||||
const response = await fetcher(image, {
|
|
||||||
cache: "no-store",
|
|
||||||
signal: AbortSignal.timeout(60_000),
|
|
||||||
});
|
|
||||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
||||||
buffer = Buffer.from(await response.arrayBuffer());
|
|
||||||
} else {
|
|
||||||
buffer = Buffer.from(image, "base64");
|
|
||||||
}
|
|
||||||
const { default: sharp } = await import("sharp");
|
|
||||||
const { format } = await sharp(buffer).metadata();
|
|
||||||
if (!format || !["jpeg", "png", "webp", "tiff"].includes(format)) {
|
|
||||||
throw new Error("处理结果的图片格式不可用");
|
|
||||||
}
|
|
||||||
return { buffer, mimeType: `image/${format}` };
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error("图片变清晰已完成,但结果图片未取回。", { cause: error });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function pollTaskResult(
|
export async function pollTaskResult(
|
||||||
apiUrl: string,
|
apiUrl: string,
|
||||||
apiKey: string,
|
apiKey: string,
|
||||||
@ -47,23 +17,17 @@ export async function pollTaskResult(
|
|||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: { "X-API-KEY": apiKey },
|
headers: { "X-API-KEY": apiKey },
|
||||||
signal: AbortSignal.timeout(
|
signal: AbortSignal.timeout(Math.max(1, Math.min(10000, deadline - Date.now()))),
|
||||||
Math.max(1, Math.min(AOS_ENHANCE_RESULT_TIMEOUT_MS, deadline - Date.now())),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
if (!response.ok) throw Error(`轮询请求失败: ${response.status}`);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result?.data) {
|
if (!result.data) throw Error("高清查询未返回任务状态");
|
||||||
const state = Number(result.data.state);
|
if (result.data.state < 0)
|
||||||
if (state < 0) {
|
|
||||||
throw new EnhanceTerminalError(
|
throw new EnhanceTerminalError(
|
||||||
`AOS任务失败: ${String(result.data.err_message || result.data.err_info || result.data.state_detail || result.data.state)}`,
|
`AOS任务失败: ${String(result.data.err_message || result.data.err_info || result.data.state_detail || result.data.state)}`,
|
||||||
);
|
);
|
||||||
}
|
if (result.data.progress >= 100) return result;
|
||||||
if (response.ok && (state === 1 || (!(state > 1) && result.data.progress >= 100))) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof EnhanceTerminalError) throw error;
|
if (error instanceof EnhanceTerminalError) throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,78 +0,0 @@
|
|||||||
import type { FeedbackMessage } from "./feedback-contract";
|
|
||||||
|
|
||||||
export const CANVAS_FEEDBACK_CONTEXT_EVENT = "canvas-feedback-context";
|
|
||||||
export type FeedbackChatCapture = { chatId: string | null; messages: FeedbackMessage[] };
|
|
||||||
export type FeedbackCaptureEvent = CustomEvent<{
|
|
||||||
projectId: string;
|
|
||||||
receive: (value: FeedbackChatCapture) => void;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export function captureFeedbackChat(projectId: string): FeedbackChatCapture {
|
|
||||||
let result: FeedbackChatCapture = { chatId: null, messages: [] };
|
|
||||||
window.dispatchEvent(
|
|
||||||
new CustomEvent(CANVAS_FEEDBACK_CONTEXT_EVENT, {
|
|
||||||
detail: {
|
|
||||||
projectId,
|
|
||||||
receive: (value: FeedbackChatCapture) => {
|
|
||||||
result = value;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function feedbackMessages(messages: readonly unknown[]): FeedbackMessage[] {
|
|
||||||
let remaining = 48000;
|
|
||||||
return messages
|
|
||||||
.slice(-12)
|
|
||||||
.reverse()
|
|
||||||
.flatMap((value: any) => {
|
|
||||||
if (!value || !["user", "assistant"].includes(value.role) || typeof value.id !== "string")
|
|
||||||
return [];
|
|
||||||
const parts = Array.isArray(value.parts) ? value.parts : [];
|
|
||||||
let state: any = null;
|
|
||||||
for (const part of parts) {
|
|
||||||
if (part.type !== "data-imageGenerationStatus") continue;
|
|
||||||
try {
|
|
||||||
state = typeof part.data === "string" ? JSON.parse(part.data) : part.data;
|
|
||||||
} catch {
|
|
||||||
/* Keep public message text when a stream part is incomplete. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const fullText = parts
|
|
||||||
.filter((part: any) => part.type === "text")
|
|
||||||
.map((part: any) => String(part.text || ""))
|
|
||||||
.join("\n");
|
|
||||||
const text = fullText.slice(0, Math.min(16000, remaining));
|
|
||||||
remaining -= text.length;
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: value.id.slice(0, 180),
|
|
||||||
role: value.role,
|
|
||||||
text,
|
|
||||||
...(value.createdAt
|
|
||||||
? {
|
|
||||||
createdAt: String(
|
|
||||||
value.createdAt instanceof Date ? value.createdAt.toISOString() : value.createdAt,
|
|
||||||
).slice(0, 64),
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
...(state?.requestId ? { requestId: String(state.requestId).slice(0, 180) } : {}),
|
|
||||||
...(state?.userMessageId
|
|
||||||
? { userMessageId: String(state.userMessageId).slice(0, 180) }
|
|
||||||
: {}),
|
|
||||||
...(state?.phase ? { status: String(state.phase).slice(0, 64) } : {}),
|
|
||||||
...(state?.failure?.message
|
|
||||||
? {
|
|
||||||
error: [state.failure.message, state.failure.recommendation]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join("\n")
|
|
||||||
.slice(0, 2000),
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
})
|
|
||||||
.reverse();
|
|
||||||
}
|
|
||||||
@ -1,307 +0,0 @@
|
|||||||
import "server-only";
|
|
||||||
import { and, asc, desc, eq, gte, inArray, sql } from "drizzle-orm";
|
|
||||||
import { db } from "@/lib/db";
|
|
||||||
import {
|
|
||||||
canvasProject,
|
|
||||||
canvasAgentRun,
|
|
||||||
canvasCapabilityTask,
|
|
||||||
canvasImageTask,
|
|
||||||
chat,
|
|
||||||
message,
|
|
||||||
user,
|
|
||||||
} from "@/lib/db/schema";
|
|
||||||
import { feedbackMessages } from "./feedback-client";
|
|
||||||
import type {
|
|
||||||
FeedbackClient,
|
|
||||||
FeedbackContext,
|
|
||||||
FeedbackMessage,
|
|
||||||
FeedbackRequest,
|
|
||||||
} from "./feedback-contract";
|
|
||||||
|
|
||||||
export class CanvasFeedbackError extends Error {
|
|
||||||
status: number;
|
|
||||||
constructor(message: string, status = 400) {
|
|
||||||
super(message);
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const text = (value: unknown) => (typeof value === "string" ? value : "");
|
|
||||||
const duration = (started: Date | null, completed: Date | null) =>
|
|
||||||
started && completed ? Math.max(0, completed.getTime() - started.getTime()) : null;
|
|
||||||
// The general capability store uses the database default; the video queue writes UTC.
|
|
||||||
const capabilityCreatedAt = sql<string>`to_char(
|
|
||||||
case when ${canvasCapabilityTask.capabilityId} = 'video-canvas.generation'
|
|
||||||
then ${canvasCapabilityTask.createdAt}
|
|
||||||
else ${canvasCapabilityTask.createdAt} at time zone current_setting('TimeZone') at time zone 'UTC'
|
|
||||||
end, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')`;
|
|
||||||
function requestSummary(
|
|
||||||
column: typeof canvasImageTask.request | typeof canvasCapabilityTask.request,
|
|
||||||
) {
|
|
||||||
return sql<Record<string, unknown>>`jsonb_build_object(
|
|
||||||
'prompt', coalesce(${column}->'params'->>'prompt', ${column}->'input'->>'prompt', ${column}->>'displayPrompt', ${column}->>'prompt'),
|
|
||||||
'model', coalesce(${column}->'params'->>'model', ${column}->>'model'))`;
|
|
||||||
}
|
|
||||||
function requestParameters(request: Record<string, any>) {
|
|
||||||
const values = request.params || request.input || request;
|
|
||||||
const keys = [
|
|
||||||
"aspectRatio",
|
|
||||||
"imageSize",
|
|
||||||
"imageCount",
|
|
||||||
"sourceNodeIds",
|
|
||||||
"targetNodeIds",
|
|
||||||
"imageUrl",
|
|
||||||
"sourceImageUrl",
|
|
||||||
"referenceImage",
|
|
||||||
"referenceImages",
|
|
||||||
"region",
|
|
||||||
"selectionRect",
|
|
||||||
"width",
|
|
||||||
"height",
|
|
||||||
"operation",
|
|
||||||
"capabilityId",
|
|
||||||
];
|
|
||||||
const compact = (value: unknown): unknown => {
|
|
||||||
if (typeof value === "string")
|
|
||||||
return value.startsWith("data:") ? "内嵌图片,已省略二进制内容" : value.slice(0, 4000);
|
|
||||||
if (Array.isArray(value)) return value.slice(0, 20).map(compact);
|
|
||||||
return value;
|
|
||||||
};
|
|
||||||
return Object.fromEntries(
|
|
||||||
keys.filter((key) => values[key] !== undefined).map((key) => [key, compact(values[key])]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function feedbackConversationRequests(
|
|
||||||
messages: FeedbackMessage[],
|
|
||||||
verifiedIds: Set<string>,
|
|
||||||
) {
|
|
||||||
const requests: FeedbackRequest[] = [];
|
|
||||||
for (const item of messages) {
|
|
||||||
if (item.role === "user") {
|
|
||||||
requests.push({
|
|
||||||
key: `message:${item.id}`,
|
|
||||||
kind: "message",
|
|
||||||
id: item.id,
|
|
||||||
requestId: null,
|
|
||||||
createdAt: item.createdAt || "",
|
|
||||||
prompt: item.text,
|
|
||||||
status: "未获取任务状态",
|
|
||||||
model: null,
|
|
||||||
error: null,
|
|
||||||
evidence: verifiedIds.has(item.id) ? "server" : "browser",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const latest = item.userMessageId
|
|
||||||
? requests.find((request) => request.id === item.userMessageId)
|
|
||||||
: requests.at(-1);
|
|
||||||
if (!latest) continue;
|
|
||||||
if (item.requestId) latest.requestId = item.requestId;
|
|
||||||
if (item.status) latest.status = item.status;
|
|
||||||
if (item.error) latest.error = item.error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return requests.filter((item) => item.prompt).reverse();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function collectCanvasFeedbackContext(
|
|
||||||
userId: string,
|
|
||||||
projectId: string,
|
|
||||||
client: FeedbackClient,
|
|
||||||
selection?: string | null,
|
|
||||||
): Promise<FeedbackContext> {
|
|
||||||
const [project] = await db
|
|
||||||
.select({ id: canvasProject.id, title: canvasProject.title })
|
|
||||||
.from(canvasProject)
|
|
||||||
.where(and(eq(canvasProject.id, projectId), eq(canvasProject.userId, userId)))
|
|
||||||
.limit(1);
|
|
||||||
if (!project) throw new CanvasFeedbackError("画布不存在或无权反馈该画布", 404);
|
|
||||||
const [reporter] = await db
|
|
||||||
.select({ id: user.id, name: user.name, email: user.email, department: user.department })
|
|
||||||
.from(user)
|
|
||||||
.where(eq(user.id, userId))
|
|
||||||
.limit(1);
|
|
||||||
if (!reporter) throw new CanvasFeedbackError("登录状态已失效,请重新登录", 401);
|
|
||||||
const [kind, selectedId] = (selection || "").split(":", 2);
|
|
||||||
const validId = /^[0-9a-f-]{36}$/i.test(selectedId || "");
|
|
||||||
const selectedMessage =
|
|
||||||
kind === "message" && validId && client.chatId
|
|
||||||
? (
|
|
||||||
await db
|
|
||||||
.select({ createdAt: message.createdAt })
|
|
||||||
.from(message)
|
|
||||||
.innerJoin(chat, and(eq(chat.id, message.chatId), eq(chat.userId, userId)))
|
|
||||||
.where(and(eq(message.chatId, client.chatId), eq(message.id, selectedId)))
|
|
||||||
.limit(1)
|
|
||||||
)[0]
|
|
||||||
: null;
|
|
||||||
const [runs, capabilities, storedMessages] = await Promise.all([
|
|
||||||
db
|
|
||||||
.select({
|
|
||||||
id: canvasAgentRun.id,
|
|
||||||
createdAt: canvasAgentRun.createdAt,
|
|
||||||
status: canvasAgentRun.status,
|
|
||||||
objective: sql<string>`${canvasAgentRun.snapshot}->>'objective'`,
|
|
||||||
errors: sql<
|
|
||||||
string[]
|
|
||||||
>`jsonb_path_query_array(${canvasAgentRun.snapshot}, '$.calls[*].error')`,
|
|
||||||
})
|
|
||||||
.from(canvasAgentRun)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(canvasAgentRun.userId, userId),
|
|
||||||
eq(canvasAgentRun.projectId, projectId),
|
|
||||||
...(client.chatId ? [eq(canvasAgentRun.chatId, client.chatId)] : []),
|
|
||||||
...(kind === "agent" && validId ? [eq(canvasAgentRun.id, selectedId)] : []),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.orderBy(desc(canvasAgentRun.createdAt))
|
|
||||||
.limit(10),
|
|
||||||
db
|
|
||||||
.select({
|
|
||||||
id: canvasCapabilityTask.id,
|
|
||||||
requestId: canvasCapabilityTask.requestId,
|
|
||||||
capabilityId: canvasCapabilityTask.capabilityId,
|
|
||||||
createdAt: capabilityCreatedAt,
|
|
||||||
startedAt: canvasCapabilityTask.startedAt,
|
|
||||||
completedAt: canvasCapabilityTask.completedAt,
|
|
||||||
status: canvasCapabilityTask.status,
|
|
||||||
error: canvasCapabilityTask.error,
|
|
||||||
request:
|
|
||||||
kind === "capability" && validId
|
|
||||||
? canvasCapabilityTask.request
|
|
||||||
: requestSummary(canvasCapabilityTask.request),
|
|
||||||
})
|
|
||||||
.from(canvasCapabilityTask)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(canvasCapabilityTask.userId, userId),
|
|
||||||
eq(canvasCapabilityTask.projectId, projectId),
|
|
||||||
...(kind === "capability" && validId ? [eq(canvasCapabilityTask.id, selectedId)] : []),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.orderBy(desc(capabilityCreatedAt))
|
|
||||||
.limit(10),
|
|
||||||
client.chatId
|
|
||||||
? db
|
|
||||||
.select({
|
|
||||||
id: message.id,
|
|
||||||
role: message.role,
|
|
||||||
parts: message.parts,
|
|
||||||
createdAt: message.createdAt,
|
|
||||||
})
|
|
||||||
.from(message)
|
|
||||||
.innerJoin(chat, and(eq(chat.id, message.chatId), eq(chat.userId, userId)))
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(message.chatId, client.chatId),
|
|
||||||
...(selectedMessage ? [gte(message.createdAt, selectedMessage.createdAt)] : []),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.orderBy(selectedMessage ? asc(message.createdAt) : desc(message.createdAt))
|
|
||||||
.limit(12)
|
|
||||||
: Promise.resolve([]),
|
|
||||||
]);
|
|
||||||
const verifiedIds = new Set(storedMessages.map((item) => item.id));
|
|
||||||
const serverById = new Map(
|
|
||||||
feedbackMessages(selectedMessage ? storedMessages : [...storedMessages].reverse()).map(
|
|
||||||
(item) => [item.id, item],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const browserIds = new Set(client.messages.map((item) => item.id));
|
|
||||||
const combined = [...serverById.values()].filter((item) => !browserIds.has(item.id));
|
|
||||||
combined.push(...client.messages.map((item) => ({ ...item, ...serverById.get(item.id) })));
|
|
||||||
// Browser stream metadata can arrive before the final assistant row is persisted.
|
|
||||||
const conversation = feedbackConversationRequests(combined, verifiedIds);
|
|
||||||
const imageIds = Array.from(
|
|
||||||
new Set(
|
|
||||||
[
|
|
||||||
...conversation.map((item) => item.requestId),
|
|
||||||
...client.nodes.map((node) => node.taskId),
|
|
||||||
].filter((id): id is string => Boolean(id && /^[0-9a-f-]{36}$/i.test(id))),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (kind === "image" && validId) imageIds.push(selectedId);
|
|
||||||
const images = imageIds.length
|
|
||||||
? await db
|
|
||||||
.select({
|
|
||||||
id: canvasImageTask.id,
|
|
||||||
createdAt: canvasImageTask.createdAt,
|
|
||||||
startedAt: canvasImageTask.startedAt,
|
|
||||||
completedAt: canvasImageTask.completedAt,
|
|
||||||
status: canvasImageTask.status,
|
|
||||||
error: canvasImageTask.error,
|
|
||||||
request:
|
|
||||||
kind === "image" && validId
|
|
||||||
? canvasImageTask.request
|
|
||||||
: requestSummary(canvasImageTask.request),
|
|
||||||
})
|
|
||||||
.from(canvasImageTask)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(canvasImageTask.userId, userId),
|
|
||||||
inArray(canvasImageTask.id, imageIds),
|
|
||||||
...(kind === "image" && validId ? [eq(canvasImageTask.id, selectedId)] : []),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.limit(12)
|
|
||||||
: [];
|
|
||||||
const requests: FeedbackRequest[] = [
|
|
||||||
...conversation,
|
|
||||||
...runs.map(
|
|
||||||
(run): FeedbackRequest => ({
|
|
||||||
key: `agent:${run.id}`,
|
|
||||||
kind: "agent",
|
|
||||||
id: run.id,
|
|
||||||
requestId: run.id,
|
|
||||||
createdAt: run.createdAt.toISOString(),
|
|
||||||
prompt: run.objective || "Agent 任务",
|
|
||||||
status: run.status,
|
|
||||||
model: null,
|
|
||||||
error: (run.errors || []).join("\n") || null,
|
|
||||||
evidence: "server",
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
...capabilities.map((task): FeedbackRequest => {
|
|
||||||
const request = task.request as Record<string, any>;
|
|
||||||
return {
|
|
||||||
key: `capability:${task.id}`,
|
|
||||||
kind: "capability",
|
|
||||||
id: task.id,
|
|
||||||
requestId: task.requestId,
|
|
||||||
createdAt: task.createdAt,
|
|
||||||
prompt:
|
|
||||||
text(request.params?.prompt) ||
|
|
||||||
text(request.input?.prompt) ||
|
|
||||||
text(request.prompt) ||
|
|
||||||
task.capabilityId,
|
|
||||||
status: task.status,
|
|
||||||
model: text(request.params?.model) || text(request.model) || null,
|
|
||||||
error: task.error,
|
|
||||||
durationMs: duration(task.startedAt, task.completedAt),
|
|
||||||
parameters: requestParameters(request),
|
|
||||||
evidence: "server",
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
...images.map((task): FeedbackRequest => {
|
|
||||||
const request = task.request as Record<string, any>;
|
|
||||||
return {
|
|
||||||
key: `image:${task.id}`,
|
|
||||||
kind: "image",
|
|
||||||
id: task.id,
|
|
||||||
requestId: task.id,
|
|
||||||
createdAt: task.createdAt.toISOString(),
|
|
||||||
prompt: text(request.displayPrompt) || text(request.prompt),
|
|
||||||
status: task.status,
|
|
||||||
model: text(request.model) || null,
|
|
||||||
error: task.error,
|
|
||||||
durationMs: duration(task.startedAt, task.completedAt),
|
|
||||||
parameters: requestParameters(request),
|
|
||||||
evidence: "server",
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
requests.sort((a, b) => (Date.parse(b.createdAt) || 0) - (Date.parse(a.createdAt) || 0));
|
|
||||||
if (selection && !requests.some((item) => item.key === selection))
|
|
||||||
throw new CanvasFeedbackError("关联请求已变化,请重新选择要反馈的请求", 409);
|
|
||||||
return { project, reporter: { ...reporter, name: reporter.name || reporter.email }, requests };
|
|
||||||
}
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
export const feedbackMessageSchema = z.object({
|
|
||||||
id: z.string().max(180),
|
|
||||||
role: z.enum(["user", "assistant"]),
|
|
||||||
text: z.string().max(16000),
|
|
||||||
createdAt: z.string().max(64).optional(),
|
|
||||||
requestId: z.string().max(180).optional(),
|
|
||||||
status: z.string().max(64).optional(),
|
|
||||||
error: z.string().max(2000).optional(),
|
|
||||||
userMessageId: z.string().max(180).optional(),
|
|
||||||
});
|
|
||||||
export const feedbackClientSchema = z.object({
|
|
||||||
chatId: z.string().uuid().nullable(),
|
|
||||||
messages: z.array(feedbackMessageSchema).max(12),
|
|
||||||
pageVersion: z.string().max(100),
|
|
||||||
capturedAt: z.string().datetime(),
|
|
||||||
viewport: z.object({
|
|
||||||
width: z.number().int().min(0).max(30000),
|
|
||||||
height: z.number().int().min(0).max(30000),
|
|
||||||
}),
|
|
||||||
online: z.boolean(),
|
|
||||||
errors: z.array(z.string().max(2000)).max(5),
|
|
||||||
nodes: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
id: z.string().max(180),
|
|
||||||
type: z.string().max(64),
|
|
||||||
title: z.string().max(256),
|
|
||||||
status: z.string().max(64),
|
|
||||||
taskId: z.string().max(180),
|
|
||||||
width: z.number().optional(),
|
|
||||||
height: z.number().optional(),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.max(20)
|
|
||||||
.default([]),
|
|
||||||
});
|
|
||||||
export const feedbackCommandSchema = z.discriminatedUnion("action", [
|
|
||||||
z.object({ action: z.literal("context"), client: feedbackClientSchema }),
|
|
||||||
z.object({
|
|
||||||
action: z.literal("submit"),
|
|
||||||
id: z.string().uuid(),
|
|
||||||
description: z.string().trim().max(2000),
|
|
||||||
selection: z.string().max(220).nullable(),
|
|
||||||
client: feedbackClientSchema,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
export type FeedbackClient = z.infer<typeof feedbackClientSchema>;
|
|
||||||
export type FeedbackMessage = z.infer<typeof feedbackMessageSchema>;
|
|
||||||
export type FeedbackRequest = {
|
|
||||||
key: string;
|
|
||||||
kind: "message" | "agent" | "capability" | "image";
|
|
||||||
id: string;
|
|
||||||
requestId: string | null;
|
|
||||||
createdAt: string;
|
|
||||||
prompt: string;
|
|
||||||
status: string;
|
|
||||||
model: string | null;
|
|
||||||
error: string | null;
|
|
||||||
durationMs?: number | null;
|
|
||||||
parameters?: Record<string, unknown>;
|
|
||||||
evidence: "server" | "browser";
|
|
||||||
};
|
|
||||||
export type FeedbackContext = {
|
|
||||||
reporter: { id: string; name: string; email: string; department: string | null };
|
|
||||||
project: { id: string; title: string };
|
|
||||||
requests: FeedbackRequest[];
|
|
||||||
};
|
|
||||||
export type FeedbackSnapshot = Omit<FeedbackContext, "requests"> & {
|
|
||||||
request: FeedbackRequest | null;
|
|
||||||
client: FeedbackClient;
|
|
||||||
userAgent: string;
|
|
||||||
};
|
|
||||||
export type FeedbackReceipt = {
|
|
||||||
id: string;
|
|
||||||
status: string;
|
|
||||||
deliveryId: string | null;
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function feedbackStatusMessage(status: string, errorCode?: string | null) {
|
|
||||||
if (["sent", "unread", "read"].includes(status)) return "反馈已投递给魔礼红。";
|
|
||||||
if (status === "failed")
|
|
||||||
return errorCode === "DELIVERY_OUTCOME_UNKNOWN"
|
|
||||||
? "反馈已保存,但钉钉投递结果暂无法确认。请保留反馈编号,避免重复提交。"
|
|
||||||
: "反馈已保存,但钉钉通知投递失败。请保留反馈编号并联系管理员。";
|
|
||||||
if (status === "pending") return "反馈已保存,正在提交通知;短暂故障会自动重试,无需再次反馈。";
|
|
||||||
return "反馈已保存,通知中心已受理,等待投递给魔礼红。";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatFeedbackTime(value: string) {
|
|
||||||
if (!Number.isFinite(Date.parse(value))) return "未记录";
|
|
||||||
return new Intl.DateTimeFormat("zh-CN", {
|
|
||||||
timeZone: "Asia/Shanghai",
|
|
||||||
dateStyle: "short",
|
|
||||||
timeStyle: "medium",
|
|
||||||
hour12: false,
|
|
||||||
}).format(new Date(value));
|
|
||||||
}
|
|
||||||
@ -1,190 +0,0 @@
|
|||||||
import "server-only";
|
|
||||||
import { and, asc, eq, isNull, lt, lte, sql } from "drizzle-orm";
|
|
||||||
import { db } from "@/lib/db";
|
|
||||||
import { canvasFeedback } from "@/lib/db/schema";
|
|
||||||
import {
|
|
||||||
notificationCenterConfigured,
|
|
||||||
notificationCenterRequest,
|
|
||||||
NotificationCenterError,
|
|
||||||
type NotificationPayload,
|
|
||||||
} from "@/lib/notifications/notification-center";
|
|
||||||
import { CanvasFeedbackError } from "./feedback-context";
|
|
||||||
import {
|
|
||||||
feedbackStatusMessage,
|
|
||||||
formatFeedbackTime,
|
|
||||||
type FeedbackReceipt,
|
|
||||||
type FeedbackSnapshot,
|
|
||||||
} from "./feedback-contract";
|
|
||||||
|
|
||||||
type FeedbackRow = typeof canvasFeedback.$inferSelect;
|
|
||||||
const backoffMs = [60_000, 300_000, 900_000, 1800_000, 1800_000];
|
|
||||||
const clip = (value: string, length: number) =>
|
|
||||||
value.length > length ? `${value.slice(0, length)}…(完整内容见反馈详情)` : value;
|
|
||||||
const quote = (value: string) =>
|
|
||||||
value
|
|
||||||
.replace(/\r\n?/g, "\n")
|
|
||||||
.split("\n")
|
|
||||||
.map((line) => `> ${line}`)
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
export function buildFeedbackNotification(input: {
|
|
||||||
id: string;
|
|
||||||
description: string;
|
|
||||||
snapshot: FeedbackSnapshot;
|
|
||||||
createdAt: string;
|
|
||||||
appUrl: string;
|
|
||||||
}): NotificationPayload {
|
|
||||||
const { reporter, project, request } = input.snapshot;
|
|
||||||
const content = [
|
|
||||||
`**反馈人:** ${reporter.name} · ${reporter.department || "未登记部门"}`,
|
|
||||||
`**反馈时间:** ${formatFeedbackTime(input.createdAt)}`,
|
|
||||||
`**画布:** ${project.title}`,
|
|
||||||
`**请求时间:** ${request?.createdAt ? formatFeedbackTime(request.createdAt) : "未关联请求"}`,
|
|
||||||
`**请求号:** ${request?.requestId || "尚未获取;可通过消息或任务编号排查"}`,
|
|
||||||
`**状态 / 模型:** ${request?.status || "页面问题"} / ${request?.model || "未记录"}`,
|
|
||||||
`**处理耗时:** ${request?.durationMs != null ? `${(request.durationMs / 1000).toFixed(1)} 秒` : "未记录或尚未结束"}`,
|
|
||||||
`**用户说明**\n${quote(clip(input.description || "用户未补充说明", 900))}`,
|
|
||||||
`**请求内容**\n${quote(clip(request?.prompt || "未关联具体请求", 1600))}`,
|
|
||||||
`**错误信息**\n${quote(clip(request?.error || input.snapshot.client.errors.join("\n") || "未记录明确错误", 600))}`,
|
|
||||||
`**反馈编号:** ${input.id}`,
|
|
||||||
`**页面版本:** ${input.snapshot.client.pageVersion}`,
|
|
||||||
].join("\n\n");
|
|
||||||
return {
|
|
||||||
idempotencyKey: `canvas-feedback:${input.id}:v1`,
|
|
||||||
recipientAlias: "魔礼红",
|
|
||||||
title: "画布问题反馈",
|
|
||||||
content: clip(content, 4400),
|
|
||||||
actionTitle: "查看完整反馈",
|
|
||||||
actionUrl: `${input.appUrl.replace(/\/$/, "")}/feedback/${input.id}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const feedbackReceipt = (row: FeedbackRow): FeedbackReceipt => {
|
|
||||||
const status = row.deliveryId && row.status === "pending" ? "accepted" : row.status;
|
|
||||||
return {
|
|
||||||
id: row.id,
|
|
||||||
deliveryId: row.deliveryId,
|
|
||||||
status,
|
|
||||||
message: feedbackStatusMessage(status, row.lastErrorCode),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function findCanvasFeedback(id: string) {
|
|
||||||
return (
|
|
||||||
(await db.select().from(canvasFeedback).where(eq(canvasFeedback.id, id)).limit(1))[0] || null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function saveCanvasFeedback(input: {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
description: string;
|
|
||||||
snapshot: FeedbackSnapshot;
|
|
||||||
appUrl: string;
|
|
||||||
}) {
|
|
||||||
const createdAt = new Date();
|
|
||||||
await db
|
|
||||||
.insert(canvasFeedback)
|
|
||||||
.values({
|
|
||||||
id: input.id,
|
|
||||||
userId: input.userId,
|
|
||||||
projectId: input.snapshot.project.id,
|
|
||||||
description: input.description,
|
|
||||||
snapshot: input.snapshot,
|
|
||||||
notification: buildFeedbackNotification({ ...input, createdAt: createdAt.toISOString() }),
|
|
||||||
createdAt,
|
|
||||||
nextAttemptAt: createdAt,
|
|
||||||
})
|
|
||||||
.onConflictDoNothing({ target: canvasFeedback.id });
|
|
||||||
const row = await findCanvasFeedback(input.id);
|
|
||||||
if (!row || row.userId !== input.userId || row.projectId !== input.snapshot.project.id)
|
|
||||||
throw new CanvasFeedbackError("反馈编号不可用", 409);
|
|
||||||
// The persisted notification is immutable so a lost response can be retried safely.
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deliverCanvasFeedback(id: string) {
|
|
||||||
const [claimed] = await db
|
|
||||||
.update(canvasFeedback)
|
|
||||||
.set({
|
|
||||||
attempts: sql`${canvasFeedback.attempts} + 1`,
|
|
||||||
nextAttemptAt: new Date(Date.now() + 60_000),
|
|
||||||
})
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(canvasFeedback.id, id),
|
|
||||||
eq(canvasFeedback.status, "pending"),
|
|
||||||
isNull(canvasFeedback.deliveryId),
|
|
||||||
lte(canvasFeedback.nextAttemptAt, new Date()),
|
|
||||||
lt(canvasFeedback.attempts, 5),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.returning();
|
|
||||||
if (!claimed) return;
|
|
||||||
try {
|
|
||||||
const delivery = await notificationCenterRequest(
|
|
||||||
"POST",
|
|
||||||
"/v1/notifications",
|
|
||||||
claimed.notification,
|
|
||||||
);
|
|
||||||
await db
|
|
||||||
.update(canvasFeedback)
|
|
||||||
.set({
|
|
||||||
deliveryId: delivery.id,
|
|
||||||
status: delivery.status,
|
|
||||||
lastErrorCode: delivery.lastErrorCode || null,
|
|
||||||
})
|
|
||||||
.where(eq(canvasFeedback.id, id));
|
|
||||||
} catch (error) {
|
|
||||||
const failure =
|
|
||||||
error instanceof NotificationCenterError
|
|
||||||
? error
|
|
||||||
: new NotificationCenterError("NOTIFICATION_CONNECTION_FAILED", true);
|
|
||||||
await db
|
|
||||||
.update(canvasFeedback)
|
|
||||||
.set({
|
|
||||||
status: failure.retryable && claimed.attempts < 5 ? "pending" : "failed",
|
|
||||||
lastErrorCode: failure.code,
|
|
||||||
nextAttemptAt: new Date(Date.now() + backoffMs[Math.min(claimed.attempts - 1, 4)]),
|
|
||||||
})
|
|
||||||
.where(and(eq(canvasFeedback.id, id), isNull(canvasFeedback.deliveryId)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function refreshCanvasFeedback(row: FeedbackRow) {
|
|
||||||
if (!row.deliveryId) {
|
|
||||||
await deliverCanvasFeedback(row.id);
|
|
||||||
} else if (!["read", "failed"].includes(row.status)) {
|
|
||||||
try {
|
|
||||||
const delivery = await notificationCenterRequest(
|
|
||||||
"GET",
|
|
||||||
`/v1/notifications/${encodeURIComponent(row.deliveryId)}`,
|
|
||||||
);
|
|
||||||
await db
|
|
||||||
.update(canvasFeedback)
|
|
||||||
.set({ status: delivery.status, lastErrorCode: delivery.lastErrorCode || null })
|
|
||||||
.where(eq(canvasFeedback.id, row.id));
|
|
||||||
} catch {
|
|
||||||
/* A status lookup failure does not invalidate the accepted notification. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (await findCanvasFeedback(row.id))!;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function runCanvasFeedbackDelivery() {
|
|
||||||
if (!notificationCenterConfigured()) return;
|
|
||||||
const rows = await db
|
|
||||||
.select({ id: canvasFeedback.id })
|
|
||||||
.from(canvasFeedback)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(canvasFeedback.status, "pending"),
|
|
||||||
isNull(canvasFeedback.deliveryId),
|
|
||||||
lte(canvasFeedback.nextAttemptAt, new Date()),
|
|
||||||
lt(canvasFeedback.attempts, 5),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.orderBy(asc(canvasFeedback.createdAt))
|
|
||||||
.limit(10);
|
|
||||||
for (const row of rows) await deliverCanvasFeedback(row.id);
|
|
||||||
}
|
|
||||||
@ -1,9 +1,4 @@
|
|||||||
import {
|
import { pollTaskResult, EnhanceTerminalError } from "@/lib/canvas/enhance-task-poll";
|
||||||
AOS_ENHANCE_RESULT_TIMEOUT_MS,
|
|
||||||
EnhanceTerminalError,
|
|
||||||
pollTaskResult,
|
|
||||||
readCompletedEnhanceImage,
|
|
||||||
} from "@/lib/canvas/enhance-task-poll";
|
|
||||||
import "server-only";
|
import "server-only";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import {
|
import {
|
||||||
@ -16,7 +11,6 @@ import {
|
|||||||
import { uploadFile } from "@/lib/storage/service";
|
import { uploadFile } from "@/lib/storage/service";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { generatedImage } from "@/lib/db/schema";
|
import { generatedImage } from "@/lib/db/schema";
|
||||||
import { archiveAosResult, readAosQiniuInput } from "@/lib/ai/aos-image-transfer";
|
|
||||||
import { executeConfiguredVip98kTask } from "@/lib/ai/vip98k-runtime";
|
import { executeConfiguredVip98kTask } from "@/lib/ai/vip98k-runtime";
|
||||||
import { createFalClient } from "@fal-ai/client";
|
import { createFalClient } from "@fal-ai/client";
|
||||||
|
|
||||||
@ -113,14 +107,13 @@ async function createThumbnail(buffer: Buffer, mimeType: string): Promise<Buffer
|
|||||||
const sharp = await import("sharp");
|
const sharp = await import("sharp");
|
||||||
|
|
||||||
// 创建缩略图(宽度 500px,高度按比例,质量 80%)
|
// 创建缩略图(宽度 500px,高度按比例,质量 80%)
|
||||||
const resized = sharp.default(buffer)
|
const thumbnailBuffer = await sharp.default(buffer)
|
||||||
.resize(500, null, {
|
.resize(500, null, {
|
||||||
fit: "inside",
|
fit: "inside",
|
||||||
withoutEnlargement: true,
|
withoutEnlargement: true,
|
||||||
});
|
})
|
||||||
const thumbnailBuffer = await (
|
.jpeg({ quality: 80 }) // JPEG格式
|
||||||
mimeType === "image/jpeg" ? resized.jpeg({ quality: 80 }) : resized
|
.toBuffer();
|
||||||
).toBuffer();
|
|
||||||
|
|
||||||
console.log(`[Enhance] Thumbnail created, size: ${thumbnailBuffer.length} bytes (original: ${buffer.length} bytes)`);
|
console.log(`[Enhance] Thumbnail created, size: ${thumbnailBuffer.length} bytes (original: ${buffer.length} bytes)`);
|
||||||
return thumbnailBuffer;
|
return thumbnailBuffer;
|
||||||
@ -132,11 +125,12 @@ async function createThumbnail(buffer: Buffer, mimeType: string): Promise<Buffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传图片,返回缩略图和原图的 URL。
|
* 将 base64 图片上传到 S3,返回缩略图和原图的 URL
|
||||||
*/
|
*/
|
||||||
async function uploadEnhanceImage(image: string | Buffer, mimeType: string = "image/jpeg"): Promise<{ thumbnail: string; original: string }> {
|
async function uploadBase64ToS3(base64Data: string, mimeType: string = "image/jpeg"): Promise<{ thumbnail: string; original: string }> {
|
||||||
try {
|
try {
|
||||||
const buffer = typeof image === "string" ? Buffer.from(image, "base64") : image;
|
// 解析 base64 数据
|
||||||
|
const buffer = Buffer.from(base64Data, "base64");
|
||||||
|
|
||||||
// 生成文件名
|
// 生成文件名
|
||||||
const ext = mimeType.split("/")[1] || "jpg";
|
const ext = mimeType.split("/")[1] || "jpg";
|
||||||
@ -409,7 +403,7 @@ async function processWithVip98kEnhance(params: {
|
|||||||
}
|
}
|
||||||
const outputBuffer = Buffer.from(await response.arrayBuffer());
|
const outputBuffer = Buffer.from(await response.arrayBuffer());
|
||||||
const outputBase64 = outputBuffer.toString("base64");
|
const outputBase64 = outputBuffer.toString("base64");
|
||||||
const uploaded = await uploadEnhanceImage(outputBase64, "image/png");
|
const uploaded = await uploadBase64ToS3(outputBase64, "image/png");
|
||||||
const [savedImage] = await db
|
const [savedImage] = await db
|
||||||
.insert(generatedImage)
|
.insert(generatedImage)
|
||||||
.values({
|
.values({
|
||||||
@ -494,21 +488,9 @@ function buildEnhanceTaskPendingResponse(taskId: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildEnhanceTaskFailureResponse(error: EnhanceTerminalError) {
|
|
||||||
const message =
|
|
||||||
getAosFriendlyErrorMessage(error.message) ||
|
|
||||||
"图片变清晰失败,处理服务已确认任务失败。";
|
|
||||||
return NextResponse.json(
|
|
||||||
{ success: false, status: "failed", terminal: true, error: message, detail: message },
|
|
||||||
{ status: 422 },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function finalizeEnhanceTaskResult(params: {
|
async function finalizeEnhanceTaskResult(params: {
|
||||||
userId: string;
|
userId: string;
|
||||||
taskResult: any;
|
taskResult: any;
|
||||||
taskId?: string;
|
|
||||||
includeBase64?: boolean;
|
|
||||||
prompt?: string;
|
prompt?: string;
|
||||||
chatId?: string | null;
|
chatId?: string | null;
|
||||||
messageId?: string | null;
|
messageId?: string | null;
|
||||||
@ -519,17 +501,28 @@ async function finalizeEnhanceTaskResult(params: {
|
|||||||
throw new Error(params.taskResult?.message || "未知错误");
|
throw new Error(params.taskResult?.message || "未知错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = params.taskResult.data;
|
let enhancedImageBase64: string | null = null;
|
||||||
const includeBase64 = params.includeBase64 !== false;
|
if (typeof params.taskResult.data.image_base64 === "string" && params.taskResult.data.image_base64) {
|
||||||
let uploadResult = !includeBase64 && params.taskId
|
enhancedImageBase64 = params.taskResult.data.image_base64;
|
||||||
? await archiveAosResult(data.image, `aos-enhance-${params.taskId}`)
|
} else if (typeof params.taskResult.data.image === "string" && params.taskResult.data.image) {
|
||||||
: null;
|
const imageData = params.taskResult.data.image;
|
||||||
let imageBase64: string | undefined;
|
if (/^https?:\/\//i.test(imageData)) {
|
||||||
if (!uploadResult) {
|
const imageResponse = await fetch(imageData);
|
||||||
const completedImage = await readCompletedEnhanceImage(data);
|
if (!imageResponse.ok) {
|
||||||
uploadResult = await uploadEnhanceImage(completedImage.buffer, completedImage.mimeType);
|
throw new Error(`无法下载处理后的图片: ${imageResponse.status}`);
|
||||||
if (includeBase64) imageBase64 = completedImage.buffer.toString("base64");
|
|
||||||
}
|
}
|
||||||
|
const downloadedBuffer = await imageResponse.arrayBuffer();
|
||||||
|
enhancedImageBase64 = Buffer.from(downloadedBuffer).toString("base64");
|
||||||
|
} else {
|
||||||
|
enhancedImageBase64 = imageData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enhancedImageBase64) {
|
||||||
|
throw new Error("轮询结果未包含图片数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadResult = await uploadBase64ToS3(enhancedImageBase64, "image/jpeg");
|
||||||
const finalPrompt = params.prompt?.trim() || "图片变清晰处理";
|
const finalPrompt = params.prompt?.trim() || "图片变清晰处理";
|
||||||
|
|
||||||
let saved = false;
|
let saved = false;
|
||||||
@ -619,7 +612,7 @@ async function finalizeEnhanceTaskResult(params: {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
image_base64: imageBase64,
|
image_base64: enhancedImageBase64,
|
||||||
thumbnail_url: uploadResult.thumbnail,
|
thumbnail_url: uploadResult.thumbnail,
|
||||||
original_url: uploadResult.original,
|
original_url: uploadResult.original,
|
||||||
processing_time: processingTime,
|
processing_time: processingTime,
|
||||||
@ -717,18 +710,15 @@ export async function executeEnhanceGET(request: Request, trustedUserId: string)
|
|||||||
config.apiKey,
|
config.apiKey,
|
||||||
taskId,
|
taskId,
|
||||||
ENHANCE_TASK_POLL_INTERVAL_MS,
|
ENHANCE_TASK_POLL_INTERVAL_MS,
|
||||||
AOS_ENHANCE_RESULT_TIMEOUT_MS
|
ENHANCE_SYNC_WAIT_TIMEOUT_MS
|
||||||
);
|
);
|
||||||
} catch (pollError) {
|
} catch (pollError) {
|
||||||
if (isEnhanceTaskStillProcessing(pollError)) {
|
if (isEnhanceTaskStillProcessing(pollError)) {
|
||||||
return buildEnhanceTaskPendingResponse(taskId);
|
return buildEnhanceTaskPendingResponse(taskId);
|
||||||
}
|
}
|
||||||
if (pollError instanceof EnhanceTerminalError) {
|
|
||||||
return buildEnhanceTaskFailureResponse(pollError);
|
|
||||||
}
|
|
||||||
const detail = pollError instanceof Error ? pollError.message : "轮询失败";
|
const detail = pollError instanceof Error ? pollError.message : "轮询失败";
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "变清晰处理失败", detail },
|
{ error: "变清晰处理失败", detail, terminal: pollError instanceof EnhanceTerminalError },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -736,8 +726,6 @@ export async function executeEnhanceGET(request: Request, trustedUserId: string)
|
|||||||
const responsePayload = await finalizeEnhanceTaskResult({
|
const responsePayload = await finalizeEnhanceTaskResult({
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
taskResult,
|
taskResult,
|
||||||
taskId,
|
|
||||||
includeBase64: searchParams.get("includeBase64") !== "false",
|
|
||||||
prompt,
|
prompt,
|
||||||
chatId,
|
chatId,
|
||||||
messageId,
|
messageId,
|
||||||
@ -819,9 +807,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
const contentType = request.headers.get("content-type") || "";
|
const contentType = request.headers.get("content-type") || "";
|
||||||
console.log("[Enhance API] Content-Type:", contentType);
|
console.log("[Enhance API] Content-Type:", contentType);
|
||||||
|
|
||||||
let imageBase64 = "";
|
let imageBase64: string;
|
||||||
let includeBase64 = true;
|
|
||||||
let directImageUrl: string | undefined;
|
|
||||||
let prompt = ""; // 用户提示词(可选)
|
let prompt = ""; // 用户提示词(可选)
|
||||||
let chatId: string | null = null; // 聊天ID(可选)
|
let chatId: string | null = null; // 聊天ID(可选)
|
||||||
let messageId: string | null = null; // 消息ID(可选)
|
let messageId: string | null = null; // 消息ID(可选)
|
||||||
@ -831,7 +817,6 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
if (contentType.includes("application/json")) {
|
if (contentType.includes("application/json")) {
|
||||||
console.log("[Enhance API] 解析JSON请求体...");
|
console.log("[Enhance API] 解析JSON请求体...");
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
includeBase64 = body.includeBase64 !== false;
|
|
||||||
prompt = body.prompt || "图片变清晰处理";
|
prompt = body.prompt || "图片变清晰处理";
|
||||||
chatId = body.chatId || null;
|
chatId = body.chatId || null;
|
||||||
messageId = body.messageId || null;
|
messageId = body.messageId || null;
|
||||||
@ -844,22 +829,20 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
// 优先使用 imageUrl,其次使用 image_base64
|
// 优先使用 imageUrl,其次使用 image_base64
|
||||||
if (body.imageUrl) {
|
if (body.imageUrl) {
|
||||||
sourceImageUrl = String(body.imageUrl);
|
sourceImageUrl = String(body.imageUrl);
|
||||||
if (!includeBase64 && !useVip98k && !useBackupApi) {
|
// 从 URL 获取图片并转换为 Base64
|
||||||
const input = await readAosQiniuInput(sourceImageUrl);
|
console.log(`[Enhance API] 从 URL 获取图片: ${body.imageUrl}`);
|
||||||
if (input && input.width <= AOS_MAX_RESOLUTION && input.height <= AOS_MAX_RESOLUTION) {
|
|
||||||
directImageUrl = input.url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!directImageUrl) {
|
|
||||||
try {
|
try {
|
||||||
const imageResponse = await fetch(sourceImageUrl);
|
const imageResponse = await fetch(body.imageUrl);
|
||||||
if (!imageResponse.ok) {
|
if (!imageResponse.ok) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: `无法获取图片: ${imageResponse.status} ${imageResponse.statusText}` },
|
{ error: `无法获取图片: ${imageResponse.status} ${imageResponse.statusText}` },
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
imageBase64 = Buffer.from(await imageResponse.arrayBuffer()).toString("base64");
|
const arrayBuffer = await imageResponse.arrayBuffer();
|
||||||
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
|
imageBase64 = buffer.toString("base64");
|
||||||
|
console.log(`[Enhance API] 图片已转换为 Base64,大小: ${buffer.length} bytes`);
|
||||||
} catch (fetchError) {
|
} catch (fetchError) {
|
||||||
console.error("[Enhance API] 获取图片失败:", fetchError);
|
console.error("[Enhance API] 获取图片失败:", fetchError);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@ -867,7 +850,6 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (body.image_base64) {
|
} else if (body.image_base64) {
|
||||||
console.log("[Enhance API] JSON请求体解析完成,image_base64长度:", body.image_base64?.length || 0);
|
console.log("[Enhance API] JSON请求体解析完成,image_base64长度:", body.image_base64?.length || 0);
|
||||||
imageBase64 = body.image_base64;
|
imageBase64 = body.image_base64;
|
||||||
@ -935,7 +917,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
try {
|
try {
|
||||||
// 步骤1: 先将Base64图片上传到S3获取公开可访问的URL
|
// 步骤1: 先将Base64图片上传到S3获取公开可访问的URL
|
||||||
console.log(`[Enhance-RealESRGAN] 📤 步骤1: 上传原图到S3获取URL...`);
|
console.log(`[Enhance-RealESRGAN] 📤 步骤1: 上传原图到S3获取URL...`);
|
||||||
const tempUploadResult = await uploadEnhanceImage(imageBase64, "image/jpeg");
|
const tempUploadResult = await uploadBase64ToS3(imageBase64, "image/jpeg");
|
||||||
const sourceImageUrl = tempUploadResult.original;
|
const sourceImageUrl = tempUploadResult.original;
|
||||||
console.log(`[Enhance-RealESRGAN] ✅ 原图已上传,URL: ${sourceImageUrl}`);
|
console.log(`[Enhance-RealESRGAN] ✅ 原图已上传,URL: ${sourceImageUrl}`);
|
||||||
|
|
||||||
@ -955,7 +937,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
let originalUrl: string;
|
let originalUrl: string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const uploadResult = await uploadEnhanceImage(result.imageBase64, "image/png");
|
const uploadResult = await uploadBase64ToS3(result.imageBase64, "image/png");
|
||||||
thumbnailUrl = uploadResult.thumbnail;
|
thumbnailUrl = uploadResult.thumbnail;
|
||||||
originalUrl = uploadResult.original;
|
originalUrl = uploadResult.original;
|
||||||
console.log(`[Enhance-RealESRGAN] ✅ 处理后图片已上传: ${originalUrl}`);
|
console.log(`[Enhance-RealESRGAN] ✅ 处理后图片已上传: ${originalUrl}`);
|
||||||
@ -1100,20 +1082,21 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
const enhanceUrl = `${apiUrl}/api/tasks/visual/scale`;
|
const enhanceUrl = `${apiUrl}/api/tasks/visual/scale`;
|
||||||
console.log("[Enhance API] API URL:", enhanceUrl);
|
console.log("[Enhance API] API URL:", enhanceUrl);
|
||||||
|
|
||||||
|
// 将Base64转换为Buffer
|
||||||
|
console.log("[Enhance API] 转换Base64为Buffer,长度:", imageBase64.length);
|
||||||
|
const rawImageBuffer = Buffer.from(imageBase64, "base64");
|
||||||
|
const imageBuffer = await ensureAosResolutionLimit(rawImageBuffer, "Enhance API");
|
||||||
|
console.log("[Enhance API] Buffer创建完成,大小:", imageBuffer.length, "bytes");
|
||||||
|
|
||||||
// 创建FormData(使用form-data包,Node.js环境)
|
// 创建FormData(使用form-data包,Node.js环境)
|
||||||
console.log("[Enhance API] 创建FormData...");
|
console.log("[Enhance API] 创建FormData...");
|
||||||
const FormDataLib = await import("form-data");
|
const FormDataLib = await import("form-data");
|
||||||
const formData = new FormDataLib.default();
|
const formData = new FormDataLib.default();
|
||||||
console.log("[Enhance API] FormData创建完成");
|
console.log("[Enhance API] FormData创建完成");
|
||||||
if (directImageUrl) {
|
|
||||||
formData.append("image_url", directImageUrl);
|
|
||||||
} else {
|
|
||||||
const imageBuffer = await ensureAosResolutionLimit(Buffer.from(imageBase64, "base64"), "Enhance API");
|
|
||||||
formData.append("image_file", imageBuffer, {
|
formData.append("image_file", imageBuffer, {
|
||||||
filename: "image.jpg",
|
filename: "image.jpg",
|
||||||
contentType: "image/jpeg",
|
contentType: "image/jpeg",
|
||||||
});
|
});
|
||||||
}
|
|
||||||
// 使用异步模式(sync=0),根据官方示例
|
// 使用异步模式(sync=0),根据官方示例
|
||||||
formData.append("sync", "0");
|
formData.append("sync", "0");
|
||||||
formData.append("type", config.type || "clean"); // 默认通用清晰化
|
formData.append("type", config.type || "clean"); // 默认通用清晰化
|
||||||
@ -1127,7 +1110,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
if (scaleFactorValue) {
|
if (scaleFactorValue) {
|
||||||
formData.append("scale_factor", String(scaleFactorValue));
|
formData.append("scale_factor", String(scaleFactorValue));
|
||||||
}
|
}
|
||||||
formData.append("return_type", "1"); // 状态查询返回图片链接。
|
formData.append("return_type", "2"); // 返回base64
|
||||||
|
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
"X-API-KEY": config.apiKey!,
|
"X-API-KEY": config.apiKey!,
|
||||||
@ -1197,7 +1180,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
} catch (fetchError) {
|
} catch (fetchError) {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
lastFetchError = fetchError;
|
lastFetchError = fetchError;
|
||||||
const canRetry = !directImageUrl && attempt <= ENHANCE_CREATE_RETRY_COUNT && isRetryableNetworkError(fetchError);
|
const canRetry = attempt <= ENHANCE_CREATE_RETRY_COUNT && isRetryableNetworkError(fetchError);
|
||||||
if (canRetry) {
|
if (canRetry) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`[Enhance API] 创建任务失败,准备重试: attempt=${attempt}, error=${fetchError instanceof Error ? fetchError.message : String(fetchError)}`
|
`[Enhance API] 创建任务失败,准备重试: attempt=${attempt}, error=${fetchError instanceof Error ? fetchError.message : String(fetchError)}`
|
||||||
@ -1215,10 +1198,6 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
|
|
||||||
if (!createResponse.ok) {
|
if (!createResponse.ok) {
|
||||||
const errorText = await createResponse.text();
|
const errorText = await createResponse.text();
|
||||||
if (directImageUrl && createResponse.status >= 400 && createResponse.status < 500 && createResponse.status !== 408) {
|
|
||||||
const friendlyMessage = getAosFriendlyErrorMessage(errorText);
|
|
||||||
return NextResponse.json({ error: friendlyMessage || "变清晰任务提交失败" }, { status: createResponse.status });
|
|
||||||
}
|
|
||||||
throw new Error(`创建任务失败: ${errorText || createResponse.statusText}`);
|
throw new Error(`创建任务失败: ${errorText || createResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1238,13 +1217,6 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
processingTime,
|
processingTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (directImageUrl) {
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: "变清晰任务提交结果尚未确认,请核对原任务,避免重复提交。" },
|
|
||||||
{ status: 504 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fallbackPayload = await executeFalEsrganFallback({
|
const fallbackPayload = await executeFalEsrganFallback({
|
||||||
userId,
|
userId,
|
||||||
@ -1333,10 +1305,22 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
if (isEnhanceTaskStillProcessing(pollError)) {
|
if (isEnhanceTaskStillProcessing(pollError)) {
|
||||||
return buildEnhanceTaskPendingResponse(taskId);
|
return buildEnhanceTaskPendingResponse(taskId);
|
||||||
}
|
}
|
||||||
if (pollError instanceof EnhanceTerminalError) {
|
|
||||||
return buildEnhanceTaskFailureResponse(pollError);
|
|
||||||
}
|
|
||||||
const detail = pollError instanceof Error ? pollError.message : "轮询失败";
|
const detail = pollError instanceof Error ? pollError.message : "轮询失败";
|
||||||
|
try {
|
||||||
|
const fallbackPayload = await executeFalEsrganFallback({
|
||||||
|
userId,
|
||||||
|
imageBase64,
|
||||||
|
prompt,
|
||||||
|
chatId,
|
||||||
|
messageId,
|
||||||
|
sourceImageUrl,
|
||||||
|
requestedScaleFactor,
|
||||||
|
reason: detail,
|
||||||
|
});
|
||||||
|
return NextResponse.json(fallbackPayload);
|
||||||
|
} catch (falError) {
|
||||||
|
console.error("[Enhance-FAL-ESRGAN] 专用高清备用链路失败:", falError);
|
||||||
|
}
|
||||||
const friendlyMessage = getAosFriendlyErrorMessage(detail);
|
const friendlyMessage = getAosFriendlyErrorMessage(detail);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "变清晰处理失败", detail: friendlyMessage || detail },
|
{ error: "变清晰处理失败", detail: friendlyMessage || detail },
|
||||||
@ -1347,8 +1331,6 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string
|
|||||||
const responsePayload = await finalizeEnhanceTaskResult({
|
const responsePayload = await finalizeEnhanceTaskResult({
|
||||||
userId,
|
userId,
|
||||||
taskResult,
|
taskResult,
|
||||||
taskId,
|
|
||||||
includeBase64,
|
|
||||||
prompt,
|
prompt,
|
||||||
chatId,
|
chatId,
|
||||||
messageId,
|
messageId,
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export async function executeRemoveBackgroundPOST(request: Request, trustedUserI
|
|||||||
|
|
||||||
const contentType = request.headers.get("content-type") || "";
|
const contentType = request.headers.get("content-type") || "";
|
||||||
|
|
||||||
let imageBuffer: Buffer | undefined;
|
let imageBuffer: Buffer;
|
||||||
let imageBase64: string | undefined;
|
let imageBase64: string | undefined;
|
||||||
let prompt = "抠图处理";
|
let prompt = "抠图处理";
|
||||||
let chatId: string | null = null;
|
let chatId: string | null = null;
|
||||||
@ -30,11 +30,9 @@ export async function executeRemoveBackgroundPOST(request: Request, trustedUserI
|
|||||||
let skipGallerySave = false;
|
let skipGallerySave = false;
|
||||||
let sourceImageUrl: string | null = null;
|
let sourceImageUrl: string | null = null;
|
||||||
let inputImageUrl: string | null = null;
|
let inputImageUrl: string | null = null;
|
||||||
let includeBase64 = true;
|
|
||||||
|
|
||||||
if (contentType.includes("application/json")) {
|
if (contentType.includes("application/json")) {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
includeBase64 = body.includeBase64 !== false;
|
|
||||||
prompt = body.prompt || "抠图处理";
|
prompt = body.prompt || "抠图处理";
|
||||||
chatId = body.chatId || null;
|
chatId = body.chatId || null;
|
||||||
messageId = body.messageId || null;
|
messageId = body.messageId || null;
|
||||||
@ -46,7 +44,7 @@ export async function executeRemoveBackgroundPOST(request: Request, trustedUserI
|
|||||||
if (imageUrl) {
|
if (imageUrl) {
|
||||||
sourceImageUrl = String(imageUrl);
|
sourceImageUrl = String(imageUrl);
|
||||||
inputImageUrl = sourceImageUrl;
|
inputImageUrl = sourceImageUrl;
|
||||||
if (includeBase64) imageBuffer = await fetchImageBufferFromUrl(sourceImageUrl);
|
imageBuffer = await fetchImageBufferFromUrl(sourceImageUrl);
|
||||||
} else if (body.image_base64) {
|
} else if (body.image_base64) {
|
||||||
imageBase64 = String(body.image_base64);
|
imageBase64 = String(body.image_base64);
|
||||||
imageBuffer = Buffer.from(imageBase64, "base64");
|
imageBuffer = Buffer.from(imageBase64, "base64");
|
||||||
@ -102,13 +100,13 @@ export async function executeRemoveBackgroundPOST(request: Request, trustedUserI
|
|||||||
const result = await executeRmbgJob({
|
const result = await executeRmbgJob({
|
||||||
requestId,
|
requestId,
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
...(imageBuffer ? { imageBuffer, inputImageUrl } : { inputImageUrl: inputImageUrl! }),
|
imageBuffer,
|
||||||
imageBase64,
|
imageBase64,
|
||||||
includeBase64,
|
|
||||||
prompt,
|
prompt,
|
||||||
chatId,
|
chatId,
|
||||||
messageId,
|
messageId,
|
||||||
skipGallerySave,
|
skipGallerySave,
|
||||||
|
inputImageUrl,
|
||||||
sourceImageUrl,
|
sourceImageUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,6 @@ async function requestCapabilityResult(command: CanvasCapabilityClientCommand) {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(command),
|
body: JSON.stringify(command),
|
||||||
signal: AbortSignal.timeout(12_000),
|
|
||||||
});
|
});
|
||||||
payload = await response.json().catch(() => null);
|
payload = await response.json().catch(() => null);
|
||||||
if (payload?.success === false || (!response.ok && ![502, 503, 504, 524].includes(response.status))) {
|
if (payload?.success === false || (!response.ok && ![502, 503, 504, 524].includes(response.status))) {
|
||||||
@ -22,7 +21,6 @@ async function requestCapabilityResult(command: CanvasCapabilityClientCommand) {
|
|||||||
if ((error as { confirmedRejection?: boolean })?.confirmedRejection) throw error;
|
if ((error as { confirmedRejection?: boolean })?.confirmedRejection) throw error;
|
||||||
}
|
}
|
||||||
const deadline = Date.now() + 20 * 60 * 1000;
|
const deadline = Date.now() + 20 * 60 * 1000;
|
||||||
let consecutiveMissingStatuses = 0;
|
|
||||||
while (Date.now() < deadline) {
|
while (Date.now() < deadline) {
|
||||||
const task = payload?.task;
|
const task = payload?.task;
|
||||||
if (task?.status === "succeeded") return payload;
|
if (task?.status === "succeeded") return payload;
|
||||||
@ -34,8 +32,6 @@ async function requestCapabilityResult(command: CanvasCapabilityClientCommand) {
|
|||||||
} catch {
|
} catch {
|
||||||
payload = null;
|
payload = null;
|
||||||
}
|
}
|
||||||
consecutiveMissingStatuses = payload?.task?.status ? 0 : consecutiveMissingStatuses + 1;
|
|
||||||
if (consecutiveMissingStatuses >= 4) break;
|
|
||||||
}
|
}
|
||||||
throw new Error(formatRequestFailure(getRequestFailureDetails({ providerOutcomeUnknown: true }), command.requestId));
|
throw new Error(formatRequestFailure(getRequestFailureDetails({ providerOutcomeUnknown: true }), command.requestId));
|
||||||
}
|
}
|
||||||
@ -50,11 +46,7 @@ export async function executeCanvasToolbarCapability(
|
|||||||
const base = JSON.stringify({ canvasData: before.getCanvasState() });
|
const base = JSON.stringify({ canvasData: before.getCanvasState() });
|
||||||
await requestCapabilityResult(command);
|
await requestCapabilityResult(command);
|
||||||
|
|
||||||
const projectResponse = await fetch(`/api/canvas/${projectId}`, {
|
const projectResponse = await fetch(`/api/canvas/${projectId}`);
|
||||||
signal: AbortSignal.timeout(12_000),
|
|
||||||
}).catch(() => {
|
|
||||||
throw new Error("结果已生成,但画布同步失败,请刷新查看结果。");
|
|
||||||
});
|
|
||||||
const result = await projectResponse.json();
|
const result = await projectResponse.json();
|
||||||
if (!projectResponse.ok || !result.success || !result.data?.canvasData) {
|
if (!projectResponse.ok || !result.success || !result.data?.canvasData) {
|
||||||
throw new Error(result.error || "结果已生成,但画布同步失败");
|
throw new Error(result.error || "结果已生成,但画布同步失败");
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { getFriendlyRateLimitMessage, getUserFacingRequestErrorMessage } from "@
|
|||||||
type LongTaskResponse = {
|
type LongTaskResponse = {
|
||||||
success?: boolean;
|
success?: boolean;
|
||||||
processing?: boolean;
|
processing?: boolean;
|
||||||
terminal?: boolean;
|
|
||||||
status?: string;
|
status?: string;
|
||||||
taskId?: string;
|
taskId?: string;
|
||||||
pollAfterMs?: number;
|
pollAfterMs?: number;
|
||||||
@ -20,10 +19,6 @@ function isProcessingPayload(payload: LongTaskResponse | null | undefined) {
|
|||||||
return status === "queued" || status === "running" || status === "pending";
|
return status === "queued" || status === "running" || status === "pending";
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFailedPayload(payload: LongTaskResponse | null) {
|
|
||||||
return payload?.terminal === true || String(payload?.status || "").toLowerCase() === "failed";
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildTaskError(payload: LongTaskResponse | null | undefined, fallback: string) {
|
function buildTaskError(payload: LongTaskResponse | null | undefined, fallback: string) {
|
||||||
const message = getUserFacingRequestErrorMessage(
|
const message = getUserFacingRequestErrorMessage(
|
||||||
payload,
|
payload,
|
||||||
@ -37,7 +32,7 @@ function buildTaskError(payload: LongTaskResponse | null | undefined, fallback:
|
|||||||
|
|
||||||
function buildTaskInterruptedError(taskId: string) {
|
function buildTaskInterruptedError(taskId: string) {
|
||||||
const error = new Error(
|
const error = new Error(
|
||||||
`任务已提交,结果尚未确认。请联系管理员核对原任务(${taskId}),避免重复提交。`
|
"任务已提交,网络连接暂时中断,请稍后重试查看结果,避免重复提交。"
|
||||||
) as Error & { taskId?: string };
|
) as Error & { taskId?: string };
|
||||||
error.taskId = taskId;
|
error.taskId = taskId;
|
||||||
return error;
|
return error;
|
||||||
@ -100,7 +95,7 @@ export async function requestLongTaskResult(params: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const result = await safeParseJson(response);
|
const result = await safeParseJson(response);
|
||||||
if (!response.ok || isFailedPayload(result)) {
|
if (!response.ok) {
|
||||||
throw buildTaskError(result, "请求失败");
|
throw buildTaskError(result, "请求失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,10 +146,6 @@ export async function requestLongTaskResult(params: {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFailedPayload(statusPayload)) {
|
|
||||||
throw buildTaskError(statusPayload, "任务已失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!statusResponse.ok) {
|
if (!statusResponse.ok) {
|
||||||
if (
|
if (
|
||||||
shouldRetryLongTaskPoll(statusResponse.status, statusPayload) &&
|
shouldRetryLongTaskPoll(statusResponse.status, statusPayload) &&
|
||||||
@ -182,5 +173,5 @@ export async function requestLongTaskResult(params: {
|
|||||||
pollAfterMs = Math.max(800, Number(statusPayload?.pollAfterMs || pollAfterMs));
|
pollAfterMs = Math.max(800, Number(statusPayload?.pollAfterMs || pollAfterMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw buildTaskInterruptedError(taskId);
|
throw new Error("任务处理超时,请稍后再试");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS "CanvasFeedback" (
|
|
||||||
"id" uuid PRIMARY KEY NOT NULL,
|
|
||||||
"userId" uuid NOT NULL REFERENCES "User"("id") ON DELETE CASCADE,
|
|
||||||
"projectId" uuid NOT NULL,
|
|
||||||
"description" text NOT NULL,
|
|
||||||
"snapshot" jsonb NOT NULL,
|
|
||||||
"notification" jsonb NOT NULL,
|
|
||||||
"deliveryId" varchar(128),
|
|
||||||
"status" varchar(24) NOT NULL DEFAULT 'pending',
|
|
||||||
"attempts" integer NOT NULL DEFAULT 0,
|
|
||||||
"nextAttemptAt" timestamp NOT NULL DEFAULT now(),
|
|
||||||
"lastErrorCode" varchar(128),
|
|
||||||
"createdAt" timestamp NOT NULL DEFAULT now()
|
|
||||||
);
|
|
||||||
CREATE INDEX IF NOT EXISTS "CanvasFeedback_due_idx" ON "CanvasFeedback" ("status", "nextAttemptAt");
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
ALTER TABLE "CanvasFeedback"
|
|
||||||
ALTER COLUMN "nextAttemptAt" SET DEFAULT (now() AT TIME ZONE 'UTC'),
|
|
||||||
ALTER COLUMN "createdAt" SET DEFAULT (now() AT TIME ZONE 'UTC');
|
|
||||||
@ -638,20 +638,6 @@
|
|||||||
"when": 1792454400000,
|
"when": 1792454400000,
|
||||||
"tag": "0104_add_canvas_agent_runs",
|
"tag": "0104_add_canvas_agent_runs",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"idx": 89,
|
|
||||||
"version": "7",
|
|
||||||
"when": 1794960000000,
|
|
||||||
"tag": "0105_add_canvas_feedback",
|
|
||||||
"breakpoints": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idx": 90,
|
|
||||||
"version": "7",
|
|
||||||
"when": 1794960000001,
|
|
||||||
"tag": "0106_canvas_feedback_utc_defaults",
|
|
||||||
"breakpoints": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { type InferSelectModel, sql } from "drizzle-orm";
|
import type { InferSelectModel } from "drizzle-orm";
|
||||||
import {
|
import {
|
||||||
boolean,
|
boolean,
|
||||||
foreignKey,
|
foreignKey,
|
||||||
@ -704,21 +704,6 @@ export type ClientPerformanceEvent = InferSelectModel<
|
|||||||
typeof clientPerformanceEvent
|
typeof clientPerformanceEvent
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export const canvasFeedback = pgTable("CanvasFeedback", {
|
|
||||||
id: uuid("id").primaryKey().notNull(),
|
|
||||||
userId: uuid("userId").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
||||||
projectId: uuid("projectId").notNull(),
|
|
||||||
description: text("description").notNull(),
|
|
||||||
snapshot: jsonb("snapshot").$type<import("@/lib/canvas/feedback-contract").FeedbackSnapshot>().notNull(),
|
|
||||||
notification: jsonb("notification").$type<import("@/lib/notifications/notification-center").NotificationPayload>().notNull(),
|
|
||||||
deliveryId: varchar("deliveryId", { length: 128 }),
|
|
||||||
status: varchar("status", { length: 24 }).notNull().default("pending"),
|
|
||||||
attempts: integer("attempts").notNull().default(0),
|
|
||||||
nextAttemptAt: timestamp("nextAttemptAt").notNull().default(sql`(now() AT TIME ZONE 'UTC')`),
|
|
||||||
lastErrorCode: varchar("lastErrorCode", { length: 128 }),
|
|
||||||
createdAt: timestamp("createdAt").notNull().default(sql`(now() AT TIME ZONE 'UTC')`),
|
|
||||||
}, (table) => ({ dueIndex: index("CanvasFeedback_due_idx").on(table.status, table.nextAttemptAt) }));
|
|
||||||
|
|
||||||
export const accessIpEvent = pgTable("AccessIpEvent", {
|
export const accessIpEvent = pgTable("AccessIpEvent", {
|
||||||
id: uuid("id").primaryKey().notNull().defaultRandom(),
|
id: uuid("id").primaryKey().notNull().defaultRandom(),
|
||||||
eventType: varchar("eventType", { length: 32 }).notNull().default("request"),
|
eventType: varchar("eventType", { length: 32 }).notNull().default("request"),
|
||||||
|
|||||||
@ -1,83 +0,0 @@
|
|||||||
import "server-only";
|
|
||||||
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
||||||
|
|
||||||
export type NotificationPayload = {
|
|
||||||
idempotencyKey: string;
|
|
||||||
recipientAlias: string;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
actionTitle: string;
|
|
||||||
actionUrl: string;
|
|
||||||
};
|
|
||||||
export type NotificationDelivery = { id: string; status: string; lastErrorCode?: string | null };
|
|
||||||
export class NotificationCenterError extends Error {
|
|
||||||
code: string;
|
|
||||||
retryable: boolean;
|
|
||||||
constructor(code: string, retryable: boolean) {
|
|
||||||
super(code);
|
|
||||||
this.code = code;
|
|
||||||
this.retryable = retryable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function notificationCenterConfigured() {
|
|
||||||
return Boolean(
|
|
||||||
process.env.YYD_NOTIFICATION_CENTER_URL &&
|
|
||||||
process.env.YYD_NOTIFICATION_CENTER_PROJECT_CODE &&
|
|
||||||
process.env.YYD_NOTIFICATION_CENTER_PROJECT_SECRET,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function notificationCenterRequest(
|
|
||||||
method: "GET" | "POST",
|
|
||||||
path: string,
|
|
||||||
payload?: NotificationPayload,
|
|
||||||
): Promise<NotificationDelivery> {
|
|
||||||
if (!notificationCenterConfigured())
|
|
||||||
throw new NotificationCenterError("NOTIFICATION_CONFIG_MISSING", true);
|
|
||||||
const body = payload ? JSON.stringify(payload) : "";
|
|
||||||
const timestamp = String(Math.floor(Date.now() / 1000));
|
|
||||||
const nonce = randomBytes(18).toString("base64url");
|
|
||||||
const canonical = [
|
|
||||||
timestamp,
|
|
||||||
nonce,
|
|
||||||
method,
|
|
||||||
path,
|
|
||||||
createHash("sha256").update(body).digest("hex"),
|
|
||||||
].join("\n");
|
|
||||||
let response: Response;
|
|
||||||
try {
|
|
||||||
response = await fetch(
|
|
||||||
`${process.env.YYD_NOTIFICATION_CENTER_URL!.replace(/\/$/, "")}${path}`,
|
|
||||||
{
|
|
||||||
method,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-yyd-project-code": process.env.YYD_NOTIFICATION_CENTER_PROJECT_CODE!,
|
|
||||||
"x-yyd-timestamp": timestamp,
|
|
||||||
"x-yyd-nonce": nonce,
|
|
||||||
"x-yyd-signature": createHmac(
|
|
||||||
"sha256",
|
|
||||||
process.env.YYD_NOTIFICATION_CENTER_PROJECT_SECRET!,
|
|
||||||
)
|
|
||||||
.update(canonical)
|
|
||||||
.digest("hex"),
|
|
||||||
},
|
|
||||||
...(body ? { body } : {}),
|
|
||||||
cache: "no-store",
|
|
||||||
signal: AbortSignal.timeout(8000),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
throw new NotificationCenterError("NOTIFICATION_CONNECTION_FAILED", true);
|
|
||||||
}
|
|
||||||
const data = await response.json().catch(() => null);
|
|
||||||
if (!response.ok)
|
|
||||||
throw new NotificationCenterError(
|
|
||||||
typeof data?.error === "string" ? data.error : "NOTIFICATION_RESPONSE_FAILED",
|
|
||||||
response.status >= 500 || response.status === 429,
|
|
||||||
);
|
|
||||||
if (!data || typeof data.id !== "string" || typeof data.status !== "string")
|
|
||||||
throw new NotificationCenterError("NOTIFICATION_RESPONSE_INVALID", true);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
@ -18,7 +18,6 @@ const PROVIDER_BALANCE_PATTERNS = [
|
|||||||
/\b(?:exceeded_current_quota|pre_consume_token_quota_failed)\b/i,
|
/\b(?:exceeded_current_quota|pre_consume_token_quota_failed)\b/i,
|
||||||
/\btoken quota is not enough\b/i,
|
/\btoken quota is not enough\b/i,
|
||||||
/\bquota is not enough\b/i,
|
/\bquota is not enough\b/i,
|
||||||
/\bdoes not have enough available quota\b/i,
|
|
||||||
/\b(?:not enough credits?|credits? is not enough)\b/i,
|
/\b(?:not enough credits?|credits? is not enough)\b/i,
|
||||||
/\b(?:billing_hard_limit_reached|payment_required)\b/i,
|
/\b(?:billing_hard_limit_reached|payment_required)\b/i,
|
||||||
];
|
];
|
||||||
@ -331,9 +330,6 @@ export function getRequestFailureDetails(
|
|||||||
if (/no_eligible_route|service_unavailable|service_rejected|channel.*unavailable|暂无可用服务|未配置.*模型|没有可用.*(?:模型|通道)|通道.*(?:不可用|未通过)|鉴权/i.test(text)) {
|
if (/no_eligible_route|service_unavailable|service_rejected|channel.*unavailable|暂无可用服务|未配置.*模型|没有可用.*(?:模型|通道)|通道.*(?:不可用|未通过)|鉴权/i.test(text)) {
|
||||||
return detail("PROVIDER_UNAVAILABLE", "当前模型服务或通道暂不可用。", "请切换其他可用模型;若多个模型都失败,请联系管理员检查服务配置。");
|
return detail("PROVIDER_UNAVAILABLE", "当前模型服务或通道暂不可用。", "请切换其他可用模型;若多个模型都失败,请联系管理员检查服务配置。");
|
||||||
}
|
}
|
||||||
if (/图片变清晰已完成,但结果图片未取回/.test(text)) {
|
|
||||||
return detail("ENHANCE_RESULT_UNAVAILABLE", "图片变清晰已完成,但结果图片未取回。", "请联系管理员核对原任务,避免重复提交。", "unknown");
|
|
||||||
}
|
|
||||||
if (/neither a task ID nor output URLs|已完成.*未取回|completed without.*output/i.test(text)) {
|
if (/neither a task ID nor output URLs|已完成.*未取回|completed without.*output/i.test(text)) {
|
||||||
return detail("RESULT_UNCONFIRMED", "模型服务没有返回可读取的任务结果,生成状态尚未确认。", "请保留当前任务并联系管理员核对,避免重复生成。", "unknown");
|
return detail("RESULT_UNCONFIRMED", "模型服务没有返回可读取的任务结果,生成状态尚未确认。", "请保留当前任务并联系管理员核对,避免重复生成。", "unknown");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import {
|
|||||||
imageArchiveSourceKey,
|
imageArchiveSourceKey,
|
||||||
} from "@/lib/storage/image-archive-db";
|
} from "@/lib/storage/image-archive-db";
|
||||||
import { uploadFile } from "@/lib/storage/service";
|
import { uploadFile } from "@/lib/storage/service";
|
||||||
import { archiveImageThroughQiniu, QiniuArchiveSourceMissingError } from "./qiniu-image-archive";
|
import { archiveImageThroughQiniu } from "./qiniu-image-archive";
|
||||||
|
|
||||||
const logger = createLogger("image-archive");
|
const logger = createLogger("image-archive");
|
||||||
|
|
||||||
@ -195,7 +195,6 @@ export async function downloadTemporaryImage(params: { sourceUrl: string; retrie
|
|||||||
export async function archiveTemporaryImage(sourceUrl: string, archiveId?: string) {
|
export async function archiveTemporaryImage(sourceUrl: string, archiveId?: string) {
|
||||||
if (archiveId) {
|
if (archiveId) {
|
||||||
const direct = await archiveImageThroughQiniu(sourceUrl, archiveId).catch(error => {
|
const direct = await archiveImageThroughQiniu(sourceUrl, archiveId).catch(error => {
|
||||||
if (error instanceof QiniuArchiveSourceMissingError) throw error;
|
|
||||||
logger.warn("cloud_archive_fallback", error, { archiveId });
|
logger.warn("cloud_archive_fallback", error, { archiveId });
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import "server-only";
|
import "server-only";
|
||||||
|
|
||||||
import { GetObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3";
|
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
||||||
import { createHmac } from "node:crypto";
|
import { createHmac } from "node:crypto";
|
||||||
import { createLogger } from "@/lib/observability/logger";
|
|
||||||
import {
|
import {
|
||||||
buildS3PublicUrl,
|
buildS3PublicUrl,
|
||||||
createS3Client,
|
createS3Client,
|
||||||
@ -12,23 +11,6 @@ import {
|
|||||||
const QINIU_EAST_CHINA_IO = "iovip-z0.qiniuio.com";
|
const QINIU_EAST_CHINA_IO = "iovip-z0.qiniuio.com";
|
||||||
const PNG_HEADER_LIMIT = 64 * 1024;
|
const PNG_HEADER_LIMIT = 64 * 1024;
|
||||||
const PNG_SIGNATURE = Buffer.from("89504e470d0a1a0a", "hex");
|
const PNG_SIGNATURE = Buffer.from("89504e470d0a1a0a", "hex");
|
||||||
const QINIU_FETCH_TIMEOUT_MS = 40_000;
|
|
||||||
const RELAY_RETRY_TIMEOUT_MS = 25_000;
|
|
||||||
const logger = createLogger("qiniu-image-archive");
|
|
||||||
|
|
||||||
type QiniuUploadTarget = NonNullable<Awaited<ReturnType<typeof resolveS3UploadTarget>>>;
|
|
||||||
|
|
||||||
class QiniuFetchError extends Error {
|
|
||||||
constructor(readonly status: number, readonly requestId: string | null) {
|
|
||||||
super(`Qiniu archive fetch returned HTTP ${status}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class QiniuArchiveSourceMissingError extends Error {
|
|
||||||
constructor(status: number) {
|
|
||||||
super(`98K original image is no longer available (HTTP ${status})`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ReadyImageDownload = {
|
export type ReadyImageDownload = {
|
||||||
status: "ready";
|
status: "ready";
|
||||||
@ -117,84 +99,9 @@ async function archiveThroughQiniu(sourceUrl: string, archiveId: string, kind: "
|
|||||||
|
|
||||||
// The archive task owns this object key, including retries after a timeout.
|
// The archive task owns this object key, including retries after a timeout.
|
||||||
const pathname = kind === "image" ? `uploads/ai-generated-archive-${archiveId}` : `uploads/canvas-${kind}-${archiveId}`;
|
const pathname = kind === "image" ? `uploads/ai-generated-archive-${archiveId}` : `uploads/canvas-${kind}-${archiveId}`;
|
||||||
if (kind === "image" && source.origin === "https://api.vip98k.com" &&
|
|
||||||
source.pathname.startsWith("/api/external/assets/")) {
|
|
||||||
return fetchRelayImageIntoQiniu(sourceUrl, pathname, target!, archiveId);
|
|
||||||
}
|
|
||||||
return fetchImageIntoQiniu(sourceUrl, pathname, target!, kind);
|
return fetchImageIntoQiniu(sourceUrl, pathname, target!, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRetryableQiniuFetch(error: unknown) {
|
|
||||||
if (error instanceof QiniuFetchError) {
|
|
||||||
return [408, 478, 502, 503, 504, 599].includes(error.status);
|
|
||||||
}
|
|
||||||
if (!(error instanceof Error)) return false;
|
|
||||||
const cause = error.cause as { code?: string } | undefined;
|
|
||||||
return error.name === "TimeoutError" || error.name === "AbortError" ||
|
|
||||||
["ECONNRESET", "ETIMEDOUT", "UND_ERR_SOCKET"].includes(cause?.code ?? "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function relaySourceStatus(error: unknown) {
|
|
||||||
if (error instanceof QiniuFetchError && [404, 410].includes(error.status)) return error.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readStoredRelayImage(pathname: string, target: QiniuUploadTarget) {
|
|
||||||
const client = createS3Client(target.config);
|
|
||||||
try {
|
|
||||||
const response = await client.send(new HeadObjectCommand({
|
|
||||||
Bucket: target.config.bucket, Key: pathname,
|
|
||||||
}), { abortSignal: AbortSignal.timeout(4_000) });
|
|
||||||
if (response.ContentType?.startsWith("image/") && response.ContentLength && response.ContentLength > 0) {
|
|
||||||
return describeArchivedObject(pathname, target, response.ContentType, response.ContentLength);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return;
|
|
||||||
} finally {
|
|
||||||
client.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchRelayImageIntoQiniu(
|
|
||||||
sourceUrl: string,
|
|
||||||
pathname: string,
|
|
||||||
target: QiniuUploadTarget,
|
|
||||||
archiveId: string,
|
|
||||||
) {
|
|
||||||
const startedAt = Date.now();
|
|
||||||
try {
|
|
||||||
return await fetchImageIntoQiniu(sourceUrl, pathname, target);
|
|
||||||
} catch (error) {
|
|
||||||
const missing = relaySourceStatus(error);
|
|
||||||
const retryable = isRetryableQiniuFetch(error);
|
|
||||||
const alreadyExists = error instanceof QiniuFetchError && error.status === 614;
|
|
||||||
if (!missing && !retryable && !alreadyExists) throw error;
|
|
||||||
|
|
||||||
// Losing the fetch response does not establish whether Kodo stored the file.
|
|
||||||
const stored = await readStoredRelayImage(pathname, target);
|
|
||||||
if (stored) return stored;
|
|
||||||
if (missing) throw new QiniuArchiveSourceMissingError(missing);
|
|
||||||
if (!retryable) throw error;
|
|
||||||
|
|
||||||
logger.warn("relay_fetch_retry", {
|
|
||||||
archiveId,
|
|
||||||
elapsedMs: Date.now() - startedAt,
|
|
||||||
...(error instanceof QiniuFetchError
|
|
||||||
? { status: error.status, requestId: error.requestId }
|
|
||||||
: { errorType: error instanceof Error ? error.name : "unknown" }),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await fetchImageIntoQiniu(sourceUrl, pathname, target, "image", RELAY_RETRY_TIMEOUT_MS);
|
|
||||||
} catch (error) {
|
|
||||||
const stored = await readStoredRelayImage(pathname, target);
|
|
||||||
if (stored) return stored;
|
|
||||||
const missing = relaySourceStatus(error);
|
|
||||||
if (missing) throw new QiniuArchiveSourceMissingError(missing);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prepare uploaded WebP images inside Kodo, retaining their embedded colour profile. */
|
/** Prepare uploaded WebP images inside Kodo, retaining their embedded colour profile. */
|
||||||
export async function prepareQiniuWebpDownload(url: string, taskId: string) {
|
export async function prepareQiniuWebpDownload(url: string, taskId: string) {
|
||||||
const target = await resolveS3UploadTarget();
|
const target = await resolveS3UploadTarget();
|
||||||
@ -211,9 +118,8 @@ export async function prepareQiniuWebpDownload(url: string, taskId: string) {
|
|||||||
async function fetchImageIntoQiniu(
|
async function fetchImageIntoQiniu(
|
||||||
sourceUrl: string,
|
sourceUrl: string,
|
||||||
pathname: string,
|
pathname: string,
|
||||||
target: QiniuUploadTarget,
|
target: NonNullable<Awaited<ReturnType<typeof resolveS3UploadTarget>>>,
|
||||||
kind: "image" | "audio" | "video" = "image",
|
kind: "image" | "audio" | "video" = "image",
|
||||||
timeoutMs = QINIU_FETCH_TIMEOUT_MS,
|
|
||||||
) {
|
) {
|
||||||
const config = target.config;
|
const config = target.config;
|
||||||
const path = `/fetch/${encodeQiniu(sourceUrl)}/to/${encodeQiniu(`${config.bucket}:${pathname}`)}`;
|
const path = `/fetch/${encodeQiniu(sourceUrl)}/to/${encodeQiniu(`${config.bucket}:${pathname}`)}`;
|
||||||
@ -228,28 +134,24 @@ async function fetchImageIntoQiniu(
|
|||||||
},
|
},
|
||||||
body: "",
|
body: "",
|
||||||
redirect: "error",
|
redirect: "error",
|
||||||
signal: AbortSignal.timeout(timeoutMs),
|
signal: AbortSignal.timeout(40_000),
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
await response.body?.cancel();
|
await response.body?.cancel();
|
||||||
throw new QiniuFetchError(response.status, response.headers.get("x-reqid"));
|
throw new Error(`Qiniu archive fetch returned HTTP ${response.status}`);
|
||||||
}
|
}
|
||||||
const result = await response.json() as { key?: string; fsize?: number; mimeType?: string };
|
const result = await response.json() as { key?: string; fsize?: number; mimeType?: string };
|
||||||
if (result.key !== pathname || !result.fsize || !result.mimeType?.startsWith(`${kind}/`)) {
|
if (result.key !== pathname || !result.fsize || !result.mimeType?.startsWith(`${kind}/`)) {
|
||||||
throw new Error(`Qiniu archive fetch did not return ${kind}`);
|
throw new Error(`Qiniu archive fetch did not return ${kind}`);
|
||||||
}
|
}
|
||||||
return describeArchivedObject(pathname, target, result.mimeType, result.fsize);
|
const url = buildS3PublicUrl(config, pathname);
|
||||||
}
|
|
||||||
|
|
||||||
async function describeArchivedObject(pathname: string, target: QiniuUploadTarget, contentType: string, bytes: number) {
|
|
||||||
const url = buildS3PublicUrl(target.config, pathname);
|
|
||||||
return {
|
return {
|
||||||
url,
|
url,
|
||||||
thumbnailUrl: url,
|
thumbnailUrl: url,
|
||||||
pathname,
|
pathname,
|
||||||
contentType,
|
contentType: result.mimeType,
|
||||||
bytes,
|
bytes: result.fsize,
|
||||||
downloadAsset: contentType === "image/png"
|
downloadAsset: result.mimeType === "image/png"
|
||||||
? await getReadyQiniuImageDownload(url, target).catch(() => undefined)
|
? await getReadyQiniuImageDownload(url, target).catch(() => undefined)
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -259,7 +259,7 @@ async function interpretStoryboardCommandWithLLM(params: {
|
|||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join("\n\n"),
|
.join("\n\n"),
|
||||||
temperature: 0.1,
|
temperature: 0.1,
|
||||||
maxOutputTokens: 200,
|
maxTokens: 200,
|
||||||
abortSignal: AbortSignal.timeout(12000),
|
abortSignal: AbortSignal.timeout(12000),
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
|||||||
@ -65,7 +65,7 @@ export async function executeImageOperation(
|
|||||||
vertical_angle: input.verticalAngle,
|
vertical_angle: input.verticalAngle,
|
||||||
zoom: input.zoom,
|
zoom: input.zoom,
|
||||||
}
|
}
|
||||||
: { imageUrl: input.imageUrl, scaleFactor: input.scaleFactor, includeBase64: false };
|
: { imageUrl: input.imageUrl, scaleFactor: input.scaleFactor };
|
||||||
const handler = {
|
const handler = {
|
||||||
enhance: handlers.enhance,
|
enhance: handlers.enhance,
|
||||||
extend: handlers.extend,
|
extend: handlers.extend,
|
||||||
@ -109,7 +109,7 @@ export async function executeImageOperation(
|
|||||||
if (error instanceof CanvasTaskLeaseLostError) throw error;
|
if (error instanceof CanvasTaskLeaseLostError) throw error;
|
||||||
throw new ImageOperationUncertainError("高清任务已受理,但任务标识保存失败,请勿重复提交");
|
throw new ImageOperationUncertainError("高清任务已受理,但任务标识保存失败,请勿重复提交");
|
||||||
}
|
}
|
||||||
const query = new URLSearchParams({ taskId, sourceImageUrl: input.imageUrl, includeBase64: "false" });
|
const query = new URLSearchParams({ taskId, sourceImageUrl: input.imageUrl });
|
||||||
for (let i = 0; i < (options.maxPolls ?? 30); i++) {
|
for (let i = 0; i < (options.maxPolls ?? 30); i++) {
|
||||||
await (options.wait || ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(1200);
|
await (options.wait || ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(1200);
|
||||||
await options.assertLease?.();
|
await options.assertLease?.();
|
||||||
|
|||||||
@ -86,7 +86,7 @@ export function filterCanvasModels<T extends CanvasModelDescriptor>(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCanvasVideoParameters(model: CanvasModelDescriptor | undefined, mode?: VideoGenerationMode, resolution?: string) {
|
export function getCanvasVideoParameters(model: CanvasModelDescriptor | undefined, mode?: VideoGenerationMode) {
|
||||||
const caps = record(model?.capabilities);
|
const caps = record(model?.capabilities);
|
||||||
const scoped = record(record(caps.modeConstraints || caps.constraints)[mode || ""]);
|
const scoped = record(record(caps.modeConstraints || caps.constraints)[mode || ""]);
|
||||||
const strings = (value: unknown) => Array.isArray(value) ? [...new Set(value.map(String).filter(Boolean))] : [];
|
const strings = (value: unknown) => Array.isArray(value) ? [...new Set(value.map(String).filter(Boolean))] : [];
|
||||||
@ -94,15 +94,11 @@ export function getCanvasVideoParameters(model: CanvasModelDescriptor | undefine
|
|||||||
const min = Number(durationRange.min), max = Number(durationRange.max);
|
const min = Number(durationRange.min), max = Number(durationRange.max);
|
||||||
const configured = record((model as CanvasModelDescriptor & {imageGenConfig?: unknown})?.imageGenConfig).videoDurationOptions;
|
const configured = record((model as CanvasModelDescriptor & {imageGenConfig?: unknown})?.imageGenConfig).videoDurationOptions;
|
||||||
const durations = Array.isArray(scoped.durationOptions) ? scoped.durationOptions : Array.isArray(configured) && configured.length ? configured : caps.durationOptions;
|
const durations = Array.isArray(scoped.durationOptions) ? scoped.durationOptions : Array.isArray(configured) && configured.length ? configured : caps.durationOptions;
|
||||||
const durationValues = Array.isArray(durations) ? [...new Set(durations.map(Number).filter(n => Number.isFinite(n) && n > 0))].sort((a,b) => a-b) :
|
|
||||||
min > 0 && max >= min && max-min <= 120 ? Array.from({length: max-min+1}, (_,i) => min+i) : [];
|
|
||||||
const bounds = model?.providerType === "vip98k" && resolution
|
|
||||||
? vip98kVideoDurationBounds(record(caps.vip98k).invocation?.inputSchema, resolution.toLowerCase())
|
|
||||||
: { min: 0, max: Infinity, durations: undefined };
|
|
||||||
return {
|
return {
|
||||||
ratios: strings(scoped.ratioOptions || caps.supportedRatios),
|
ratios: strings(scoped.ratioOptions || caps.supportedRatios),
|
||||||
resolutions: strings(scoped.resolutionOptions || caps.supportedResolutions),
|
resolutions: strings(scoped.resolutionOptions || caps.supportedResolutions),
|
||||||
durations: durationValues.filter(value => value >= bounds.min && value <= bounds.max && (!bounds.durations || bounds.durations.includes(value))),
|
durations: Array.isArray(durations) ? [...new Set(durations.map(Number).filter(n => Number.isFinite(n) && n > 0))].sort((a,b) => a-b) :
|
||||||
|
min > 0 && max >= min && max-min <= 120 ? Array.from({length: max-min+1}, (_,i) => min+i) : [],
|
||||||
supportsAudio: caps.supportGenerateAudio === true || caps.supportsAudio === true || caps.generateAudio === true || strings(record(record(model?.imageGenConfig).atlasCloud).propertyNames).includes("generate_audio"),
|
supportsAudio: caps.supportGenerateAudio === true || caps.supportsAudio === true || caps.generateAudio === true || strings(record(record(model?.imageGenConfig).atlasCloud).propertyNames).includes("generate_audio"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -227,7 +227,7 @@ export function reconcileCanvasTasks<
|
|||||||
}
|
}
|
||||||
if (task.request.kind === "audio")
|
if (task.request.kind === "audio")
|
||||||
Object.assign(nextDraft, {
|
Object.assign(nextDraft, {
|
||||||
...(data.text ? { text: data.text, content: [data.text], prompt: data.text, action: "TEXT_RESOURCE", mediaType: "text" } : {
|
...(data.text ? { text: data.text, content: data.text, prompt: data.text, action: "TEXT_RESOURCE", mediaType: "text" } : {
|
||||||
mediaUrl: data.url, url: data.urls || [data.url], action: "AUDIO_RESOURCE", mediaType: "audio",
|
mediaUrl: data.url, url: data.urls || [data.url], action: "AUDIO_RESOURCE", mediaType: "audio",
|
||||||
}),
|
}),
|
||||||
audioMeta: data.metadata,
|
audioMeta: data.metadata,
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
export function restoreTextResourceContent(draft?: Record<string, any>): string[] {
|
|
||||||
const content = draft?.content;
|
|
||||||
if (typeof content === "string") return [content];
|
|
||||||
// Empty arrays and strings both represent an intentional edit.
|
|
||||||
if (Array.isArray(content)) return content;
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
@ -3,8 +3,6 @@ import { defineConfig } from "@playwright/test";
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: "./tests",
|
testDir: "./tests",
|
||||||
testMatch: [
|
testMatch: [
|
||||||
/routes\/canvas-feedback\.test\.ts/,
|
|
||||||
/routes\/aos-image-transfer\.test\.ts/,
|
|
||||||
/routes\/rmbg-delivery\.test\.ts/,
|
/routes\/rmbg-delivery\.test\.ts/,
|
||||||
/routes\/legacy-oss-recovery\.test\.ts/,
|
/routes\/legacy-oss-recovery\.test\.ts/,
|
||||||
/routes\/retired-storage\.test\.ts/,
|
/routes\/retired-storage\.test\.ts/,
|
||||||
@ -25,7 +23,6 @@ export default defineConfig({
|
|||||||
/routes\/video-canvas-media-import\.test\.ts/,
|
/routes\/video-canvas-media-import\.test\.ts/,
|
||||||
/routes\/video-canvas-toolbar-jobs\.test\.ts/,
|
/routes\/video-canvas-toolbar-jobs\.test\.ts/,
|
||||||
/routes\/image-provider-error-classification\.test\.ts/,
|
/routes\/image-provider-error-classification\.test\.ts/,
|
||||||
/routes\/chat-image-fallback-contract\.test\.ts/,
|
|
||||||
/routes\/image-generation-status\.test\.ts/,
|
/routes\/image-generation-status\.test\.ts/,
|
||||||
/routes\/canvas-agent-runtime-image-failover\.test\.ts/,
|
/routes\/canvas-agent-runtime-image-failover\.test\.ts/,
|
||||||
/routes\/video-canvas-audio-remote\.test\.ts/,
|
/routes\/video-canvas-audio-remote\.test\.ts/,
|
||||||
|
|||||||
@ -143,7 +143,7 @@
|
|||||||
<div class="brand-mark">AI</div>
|
<div class="brand-mark">AI</div>
|
||||||
<div class="loading-spinner"></div>
|
<div class="loading-spinner"></div>
|
||||||
<p id="statusText" class="status-text">正在登录...</p>
|
<p id="statusText" class="status-text">正在登录...</p>
|
||||||
<p class="hint-text">正在通过钉钉确认企业身份,完成后会自动返回原页面。</p>
|
<p class="hint-text">正在通过钉钉确认企业身份,完成后会自动回到工作台。</p>
|
||||||
<div class="status-row">
|
<div class="status-row">
|
||||||
<span class="status-dot"></span>
|
<span class="status-dot"></span>
|
||||||
安全连接已建立
|
安全连接已建立
|
||||||
@ -215,7 +215,7 @@
|
|||||||
if (typeof callbackUrl !== 'string' || !callbackUrl) return '/';
|
if (typeof callbackUrl !== 'string' || !callbackUrl) return '/';
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(callbackUrl, window.location.origin);
|
const parsed = new URL(callbackUrl, window.location.origin);
|
||||||
if (parsed.origin !== window.location.origin || parsed.pathname.startsWith('//')) return '/';
|
if (parsed.origin !== window.location.origin) return '/';
|
||||||
return parsed.pathname + parsed.search + parsed.hash;
|
return parsed.pathname + parsed.search + parsed.hash;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return '/';
|
return '/';
|
||||||
@ -238,7 +238,6 @@
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
'X-Auth-Return-Redirect': '1',
|
|
||||||
},
|
},
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
csrfToken: csrfToken,
|
csrfToken: csrfToken,
|
||||||
@ -252,7 +251,7 @@
|
|||||||
|
|
||||||
if (loginRes.ok || loginRes.redirected) {
|
if (loginRes.ok || loginRes.redirected) {
|
||||||
statusText.textContent = '登录成功,正在跳转...';
|
statusText.textContent = '登录成功,正在跳转...';
|
||||||
console.log('[DingTalk Callback] Login successful, validating session...');
|
console.log('[DingTalk Callback] Login successful, redirecting to home...');
|
||||||
|
|
||||||
// 等待更长时间确保 cookie 被设置并同步
|
// 等待更长时间确保 cookie 被设置并同步
|
||||||
await new Promise(resolve => setTimeout(resolve, 800));
|
await new Promise(resolve => setTimeout(resolve, 800));
|
||||||
|
|||||||
@ -1,225 +0,0 @@
|
|||||||
import { expect, test, type Page } from "@playwright/test";
|
|
||||||
|
|
||||||
const projectId = "24cce650-7cfb-48bb-aa65-b04f490ac978";
|
|
||||||
const userMessageId = "998c3990-3e3b-49a0-91d9-4e29488231c0";
|
|
||||||
const prompt = "把背景换成游乐场,保持杯子外观不变";
|
|
||||||
const requestId = "source-request-for-feedback";
|
|
||||||
test.setTimeout(60000);
|
|
||||||
|
|
||||||
async function setup(page: Page, loseFirstResponse = false) {
|
|
||||||
const submissions: any[] = [];
|
|
||||||
const contexts: any[] = [];
|
|
||||||
const businessRequests: string[] = [];
|
|
||||||
const errors: string[] = [];
|
|
||||||
let saved: any = null;
|
|
||||||
let polls = 0;
|
|
||||||
page.on("pageerror", (error) => errors.push(error.message));
|
|
||||||
await page.context().addInitScript(() => localStorage.setItem("theme", "light"));
|
|
||||||
await page.context().route("**/api/**", async (route) => {
|
|
||||||
const request = route.request();
|
|
||||||
const path = new URL(request.url()).pathname;
|
|
||||||
const method = request.method();
|
|
||||||
let data: any = {};
|
|
||||||
if (path.endsWith("/feedback")) {
|
|
||||||
if (method === "GET") {
|
|
||||||
data = {
|
|
||||||
feedback: {
|
|
||||||
id: saved.id,
|
|
||||||
deliveryId: "test-delivery",
|
|
||||||
status: ++polls > 1 ? "sent" : "accepted",
|
|
||||||
message:
|
|
||||||
polls > 1 ? "反馈已投递给魔礼红。" : "反馈已保存,通知中心已受理,等待投递给魔礼红。",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const input = request.postDataJSON();
|
|
||||||
if (input.action === "context") {
|
|
||||||
contexts.push(input);
|
|
||||||
data = {
|
|
||||||
context: {
|
|
||||||
reporter: {
|
|
||||||
id: "feedback-user",
|
|
||||||
name: "反馈验收用户",
|
|
||||||
email: "test@example.com",
|
|
||||||
department: "设计",
|
|
||||||
},
|
|
||||||
project: { id: projectId, title: "问题反馈验收" },
|
|
||||||
requests: [
|
|
||||||
{
|
|
||||||
key: `message:${userMessageId}`,
|
|
||||||
kind: "message",
|
|
||||||
id: userMessageId,
|
|
||||||
requestId,
|
|
||||||
createdAt: "2026-11-18T08:00:00Z",
|
|
||||||
prompt,
|
|
||||||
status: "failed",
|
|
||||||
model: "Qwen Image 3.0",
|
|
||||||
error: "参考图片无法读取,请重新上传原图。",
|
|
||||||
evidence: "server",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
submissions.push(input);
|
|
||||||
saved = input;
|
|
||||||
if (loseFirstResponse && submissions.length === 1) {
|
|
||||||
await route.abort("connectionreset");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
||||||
data = {
|
|
||||||
feedback: {
|
|
||||||
id: input.id,
|
|
||||||
status: "pending",
|
|
||||||
deliveryId: null,
|
|
||||||
message: "反馈已保存,正在提交通知;短暂故障会自动重试,无需再次反馈。",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (path.includes("validate-session")) data = { valid: true, success: true };
|
|
||||||
else if (path === "/api/auth/session")
|
|
||||||
data = {
|
|
||||||
user: { id: "feedback-user", name: "反馈验收用户", type: "admin" },
|
|
||||||
expires: "2099-01-01",
|
|
||||||
};
|
|
||||||
else if (path === "/api/site-settings")
|
|
||||||
data = { canvasEnabled: true, agentEnabled: true, membershipEnabled: false };
|
|
||||||
else if (path === "/api/vote") data = [];
|
|
||||||
else if (path === "/api/models")
|
|
||||||
data = {
|
|
||||||
models: [
|
|
||||||
{
|
|
||||||
id: "image-test",
|
|
||||||
modelId: "gpt-image-2",
|
|
||||||
name: "GPT Image",
|
|
||||||
type: "image",
|
|
||||||
providerType: "openai",
|
|
||||||
enabled: true,
|
|
||||||
supportsImageGen: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
else if (path === `/api/canvas/${projectId}` && method === "GET")
|
|
||||||
data = {
|
|
||||||
success: true,
|
|
||||||
data: {
|
|
||||||
id: projectId,
|
|
||||||
title: "问题反馈验收",
|
|
||||||
workspaceType: "canvas",
|
|
||||||
canvasData: { nodes: [], edges: [], viewport: { x: 0, y: 0, zoom: 1 } },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
else if (path.includes("messages"))
|
|
||||||
data = {
|
|
||||||
messages: [
|
|
||||||
{
|
|
||||||
id: userMessageId,
|
|
||||||
role: "user",
|
|
||||||
createdAt: "2026-11-18T08:00:00Z",
|
|
||||||
parts: [{ type: "text", text: prompt }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "bd7ca4ea-8f4d-4437-8e9d-23897e27b144",
|
|
||||||
role: "assistant",
|
|
||||||
createdAt: "2026-11-18T08:00:30Z",
|
|
||||||
parts: [
|
|
||||||
{ type: "text", text: "参考图片无法读取,请重新上传原图。" },
|
|
||||||
{
|
|
||||||
type: "data-imageGenerationStatus",
|
|
||||||
data: {
|
|
||||||
phase: "failed",
|
|
||||||
userMessageId,
|
|
||||||
requestId,
|
|
||||||
failure: { message: "参考图片无法读取。", recommendation: "请重新上传原图。" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
else if (path.includes("sessions")) data = { sessions: [] };
|
|
||||||
else if (path.startsWith("/api/canvas/")) data = { success: true, runs: [] };
|
|
||||||
if (method === "POST" && /\/(?:agent-chat|generate|capabilities|chat)(?:\/|$)/.test(path))
|
|
||||||
businessRequests.push(path);
|
|
||||||
await route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: "application/json",
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
await page.goto(`/canvas/${projectId}`, { waitUntil: "domcontentloaded" });
|
|
||||||
await expect(page.getByRole("button", { name: "问题反馈", exact: true })).toBeVisible();
|
|
||||||
await expect(
|
|
||||||
page.getByTestId("canvas-chat-messages").getByText(prompt, { exact: true }),
|
|
||||||
).toBeVisible();
|
|
||||||
return { submissions, contexts, businessRequests, errors };
|
|
||||||
}
|
|
||||||
|
|
||||||
test("collect current conversation, send once and distinguish queued from delivered", async ({
|
|
||||||
page,
|
|
||||||
}) => {
|
|
||||||
const state = await setup(page);
|
|
||||||
await page.getByRole("button", { name: "问题反馈", exact: true }).click();
|
|
||||||
const dialog = page.getByRole("dialog");
|
|
||||||
await expect(dialog.getByText(requestId, { exact: true })).toBeVisible();
|
|
||||||
await dialog
|
|
||||||
.getByLabel("补充说明", { exact: false })
|
|
||||||
.fill("点击预览等待约 30 秒,仍无法查看图片。");
|
|
||||||
expect(
|
|
||||||
state.contexts[0].client.messages.some(
|
|
||||||
(item: any) => item.id === userMessageId && item.text === prompt,
|
|
||||||
),
|
|
||||||
).toBe(true);
|
|
||||||
expect(state.contexts[0].client.chatId).toBe(projectId);
|
|
||||||
await page.screenshot({ path: "test-results/canvas-feedback-desktop.png", animations: "disabled" });
|
|
||||||
await page
|
|
||||||
.getByRole("button", { name: "发送给魔礼红", exact: true })
|
|
||||||
.evaluate((button: HTMLButtonElement) => {
|
|
||||||
button.click();
|
|
||||||
button.click();
|
|
||||||
});
|
|
||||||
await expect(dialog.getByText(/反馈已保存,正在提交通知/)).toBeVisible();
|
|
||||||
expect(state.submissions).toHaveLength(1);
|
|
||||||
expect(state.submissions[0]).toMatchObject({
|
|
||||||
selection: `message:${userMessageId}`,
|
|
||||||
description: "点击预览等待约 30 秒,仍无法查看图片。",
|
|
||||||
});
|
|
||||||
await expect(dialog.getByText("反馈已投递给魔礼红。", { exact: true })).toBeVisible({
|
|
||||||
timeout: 12000,
|
|
||||||
});
|
|
||||||
expect(state.businessRequests).toEqual([]);
|
|
||||||
expect(state.errors).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("lost response and refresh recover original report without creating another notification", async ({
|
|
||||||
page,
|
|
||||||
}) => {
|
|
||||||
const state = await setup(page, true);
|
|
||||||
await page.getByRole("button", { name: "问题反馈", exact: true }).click();
|
|
||||||
await expect(page.getByRole("dialog").getByText(requestId, { exact: true })).toBeVisible();
|
|
||||||
await page.getByRole("button", { name: "发送给魔礼红", exact: true }).click();
|
|
||||||
await expect(page.getByRole("alert")).toBeVisible();
|
|
||||||
const originalId = state.submissions[0].id;
|
|
||||||
await page.reload({ waitUntil: "domcontentloaded" });
|
|
||||||
await page.getByRole("button", { name: "问题反馈", exact: true }).click();
|
|
||||||
await expect(
|
|
||||||
page.getByRole("dialog").getByText(`反馈编号:${originalId}`, { exact: true }),
|
|
||||||
).toBeVisible();
|
|
||||||
expect(state.submissions).toHaveLength(1);
|
|
||||||
expect(state.businessRequests).toEqual([]);
|
|
||||||
expect(state.errors).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("narrow screen retains a usable feedback entry and complete form", async ({ page }) => {
|
|
||||||
await page.setViewportSize({ width: 390, height: 844 });
|
|
||||||
await setup(page);
|
|
||||||
await page.getByRole("button", { name: "问题反馈", exact: true }).click();
|
|
||||||
await expect(page.getByRole("dialog").getByText(requestId, { exact: true })).toBeVisible();
|
|
||||||
await expect(page.getByRole("button", { name: "发送给魔礼红", exact: true })).toBeVisible();
|
|
||||||
await page.screenshot({ path: "test-results/canvas-feedback-mobile.png", animations: "disabled" });
|
|
||||||
const box = await page.getByRole("dialog").boundingBox();
|
|
||||||
expect(box!.x).toBeGreaterThanOrEqual(0);
|
|
||||||
expect(box!.x + box!.width).toBeLessThanOrEqual(391);
|
|
||||||
});
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
import { expect, test } from "@playwright/test";
|
|
||||||
import { serverLoader } from "../helpers/canvas-download-server-loader";
|
|
||||||
|
|
||||||
const cdn = "https://assets.example";
|
|
||||||
const input = `${cdn}/uploads/original.png`;
|
|
||||||
const output = "https://result.example/result.png";
|
|
||||||
const archived = `${cdn}/uploads/archived-result`;
|
|
||||||
const aos = "https://api.example";
|
|
||||||
|
|
||||||
function testImageTransfer(operation: "scale" | "segmentation") {
|
|
||||||
const endpoint = `${aos}/api/tasks/visual/${operation}`;
|
|
||||||
const calls: string[] = [];
|
|
||||||
const load = serverLoader({
|
|
||||||
"next/server": { NextResponse: Response },
|
|
||||||
"@/lib/db/queries": {
|
|
||||||
getSystemSetting: async () => ({ value: {
|
|
||||||
provider: "aoscdn", apiUrl: aos, apiKey: "test-key", aosApiBaseUrl: aos, aosApiKey: "test-key",
|
|
||||||
} }),
|
|
||||||
getMediaAssetsByUserAndUrls: async () => [],
|
|
||||||
upsertMediaAsset: async () => null,
|
|
||||||
},
|
|
||||||
"@/lib/db": { db: { insert: () => ({ values: () => ({ returning: async () => [{ id: "saved" }] }) }) } },
|
|
||||||
"@/lib/db/schema": { generatedImage: {} },
|
|
||||||
"@/lib/ai/vip98k-runtime": {},
|
|
||||||
"@/lib/storage/service": {},
|
|
||||||
"@/lib/storage/qiniu-image-archive": {
|
|
||||||
archiveImageThroughQiniu: async (url: string, key: string) => {
|
|
||||||
expect(url).toBe(output);
|
|
||||||
calls.push(key);
|
|
||||||
return { url: archived, contentType: "image/png" };
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"@/lib/observability/active-work": { trackRuntimeWork: (fn: () => unknown) => fn() },
|
|
||||||
setTimeout: (callback: () => void, ms: number) => setTimeout(callback, ms <= 2000 ? 0 : ms),
|
|
||||||
fetch: async (rawUrl: string, options?: RequestInit) => {
|
|
||||||
const url = String(rawUrl);
|
|
||||||
calls.push(url);
|
|
||||||
if (url === `${input}?imageInfo`) {
|
|
||||||
return Response.json({ width: 1024, height: 768, size: 100_000, format: "png" });
|
|
||||||
}
|
|
||||||
if (url === endpoint && options?.method === "POST") {
|
|
||||||
const body = options.body instanceof FormData
|
|
||||||
? options.body
|
|
||||||
: await new Request(endpoint, options).formData();
|
|
||||||
expect(body.get("image_url")).toBe(input);
|
|
||||||
expect(body.has("image_file")).toBe(false);
|
|
||||||
expect(body.get("return_type")).toBe("1");
|
|
||||||
expect(body.get(operation === "scale" ? "scale_factor" : "format"))
|
|
||||||
.toBe(operation === "scale" ? "2" : "png");
|
|
||||||
return Response.json({ data: { task_id: "test-aos-task" } });
|
|
||||||
}
|
|
||||||
if (url === `${endpoint}/test-aos-task`) {
|
|
||||||
return Response.json({ status: 200, data: { state: 1, image: output } });
|
|
||||||
}
|
|
||||||
throw Error(`Unexpected request to ${url}`);
|
|
||||||
},
|
|
||||||
}, { NEXT_PUBLIC_CANVAS_CDN_ORIGIN: cdn });
|
|
||||||
return { endpoint, calls, load };
|
|
||||||
}
|
|
||||||
|
|
||||||
test("canvas enhancement sends a stored input URL and returns a stored result URL after polling", async () => {
|
|
||||||
const { load, calls, endpoint } = testImageTransfer("scale");
|
|
||||||
const enhance = load("lib/canvas/operations/enhance.ts");
|
|
||||||
const checkpoint: string[] = [];
|
|
||||||
const response = await enhance.executeEnhancePOST(
|
|
||||||
new Request("https://app.example/enhance", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
body: JSON.stringify({ imageUrl: input, scaleFactor: 2, includeBase64: false }),
|
|
||||||
}),
|
|
||||||
"test-user",
|
|
||||||
async (id: string) => { checkpoint.push(id); },
|
|
||||||
);
|
|
||||||
expect(response.status).toBe(202);
|
|
||||||
expect(checkpoint).toEqual(["test-aos-task"]);
|
|
||||||
const poll = await enhance.executeEnhanceGET(
|
|
||||||
new Request("https://app.example/enhance?taskId=test-aos-task&includeBase64=false"), "test-user",
|
|
||||||
);
|
|
||||||
expect(poll.ok).toBe(true);
|
|
||||||
const result = await poll.json();
|
|
||||||
expect(result.original_url).toBe(archived);
|
|
||||||
expect(result).not.toHaveProperty("image_base64");
|
|
||||||
expect(calls).toEqual([`${input}?imageInfo`, endpoint, `${endpoint}/test-aos-task`, "aos-enhance-test-aos-task"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("canvas cutout keeps the archived PNG as the original and skips production image transfers", async () => {
|
|
||||||
const { load, calls, endpoint } = testImageTransfer("segmentation");
|
|
||||||
const rmbg = load("lib/ai/rmbg/service.ts");
|
|
||||||
const result = await rmbg.executeRmbgJob({
|
|
||||||
userId: "test-user", inputImageUrl: input, includeBase64: false, skipGallerySave: true,
|
|
||||||
});
|
|
||||||
expect(result.original_url).toBe(archived);
|
|
||||||
expect(result.image_base64).toBeUndefined();
|
|
||||||
expect(calls).toEqual([`${input}?imageInfo`, endpoint, `${endpoint}/test-aos-task`, "aos-rmbg-test-aos-task"]);
|
|
||||||
});
|
|
||||||
@ -1,194 +0,0 @@
|
|||||||
import { createHash, createHmac } from "node:crypto";
|
|
||||||
import { expect, test } from "@playwright/test";
|
|
||||||
import { feedbackMessages } from "@/lib/canvas/feedback-client";
|
|
||||||
import { feedbackConversationRequests } from "@/lib/canvas/feedback-context";
|
|
||||||
import { feedbackCommandSchema, type FeedbackSnapshot } from "@/lib/canvas/feedback-contract";
|
|
||||||
import { buildFeedbackNotification, feedbackReceipt } from "@/lib/canvas/feedback-store";
|
|
||||||
import {
|
|
||||||
notificationCenterRequest,
|
|
||||||
NotificationCenterError,
|
|
||||||
} from "@/lib/notifications/notification-center";
|
|
||||||
|
|
||||||
test("a late failure is associated with its original user message", () => {
|
|
||||||
const messages = feedbackMessages([
|
|
||||||
{
|
|
||||||
id: "first",
|
|
||||||
role: "user",
|
|
||||||
parts: [
|
|
||||||
{ type: "text", text: "第一笔需求" },
|
|
||||||
{ type: "data-hiddenPrompt", data: "内部信息" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ id: "second", role: "user", parts: [{ type: "text", text: "第二笔需求" }] },
|
|
||||||
{
|
|
||||||
id: "reply",
|
|
||||||
role: "assistant",
|
|
||||||
parts: [
|
|
||||||
{
|
|
||||||
type: "data-imageGenerationStatus",
|
|
||||||
data: JSON.stringify({
|
|
||||||
phase: "failed",
|
|
||||||
userMessageId: "first",
|
|
||||||
requestId: "original-request",
|
|
||||||
failure: { message: "参考图读取失败", recommendation: "重新上传原图" },
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
const requests = feedbackConversationRequests(messages, new Set(["first"]));
|
|
||||||
expect(requests.find((item) => item.id === "first")).toMatchObject({
|
|
||||||
prompt: "第一笔需求",
|
|
||||||
requestId: "original-request",
|
|
||||||
error: "参考图读取失败\n重新上传原图",
|
|
||||||
evidence: "server",
|
|
||||||
});
|
|
||||||
expect(requests.find((item) => item.id === "second")?.requestId).toBeNull();
|
|
||||||
expect(JSON.stringify(messages)).not.toContain("内部信息");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("notification uses a fixed recipient, stable event key and full-detail link within the center limit", () => {
|
|
||||||
const snapshot: FeedbackSnapshot = {
|
|
||||||
reporter: { id: "reporter", name: "验收用户", email: "test@example.com", department: "设计" },
|
|
||||||
project: { id: "project", title: "验收画布" },
|
|
||||||
request: {
|
|
||||||
key: "image:task",
|
|
||||||
kind: "image",
|
|
||||||
id: "task",
|
|
||||||
requestId: "request",
|
|
||||||
createdAt: "2026-11-18T08:00:00Z",
|
|
||||||
prompt: "长提示词".repeat(10000),
|
|
||||||
status: "failed",
|
|
||||||
model: "Qwen",
|
|
||||||
error: "错误".repeat(10000),
|
|
||||||
evidence: "server",
|
|
||||||
},
|
|
||||||
client: {
|
|
||||||
chatId: null,
|
|
||||||
messages: [],
|
|
||||||
pageVersion: "test-release",
|
|
||||||
capturedAt: "2026-11-18T08:00:00Z",
|
|
||||||
viewport: { width: 1440, height: 900 },
|
|
||||||
online: true,
|
|
||||||
errors: [],
|
|
||||||
nodes: [],
|
|
||||||
},
|
|
||||||
userAgent: "Test browser",
|
|
||||||
};
|
|
||||||
const notification = buildFeedbackNotification({
|
|
||||||
id: "feedback",
|
|
||||||
description: "补充".repeat(1000),
|
|
||||||
snapshot,
|
|
||||||
createdAt: "2026-11-18T08:01:00Z",
|
|
||||||
appUrl: "https://ai.yydd.ai/",
|
|
||||||
});
|
|
||||||
expect(notification).toMatchObject({
|
|
||||||
recipientAlias: "魔礼红",
|
|
||||||
idempotencyKey: "canvas-feedback:feedback:v1",
|
|
||||||
actionUrl: "https://ai.yydd.ai/feedback/feedback",
|
|
||||||
});
|
|
||||||
expect(notification.content.length).toBeLessThanOrEqual(4400);
|
|
||||||
expect(notification.content).toContain("完整内容见反馈详情");
|
|
||||||
expect(snapshot.request?.prompt.length).toBe(40000);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("accepted queue status does not claim DingTalk delivery", () => {
|
|
||||||
const accepted = feedbackReceipt({
|
|
||||||
id: "feedback",
|
|
||||||
deliveryId: "delivery",
|
|
||||||
status: "pending",
|
|
||||||
lastErrorCode: null,
|
|
||||||
} as any);
|
|
||||||
expect(accepted.status).toBe("accepted");
|
|
||||||
expect(accepted.message).toContain("已受理");
|
|
||||||
expect(accepted.message).not.toContain("已投递");
|
|
||||||
expect(
|
|
||||||
feedbackReceipt({
|
|
||||||
id: "feedback",
|
|
||||||
deliveryId: "delivery",
|
|
||||||
status: "failed",
|
|
||||||
lastErrorCode: "DELIVERY_OUTCOME_UNKNOWN",
|
|
||||||
} as any).message,
|
|
||||||
).toContain("避免重复提交");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("signed retries use identical business payload and fresh nonces", async () => {
|
|
||||||
const originalFetch = globalThis.fetch;
|
|
||||||
const originalEnv = { ...process.env };
|
|
||||||
const calls: RequestInit[] = [];
|
|
||||||
process.env.YYD_NOTIFICATION_CENTER_URL = "https://notify.example.test/notification-center";
|
|
||||||
process.env.YYD_NOTIFICATION_CENTER_PROJECT_CODE = "feedback-test";
|
|
||||||
process.env.YYD_NOTIFICATION_CENTER_PROJECT_SECRET = "test-secret-for-signature-verification";
|
|
||||||
globalThis.fetch = async (_input, init) => {
|
|
||||||
calls.push(init!);
|
|
||||||
return new Response(JSON.stringify({ id: "same-delivery", status: "pending" }), {
|
|
||||||
status: 202,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const payload = {
|
|
||||||
idempotencyKey: "feedback:stable",
|
|
||||||
recipientAlias: "魔礼红",
|
|
||||||
title: "反馈",
|
|
||||||
content: "测试",
|
|
||||||
actionTitle: "详情",
|
|
||||||
actionUrl: "https://ai.yydd.ai/feedback/test",
|
|
||||||
};
|
|
||||||
await notificationCenterRequest("POST", "/v1/notifications", payload);
|
|
||||||
await notificationCenterRequest("POST", "/v1/notifications", payload);
|
|
||||||
expect(calls[0].body).toBe(calls[1].body);
|
|
||||||
const headers = calls[0].headers as Record<string, string>;
|
|
||||||
expect(headers["x-yyd-nonce"]).not.toBe(
|
|
||||||
(calls[1].headers as Record<string, string>)["x-yyd-nonce"],
|
|
||||||
);
|
|
||||||
const canonical = [
|
|
||||||
headers["x-yyd-timestamp"],
|
|
||||||
headers["x-yyd-nonce"],
|
|
||||||
"POST",
|
|
||||||
"/v1/notifications",
|
|
||||||
createHash("sha256")
|
|
||||||
.update(calls[0].body as string)
|
|
||||||
.digest("hex"),
|
|
||||||
].join("\n");
|
|
||||||
expect(headers["x-yyd-signature"]).toBe(
|
|
||||||
createHmac("sha256", process.env.YYD_NOTIFICATION_CENTER_PROJECT_SECRET!)
|
|
||||||
.update(canonical)
|
|
||||||
.digest("hex"),
|
|
||||||
);
|
|
||||||
globalThis.fetch = async () =>
|
|
||||||
new Response(JSON.stringify({ error: "SIGNATURE_INVALID" }), { status: 401 });
|
|
||||||
await expect(notificationCenterRequest("GET", "/v1/notifications/test")).rejects.toMatchObject({
|
|
||||||
code: "SIGNATURE_INVALID",
|
|
||||||
retryable: false,
|
|
||||||
});
|
|
||||||
globalThis.fetch = async () => {
|
|
||||||
throw new Error("private transport detail");
|
|
||||||
};
|
|
||||||
await expect(notificationCenterRequest("GET", "/v1/notifications/test")).rejects.toEqual(
|
|
||||||
new NotificationCenterError("NOTIFICATION_CONNECTION_FAILED", true),
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
globalThis.fetch = originalFetch;
|
|
||||||
process.env = originalEnv;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("feedback input bounds and fixed contract exclude recipient and arbitrary browser objects", () => {
|
|
||||||
const result = feedbackCommandSchema.parse({
|
|
||||||
action: "context",
|
|
||||||
recipientAlias: "其他人",
|
|
||||||
client: {
|
|
||||||
chatId: null,
|
|
||||||
messages: [],
|
|
||||||
pageVersion: "test",
|
|
||||||
capturedAt: new Date().toISOString(),
|
|
||||||
viewport: { width: 1000, height: 700 },
|
|
||||||
online: true,
|
|
||||||
errors: [],
|
|
||||||
cookies: "private",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(result).not.toHaveProperty("recipientAlias");
|
|
||||||
expect(result.client).not.toHaveProperty("cookies");
|
|
||||||
expect(result.client.nodes).toEqual([]);
|
|
||||||
});
|
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import { expect, test } from "@playwright/test";
|
import { expect, test } from "@playwright/test";
|
||||||
import { createCanvasSaveQueue } from "@/lib/client/canvas-save-queue";
|
import { createCanvasSaveQueue } from "@/lib/client/canvas-save-queue";
|
||||||
import { executeCanvasToolbarCapability } from "@/lib/client/canvas-toolbar-capability";
|
import { executeCanvasToolbarCapability } from "@/lib/client/canvas-toolbar-capability";
|
||||||
import { requestLongTaskResult } from "@/lib/client/long-task";
|
|
||||||
import { createCanvasCapabilityClientCommand } from "@/lib/canvas/capabilities/client-command";
|
import { createCanvasCapabilityClientCommand } from "@/lib/canvas/capabilities/client-command";
|
||||||
import { useCanvasStore } from "@/store/canvas";
|
import { useCanvasStore } from "@/store/canvas";
|
||||||
import { canvasService } from "@/services/canvas";
|
import { canvasService } from "@/services/canvas";
|
||||||
@ -88,62 +87,6 @@ test("a lost submission response polls the original task and never resubmits", a
|
|||||||
expect(useCanvasStore.getState().nodes.map(n => n.id)).toEqual(["source", "result"]);
|
expect(useCanvasStore.getState().nodes.map(n => n.id)).toEqual(["source", "result"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a terminal enhance result ends polling even if the response also says it is processing", async () => {
|
|
||||||
const methods: string[] = [];
|
|
||||||
globalThis.fetch = (async (url, init) => {
|
|
||||||
methods.push(init?.method || "GET");
|
|
||||||
if (init?.method === "POST") {
|
|
||||||
return Response.json({ success: true, status: "running", taskId: "upstream-1" }, { status: 202 });
|
|
||||||
}
|
|
||||||
expect(String(url)).toContain("taskId=upstream-1");
|
|
||||||
return Response.json({
|
|
||||||
success: false,
|
|
||||||
status: "failed",
|
|
||||||
processing: true,
|
|
||||||
error: "图片变清晰失败,处理服务已确认任务失败。",
|
|
||||||
terminal: true,
|
|
||||||
}, { status: 500 });
|
|
||||||
}) as typeof fetch;
|
|
||||||
await expect(requestLongTaskResult({ endpoint: "/api/enhance", payload: {} }))
|
|
||||||
.rejects.toThrow("已确认任务失败");
|
|
||||||
expect(methods).toEqual(["POST", "GET"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("missing capability status stops waiting with the original request number", async () => {
|
|
||||||
const submitted = command();
|
|
||||||
const methods: string[] = [];
|
|
||||||
const originalSetTimeout = globalThis.setTimeout;
|
|
||||||
globalThis.setTimeout = ((fn: () => void) => originalSetTimeout(fn, 0)) as typeof setTimeout;
|
|
||||||
globalThis.fetch = (async (url, init) => {
|
|
||||||
methods.push(init?.method || "GET");
|
|
||||||
if (init?.method === "POST") return new Response(null, { status: 504 });
|
|
||||||
expect(String(url)).toContain(encodeURIComponent(submitted.requestId));
|
|
||||||
return new Response(null, { status: 404 });
|
|
||||||
}) as typeof fetch;
|
|
||||||
try {
|
|
||||||
await expect(executeCanvasToolbarCapability(submitted)).rejects.toThrow(
|
|
||||||
formatRequestFailure(getRequestFailureDetails({ providerOutcomeUnknown: true }), submitted.requestId),
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
globalThis.setTimeout = originalSetTimeout;
|
|
||||||
}
|
|
||||||
expect(methods).toEqual(["POST", "GET", "GET", "GET", "GET"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an interrupted enhance result preserves the upstream task number", async () => {
|
|
||||||
globalThis.fetch = (async (_url, init) => {
|
|
||||||
if (init?.method === "POST") {
|
|
||||||
return Response.json({ success: true, status: "running", taskId: "upstream-2" }, { status: 202 });
|
|
||||||
}
|
|
||||||
throw new TypeError("fetch failed");
|
|
||||||
}) as typeof fetch;
|
|
||||||
await expect(requestLongTaskResult({ endpoint: "/api/enhance", payload: {}, maxPollFailures: 1 }))
|
|
||||||
.rejects.toMatchObject({
|
|
||||||
taskId: "upstream-2",
|
|
||||||
message: expect.stringContaining("结果尚未确认"),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a recovered matting rejection shows its dimensions and advice without changing the canvas or resubmitting", async () => {
|
test("a recovered matting rejection shows its dimensions and advice without changing the canvas or resubmitting", async () => {
|
||||||
const submitted = createCanvasCapabilityClientCommand({ projectId: "project-a", capabilityId: "image.remove_background", nodeIds: ["source"], source: "toolbar" });
|
const submitted = createCanvasCapabilityClientCommand({ projectId: "project-a", capabilityId: "image.remove_background", nodeIds: ["source"], source: "toolbar" });
|
||||||
const failure = getRequestFailureDetails("抠图参考图分辨率超限(5056×3392 像素),当前 AOS 上游要求宽、高均不超过 4096 像素。");
|
const failure = getRequestFailureDetails("抠图参考图分辨率超限(5056×3392 像素),当前 AOS 上游要求宽、高均不超过 4096 像素。");
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
import { expect, test } from "@playwright/test";
|
|
||||||
import { serverLoader } from "../helpers/canvas-download-server-loader";
|
|
||||||
|
|
||||||
const { canUseImageFallback } = serverLoader({
|
|
||||||
"@/lib/ai/dynamic-provider": {},
|
|
||||||
"@/lib/ai/providers/fal-image": {},
|
|
||||||
"./image-media": {},
|
|
||||||
})("app/(chat)/api/chat/_lib/image-failover.ts");
|
|
||||||
|
|
||||||
const candidate = {
|
|
||||||
provider: { id: "account", type: "vip98k" },
|
|
||||||
model: {
|
|
||||||
modelId: "nano-banana-2-2k-cl", supportsVision: true,
|
|
||||||
imageGenConfig: { supportedImageSizes: ["2K"], supportedAspectRatios: ["1:1", "3:4"], maxReferenceImages: 2, maxImages: 1 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const params = { imageSize: "2K", aspectRatio: "3:4", imageCount: 1 };
|
|
||||||
const messages = [{ role: "user", parts: [
|
|
||||||
{ type: "text", text: "Replace the bookshelf" },
|
|
||||||
{ type: "file", mediaType: "image/png", url: "https://fixture.invalid/source.png" },
|
|
||||||
] }];
|
|
||||||
|
|
||||||
test("a fixed 2K fallback never receives a 1K or 4K request", () => {
|
|
||||||
for (const imageSize of ["1K", "4K"]) {
|
|
||||||
expect(canUseImageFallback(candidate, { ...params, imageSize }, messages, new Set())).toBe(false);
|
|
||||||
}
|
|
||||||
expect(canUseImageFallback(candidate, params, messages, new Set())).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("fallback preserves image ratio, quantity and all reference images", () => {
|
|
||||||
expect(canUseImageFallback(candidate, { ...params, aspectRatio: "16:9" }, messages, new Set())).toBe(false);
|
|
||||||
expect(canUseImageFallback(candidate, { ...params, imageCount: 2 }, messages, new Set())).toBe(false);
|
|
||||||
expect(canUseImageFallback(candidate, params, [messages[0], messages[0], messages[0]], new Set())).toBe(false);
|
|
||||||
const textOnly = { ...candidate, model: { ...candidate.model, supportsVision: false } };
|
|
||||||
expect(canUseImageFallback(textOnly, params, messages, new Set())).toBe(false);
|
|
||||||
expect(canUseImageFallback(textOnly, params, [], new Set())).toBe(true);
|
|
||||||
expect(canUseImageFallback(candidate, { ...params, aspectRatio: "auto" }, messages, new Set())).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an exhausted account is skipped across models, while a compatible independent account is eligible", () => {
|
|
||||||
const blocked = new Set(["account"]);
|
|
||||||
expect(canUseImageFallback(candidate, params, messages, blocked)).toBe(false);
|
|
||||||
expect(canUseImageFallback({ ...candidate, model: { ...candidate.model, modelId: "another-model" } }, params, messages, blocked)).toBe(false);
|
|
||||||
expect(canUseImageFallback({ ...candidate, provider: { ...candidate.provider, id: "other-account" } }, params, messages, blocked)).toBe(true);
|
|
||||||
});
|
|
||||||
@ -132,73 +132,6 @@ test("Qiniu archives 98K originals without relaying full image bytes through the
|
|||||||
expect(reads).toHaveLength(3);
|
expect(reads).toHaveLength(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("98K fetch checks the original archive key and retries a temporary failure once", async () => {
|
|
||||||
const source = "https://api.vip98k.com/api/external/assets/test_asset";
|
|
||||||
const id = "archive-1";
|
|
||||||
const key = `uploads/ai-generated-archive-${id}`;
|
|
||||||
const publicUrl = "https://bucket.example";
|
|
||||||
const config = { provider: "qiniu-kodo", region: "cn-east-1", bucket: "archive",
|
|
||||||
accessKeyId: "test-key", secretAccessKey: "test-secret", publicUrl };
|
|
||||||
const calls: string[] = [];
|
|
||||||
let existing = false;
|
|
||||||
let firstStatus = 478;
|
|
||||||
const load = serverLoader({
|
|
||||||
"@/lib/observability/logger": loggerMock,
|
|
||||||
"@/lib/storage/service": {
|
|
||||||
resolveS3UploadTarget: async () => ({ config }),
|
|
||||||
buildS3PublicUrl: (_: unknown, pathname: string) => `${publicUrl}/${pathname}`,
|
|
||||||
createS3Client: () => ({
|
|
||||||
async send(cmd: { input: { Bucket: string; Key: string } }) {
|
|
||||||
expect(cmd.input).toEqual({ Bucket: "archive", Key: key });
|
|
||||||
calls.push("head");
|
|
||||||
if (!existing) throw new Error("Object does not exist");
|
|
||||||
return { ContentType: "image/jpeg", ContentLength: 20 };
|
|
||||||
},
|
|
||||||
destroy() {},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
fetch: async (url: string) => {
|
|
||||||
const to = new URL(url).pathname.split("/to/")[1];
|
|
||||||
expect(Buffer.from(to, "base64url").toString()).toBe(`archive:${key}`);
|
|
||||||
calls.push("fetch");
|
|
||||||
return calls.length === 1
|
|
||||||
? { ok: false, status: firstStatus, headers: new Headers() }
|
|
||||||
: Response.json({ key, fsize: 20, mimeType: "image/jpeg" });
|
|
||||||
},
|
|
||||||
})("lib/storage/qiniu-image-archive.ts");
|
|
||||||
|
|
||||||
expect(await load.archiveImageThroughQiniu(source, id)).toMatchObject({ pathname: key, bytes: 20 });
|
|
||||||
expect(calls.splice(0)).toEqual(["fetch", "head", "fetch"]);
|
|
||||||
|
|
||||||
existing = true;
|
|
||||||
firstStatus = 614;
|
|
||||||
expect(await load.archiveImageThroughQiniu(source, id)).toMatchObject({ pathname: key, bytes: 20 });
|
|
||||||
expect(calls.splice(0)).toEqual(["fetch", "head"]);
|
|
||||||
|
|
||||||
existing = false;
|
|
||||||
firstStatus = 404;
|
|
||||||
await expect(load.archiveImageThroughQiniu(source, id)).rejects.toBeInstanceOf(load.QiniuArchiveSourceMissingError);
|
|
||||||
expect(calls).toEqual(["fetch", "head"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a confirmed missing 98K image does not start a production transfer", async () => {
|
|
||||||
class QiniuArchiveSourceMissingError extends Error {}
|
|
||||||
const sourceError = new QiniuArchiveSourceMissingError("98K original image is no longer available (HTTP 404)");
|
|
||||||
const load = serverLoader({
|
|
||||||
"@/lib/storage/image-byte-cache": { fetchImageBytes() { throw new Error("Unexpected production download"); } },
|
|
||||||
"@/lib/observability/logger": loggerMock,
|
|
||||||
"@/lib/storage/image-archive-db": {},
|
|
||||||
"@/lib/storage/service": {},
|
|
||||||
"./image-archive-worker": {},
|
|
||||||
"./qiniu-image-archive": {
|
|
||||||
QiniuArchiveSourceMissingError,
|
|
||||||
async archiveImageThroughQiniu() { throw sourceError; },
|
|
||||||
},
|
|
||||||
})("lib/storage/image-archive.ts");
|
|
||||||
await expect(load.archiveTemporaryImage("https://api.vip98k.com/api/external/assets/test_asset", "task"))
|
|
||||||
.rejects.toBe(sourceError);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("160 requests from the same user and model start without admission waiting", async () => {
|
test("160 requests from the same user and model start without admission waiting", async () => {
|
||||||
const module = serverLoader({})("lib/canvas/image-concurrency.ts");
|
const module = serverLoader({})("lib/canvas/image-concurrency.ts");
|
||||||
let queued = 0;
|
let queued = 0;
|
||||||
|
|||||||
@ -37,26 +37,3 @@ test("late failures remain associated with their original user request", () => {
|
|||||||
expect(findImageGenerationFailure(messages, "second")).toBeNull();
|
expect(findImageGenerationFailure(messages, "second")).toBeNull();
|
||||||
expect(findImageGenerationFailure([{ role: "assistant", parts: [{ type: "text", text: "请分析失败原因" }] }], "second")).toBeNull();
|
expect(findImageGenerationFailure([{ role: "assistant", parts: [{ type: "text", text: "请分析失败原因" }] }], "second")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("quota rejection reports the same terminal state to the browser and history and links the upstream request", async () => {
|
|
||||||
const chunks: any[] = [];
|
|
||||||
const saved: any[] = [];
|
|
||||||
const logs: any[] = [];
|
|
||||||
const load = serverLoader({
|
|
||||||
"@/lib/db/queries": { saveMessages: async ({ messages }: any) => saved.push(...messages) },
|
|
||||||
"@/lib/observability/logger": { createLogger: () => ({ warn: (_: string, fields: any) => logs.push(fields) }) },
|
|
||||||
});
|
|
||||||
const { reportImageGenerationFailure } = load("app/(chat)/api/chat/_lib/image-generation-failure.ts");
|
|
||||||
await reportImageGenerationFailure({
|
|
||||||
writer: { write: (chunk: any) => chunks.push(chunk) },
|
|
||||||
chatId: "chat", userMessageId: "original-user", messageId: "local-request",
|
|
||||||
error: Object.assign(new Error("The API key does not have enough available quota. (HTTP 429)"), {
|
|
||||||
status: 429, providerRequestId: "upstream-request",
|
|
||||||
}), label: "test",
|
|
||||||
});
|
|
||||||
const streamed = JSON.parse(chunks.find(chunk => chunk.type === "data-imageGenerationStatus").data);
|
|
||||||
expect(findImageGenerationFailure(saved, "original-user")).toEqual(streamed);
|
|
||||||
expect(streamed).toMatchObject({ phase: "failed", failure: { code: "PROVIDER_BALANCE_EXHAUSTED", outcome: "failed" } });
|
|
||||||
expect(saved[0].parts[0].text).toContain("与您的积分余额无关");
|
|
||||||
expect(logs).toContainEqual(expect.objectContaining({ requestId: "local-request", providerRequestId: "upstream-request" }));
|
|
||||||
});
|
|
||||||
|
|||||||
@ -269,14 +269,6 @@ test("ordinary image success uses the original response directly", async () => {
|
|||||||
expect(h.calls.map(c => c.method)).toEqual(["POST"]);
|
expect(h.calls.map(c => c.method)).toEqual(["POST"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a 98K quota rejection retains its request ID without another submission", async () => {
|
|
||||||
const h = imageRecoveryHarness(() => Response.json({ error: {
|
|
||||||
code: "insufficient_quota", message: "The API key does not have enough available quota.",
|
|
||||||
} }, { status: 429, headers: { "X-Request-ID": "provider-quota-request" } }));
|
|
||||||
await expect(h.run()).rejects.toMatchObject({ status: 429, providerRequestId: "provider-quota-request" });
|
|
||||||
expect(h.calls.map(c => c.method)).toEqual(["POST"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an explicit provider balance error takes precedence over HTTP 429", () => {
|
test("an explicit provider balance error takes precedence over HTTP 429", () => {
|
||||||
const error = Object.assign(new Error("余额不足,请点击充值页面续费(HTTP 429)"), { status: 429 });
|
const error = Object.assign(new Error("余额不足,请点击充值页面续费(HTTP 429)"), { status: 429 });
|
||||||
expect(isProviderBalanceError(error)).toBe(true);
|
expect(isProviderBalanceError(error)).toBe(true);
|
||||||
@ -296,19 +288,6 @@ test("nested billing details and generic quota limits are kept distinct", () =>
|
|||||||
expect(isProviderBalanceError(new Error("该模型额度不足(HTTP 429)"))).toBe(true);
|
expect(isProviderBalanceError(new Error("该模型额度不足(HTTP 429)"))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("98K wallet rejection remains a balance error instead of rate limiting", () => {
|
|
||||||
for (const message of [
|
|
||||||
"The API key does not have enough available quota.",
|
|
||||||
"The API key does not have enough available quota for this request.",
|
|
||||||
]) {
|
|
||||||
const error = Object.assign(new Error(`${message} (HTTP 429)`), { status: 429 });
|
|
||||||
expect(isProviderBalanceError(error)).toBe(true);
|
|
||||||
expect(isRateLimitError(error)).toBe(false);
|
|
||||||
expect(getRequestFailureDetails(error)).toMatchObject({ code: "PROVIDER_BALANCE_EXHAUSTED" });
|
|
||||||
expect(getUserFacingImageGenerationErrorMessage(error)).toContain("与您的积分余额无关");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("confirmed balance failures remain isolated until explicitly restored", () => {
|
test("confirmed balance failures remain isolated until explicitly restored", () => {
|
||||||
const model = {
|
const model = {
|
||||||
healthLastEventType: "quota",
|
healthLastEventType: "quota",
|
||||||
|
|||||||
@ -309,17 +309,3 @@ test("a cancelled request can leave shared discovery without submitting a paid P
|
|||||||
finishCatalog(Response.json({ data: { sections: [{ models: [catalogModel] }] } }));
|
finishCatalog(Response.json({ data: { sections: [{ models: [catalogModel] }] } }));
|
||||||
expect(posts).toBe(0);
|
expect(posts).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("fixed-sampling native contracts omit sampling controls while preserving tools and token limits", async () => {
|
|
||||||
let sent: any;
|
|
||||||
const metadata={chatInvocation:{protocol:'anthropic-messages',path:'/v1/messages',headers:{'X-Relay-Route-Option':'native_route'}},invocation:{kind:'chat',path:'/v1/messages',headers:{'X-Relay-Route-Option':'native_route'},inputSchema:{properties:{temperature:{const:1},top_p:{const:.99},top_k:false}}}};
|
|
||||||
const selected=selectVip98kChatInvocation(metadata);
|
|
||||||
expect(selected?.omitSampling).toBe(true);
|
|
||||||
const nativeModel=createVip98kChatModel({apiKey:'fixture',baseURL:'https://relay.example',modelId:'claude-haiku-5-5',metadata,fetch:async(_url,init)=>{
|
|
||||||
sent=JSON.parse(String(init?.body));
|
|
||||||
return Response.json({id:'test',type:'message',role:'assistant',model:'claude-haiku-5-5',content:[{type:'text',text:'ok'}],stop_reason:'end_turn',stop_sequence:null,usage:{input_tokens:1,output_tokens:1}});
|
|
||||||
}});
|
|
||||||
await generateText({model:nativeModel,prompt:'test',temperature:.2,topP:.9,topK:4,maxOutputTokens:321,maxRetries:0});
|
|
||||||
expect(sent.max_tokens).toBe(321);
|
|
||||||
for(const key of ['temperature','top_p','top_k'])expect(sent).not.toHaveProperty(key);
|
|
||||||
});
|
|
||||||
|
|||||||
@ -62,9 +62,7 @@ test("download preparation only registers unsigned files in the configured bucke
|
|||||||
const module = serverLoader({
|
const module = serverLoader({
|
||||||
"@/lib/db/queries": { getDefaultStorageConfig: async () => config },
|
"@/lib/db/queries": { getDefaultStorageConfig: async () => config },
|
||||||
"./image-archive-db": { findImageArchiveDownloadTask: async () => null,
|
"./image-archive-db": { findImageArchiveDownloadTask: async () => null,
|
||||||
enqueueImageArchiveTask: async () => ({ id: "waiting", status: "pending", targetUrl: null }),
|
|
||||||
ensureStoredImageDownloadTask: async (url: string) => { stored.push(url); return { id: "1", targetUrl: url }; } },
|
ensureStoredImageDownloadTask: async (url: string) => { stored.push(url); return { id: "1", targetUrl: url }; } },
|
||||||
"./image-archive-worker": { scheduleImageArchiveWorker() {} },
|
|
||||||
}, { CANVAS_QINIU_ORIGIN_URL: "https://origin.example" })("lib/storage/canvas-cdn-download.ts");
|
}, { CANVAS_QINIU_ORIGIN_URL: "https://origin.example" })("lib/storage/canvas-cdn-download.ts");
|
||||||
for (const url of ["https://other.example/uploads/a.png", "https://cdn.example/uploads/a.png?token=signed",
|
for (const url of ["https://other.example/uploads/a.png", "https://cdn.example/uploads/a.png?token=signed",
|
||||||
"https://cdn.example/uploads/a.png?imageView2/2/w/160", "https://cdn.example/private/a.png"]) {
|
"https://cdn.example/uploads/a.png?imageView2/2/w/160", "https://cdn.example/private/a.png"]) {
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import {
|
|||||||
type CanvasGenerationTask,
|
type CanvasGenerationTask,
|
||||||
} from "@/lib/video-canvas/task-contract";
|
} from "@/lib/video-canvas/task-contract";
|
||||||
import { chooseStoryVideoSettings } from "@/lib/video-canvas/model-matching";
|
import { chooseStoryVideoSettings } from "@/lib/video-canvas/model-matching";
|
||||||
import { restoreTextResourceContent } from "@/lib/video-canvas/text-resource";
|
|
||||||
type TaskNode = { id: string; draftValues?: Record<string, any>; [key: string]: any };
|
type TaskNode = { id: string; draftValues?: Record<string, any>; [key: string]: any };
|
||||||
const node: TaskNode = {
|
const node: TaskNode = {
|
||||||
id: "n1",
|
id: "n1",
|
||||||
@ -63,22 +62,6 @@ test("music variations become separate playable resources without duplicate card
|
|||||||
expect(result[1]).toMatchObject({inputType:"audio",draftValues:{action:"AUDIO_RESOURCE",mediaUrl:"https://example.com/two.mp3"}});
|
expect(result[1]).toMatchObject({inputType:"audio",draftValues:{action:"AUDIO_RESOURCE",mediaUrl:"https://example.com/two.mp3"}});
|
||||||
expect(reconcileCanvasTasks(result,[music],"2026-09-17T01:00:00Z")).toBe(result);
|
expect(reconcileCanvasTasks(result,[music],"2026-09-17T01:00:00Z")).toBe(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("speech recognition restores editable text with the canvas resource format", () => {
|
|
||||||
const text = "这是由壹点测试画布的语音验收,中文配音正常。";
|
|
||||||
const recognition: CanvasGenerationTask = {
|
|
||||||
...task,
|
|
||||||
request: { ...task.request, kind: "audio" },
|
|
||||||
result: { text, metadata: { outputType: "text" } },
|
|
||||||
};
|
|
||||||
const result = reconcileCanvasTasks<TaskNode>([], [recognition], "2026-09-17T01:00:00Z");
|
|
||||||
expect(result[0]).toMatchObject({
|
|
||||||
inputType: "text",
|
|
||||||
draftValues: { action: "TEXT_RESOURCE", content: [text], generationStatus: "complete" },
|
|
||||||
});
|
|
||||||
const edited = [{ ...result[0], draftValues: { ...result[0].draftValues, content: ["已校对的中文"] } }];
|
|
||||||
expect(reconcileCanvasTasks(edited, [recognition], "2026-09-17T01:00:00Z")).toBe(edited);
|
|
||||||
});
|
|
||||||
test("does not resurrect nodes removed after task creation or hidden on the server", () => {
|
test("does not resurrect nodes removed after task creation or hidden on the server", () => {
|
||||||
expect(reconcileCanvasTasks<TaskNode>([], [task], "2026-09-17T01:02:00Z")).toEqual([]);
|
expect(reconcileCanvasTasks<TaskNode>([], [task], "2026-09-17T01:02:00Z")).toEqual([]);
|
||||||
expect(
|
expect(
|
||||||
@ -89,18 +72,6 @@ test("does not resurrect nodes removed after task creation or hidden on the serv
|
|||||||
),
|
),
|
||||||
).toEqual([]);
|
).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("saved speech text survives reload and retains subsequent edits, including an empty edit", () => {
|
|
||||||
const text = "这是由壹点测试画布的语音验收,尺寸 15mm。 ";
|
|
||||||
const saved = { content: text, text, audioMeta: { outputType: "text" } };
|
|
||||||
expect(restoreTextResourceContent(JSON.parse(JSON.stringify(saved)))).toEqual([text]);
|
|
||||||
expect(restoreTextResourceContent({ ...saved, content: [] })).toEqual([]);
|
|
||||||
for (const edit of ["已校对的中文 20mm。 ", ""]) {
|
|
||||||
const updated = { ...saved, content: edit ? [edit] : [] };
|
|
||||||
expect(restoreTextResourceContent(JSON.parse(JSON.stringify(updated)))).toEqual(edit ? [edit] : []);
|
|
||||||
}
|
|
||||||
expect(restoreTextResourceContent({ content: [] })).toEqual([]);
|
|
||||||
});
|
|
||||||
test("late result from an older request cannot overwrite a new generation on the same node", () => {
|
test("late result from an older request cannot overwrite a new generation on the same node", () => {
|
||||||
const current = {
|
const current = {
|
||||||
...node,
|
...node,
|
||||||
@ -468,7 +439,7 @@ import {
|
|||||||
} from "@/lib/video-canvas/task-recovery";
|
} from "@/lib/video-canvas/task-recovery";
|
||||||
import { CanvasTaskLeaseLostError } from "@/lib/video-canvas/image-operation";
|
import { CanvasTaskLeaseLostError } from "@/lib/video-canvas/image-operation";
|
||||||
import { normalizeVideoAnalysisRows } from "@/lib/video-canvas/video-story";
|
import { normalizeVideoAnalysisRows } from "@/lib/video-canvas/video-story";
|
||||||
import { pollTaskResult, EnhanceTerminalError, readCompletedEnhanceImage } from "@/lib/canvas/enhance-task-poll";
|
import { pollTaskResult, EnhanceTerminalError } from "@/lib/canvas/enhance-task-poll";
|
||||||
const recoveryTime = Date.parse("2026-09-17T04:00:00Z");
|
const recoveryTime = Date.parse("2026-09-17T04:00:00Z");
|
||||||
const checkpoint = {
|
const checkpoint = {
|
||||||
operation: "enhance" as const,
|
operation: "enhance" as const,
|
||||||
@ -592,11 +563,6 @@ test("actual AOS polling propagates negative state immediately and bounds elapse
|
|||||||
}),
|
}),
|
||||||
).rejects.toBeInstanceOf(EnhanceTerminalError);
|
).rejects.toBeInstanceOf(EnhanceTerminalError);
|
||||||
expect(calls).toBe(1);
|
expect(calls).toBe(1);
|
||||||
await expect(
|
|
||||||
pollTaskResult("https://example.com", "qa", "id", 1, 1000, async () =>
|
|
||||||
Response.json({ data: { state: -1, err_message: "bad image" } }, { status: 422 }),
|
|
||||||
),
|
|
||||||
).rejects.toThrow("bad image");
|
|
||||||
const started = Date.now();
|
const started = Date.now();
|
||||||
await expect(
|
await expect(
|
||||||
pollTaskResult("https://example.com", "qa", "id", 1, 25, async () =>
|
pollTaskResult("https://example.com", "qa", "id", 1, 25, async () =>
|
||||||
@ -605,40 +571,6 @@ test("actual AOS polling propagates negative state immediately and bounds elapse
|
|||||||
).rejects.toThrow("轮询超时");
|
).rejects.toThrow("轮询超时");
|
||||||
expect(Date.now() - started).toBeLessThan(500);
|
expect(Date.now() - started).toBeLessThan(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("AOS polling allows time to read a completed legacy inline result", async () => {
|
|
||||||
const timeout = AbortSignal.timeout;
|
|
||||||
const readBudgets: number[] = [];
|
|
||||||
AbortSignal.timeout = (ms) => {
|
|
||||||
readBudgets.push(ms);
|
|
||||||
return timeout(ms);
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const result = await pollTaskResult("https://example.com", "qa", "original-task", 1, 30_000, async () =>
|
|
||||||
Response.json({ status: 200, data: { state: 1, image: "aW1hZ2U=", progress: 100 } }),
|
|
||||||
);
|
|
||||||
expect(result.data.image).toBe("aW1hZ2U=");
|
|
||||||
expect(readBudgets[0]).toBeGreaterThan(25_000);
|
|
||||||
} finally {
|
|
||||||
AbortSignal.timeout = timeout;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("completed AOS images retain their PNG format through both result transports", async () => {
|
|
||||||
const { default: sharp } = await import("sharp");
|
|
||||||
const png = await sharp({
|
|
||||||
create: { width: 2, height: 2, channels: 4, background: "#20304f80" },
|
|
||||||
}).png().toBuffer();
|
|
||||||
const inline = await readCompletedEnhanceImage({ image: png.toString("base64") });
|
|
||||||
const linked = await readCompletedEnhanceImage({ image: "https://example.com/result.png" },
|
|
||||||
async () => new Response(new Uint8Array(png)));
|
|
||||||
expect(inline).toEqual({ buffer: png, mimeType: "image/png" });
|
|
||||||
expect(linked).toEqual(inline);
|
|
||||||
await expect(
|
|
||||||
readCompletedEnhanceImage({ image: "https://example.com/result.png" },
|
|
||||||
async () => new Response("unavailable", { status: 200 })),
|
|
||||||
).rejects.toThrow("已完成,但结果图片未取回");
|
|
||||||
});
|
|
||||||
test("video analysis preserves zero timestamps and all shots without invented camera or audio facts", () => {
|
test("video analysis preserves zero timestamps and all shots without invented camera or audio facts", () => {
|
||||||
const rows = normalizeVideoAnalysisRows(
|
const rows = normalizeVideoAnalysisRows(
|
||||||
Array.from({ length: 12 }, (_, i) => ({ sceneDescription: `镜头${i}`, startTime: 0 })),
|
Array.from({ length: 12 }, (_, i) => ({ sceneDescription: `镜头${i}`, startTime: 0 })),
|
||||||
|
|||||||
@ -47,59 +47,6 @@ test("ratio-sized image contracts bind size and resolution without stale square
|
|||||||
const result = buildTaskBody(params,invocation({size:{enum:["1:1","16:9"]},resolution:{enum:["1K","2K"]}},{size:"1:1",resolution:"1K"}));
|
const result = buildTaskBody(params,invocation({size:{enum:["1:1","16:9"]},resolution:{enum:["1K","2K"]}},{size:"1:1",resolution:"1K"}));
|
||||||
expect(result.body).toMatchObject({size:"16:9",resolution:"2K",prompt:"a blue cup"});
|
expect(result.body).toMatchObject({size:"16:9",resolution:"2K",prompt:"a blue cup"});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("mixed size enums retain ratio aliases when size is the ratio field", () => {
|
|
||||||
const { body } = buildTaskBody(params, invocation({
|
|
||||||
size: { enum: ["16:9", "2048x1152"] },
|
|
||||||
resolution: { enum: ["1K", "2K"] },
|
|
||||||
}));
|
|
||||||
expect(body).toMatchObject({ size: "16:9", resolution: "2K" });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("GPT Image 2.6 sends the selected ratio without a competing pixel size", () => {
|
|
||||||
const presets = [
|
|
||||||
["9:16", "941x1672"],
|
|
||||||
["21:9", "1920x832"],
|
|
||||||
["9:21", "832x1920"],
|
|
||||||
["1:1", "1024x1024"],
|
|
||||||
];
|
|
||||||
const ratios = presets.map(([ratio]) => ratio);
|
|
||||||
const contract = invocation({
|
|
||||||
size: { enum: ["auto", ...ratios, ...presets.map(([, size]) => size)] },
|
|
||||||
aspect_ratio: { enum: ratios },
|
|
||||||
image: { type: "array", items: { type: "string" } },
|
|
||||||
quality: { enum: ["auto"] },
|
|
||||||
}, { size: "1024x1024", image: [], quality: "auto" });
|
|
||||||
const references = ["https://example.com/one.png"];
|
|
||||||
|
|
||||||
for (const aspectRatio of ratios) {
|
|
||||||
const { body } = buildTaskBody({
|
|
||||||
...params, modelId: "gpt-image-2.6", imageUrls: references,
|
|
||||||
modelConfig: { imageGenConfig: { supportedImageSizes: ["1K"] } },
|
|
||||||
imageParams: { aspectRatio, imageSize: "1K" },
|
|
||||||
}, contract);
|
|
||||||
expect(body).toMatchObject({ size: "auto", aspect_ratio: aspectRatio, image: references, quality: "auto" });
|
|
||||||
expect(body).not.toHaveProperty("resolution");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("fixed-tier catalog models keep their declared tier for tall pixel presets", () => {
|
|
||||||
const [preset] = buildVip98kModelPresets([{
|
|
||||||
id: "gpt-image-2.6",
|
|
||||||
type: "image",
|
|
||||||
supported_resolutions: ["1K"],
|
|
||||||
invocation: {
|
|
||||||
kind: "tool", path: "/v1/images/generations",
|
|
||||||
input_schema: { properties: { size: { enum: ["1024x1024", "941x1672"] } } },
|
|
||||||
request_example: { model: "gpt-image-2.6", prompt: "", size: "1024x1024" },
|
|
||||||
},
|
|
||||||
}]);
|
|
||||||
expect(preset.defaultParams.imageSize).toBe("1K");
|
|
||||||
expect(preset.imageGenConfig).toMatchObject({
|
|
||||||
supports1K: true, supports2K: false, supports4K: false, supportedImageSizes: ["1K"],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("pixel-only image contracts use a supported size in the requested tier", () => {
|
test("pixel-only image contracts use a supported size in the requested tier", () => {
|
||||||
const result = buildTaskBody(params,invocation({size:{enum:["1024x1024","1280x720","2048x1152","3840x2160"]}},{size:"1024x1024"}));
|
const result = buildTaskBody(params,invocation({size:{enum:["1024x1024","1280x720","2048x1152","3840x2160"]}},{size:"1024x1024"}));
|
||||||
expect(result.body.size).toBe("2048x1152");
|
expect(result.body.size).toBe("2048x1152");
|
||||||
@ -113,24 +60,6 @@ test("square image dimensions agree with the requested resolution tier", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("automatic proportions stay automatic at every published resolution with references", () => {
|
|
||||||
const contract = invocation({
|
|
||||||
size: { enum: ["auto", "1024x1024", "2048x2048", "4096x4096", "1K", "2K", "4K"] },
|
|
||||||
resolution: { enum: ["1K", "2K", "4K"] },
|
|
||||||
aspect_ratio: { enum: ["auto", "1:1", "3:4", "16:9"] },
|
|
||||||
image: { type: "array", items: { type: "string" } },
|
|
||||||
}, { size: "1024x1024", aspect_ratio: "auto", response_format: "url" });
|
|
||||||
const imageUrls = ["https://example.com/one.png", "https://example.com/two.png"];
|
|
||||||
for (const imageSize of ["1K", "2K", "4K"]) {
|
|
||||||
const { body } = buildTaskBody({
|
|
||||||
...params, modelId: "nano-banana-2", imageUrls, imageParams: { imageSize, aspectRatio: "auto" },
|
|
||||||
}, contract);
|
|
||||||
expect(body).toMatchObject({
|
|
||||||
size: imageSize, resolution: imageSize, aspect_ratio: "auto", image: imageUrls, response_format: "url",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("4K uses the largest published square size for area-based image contracts", () => {
|
test("4K uses the largest published square size for area-based image contracts", () => {
|
||||||
const result=buildTaskBody({...params,imageParams:{imageSize:"4K",aspectRatio:"1:1"}},invocation({size:{enum:["1024x1024","2048x2048","2880x2880"]},resolution:{enum:["1K","2K","4K"]}}));
|
const result=buildTaskBody({...params,imageParams:{imageSize:"4K",aspectRatio:"1:1"}},invocation({size:{enum:["1024x1024","2048x2048","2880x2880"]},resolution:{enum:["1K","2K","4K"]}}));
|
||||||
expect(result.body).toMatchObject({size:"2880x2880",resolution:"4K"});
|
expect(result.body).toMatchObject({size:"2880x2880",resolution:"4K"});
|
||||||
@ -249,90 +178,3 @@ test("completed audio checkpoints retain the original provider and resumable tas
|
|||||||
const checkpoint={operation:"audio",provider:"vip98k",modelRef:"test",modelId:"gem-2.5-tts",providerId:"source",baseUrl:"https://relay.example",taskId:"original",url:"https://example.com/audio.wav",format:"wav"};
|
const checkpoint={operation:"audio",provider:"vip98k",modelRef:"test",modelId:"gem-2.5-tts",providerId:"source",baseUrl:"https://relay.example",taskId:"original",url:"https://example.com/audio.wav",format:"wav"};
|
||||||
expect(getAudioCheckpoint({request:{kind:"audio",params:{modelRef:"test"}},result:{upstreamAudio:checkpoint}})).toEqual(checkpoint);
|
expect(getAudioCheckpoint({request:{kind:"audio",params:{modelRef:"test"}},result:{upstreamAudio:checkpoint}})).toEqual(checkpoint);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("route-scoped image contracts take precedence over generic task examples", () => {
|
|
||||||
const selected = {...invocation({size:{type:'string'},image:{type:'array',maxItems:8}}),headers:{'X-Relay-Route-Option':'selected'}};
|
|
||||||
const generic = {...invocation({resolution:{enum:['1K','2K']},aspect_ratio:{enum:['1:1','16:9']},file_urls:{type:'array'}},{file_urls:[]}),kind:'task',path:'/extensions/v1/tasks'};
|
|
||||||
for(const imageCount of [0,1]) {
|
|
||||||
const resolved=selectVip98kTaskInvocation({modelId:'image',kind:'image',configuredInvocation:selected,configuredInvocations:[generic,selected],imageCount});
|
|
||||||
expect(resolved?.headers).toEqual({'X-Relay-Route-Option':'selected'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("native ratio and resolution contracts can use automatic pixels for non-square images", () => {
|
|
||||||
const contract=invocation({size:{enum:['auto','1024x1024','2048x2048','4096x4096']},resolution:{enum:['1K','2K','4K']},aspect_ratio:{enum:['1:1','16:9','9:16']}},{size:'1024x1024'});
|
|
||||||
for(const aspectRatio of ['16:9','9:16'])for(const imageSize of ['1K','2K','4K']) {
|
|
||||||
const result=buildTaskBody({...params,imageParams:{imageSize,aspectRatio}},contract);
|
|
||||||
expect(result.body).toMatchObject({size:'auto',resolution:imageSize,aspect_ratio:aspectRatio});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("reference limits inside allOf are enforced before submission and during import", () => {
|
|
||||||
const schema={properties:{model:{type:'string'},prompt:{type:'string'},images:{allOf:[{type:'array',maxItems:16},{maxItems:14}]}}};
|
|
||||||
const contract={...invocation({},{images:[]}),inputSchema:schema};
|
|
||||||
const images=Array.from({length:15},(_,i)=>`https://fixture.example/${i}.png`);
|
|
||||||
expect(()=>buildTaskBody({...params,imageUrls:images},contract)).toThrow('14');
|
|
||||||
const [model]=buildVip98kModelPresets([{id:'image',type:'image',invocation:{kind:'tool',path:contract.path,input_schema:schema,request_example:contract.requestExample}}]);
|
|
||||||
expect(model.imageGenConfig?.maxReferenceImages).toBe(14);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("quality and negative prompt have a single effective location", () => {
|
|
||||||
const metadata={quality:'high'};
|
|
||||||
const contract=invocation({quality:{const:'high'},negative_prompt:{type:'string'},negativePrompt:{type:'string'}},{metadata,negativePrompt:'example'});
|
|
||||||
const result=buildTaskBody({...params,imageParams:{quality:'auto',negativePrompt:'blurry'}},contract);
|
|
||||||
expect(result.body.metadata).toEqual({quality:'high'});
|
|
||||||
expect(result.body).not.toHaveProperty('quality');
|
|
||||||
expect(result.body.negative_prompt).toBe('blurry');
|
|
||||||
expect(result.body).not.toHaveProperty('negativePrompt');
|
|
||||||
expect(metadata).toEqual({quality:'high'});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("fixed resolution edit contracts determine the imported default", () => {
|
|
||||||
for(const resolution of ['2K','4K']){
|
|
||||||
const [model] = buildVip98kModelPresets([{
|
|
||||||
id: 'fixed-image', type: 'image',
|
|
||||||
invocation: {
|
|
||||||
kind: 'tool', path: '/v1/images/generations',
|
|
||||||
request_example: { model: 'fixed-image', prompt: 'test' },
|
|
||||||
input_schema: { properties: { size: { type: 'string' } } },
|
|
||||||
},
|
|
||||||
invocations: [{
|
|
||||||
kind: 'tool', path: '/v1/images/edits',
|
|
||||||
request_example: { model: 'fixed-image', prompt: 'test', file_urls: [] },
|
|
||||||
input_schema: { properties: {
|
|
||||||
file_urls: { type: 'array', maxItems: 16 }, size: { enum: ['auto'] },
|
|
||||||
resolution: { enum: [resolution] }, aspect_ratio: { enum: ['1:1', '16:9'] },
|
|
||||||
} },
|
|
||||||
}],
|
|
||||||
}]);
|
|
||||||
expect(model.defaultParams.imageSize).toBe(resolution);
|
|
||||||
expect(model.imageGenConfig?.supportedImageSizes).toEqual([resolution]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("video duration choices follow the selected resolution", () => {
|
|
||||||
const schema={properties:{duration:{minimum:1,maximum:15}},allOf:[{if:{properties:{resolution:{const:'1080p'}}},then:{properties:{duration:{maximum:10}}}}]};
|
|
||||||
const model={providerType:'vip98k',capabilities:{kind:'video',durationOptions:[5,10,15],vip98k:{invocation:{inputSchema:schema}}}};
|
|
||||||
expect(getCanvasVideoParameters(model,'text-to-video','1080P').durations).toEqual([5,10]);
|
|
||||||
expect(getCanvasVideoParameters(model,'text-to-video','720p').durations).toEqual([5,10,15]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("generation controls preserve false and zero in the declared wire fields", () => {
|
|
||||||
const contract=invocation({seed:{type:'integer'},watermark:{type:'boolean'},prompt_extend:{type:'boolean'},return_last_frame:{type:'boolean'},camera_fixed:{type:'boolean'}},{metadata:{watermark:true}});
|
|
||||||
const image=buildTaskBody({...params,imageParams:{seed:0,watermark:false,promptExtend:false}},contract).body;
|
|
||||||
expect(image).toMatchObject({seed:0,prompt_extend:false,metadata:{watermark:false}});
|
|
||||||
expect(image).not.toHaveProperty('watermark');
|
|
||||||
const video=buildTaskBody({...params,kind:'video',videoParams:{seed:0,watermark:false,returnLastFrame:true,cameraFixed:false}},contract).body;
|
|
||||||
expect(video).toMatchObject({seed:0,return_last_frame:true,camera_fixed:false,metadata:{watermark:false}});
|
|
||||||
const unsupported=buildTaskBody({...params,imageParams:{seed:0,watermark:false}},invocation({seed:false,watermark:false})).body;
|
|
||||||
expect(unsupported).not.toHaveProperty('seed');
|
|
||||||
expect(unsupported).not.toHaveProperty('watermark');
|
|
||||||
});
|
|
||||||
|
|
||||||
test("fixed quality routes replace stale quality choices before submission", () => {
|
|
||||||
const contract=invocation({quality:{enum:['auto']}},{quality:'auto'});
|
|
||||||
for(const quality of ['auto','low','medium','high']) {
|
|
||||||
expect(buildTaskBody({...params,imageParams:{quality}},contract).body.quality).toBe('auto');
|
|
||||||
}
|
|
||||||
expect(()=>buildTaskBody({...params,imageParams:{quality:'invalid'}},invocation({quality:{enum:['low','high']}}))).toThrow('图片质量');
|
|
||||||
});
|
|
||||||
|
|||||||
@ -970,17 +970,13 @@ test.describe("VIP98K reference-image routing", () => {
|
|||||||
properties: {
|
properties: {
|
||||||
aspect_ratio: { type: "string" },
|
aspect_ratio: { type: "string" },
|
||||||
image: { type: "array" },
|
image: { type: "array" },
|
||||||
|
size: {
|
||||||
|
enum: ["1024x1024", "2048x2048", "2880x2880"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Flare retains non-square pixel geometry", () => {
|
|
||||||
const contract = resolveVip98kTaskInvocation('gpt-image-2.5-flare', null);
|
|
||||||
const wide = buildTaskBody({apiKey:'fixture',modelId:'gpt-image-2.5-flare',kind:'image',prompt:'wide product',imageUrls:[],videoUrls:[],modelConfig:{},imageParams:{imageSize:'2K',aspectRatio:'16:9'}},contract);
|
|
||||||
expect(wide.body.size).toBe('2720x1536');
|
|
||||||
});
|
|
||||||
|
|
||||||
test("does not inherit multi-image support from broad authorized metadata", () => {
|
test("does not inherit multi-image support from broad authorized metadata", () => {
|
||||||
const presets = buildVip98kModelPresets([
|
const presets = buildVip98kModelPresets([
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user