();
const pricePolicy = Form.useWatch("pricePolicy") as LogicalModelMutation["pricePolicy"] | undefined;
const billingMode = Form.useWatch("billingMode") as LogicalModelMutation["billingMode"] | undefined;
const capability = Form.useWatch("capability") as CapabilityKind | undefined;
- const modes = [{ label: "按次", value: "fixed_request" }];
- if (capability === "video") modes.push({ label: "按秒", value: "per_second" });
+ const routes = (Form.useWatch("routes") || []) as RouteRuleRow[];
+ const enabledRoutes = routes.filter((route) => route.enabled);
+ const tokenBillingSupported =
+ capability === "text" ||
+ (capability === "video" &&
+ enabledRoutes.length > 0 &&
+ enabledRoutes.every((route) => {
+ const channelModel = channelModels.find((item) => item.id === route.channelModelId);
+ return modelProtocolSupportsTokenBilling(channelModel?.capability, channelModel?.protocol);
+ }));
+ const modes: Array<{ label: string; value: LogicalModelMutation["billingMode"]; disabled?: boolean }> = [{ label: "按次", value: "fixed_request" }];
+ if (capability === "video") {
+ modes.push({ label: "按秒", value: "per_second" });
+ modes.push({ label: "Token", value: "token", disabled: !tokenBillingSupported });
+ }
if (capability === "text") modes.push({ label: "Token", value: "token" });
+
+ useEffect(() => {
+ if (pricePolicy === "unified" && billingMode === "token" && !tokenBillingSupported) {
+ form.setFieldValue("billingMode", capability === "video" ? "per_second" : "fixed_request");
+ }
+ }, [billingMode, capability, form, pricePolicy, tokenBillingSupported]);
+
const changePolicy = (value: string | number) => {
const nextPolicy = value as LogicalModelMutation["pricePolicy"];
if (nextPolicy !== "unified") return;
- const supportedModes = modes.map((item) => item.value);
+ const supportedModes = modes.filter((item) => !item.disabled).map((item) => item.value);
if (!billingMode || !supportedModes.includes(billingMode)) {
form.setFieldValue("billingMode", capability === "text" ? "token" : capability === "video" ? "per_second" : "fixed_request");
}
@@ -639,18 +660,25 @@ function PricingFields() {
) : null}
+ {capability === "video" && !tokenBillingSupported ? Token 计费仅在所有启用供应线路都使用火山方舟视频协议时可用。
: null}
{billingMode === "token" ? (
-
-
+ capability === "video" ? (
+
-
-
-
-
-
-
-
+ ) : (
+
+
+
+
+
+
+
+
+
+
+
+ )
) : null}
>
) : (
@@ -666,6 +694,7 @@ function CreditsInput({ value = 0, onChange }: { value?: number; onChange?: (val
function logicalPriceLabel(item: AdminLogicalModel) {
if (item.pricePolicy === "channel") return 跟随供应价格;
+ if (item.billingMode === "token" && item.capability === "video") return 视频 {formatCredits(item.outputPriceMicrocredits)} / 百万 Token;
if (item.billingMode === "token")
return (