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:
qiubaishen
2026-11-10 11:05:34 +08:00
parent d8f3aee261
commit 6160a23117
275 changed files with 38656 additions and 7694 deletions
+558
View File
@@ -0,0 +1,558 @@
/*
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 {
PROMPT_HISTORY_MAX,
ROLE_FRAMES,
ROLE_REFERENCE,
acceptsImages,
activeImagesOf,
backToImage2Video,
insertAt,
legalModesForCount,
loadPromptHistory,
loadRoleMemory,
mappingAfterMove,
mappingAfterRemove,
missingFrameOf,
modeCapacity,
moveItem,
planImageUpload,
promptHistoryKeyOf,
pushPromptHistory,
rememberRole,
rewriteImageRefs,
roleMemoryKeyOf,
roleOfMode,
savePromptHistory,
suggestImageModel,
templateModelFor,
templateParamsFor,
templateParamsSummary,
usesImageRefs,
} from './creationDock.js';
// 全能力视频模型:图生 / 首尾帧 / 参考图(≤3)
const VIDEO_FULL = {
model: 'seedance',
series: 'Seedance',
modes: ['text2video', 'image2video', 'first_last_frame', 'reference2video'],
inputs: {
first_frame: { modes: ['image2video', 'first_last_frame'] },
last_frame: { modes: ['first_last_frame'] },
reference_images: { modes: ['reference2video'], max: 3 },
},
};
// 只支持图生的视频模型
const VIDEO_I2V = {
model: 'kling',
series: 'Kling',
modes: ['text2video', 'image2video'],
inputs: { first_frame: { modes: ['image2video'] } },
};
const VIDEO_TEXT = { model: 'veo', series: 'Veo', modes: ['text2video'] };
const IMAGE_EDIT = {
model: 'gpt-image',
modes: ['text2image', 'edit'],
inputs: { reference_images: { modes: ['edit'], max: 4 } },
};
const IMAGE_TEXT = { model: 'dall-e', modes: ['text2image'] };
const memoryStorage = () => {
const map = new Map();
return {
getItem: (k) => (map.has(k) ? map.get(k) : null),
setItem: (k, v) => map.set(k, String(v)),
map,
};
};
test('roles and ref modes', () => {
assert.equal(roleOfMode('image2video'), ROLE_FRAMES);
assert.equal(roleOfMode('first_last_frame'), ROLE_FRAMES);
assert.equal(roleOfMode('reference2video'), ROLE_REFERENCE);
assert.equal(roleOfMode('edit'), ROLE_REFERENCE);
assert.equal(roleOfMode('text2video'), '');
assert.equal(usesImageRefs('edit'), true);
assert.equal(usesImageRefs('first_last_frame'), false);
});
test('modeCapacity / legalModesForCount', () => {
assert.deepEqual(modeCapacity('video', VIDEO_FULL, 'text2video'), {
min: 0,
max: 0,
});
assert.deepEqual(modeCapacity('video', VIDEO_FULL, 'first_last_frame'), {
min: 2,
max: 2,
});
assert.deepEqual(modeCapacity('video', VIDEO_FULL, 'reference2video'), {
min: 1,
max: 3,
});
assert.deepEqual(modeCapacity('image', IMAGE_EDIT, 'edit'), {
min: 1,
max: 4,
});
assert.deepEqual(legalModesForCount('video', VIDEO_FULL, 1), [
'image2video',
'reference2video',
]);
assert.deepEqual(legalModesForCount('video', VIDEO_FULL, 2), [
'first_last_frame',
'reference2video',
]);
assert.deepEqual(legalModesForCount('video', VIDEO_FULL, 3), [
'reference2video',
]);
assert.deepEqual(legalModesForCount('video', VIDEO_I2V, 2), []);
assert.equal(acceptsImages('video', VIDEO_TEXT), false);
assert.equal(acceptsImages('image', IMAGE_EDIT), true);
});
test('planImageUpload: single legal mode switches directly', () => {
const r = planImageUpload({
kind: 'video',
model: VIDEO_I2V,
mode: 'text2video',
images: {},
count: 1,
});
assert.deepEqual(r, {
type: 'place',
mode: 'image2video',
targets: [{ key: 'first_frame' }],
});
const three = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'text2video',
images: {},
count: 3,
});
assert.equal(three.mode, 'reference2video');
assert.equal(three.targets.length, 3);
const img = planImageUpload({
kind: 'image',
model: IMAGE_EDIT,
mode: 'text2image',
images: {},
count: 2,
});
assert.equal(img.type, 'place');
assert.equal(img.mode, 'edit');
assert.equal(img.targets.length, 2);
});
test('planImageUpload: ambiguous count asks, remembered role is reused', () => {
const ask = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'text2video',
images: {},
count: 2,
});
assert.deepEqual(ask, {
type: 'choose',
choices: [
{ role: ROLE_FRAMES, mode: 'first_last_frame' },
{ role: ROLE_REFERENCE, mode: 'reference2video' },
],
});
const reuse = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'text2video',
images: {},
count: 2,
rememberedRole: ROLE_FRAMES,
});
assert.equal(reuse.mode, 'first_last_frame');
assert.equal(reuse.remembered, true);
assert.deepEqual(reuse.targets, [
{ key: 'first_frame' },
{ key: 'last_frame' },
]);
const one = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'text2video',
images: {},
count: 1,
rememberedRole: ROLE_REFERENCE,
});
assert.equal(one.mode, 'reference2video');
});
test('planImageUpload: existing image mode fills empty slots only', () => {
const r = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'first_last_frame',
images: { first_frame: { id: 'a' } },
count: 1,
});
assert.deepEqual(r, {
type: 'place',
mode: 'first_last_frame',
targets: [{ key: 'last_frame' }],
});
// 首帧已有 + 再加 2 张 = 3 张:只有参考图模式合法 → 重新推断并切换
const regroup = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'first_last_frame',
images: { first_frame: { id: 'a' } },
count: 2,
});
assert.equal(regroup.mode, 'reference2video');
assert.equal(regroup.regrouped, true);
const full = planImageUpload({
kind: 'video',
model: VIDEO_I2V,
mode: 'image2video',
images: { first_frame: { id: 'a' } },
count: 1,
});
assert.deepEqual(full.targets, []);
assert.equal(full.truncated, 1);
});
test('planImageUpload: unsupported model and over-limit', () => {
assert.deepEqual(
planImageUpload({
kind: 'video',
model: VIDEO_TEXT,
mode: 'text2video',
images: {},
count: 1,
}),
{ type: 'unsupported' },
);
const over = planImageUpload({
kind: 'image',
model: IMAGE_EDIT,
mode: 'text2image',
images: {},
count: 6,
});
assert.equal(over.mode, 'edit');
assert.equal(over.targets.length, 4);
assert.equal(over.truncated, 2);
});
test('suggestImageModel prefers same series, never locked', () => {
const models = [
VIDEO_TEXT,
{ ...VIDEO_FULL, model: 'locked', level_locked: true },
VIDEO_I2V,
{ ...VIDEO_FULL, model: 'veo-i2v', series: 'Veo' },
];
assert.equal(
suggestImageModel('video', models, VIDEO_TEXT, 1).model,
'veo-i2v',
);
assert.equal(
suggestImageModel('video', [VIDEO_TEXT, VIDEO_I2V], VIDEO_TEXT, 2).model,
'kling',
);
assert.equal(suggestImageModel('image', [IMAGE_TEXT], IMAGE_TEXT, 1), null);
});
test('missingFrameOf / backToImage2Video', () => {
const first = { id: 'f' };
const last = { id: 'l' };
assert.equal(
missingFrameOf('video', VIDEO_FULL, 'first_last_frame', {
first_frame: first,
}),
'last_frame',
);
assert.equal(
missingFrameOf('video', VIDEO_FULL, 'first_last_frame', {
last_frame: last,
}),
'first_frame',
);
assert.equal(missingFrameOf('video', VIDEO_FULL, 'first_last_frame', {}), '');
assert.equal(
missingFrameOf('video', VIDEO_FULL, 'image2video', { first_frame: first }),
'',
);
assert.deepEqual(backToImage2Video(VIDEO_FULL, { last_frame: last }), {
mode: 'image2video',
images: { first_frame: last, last_frame: null, reference_images: [] },
});
assert.equal(
backToImage2Video(VIDEO_FULL, { first_frame: first }).images.first_frame,
first,
);
assert.equal(backToImage2Video(VIDEO_TEXT, { first_frame: first }), null);
});
test('role memory roundtrip, invalid entries dropped, storage errors tolerated', () => {
const storage = memoryStorage();
let mem = loadRoleMemory(storage, 'video');
assert.deepEqual(mem, {});
mem = rememberRole(storage, 'video', mem, 'seedance', ROLE_REFERENCE);
mem = rememberRole(storage, 'video', mem, 'x', 'bogus');
assert.deepEqual(loadRoleMemory(storage, 'video'), {
seedance: ROLE_REFERENCE,
});
storage.setItem(roleMemoryKeyOf('image'), '{"a":"frames","b":1}');
assert.deepEqual(loadRoleMemory(storage, 'image'), { a: ROLE_FRAMES });
storage.setItem(roleMemoryKeyOf('image'), 'not json');
assert.deepEqual(loadRoleMemory(storage, 'image'), {});
const broken = {
getItem: () => {
throw new Error('denied');
},
setItem: () => {
throw new Error('denied');
},
};
assert.deepEqual(loadRoleMemory(broken, 'video'), {});
assert.deepEqual(rememberRole(broken, 'video', {}, 'm', ROLE_FRAMES), {
m: ROLE_FRAMES,
});
});
test('prompt reference rewriting on remove and reorder', () => {
assert.deepEqual(mappingAfterRemove(3, 0), { 1: null, 2: 1, 3: 2 });
assert.deepEqual(mappingAfterRemove(3, 1), { 1: 1, 2: null, 3: 2 });
assert.deepEqual(mappingAfterMove(3, 2, 0), { 3: 1, 1: 2, 2: 3 });
assert.deepEqual(mappingAfterMove(2, 5, 0), { 1: 1, 2: 2 });
const p = '把「图1」的人物放进「图2」的场景,参考图3 的光线';
assert.equal(
rewriteImageRefs(p, mappingAfterRemove(3, 0)),
'把的人物放进「图1」的场景,参考图2 的光线',
);
assert.equal(
rewriteImageRefs(p, mappingAfterMove(3, 0, 1)),
'把「图2」的人物放进「图1」的场景,参考图3 的光线',
);
// 两位数编号不被拆开;映射外的编号保持原样
assert.equal(rewriteImageRefs('图12 和 图1', { 1: 2 }), '图12 和 图2');
assert.equal(rewriteImageRefs('', { 1: 2 }), '');
assert.equal(rewriteImageRefs('a b 图1', { 1: 1 }), 'a b 图1');
});
test('moveItem / insertAt', () => {
assert.deepEqual(moveItem(['a', 'b', 'c'], 2, 0), ['c', 'a', 'b']);
assert.deepEqual(moveItem(['a'], 3, 0), ['a']);
assert.deepEqual(insertAt('ab', 1, 'X'), { text: 'aXb', caret: 2 });
assert.deepEqual(insertAt('ab', undefined, 'X'), { text: 'abX', caret: 3 });
});
test('templateParamsFor keeps only legal values', () => {
const params = [
{ key: 'aspect_ratio', type: 'ratio', options: ['16:9', '9:16'] },
{ key: 'duration', type: 'segmented', options: [5, 10] },
{ key: 'generate_audio', type: 'switch' },
];
assert.deepEqual(
templateParamsFor(params, {
aspect_ratio: '1:1',
duration: '10',
generate_audio: true,
unknown: 1,
}),
{ duration: 10, generate_audio: true },
);
const sizeParams = [
{
key: 'size',
type: 'size',
options: ['1024x1024', '1536x1024', '1024x1536'],
},
];
assert.deepEqual(templateParamsFor(sizeParams, { aspect_ratio: '3:2' }), {
size: '1536x1024',
});
assert.deepEqual(templateParamsFor(sizeParams, { aspect_ratio: '16:9' }), {});
});
test('prompt history keeps the latest unique prompts', () => {
const storage = (() => {
const data = {};
return {
getItem: (k) => (k in data ? data[k] : null),
setItem: (k, v) => {
data[k] = String(v);
},
};
})();
assert.deepEqual(loadPromptHistory(storage, 'image'), []);
let list = savePromptHistory(storage, 'image', [], ' a cat ');
list = savePromptHistory(storage, 'image', list, 'dog');
list = savePromptHistory(storage, 'image', list, 'a cat');
assert.deepEqual(list, ['a cat', 'dog']);
assert.deepEqual(loadPromptHistory(storage, 'image'), ['a cat', 'dog']);
assert.deepEqual(loadPromptHistory(storage, 'video'), []);
assert.deepEqual(pushPromptHistory(list, ' '), list);
const many = Array.from({ length: 15 }, (_, i) => `p${i}`).reduce(
(acc, p) => pushPromptHistory(acc, p),
[],
);
assert.equal(many.length, PROMPT_HISTORY_MAX);
assert.equal(many[0], 'p14');
storage.setItem(promptHistoryKeyOf('image'), '{bad');
assert.deepEqual(loadPromptHistory(storage, 'image'), []);
});
test('planImageUpload: overflow in image mode re-runs mode inference', () => {
const a = { id: 'a' };
// 图生(首帧已有)再加 1 张 → 首尾帧 / 参考图都合法 → 询问
const ask = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'image2video',
images: { first_frame: a },
count: 1,
});
assert.deepEqual(ask, {
type: 'choose',
choices: [
{ role: ROLE_FRAMES, mode: 'first_last_frame' },
{ role: ROLE_REFERENCE, mode: 'reference2video' },
],
regroup: true,
});
// 选"作为首尾帧":已有图保持首帧,新图放尾帧
const frames = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'image2video',
images: { first_frame: a },
count: 1,
rememberedRole: ROLE_FRAMES,
});
assert.equal(frames.mode, 'first_last_frame');
assert.equal(frames.remembered, true);
assert.deepEqual(frames.images, {
first_frame: a,
last_frame: null,
reference_images: [],
});
assert.deepEqual(frames.targets, [{ key: 'last_frame' }]);
// 选"作为参考图":已有首帧变成参考图 1,新图追加为参考图 2
const refs = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'image2video',
images: { first_frame: a },
count: 1,
rememberedRole: ROLE_REFERENCE,
});
assert.equal(refs.mode, 'reference2video');
assert.deepEqual(refs.images, {
first_frame: null,
last_frame: null,
reference_images: [a],
});
assert.deepEqual(refs.targets, [{ key: 'reference_images' }]);
// 首尾帧已满再加 1 张 → 3 张只有参考图合法 → 直接切换,两张帧图变参考图 1、2
const b = { id: 'b' };
const three = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'first_last_frame',
images: { first_frame: a, last_frame: b },
count: 1,
});
assert.equal(three.type, 'place');
assert.equal(three.mode, 'reference2video');
assert.deepEqual(three.images.reference_images, [a, b]);
assert.deepEqual(three.targets, [{ key: 'reference_images' }]);
});
test('planImageUpload: overflow with no legal mode keeps toast behaviour', () => {
const full = planImageUpload({
kind: 'video',
model: VIDEO_FULL,
mode: 'reference2video',
images: { reference_images: [{ id: 1 }, { id: 2 }, { id: 3 }] },
count: 1,
});
assert.deepEqual(full, {
type: 'place',
mode: 'reference2video',
targets: [],
truncated: 1,
});
const img = planImageUpload({
kind: 'image',
model: IMAGE_EDIT,
mode: 'edit',
images: { reference_images: [{ id: 1 }, { id: 2 }, { id: 3 }] },
count: 3,
});
assert.equal(img.mode, 'edit');
assert.equal(img.targets.length, 1);
assert.equal(img.truncated, 2);
});
test('activeImagesOf lists submitted images in slot order', () => {
const a = { id: 'a' };
const b = { id: 'b' };
assert.deepEqual(
activeImagesOf('video', VIDEO_FULL, 'first_last_frame', {
first_frame: a,
last_frame: b,
reference_images: [{ id: 'x' }],
}),
[a, b],
);
assert.deepEqual(
activeImagesOf('image', IMAGE_EDIT, 'text2image', {
reference_images: [a],
}),
[],
);
});
test('templateModelFor / templateParamsSummary', () => {
const rec = {
model: 'rec',
modes: ['text2video'],
badges: ['recommended'],
};
const models = [{ ...VIDEO_FULL, level_locked: true }, VIDEO_I2V, rec];
// 模板指定可用模型 → 它
assert.equal(
templateModelFor('video', { model: 'kling' }, models, rec).model,
'kling',
);
// 当前模型可用且支持文生 → 保持
assert.equal(templateModelFor('video', {}, models, VIDEO_I2V).model, 'kling');
// 当前模型锁定 → 推荐模型
assert.equal(
templateModelFor('video', { model: 'seedance' }, models, models[0]).model,
'rec',
);
assert.equal(templateModelFor('video', {}, [models[0]], null), null);
assert.equal(
templateParamsSummary({ params: { aspect_ratio: '16:9', duration: 5 } }),
'16:9 · 5s',
);
assert.equal(templateParamsSummary({}), '');
});