sync: 同步总仓库 luoguang/monkey-ai weiyuan@bfdfb339 的 web/ 改动
同步基准:总仓库 a2ca13cb(= 本仓库初始导入 d8f3aee2) 范围:a2ca13cb..bfdfb339 中触及 web/ 的提交(不含 web/.claude/settings.local.json) - 8490ac02 feat(aliyun): integrate Wan 3 and Qwen Image models - 2aff08ec perf(analytics): 运营看板概览改读汇总表,首屏从 19s 降到 0.4s - dc69335e feat(experience): 体验中心图像/视频创作升级(能力 schema、估价、新创作台) - b059c657 fix(org): 下线 /org/create 自助加入企业页与 POST /api/org/join - 4fcf47e6 fix(i18n): 修复中/英/韩/繁体多语言错乱,补齐日/越/泰译文 - e4c301d5 fix: merge enterprise task record date filters - c9369b95 feat: expose enterprise image and video task records - a410fee5 feat(claude): 无断点请求自动注入 cache_control 断点(方案 2) - 521b3376 feat(claude): 缓存命中率优化——上游粘性路由 + 缓存时长强制改写 - 73b615dd feat(pricing): 企业成员不论登录身份均按所属企业等级计价与扣费 - f73f55c3 feat(client): 新增 WeyAi 版本说明管理与公开读取接口 - 8cdf1994 fix(topup): reset amount when switching from PayPal - 93a4ac34 feat(baidu): configure Seedance liveness header by channel - cb1818c5 fix(weyai): 按评审修正内容清理竞态、默认适用端与中文退回(M21) - 04214d83 feat(weyai): WeyAi 内容管理与客户端内容接口(M21 第二部分) - e3c4a57c feat(weyai): 设置页新增 WeyAi 页签与内容专用 COS 桶(M21 第一部分) - b5ee8e70 fix(auth): 会话角色/状态以 DB 为准,修复提升管理员后管理接口报权限不足 - e4618fc2 fix: 修复企业看板日志聚合死循环导致 CPU 打满,并降低看板查询开销 - 584aad52 style(web): 个人中心侧边栏按 prettier 换行 - b8d87064 fix: 小程序教程隐藏充值后保留原步骤编号,企业充值判断直接用 isMiniProgramWebView - eee7f5b2 fix: 小程序里企业首页不落到充值页,隐藏钱包入口与教程充值步骤 - 8b254d49 fix: 小程序里隐藏企业充值入口与页面 - a67661b4 fix(web): 小程序里个人中心默认页跳过充值和发票,避免来回跳转 - cff6c543 feat(web): WeyAi 小程序里打开个人中心时不出现充值和开票 - c6c99eb6 feat(billing): Claude 全部缓存写入统一按 1h 倍率计费 - 0699d1bf fix(web): 小程序 web-view 里注册页同样只显示站内方式 - 04853331 feat(web): WeyAi 小程序 web-view 里登录页只显示站内登录方式
This commit is contained in:
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
OTHER_GROUP,
|
||||
RECENT_GROUP,
|
||||
RECENT_LIMIT,
|
||||
badgesOf,
|
||||
capabilityTags,
|
||||
flattenOptions,
|
||||
groupModels,
|
||||
incompatibilityOf,
|
||||
loadRecent,
|
||||
matchesQuery,
|
||||
moveActive,
|
||||
pushRecent,
|
||||
recentKeyOf,
|
||||
unitPriceOf,
|
||||
} from './modelPickerUtils.js';
|
||||
|
||||
const seedance = {
|
||||
model: 'doubao-seedance-1-5-pro',
|
||||
display_name: 'Seedance 1.5 Pro',
|
||||
series: 'seedance',
|
||||
badges: ['recommended', 'audio'],
|
||||
description: '电影级运镜',
|
||||
modes: ['text2video', 'image2video', 'first_last_frame'],
|
||||
params: [
|
||||
{
|
||||
key: 'resolution',
|
||||
type: 'chips',
|
||||
options: ['480P', '720P', '1080P'],
|
||||
default: '720P',
|
||||
},
|
||||
{
|
||||
key: 'duration',
|
||||
type: 'segmented',
|
||||
options: [{ value: 5 }, { value: 10 }],
|
||||
default: 5,
|
||||
},
|
||||
{ key: 'generate_audio', type: 'switch' },
|
||||
],
|
||||
pricing: {
|
||||
unit: 'second',
|
||||
by: 'resolution',
|
||||
price: 0.05,
|
||||
prices: { '480P': 0.02, '720P': 0.05, '1080P': 0.1 },
|
||||
currency: 'CNY',
|
||||
},
|
||||
};
|
||||
const kling = {
|
||||
model: 'kling-v2',
|
||||
series: 'kling',
|
||||
modes: ['text2video', 'image2video'],
|
||||
params: [{ key: 'duration', type: 'segmented', options: [5] }],
|
||||
};
|
||||
const wan = {
|
||||
model: 'wan2.5',
|
||||
series: 'seedance',
|
||||
modes: ['text2video', 'reference2video'],
|
||||
params: [],
|
||||
badges: ['new'],
|
||||
};
|
||||
const misc = { model: 'misc-video', modes: ['text2video'], params: [] };
|
||||
|
||||
const memoryStorage = () => {
|
||||
const data = {};
|
||||
return {
|
||||
data,
|
||||
getItem: (k) => (k in data ? data[k] : null),
|
||||
setItem: (k, v) => {
|
||||
data[k] = String(v);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
test('分组:按系列首次出现顺序,"其他"在最后,最近使用置顶', () => {
|
||||
const groups = groupModels([misc, seedance, kling, wan], {
|
||||
recent: ['kling-v2', 'gone-model'],
|
||||
});
|
||||
assert.deepEqual(
|
||||
groups.map((g) => g.key),
|
||||
[RECENT_GROUP, 'seedance', 'kling', OTHER_GROUP],
|
||||
);
|
||||
assert.deepEqual(
|
||||
groups[0].models.map((m) => m.model),
|
||||
['kling-v2'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
groups[1].models.map((m) => m.model),
|
||||
['doubao-seedance-1-5-pro', 'wan2.5'],
|
||||
);
|
||||
// vendor 作为系列缺失时的回退
|
||||
const byVendor = groupModels([{ model: 'x', vendor: 'OpenAI' }]);
|
||||
assert.equal(byVendor[0].key, 'OpenAI');
|
||||
});
|
||||
|
||||
test('搜索:多词匹配名称 / 展示名 / 介绍,搜索时不显示最近使用', () => {
|
||||
assert.equal(matchesQuery(seedance, 'seedance pro'), true);
|
||||
assert.equal(matchesQuery(seedance, '运镜'), true);
|
||||
assert.equal(matchesQuery(seedance, 'kling'), false);
|
||||
const groups = groupModels([seedance, kling], {
|
||||
recent: ['kling-v2'],
|
||||
query: 'kling',
|
||||
});
|
||||
assert.deepEqual(
|
||||
groups.map((g) => g.key),
|
||||
['kling'],
|
||||
);
|
||||
});
|
||||
|
||||
test('扁平选项 id 唯一(最近使用与系列中重复出现的模型)', () => {
|
||||
const groups = groupModels([seedance, kling], { recent: ['kling-v2'] });
|
||||
const opts = flattenOptions(groups, 'p');
|
||||
assert.equal(opts.length, 3);
|
||||
assert.equal(new Set(opts.map((o) => o.id)).size, 3);
|
||||
assert.ok(opts.every((o) => /^[\w-]+$/.test(o.id)));
|
||||
});
|
||||
|
||||
test('键盘移动循环', () => {
|
||||
assert.equal(moveActive(3, 2, 1), 0);
|
||||
assert.equal(moveActive(3, 0, -1), 2);
|
||||
assert.equal(moveActive(3, -1, 1), 0);
|
||||
assert.equal(moveActive(3, -1, -1), 2);
|
||||
assert.equal(moveActive(0, 0, 1), -1);
|
||||
});
|
||||
|
||||
test('能力标签:视频由模式 / 参数推导,含最长时长', () => {
|
||||
assert.deepEqual(
|
||||
capabilityTags('video', seedance).map((t) => t.key),
|
||||
['i2v', 'flf', 'audio', 'max_duration'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
capabilityTags('video', seedance).find((t) => t.key === 'max_duration')
|
||||
.values,
|
||||
{ n: 10 },
|
||||
);
|
||||
assert.deepEqual(
|
||||
capabilityTags('video', wan).map((t) => t.key),
|
||||
['reference'],
|
||||
);
|
||||
// 因系统配置禁用的模式不计入
|
||||
assert.deepEqual(
|
||||
capabilityTags('video', {
|
||||
modes: ['text2video'],
|
||||
disabled_modes: [{ mode: 'image2video' }],
|
||||
}),
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
test('能力标签:图像编辑与多图参考', () => {
|
||||
const img = {
|
||||
modes: ['text2image', 'edit'],
|
||||
inputs: { reference_images: { modes: ['edit'], max: 4 } },
|
||||
};
|
||||
assert.deepEqual(
|
||||
capabilityTags('image', img).map((t) => [t.key, t.values?.n]),
|
||||
[
|
||||
['edit', undefined],
|
||||
['reference', 4],
|
||||
],
|
||||
);
|
||||
assert.deepEqual(capabilityTags('image', { modes: ['text2image'] }), []);
|
||||
});
|
||||
|
||||
test('徽标只显示推荐 / 新', () => {
|
||||
assert.deepEqual(
|
||||
badgesOf(seedance).map((b) => b.label),
|
||||
['推荐'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
badgesOf(wan).map((b) => b.label),
|
||||
['新'],
|
||||
);
|
||||
});
|
||||
|
||||
test('单价:按当前参数取档位,缺省取参数默认档,无定价返回 null', () => {
|
||||
assert.deepEqual(unitPriceOf(seedance, { resolution: '1080p' }), {
|
||||
amount: 0.1,
|
||||
currency: 'CNY',
|
||||
unit: 'second',
|
||||
unitLabel: '秒',
|
||||
tier: '1080P',
|
||||
});
|
||||
assert.equal(unitPriceOf(seedance, {}).tier, '720P');
|
||||
// 档位缺失:退回默认价,不显示档位
|
||||
const r = unitPriceOf(seedance, { resolution: '4K' });
|
||||
assert.equal(r.amount, 0.05);
|
||||
assert.equal(r.tier, '');
|
||||
assert.equal(unitPriceOf(kling, {}), null);
|
||||
assert.equal(
|
||||
unitPriceOf({ pricing: { unit: 'task', price: 0, currency: 'CNY' } }),
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
unitPriceOf({ pricing: { unit: 'image', price: 0.2, currency: 'USD' } })
|
||||
.unitLabel,
|
||||
'张',
|
||||
);
|
||||
});
|
||||
|
||||
test('不兼容原因:非文生模式下不支持该模式的模型置灰并说明', () => {
|
||||
assert.equal(incompatibilityOf('video', kling, { mode: 'text2video' }), null);
|
||||
assert.equal(
|
||||
incompatibilityOf('video', seedance, { mode: 'first_last_frame' }),
|
||||
null,
|
||||
);
|
||||
assert.deepEqual(
|
||||
incompatibilityOf('video', kling, { mode: 'first_last_frame' }),
|
||||
{ key: '不支持{{mode}}', values: { mode: '首尾帧' } },
|
||||
);
|
||||
assert.deepEqual(
|
||||
incompatibilityOf('image', { modes: ['text2image'] }, { mode: 'edit' })
|
||||
.values,
|
||||
{ mode: '图生图' },
|
||||
);
|
||||
});
|
||||
|
||||
test('最近使用:置顶去重、限长,存储异常不抛错', () => {
|
||||
const storage = memoryStorage();
|
||||
let list = [];
|
||||
['a', 'b', 'c', 'd', 'e', 'b'].forEach((n) => {
|
||||
list = pushRecent(storage, 'video', n, list);
|
||||
});
|
||||
assert.equal(list.length, RECENT_LIMIT);
|
||||
assert.deepEqual(list, ['b', 'e', 'd', 'c']);
|
||||
assert.deepEqual(loadRecent(storage, 'video'), list);
|
||||
assert.deepEqual(loadRecent(storage, 'image'), []);
|
||||
storage.data[recentKeyOf('image')] = 'not json';
|
||||
assert.deepEqual(loadRecent(storage, 'image'), []);
|
||||
const throwing = {
|
||||
getItem: () => {
|
||||
throw new Error('x');
|
||||
},
|
||||
setItem: () => {
|
||||
throw new Error('x');
|
||||
},
|
||||
};
|
||||
assert.deepEqual(loadRecent(throwing, 'video'), []);
|
||||
assert.deepEqual(pushRecent(throwing, 'video', 'a', []), ['a']);
|
||||
});
|
||||
Reference in New Issue
Block a user