Compare commits
No commits in common. "main" and "codex/98k-image-resolution-20261116" have entirely different histories.
main
...
codex/98k-
@ -623,7 +623,7 @@ async function resolveReplacementProductIdentityProfile(params: {
|
||||
system:
|
||||
"你是高精度商品结构分析器。多张图片属于同一商品;请跨视角还原唯一结构身份,并明确每个视角最清楚的构件。",
|
||||
temperature: params.planningRuntime.kind === "local_moonshot" ? 1 : 0.1,
|
||||
maxOutputTokens: 1800,
|
||||
maxTokens: 1800,
|
||||
abortSignal: AbortSignal.timeout(
|
||||
params.planningRuntime.kind === "local_moonshot" ? 90_000 : 60_000,
|
||||
),
|
||||
@ -2376,7 +2376,7 @@ export async function analyzeReplacementReferenceImage(params: {
|
||||
},
|
||||
],
|
||||
temperature: 0,
|
||||
maxOutputTokens: 160,
|
||||
maxTokens: 160,
|
||||
abortSignal: AbortSignal.timeout(45_000),
|
||||
} as any);
|
||||
|
||||
@ -2679,7 +2679,7 @@ export async function analyzeReplacementExecutionPlan(params: {
|
||||
system:
|
||||
"你是高精度商品详情图场景规划器。你只分析当前参考图本身,负责理解这一屏的场景、机位、主体位置和人物需求,不要臆测或依赖其他输入图片。",
|
||||
temperature: params.planningRuntime.kind === "local_moonshot" ? 1 : 0.1,
|
||||
maxOutputTokens: 1600,
|
||||
maxTokens: 1600,
|
||||
abortSignal: AbortSignal.timeout(replacementScenePlanningTimeoutMs),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -264,29 +264,6 @@ export function chatMessagesHaveImageInput(messages: ChatMessage[]) {
|
||||
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) {
|
||||
switch (providerType) {
|
||||
case "bfl-image":
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
import { saveMessages } from "@/lib/db/queries";
|
||||
import type { ImageGenerationStatusStreamPayload } from "@/lib/canvas/image-generation-status";
|
||||
import { formatRequestFailure, getRequestFailureDetails } from "@/lib/request-error";
|
||||
import { createLogger } from "@/lib/observability/logger";
|
||||
import { safeWriteStreamChunk, type StreamWriter, writeAssistantTextChunk, writeStructuredDataChunk } from "./stream";
|
||||
|
||||
const logger = createLogger("chat.imageGenerationFailure");
|
||||
|
||||
export async function reportImageGenerationFailure(params: {
|
||||
writer: StreamWriter;
|
||||
chatId: string;
|
||||
@ -15,12 +12,6 @@ export async function reportImageGenerationFailure(params: {
|
||||
label: string;
|
||||
}) {
|
||||
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 = {
|
||||
phase: "failed",
|
||||
userMessageId: params.userMessageId,
|
||||
|
||||
@ -337,7 +337,6 @@ import {
|
||||
} from "./_lib/image-media";
|
||||
import {
|
||||
buildImageFallbackCandidates,
|
||||
canUseImageFallback,
|
||||
countChatMessageImageInputs,
|
||||
generateImageWithFailoverCandidate,
|
||||
getImageCrossProviderCandidates,
|
||||
@ -9217,11 +9216,8 @@ export async function POST(request: Request) {
|
||||
|
||||
// 🆕 尝试备用模型(支持跨服务商切换)
|
||||
let fallbackSuccess = false;
|
||||
const balanceBlockedProviders = new Set<string>();
|
||||
if (isProviderBalanceError(primaryError) && currentModelConfig?.providerId) balanceBlockedProviders.add(currentModelConfig.providerId);
|
||||
const triedFallbackModelIds = new Set<string>();
|
||||
for (const candidate of fallbackCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, buildMessagesForGemini(), balanceBlockedProviders)) continue;
|
||||
try {
|
||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||
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!`);
|
||||
break;
|
||||
} catch (fallbackError) {
|
||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||
@ -9297,7 +9292,6 @@ export async function POST(request: Request) {
|
||||
}).filter((candidate) => !triedFallbackModelIds.has(String(candidate.model.id || "")));
|
||||
|
||||
for (const candidate of crossProviderCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, buildMessagesForGemini(), balanceBlockedProviders)) continue;
|
||||
try {
|
||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||
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!`);
|
||||
break;
|
||||
} catch (fallbackError) {
|
||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||
@ -9991,7 +9984,7 @@ export async function POST(request: Request) {
|
||||
const balanceBlockedProviders = new Set<string>();
|
||||
if (isProviderBalanceError(primaryError) && currentModelEntry?.provider.id) balanceBlockedProviders.add(currentModelEntry.provider.id);
|
||||
for (const candidate of fallbackCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForAlibaba, balanceBlockedProviders)) continue;
|
||||
if (balanceBlockedProviders.has(candidate.provider.id)) continue;
|
||||
try {
|
||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||
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));
|
||||
|
||||
for (const candidate of crossProviderCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForAlibaba, balanceBlockedProviders)) continue;
|
||||
if (balanceBlockedProviders.has(candidate.provider.id)) continue;
|
||||
try {
|
||||
triedFallbackModelIds.add(String(candidate.model.id || ""));
|
||||
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;
|
||||
}
|
||||
let fallbackSuccess = false;
|
||||
const balanceBlockedProviders = new Set<string>();
|
||||
if (isProviderBalanceError(primaryError) && volcanoModelConfig?.providerId) balanceBlockedProviders.add(volcanoModelConfig.providerId);
|
||||
for (const candidate of fallbackCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForVolcano, balanceBlockedProviders)) continue;
|
||||
try {
|
||||
chatApiLogger.info(`[Chat API] 🔄 Volcano fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||
const fallbackResult = await generateImageWithFailoverCandidate({
|
||||
@ -10480,7 +10470,6 @@ export async function POST(request: Request) {
|
||||
chatApiLogger.info(`[Chat API] ✅ Volcano fallback model ${fallbackResult.displayName} succeeded!`);
|
||||
break;
|
||||
} catch (fallbackError) {
|
||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||
@ -10516,7 +10505,6 @@ export async function POST(request: Request) {
|
||||
});
|
||||
|
||||
for (const candidate of crossProviderCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForVolcano, balanceBlockedProviders)) continue;
|
||||
try {
|
||||
chatApiLogger.info(`[Chat API] 🔁 Volcano cross-provider failover attempt: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||
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})`);
|
||||
break;
|
||||
} catch (crossError) {
|
||||
if (isProviderBalanceError(crossError)) balanceBlockedProviders.add(candidate.provider.id);
|
||||
const crossErrorMessage = normalizeFailoverErrorMessage(crossError);
|
||||
if (shouldCooldownImageFallbackModel(crossErrorMessage)) {
|
||||
setImageFallbackModelCooldown(candidate.model.id, crossErrorMessage);
|
||||
@ -11341,10 +11328,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
let fallbackSuccess = false;
|
||||
const balanceBlockedProviders = new Set<string>();
|
||||
if (isProviderBalanceError(primaryError) && currentModelConfig?.providerId) balanceBlockedProviders.add(currentModelConfig.providerId);
|
||||
for (const candidate of fallbackCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForCrossProvider, balanceBlockedProviders)) continue;
|
||||
try {
|
||||
chatApiLogger.info(`[Chat API] 🔄 OpenAI-compatible fallback model: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||
const shouldUseOpenAICompatFallback =
|
||||
@ -11386,7 +11370,6 @@ export async function POST(request: Request) {
|
||||
chatApiLogger.info(`[Chat API] ✅ OpenAI-compatible fallback model ${candidate.model.displayName} succeeded!`);
|
||||
break;
|
||||
} catch (fallbackError) {
|
||||
if (isProviderBalanceError(fallbackError)) balanceBlockedProviders.add(candidate.provider.id);
|
||||
const fallbackErrorMessage = normalizeFailoverErrorMessage(fallbackError);
|
||||
if (shouldCooldownImageFallbackModel(fallbackErrorMessage)) {
|
||||
setImageFallbackModelCooldown(candidate.model.id, fallbackErrorMessage);
|
||||
@ -11423,7 +11406,6 @@ export async function POST(request: Request) {
|
||||
});
|
||||
|
||||
for (const candidate of crossProviderCandidates) {
|
||||
if (!canUseImageFallback(candidate, effectiveImageGenerationParams, messagesForCrossProvider, balanceBlockedProviders)) continue;
|
||||
try {
|
||||
chatApiLogger.info(`[Chat API] 🔁 OpenAI-compatible cross-provider failover: ${candidate.model.displayName} (${candidate.provider.type})`);
|
||||
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})`);
|
||||
break;
|
||||
} catch (crossError) {
|
||||
if (isProviderBalanceError(crossError)) balanceBlockedProviders.add(candidate.provider.id);
|
||||
const crossErrorMessage = normalizeFailoverErrorMessage(crossError);
|
||||
if (shouldCooldownImageFallbackModel(crossErrorMessage)) {
|
||||
setImageFallbackModelCooldown(candidate.model.id, crossErrorMessage);
|
||||
|
||||
@ -450,7 +450,7 @@ async function analyzeFunctionalShowcaseImage(params: {
|
||||
},
|
||||
],
|
||||
temperature: 0,
|
||||
maxOutputTokens: 120,
|
||||
maxTokens: 120,
|
||||
abortSignal: AbortSignal.timeout(25_000),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -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."
|
||||
: "你同时扮演高转化电商详情页的平面设计总监与营销总监。仅输出JSON。",
|
||||
temperature: params.isLocalMoonshot ? 1 : 0.1,
|
||||
maxOutputTokens: 2000,
|
||||
maxTokens: 2000,
|
||||
...(params.kimiOptions || {}),
|
||||
}, params.timeoutMs || DETAIL_PLAN_PREFLIGHT_TIMEOUT_MS);
|
||||
|
||||
@ -2040,7 +2040,7 @@ export async function POST(request: Request) {
|
||||
kimiDetailProfile: plannerKimiOptions.headers
|
||||
? {
|
||||
thinking: plannerKimiOptions.headers["x-detail-agent-kimi-thinking"],
|
||||
maxOutputTokens: plannerKimiOptions.maxOutputTokens,
|
||||
maxTokens: plannerKimiOptions.maxTokens,
|
||||
}
|
||||
: 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"}]}]}]}`,
|
||||
temperature: 0.25,
|
||||
...(localDetailAgentResolved ? { temperature: 1 } : {}),
|
||||
maxOutputTokens: 1800,
|
||||
maxTokens: 1800,
|
||||
...plannerKimiOptions,
|
||||
});
|
||||
|
||||
|
||||
@ -323,7 +323,7 @@ export async function POST(request: Request) {
|
||||
kimiDetailProfile: reviewKimiOptions.headers
|
||||
? {
|
||||
thinking: reviewKimiOptions.headers["x-detail-agent-kimi-thinking"],
|
||||
maxOutputTokens: reviewKimiOptions.maxOutputTokens,
|
||||
maxTokens: reviewKimiOptions.maxTokens,
|
||||
}
|
||||
: 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."
|
||||
: "你同时是高转化电商详情页的平面设计总监与营销总监。按严格专业标准评估,仅输出JSON。",
|
||||
temperature: localDetailAgentResolved ? 1 : 0.1,
|
||||
maxOutputTokens: 800,
|
||||
maxTokens: 800,
|
||||
...reviewKimiOptions,
|
||||
} as any);
|
||||
text = String(result?.text || "");
|
||||
|
||||
@ -114,7 +114,7 @@ export async function POST(request: NextRequest) {
|
||||
},
|
||||
],
|
||||
temperature: 0.2,
|
||||
maxOutputTokens: 1200,
|
||||
maxTokens: 1200,
|
||||
} as any);
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@ -15626,8 +15626,7 @@ function VideoTargetModuleComposer({
|
||||
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 resolution = executableResolutions.length && !executableResolutions.includes(normalizeVideoResolutionValue(current.resolution)) ? executableResolutions[0].toUpperCase() : current.resolution;
|
||||
const durations = getCanvasVideoParameters(target, activeMode, resolution || "720P").durations;
|
||||
const duration = durations.length && !durations.includes(normalizeVideoDurationValue(current.duration)) ? `${durations[0]}s` : current.duration;
|
||||
const duration = supported.durations.length && !supported.durations.includes(normalizeVideoDurationValue(current.duration)) ? `${supported.durations[0]}s` : current.duration;
|
||||
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};
|
||||
});
|
||||
@ -17930,7 +17929,7 @@ function VideoParameterEditor({
|
||||
const candidates = filterCanvasModels(modelOptions, audioRequired ? "audio-video" : "video", mode);
|
||||
const model = candidates.find(item => item.id === settings.model || item.modelId === settings.model) ||
|
||||
(!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 durationIndex = Math.max(0, options.durations.indexOf(normalizeVideoDurationValue(settings.duration)));
|
||||
return (
|
||||
|
||||
@ -5,7 +5,7 @@ import { useEffect, useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ChevronDown, ChevronUp, Link2, Scan, SlidersHorizontal, Sparkles } from "lucide-react";
|
||||
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 { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
@ -268,17 +268,6 @@ export function ImageParamsBar({
|
||||
availableAspectRatioOptions[0]?.value ||
|
||||
"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 options = getImageCountOptions();
|
||||
const fallbackCount = options[0] ?? 1;
|
||||
@ -297,7 +286,6 @@ export function ImageParamsBar({
|
||||
aspectRatio,
|
||||
imageSize,
|
||||
imageCount,
|
||||
quality: qualityOptions.some(option => option.value === raw.quality) ? raw.quality : qualityOptions[0]?.value || "auto",
|
||||
};
|
||||
};
|
||||
|
||||
@ -334,6 +322,12 @@ export function ImageParamsBar({
|
||||
...buildBaseParams(initialParams),
|
||||
});
|
||||
const [minimalParamsOpen, setMinimalParamsOpen] = useState(false);
|
||||
const qualityOptions = [
|
||||
{ label: "自动", value: "auto" },
|
||||
{ label: "高", value: "high" },
|
||||
{ label: "中", value: "medium" },
|
||||
{ label: "低", value: "low" },
|
||||
] as const;
|
||||
const qualityLabel =
|
||||
qualityOptions.find((option) => option.value === params.quality)?.label || "中";
|
||||
|
||||
|
||||
@ -1,127 +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 条模型参数配置已更新并回读核对。聊天回退与额度提示修复已上线,公开入口与正式进程版本一致;切换在旧进程工作归零后完成,未修改历史任务状态。
|
||||
|
||||
## 已知问题与验证边界
|
||||
|
||||
- 场景融合的首选模型配置指向一个视频模型,当前实现会排除该项并使用图片候选模型,因此实际没有将图片请求提交给视频接口;该首选配置尚未调整。
|
||||
- 离线参数核对不等于 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)
|
||||
@ -185,7 +185,7 @@ async function optimizeWithConfiguredQwenVisionModel(params: {
|
||||
},
|
||||
],
|
||||
temperature: 0,
|
||||
maxOutputTokens: 320,
|
||||
maxTokens: 320,
|
||||
abortSignal: AbortSignal.timeout(30_000),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ async function analyzeWithConfiguredQwenVisionModel(params: {
|
||||
},
|
||||
],
|
||||
temperature: 0,
|
||||
maxOutputTokens: 220,
|
||||
maxTokens: 220,
|
||||
abortSignal: AbortSignal.timeout(25_000),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -1737,7 +1737,7 @@ async function buildExecutionPlanWithAgent(
|
||||
.filter(Boolean)
|
||||
.join("\n\n"),
|
||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.1),
|
||||
maxOutputTokens: 420,
|
||||
maxTokens: 420,
|
||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||
} as any);
|
||||
|
||||
@ -1858,7 +1858,7 @@ async function generateAgentConversation(
|
||||
},
|
||||
],
|
||||
temperature: getCompatibleTextGenerationTemperature(visionModelConfig, 0.2),
|
||||
maxOutputTokens: 360,
|
||||
maxTokens: 360,
|
||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||
} as any);
|
||||
|
||||
@ -1920,7 +1920,7 @@ async function generateAgentConversation(
|
||||
system: systemPrompt,
|
||||
prompt,
|
||||
temperature: getCompatibleTextGenerationTemperature(reasoningModelConfig, 0.35),
|
||||
maxOutputTokens: 520,
|
||||
maxTokens: 520,
|
||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||
} as any);
|
||||
|
||||
@ -2002,7 +2002,7 @@ async function recommendImageParamsWithAgent(
|
||||
- negativePrompt 仅在明显需要避坑时填写。`,
|
||||
prompt: requestText,
|
||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.15),
|
||||
maxOutputTokens: 220,
|
||||
maxTokens: 220,
|
||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||
} as any);
|
||||
|
||||
@ -2095,7 +2095,7 @@ async function recommendVideoPlanWithAgent(
|
||||
- 避免抽象空话,必须可执行。`,
|
||||
prompt,
|
||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.2),
|
||||
maxOutputTokens: 720,
|
||||
maxTokens: 720,
|
||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||
} as any);
|
||||
|
||||
@ -2175,7 +2175,7 @@ async function refineRouteWithAgent(
|
||||
候选模型:
|
||||
${candidatesText}`,
|
||||
temperature: getCompatibleTextGenerationTemperature(plannerModelConfig, 0.1),
|
||||
maxOutputTokens: 120,
|
||||
maxTokens: 120,
|
||||
abortSignal: AbortSignal.timeout(AGENT_OPERATION_TIMEOUT_MS),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ export type DetailKimiPurpose = "plan" | "preflight" | "review" | "repair";
|
||||
export type DetailKimiGenerateOptions = {
|
||||
temperature?: number;
|
||||
topP?: number;
|
||||
maxOutputTokens?: number;
|
||||
maxTokens?: number;
|
||||
headers?: Record<string, string>;
|
||||
};
|
||||
|
||||
@ -80,7 +80,7 @@ export function buildDetailKimiGenerateOptions(params: {
|
||||
return {
|
||||
temperature: thinking === "enabled" ? 1 : 0.6,
|
||||
topP: 0.95,
|
||||
maxOutputTokens: getPurposeMaxTokens(params),
|
||||
maxTokens: getPurposeMaxTokens(params),
|
||||
headers: {
|
||||
[DETAIL_KIMI_THINKING_HEADER]: thinking,
|
||||
[DETAIL_KIMI_PROFILE_HEADER]: `detail-ui-${params.purpose}`,
|
||||
|
||||
@ -687,7 +687,7 @@ export async function optimizePromptWithLLM(params: {
|
||||
system: optimizerSystemPrompt,
|
||||
prompt: finalUserMessage,
|
||||
temperature: getCompatibleTextGenerationTemperature(selectedOptimizerModel, 0.2),
|
||||
maxOutputTokens: 200,
|
||||
maxTokens: 200,
|
||||
abortSignal: AbortSignal.timeout(12_000),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -153,30 +153,28 @@ export function createVip98kChatModel(params: {
|
||||
(!metadata.chatInvocation && invocation.protocol === "anthropic-messages"));
|
||||
const resolveModel = async (signal?: AbortSignal) => {
|
||||
signal?.throwIfAborted();
|
||||
if (!needsDiscovery) return { model, contract: invocation };
|
||||
if (!needsDiscovery) return model;
|
||||
const models = await awaitWithAbort(discoverContracts(root, baseFetch), signal);
|
||||
const contract = selectVip98kChatInvocation(models.get(params.modelId));
|
||||
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 {
|
||||
specificationVersion: model.specificationVersion,
|
||||
provider: model.provider,
|
||||
modelId: model.modelId,
|
||||
supportedUrls: model.supportedUrls,
|
||||
async doGenerate(options) {
|
||||
const active = await resolveModel(options.abortSignal);
|
||||
const result = await active.model.doGenerate(callOptions(options, active.contract));
|
||||
const activeModel = await resolveModel(options.abortSignal);
|
||||
const result = await activeModel.doGenerate(options);
|
||||
if (requiresToolCall(options) && !result.content.some((part) => part.type === "tool-call")) throw missingToolError();
|
||||
if (!result.content.some((part) => part.type === "tool-call" ||
|
||||
(part.type === "text" && part.text.trim()))) throw emptyResponseError();
|
||||
return result;
|
||||
},
|
||||
async doStream(options) {
|
||||
const active = await resolveModel(options.abortSignal);
|
||||
const result = await active.model.doStream(callOptions(options, active.contract));
|
||||
const activeModel = await resolveModel(options.abortSignal);
|
||||
const result = await activeModel.doStream(options);
|
||||
let usable = false;
|
||||
let toolCalled = false;
|
||||
let failed = false;
|
||||
|
||||
@ -28,8 +28,6 @@ import {
|
||||
normalizeVip98kInvocationHeaders,
|
||||
resolveVip98kImageTaskSize,
|
||||
selectVip98kTaskInvocation,
|
||||
vip98kReferenceLimit,
|
||||
getVip98kQualityOptions,
|
||||
type Vip98kTaskInvocation,
|
||||
} from "@/lib/ai/vip98k-task-invocation";
|
||||
import { VIP98K_BASE_URL, normalizeVip98kBaseUrl } from "@/lib/ai/vip98k-models";
|
||||
@ -1317,10 +1315,7 @@ async function submitTask(params: {
|
||||
|| [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))
|
||||
throw new ProviderTaskUncertainError(`供应商提交结果未确认,可能仍在处理,请勿重复生成:${getUserFacingImageGenerationErrorMessage({ message: errorMessage, status: response.status })} (HTTP ${response.status})`);
|
||||
throw Object.assign(new Error(`${errorMessage} (HTTP ${response.status})`), {
|
||||
status: response.status,
|
||||
providerRequestId: response.headers.get("x-request-id"),
|
||||
});
|
||||
throw new Error(`${errorMessage} (HTTP ${response.status})`);
|
||||
}
|
||||
|
||||
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 promptTitle = params.prompt.split(/\s+/).slice(0, 8).join(" ").slice(0, 80);
|
||||
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 ("displayName" in body || !invocation) {
|
||||
body.displayName = promptTitle || params.modelId;
|
||||
@ -1665,31 +1652,11 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
||||
}
|
||||
}
|
||||
if (negativePrompt) {
|
||||
const key = ["negative_prompt", "negativePrompt"].find(key =>
|
||||
invocationSupportsBodyField(invocation, key));
|
||||
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 ("negativePrompt" in body || !invocation) body.negativePrompt = negativePrompt;
|
||||
if ("negative_prompt" in body || !invocation) body.negative_prompt = negativePrompt;
|
||||
}
|
||||
if (quality && invocationSupportsBodyField(invocation, "quality")) {
|
||||
const options = getVip98kQualityOptions(invocation?.inputSchema);
|
||||
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);
|
||||
body.quality = quality;
|
||||
}
|
||||
const imageToolParamAliases = [
|
||||
["scaleFactor", "scale_factor"],
|
||||
@ -1731,8 +1698,9 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
||||
delete body.size;
|
||||
}
|
||||
const imageBindingKeys = bindVip98kImages(body, params.imageUrls, invocation?.inputSchema);
|
||||
const imageProperties = toRecord(invocation?.inputSchema?.properties) || {};
|
||||
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 (params.imageUrls.length > 0 && !invocation && imageBindingKeys.length === 0) {
|
||||
@ -1791,18 +1759,13 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
||||
}) : [];
|
||||
const selectedRatio = aspectRatio || "1:1";
|
||||
if (ratios.includes(selectedRatio)) body.size = selectedRatio;
|
||||
else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution;
|
||||
else if (pixels.length && (resolution || aspectRatio)) {
|
||||
const [rw, rh] = selectedRatio.split(":").map(Number);
|
||||
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("当前模型不支持所选图片比例");
|
||||
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));
|
||||
body.size = matching[0].size;
|
||||
}
|
||||
if (!matching.length) throw Error("当前模型不支持所选图片比例");
|
||||
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));
|
||||
body.size = matching[0].size;
|
||||
}
|
||||
if (ratios.length || pixels.length) {
|
||||
const suffix = "\n\n[Output constraints]";
|
||||
|
||||
@ -55,7 +55,7 @@ export async function buildDirectAgentImageAnalysisAnswer(params: {
|
||||
"请用中文直接回答,不要复述“根据摘要/根据图片”,也不要输出多余寒暄。",
|
||||
].join("\n\n"),
|
||||
temperature: 0.2,
|
||||
maxOutputTokens: 320,
|
||||
maxTokens: 320,
|
||||
abortSignal: AbortSignal.timeout(20_000),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -1624,7 +1624,7 @@ export async function summarizeImageForExecutionReport(params: {
|
||||
...(compatibleTemperature !== undefined
|
||||
? { temperature: compatibleTemperature }
|
||||
: {}),
|
||||
maxOutputTokens: 120,
|
||||
maxTokens: 120,
|
||||
abortSignal: AbortSignal.timeout(attemptTimeoutMs),
|
||||
} as any);
|
||||
|
||||
@ -2251,7 +2251,7 @@ ${historyText}
|
||||
},
|
||||
],
|
||||
...(analyzerTemperature !== undefined ? { temperature: analyzerTemperature } : {}),
|
||||
maxOutputTokens: 360,
|
||||
maxTokens: 360,
|
||||
abortSignal: AbortSignal.timeout(ANALYZER_TIMEOUT_MS),
|
||||
}
|
||||
: {
|
||||
@ -2259,7 +2259,7 @@ ${historyText}
|
||||
system: ANALYZER_SYSTEM_PROMPT,
|
||||
prompt: userMessage,
|
||||
...(analyzerTemperature !== undefined ? { temperature: analyzerTemperature } : {}),
|
||||
maxOutputTokens: 300,
|
||||
maxTokens: 300,
|
||||
abortSignal: AbortSignal.timeout(ANALYZER_TIMEOUT_MS),
|
||||
};
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ export type Vip98kChatInvocation = {
|
||||
protocol: "openai-chat" | "openai-responses" | "anthropic-messages";
|
||||
path: "/v1/chat/completions" | "/v1/responses" | "/v1/messages";
|
||||
headers: Record<string, string>;
|
||||
omitSampling?: boolean;
|
||||
};
|
||||
|
||||
function record(value: unknown): RecordValue | null {
|
||||
@ -57,18 +56,10 @@ export function selectVip98kChatInvocation(value: unknown): Vip98kChatInvocation
|
||||
});
|
||||
const selected = candidates[0];
|
||||
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 {
|
||||
protocol: selected.path === "/v1/messages" ? "anthropic-messages" : selected.path === "/v1/responses" ? "openai-responses" : "openai-chat",
|
||||
path: selected.path as Vip98kChatInvocation["path"],
|
||||
headers: getVip98kInvocationHeaders(selected.headers),
|
||||
...(fixedSampling ? { omitSampling: true } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -5,8 +5,6 @@ import {
|
||||
hasVerifiedVip98kOpenAiImageArrayContract,
|
||||
normalizeVip98kInvocationHeaders,
|
||||
getVip98kImageBindingKeys,
|
||||
vip98kReferenceLimit,
|
||||
selectVip98kTaskInvocation,
|
||||
} from "@/lib/ai/vip98k-task-invocation";
|
||||
import { selectVip98kChatInvocation, vip98kChatSupportsVision } from "./vip98k-chat-contract";
|
||||
|
||||
@ -570,7 +568,7 @@ function getSupportedImageSizes(model: Vip98kCatalogModel) {
|
||||
}
|
||||
const primary = toRecord(toRecord(model.invocation?.input_schema)?.properties) || {};
|
||||
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));
|
||||
const schemaSizes = getInvocationCandidates(model).flatMap((invocation) => {
|
||||
const properties =
|
||||
toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
||||
@ -754,11 +752,7 @@ function createImagePreset(
|
||||
"ratio",
|
||||
"aspect-ratio",
|
||||
].some((key) => invocationKeys.has(key)) || hasVerifiedVip98kOpenAiImageArrayContract(modelId);
|
||||
const supportsQuality = getInvocationCandidates(model).some(invocation => {
|
||||
const field = toRecord(toRecord(invocation.input_schema)?.properties)?.quality;
|
||||
return field !== false && Boolean(field || invocation.request_example?.quality !== undefined) &&
|
||||
!toRecord(field)?.const;
|
||||
});
|
||||
const supportsQuality = invocationKeys.has("quality");
|
||||
// Flare repeatedly returns 3:4/4:3 for 4:5/5:4, even with aspect_ratio supplied.
|
||||
const declaredRatios = getInvocationCandidates(model).flatMap(invocation => {
|
||||
const props = toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
||||
@ -773,17 +767,14 @@ function createImagePreset(
|
||||
: []),
|
||||
...(supportsReferenceImages ? ["image-to-image", "reference-images"] : []),
|
||||
];
|
||||
const metadata = getVip98kMetadata(model, "image");
|
||||
const referenceInvocation = selectVip98kTaskInvocation({
|
||||
modelId, kind: "image", imageCount: 1,
|
||||
configuredInvocation: metadata.invocation,
|
||||
configuredInvocations: metadata.invocations,
|
||||
const declaredReferenceLimits = getInvocationCandidates(model).flatMap(invocation => {
|
||||
const properties = toRecord(toRecord(invocation.input_schema)?.properties) || {};
|
||||
return ["file_urls", "image", "images", "reference_images"].flatMap(key => {
|
||||
const limit = toRecord(properties[key])?.maxItems;
|
||||
return typeof limit === "number" && limit > 0 ? [limit] : [];
|
||||
});
|
||||
});
|
||||
const declaredReferenceLimits = getVip98kImageBindingKeys(referenceInvocation).flatMap(key => {
|
||||
const limit = vip98kReferenceLimit(referenceInvocation?.inputSchema, key);
|
||||
return typeof limit === "number" && limit > 0 ? [limit] : [];
|
||||
});
|
||||
const maxReferenceImages = declaredReferenceLimits.length ? Math.min(...declaredReferenceLimits) : supportsMultiImageReference
|
||||
const maxReferenceImages = declaredReferenceLimits.length ? Math.max(...declaredReferenceLimits) : supportsMultiImageReference
|
||||
? 8
|
||||
: supportsReferenceImages
|
||||
? 1
|
||||
@ -814,7 +805,7 @@ function createImagePreset(
|
||||
supportedAspectRatios,
|
||||
supportsMultiImageReference,
|
||||
maxReferenceImages,
|
||||
vip98k: metadata,
|
||||
vip98k: getVip98kMetadata(model, "image"),
|
||||
},
|
||||
defaultParams: {
|
||||
provider: "vip98k",
|
||||
@ -850,7 +841,7 @@ function createImagePreset(
|
||||
},
|
||||
enableLoadingPlaceholder: true,
|
||||
loadingColor: "yellow",
|
||||
vip98k: metadata,
|
||||
vip98k: getVip98kMetadata(model, "image"),
|
||||
},
|
||||
sortOrder: TYPE_SORT_ORDER.image + index,
|
||||
};
|
||||
|
||||
@ -316,32 +316,6 @@ function scoreReferenceInvocation(invocation: Vip98kTaskInvocation) {
|
||||
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> } {
|
||||
if (contentType?.split(";", 1)[0].trim() !== "multipart/form-data") {
|
||||
return { body: JSON.stringify(body), headers: { "Content-Type": contentType || "application/json" } };
|
||||
@ -382,22 +356,14 @@ export function selectVip98kTaskInvocation(params: {
|
||||
);
|
||||
|
||||
if ((params.imageCount || 0) > 0) {
|
||||
const references = candidates.filter(invocationSupportsVip98kImages);
|
||||
const routedReferences = references.filter(candidate =>
|
||||
getVip98kInvocationHeaders(candidate.headers)["X-Relay-Route-Option"]);
|
||||
const referenceInvocation = (routedReferences.length ? routedReferences : references)
|
||||
const referenceInvocation = candidates
|
||||
.filter(invocationSupportsVip98kImages)
|
||||
.sort((a, b) => scoreReferenceInvocation(b) - scoreReferenceInvocation(a))[0];
|
||||
if (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) {
|
||||
const textImageTask = candidates.find(candidate => {
|
||||
const properties = candidate.inputSchema?.properties as Record<string, unknown> | undefined;
|
||||
@ -483,6 +449,7 @@ function createVerifiedOpenAiImageInvocation(modelId: string) {
|
||||
|
||||
function addVerifiedOpenAiImageFields(
|
||||
invocation: Vip98kTaskInvocation,
|
||||
modelId: string,
|
||||
): Vip98kTaskInvocation {
|
||||
const inputSchema = invocation.inputSchema || {};
|
||||
const properties =
|
||||
@ -501,8 +468,16 @@ function addVerifiedOpenAiImageFields(
|
||||
...inputSchema,
|
||||
properties: {
|
||||
...properties,
|
||||
image: properties.image ?? { items: { type: "string" }, type: "array" },
|
||||
aspect_ratio: properties.aspect_ratio ?? { type: "string" },
|
||||
image: { items: { type: "string" }, type: "array" },
|
||||
aspect_ratio: { type: "string" },
|
||||
...(hasVerifiedVip98kGptImage25ResolutionTiers(modelId)
|
||||
? {
|
||||
size: {
|
||||
enum: ["1024x1024", "2048x2048", "2880x2880"],
|
||||
type: "string",
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -524,7 +499,7 @@ export function resolveVip98kTaskInvocation(
|
||||
invocationTargetsModel(configuredInvocation, normalizedModelId)
|
||||
? configuredInvocation
|
||||
: createVerifiedOpenAiImageInvocation(modelId);
|
||||
return addVerifiedOpenAiImageFields(invocation);
|
||||
return addVerifiedOpenAiImageFields(invocation, normalizedModelId);
|
||||
}
|
||||
const processingRequest = KNOWN_IMAGE_PROCESSING_TOOL_REQUESTS[normalizedModelId];
|
||||
if (processingRequest) {
|
||||
|
||||
@ -18,7 +18,6 @@ const PROVIDER_BALANCE_PATTERNS = [
|
||||
/\b(?:exceeded_current_quota|pre_consume_token_quota_failed)\b/i,
|
||||
/\btoken quota 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(?:billing_hard_limit_reached|payment_required)\b/i,
|
||||
];
|
||||
|
||||
@ -259,7 +259,7 @@ async function interpretStoryboardCommandWithLLM(params: {
|
||||
.filter(Boolean)
|
||||
.join("\n\n"),
|
||||
temperature: 0.1,
|
||||
maxOutputTokens: 200,
|
||||
maxTokens: 200,
|
||||
abortSignal: AbortSignal.timeout(12000),
|
||||
} as any);
|
||||
|
||||
|
||||
@ -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 scoped = record(record(caps.modeConstraints || caps.constraints)[mode || ""]);
|
||||
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 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 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 {
|
||||
ratios: strings(scoped.ratioOptions || caps.supportedRatios),
|
||||
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"),
|
||||
};
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@ export default defineConfig({
|
||||
/routes\/video-canvas-media-import\.test\.ts/,
|
||||
/routes\/video-canvas-toolbar-jobs\.test\.ts/,
|
||||
/routes\/image-provider-error-classification\.test\.ts/,
|
||||
/routes\/chat-image-fallback-contract\.test\.ts/,
|
||||
/routes\/image-generation-status\.test\.ts/,
|
||||
/routes\/canvas-agent-runtime-image-failover\.test\.ts/,
|
||||
/routes\/video-canvas-audio-remote\.test\.ts/,
|
||||
|
||||
@ -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);
|
||||
});
|
||||
@ -37,26 +37,3 @@ test("late failures remain associated with their original user request", () => {
|
||||
expect(findImageGenerationFailure(messages, "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"]);
|
||||
});
|
||||
|
||||
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", () => {
|
||||
const error = Object.assign(new Error("余额不足,请点击充值页面续费(HTTP 429)"), { status: 429 });
|
||||
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);
|
||||
});
|
||||
|
||||
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", () => {
|
||||
const model = {
|
||||
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] }] } }));
|
||||
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);
|
||||
});
|
||||
|
||||
@ -178,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"};
|
||||
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: {
|
||||
aspect_ratio: { type: "string" },
|
||||
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", () => {
|
||||
const presets = buildVip98kModelPresets([
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user