HEL-665: implement approved reference creative and agent interfaces

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-14 22:03:32 +08:00
co-authored by multica-agent
parent ae9e34f6ab
commit d4e199f3c8
31 changed files with 4869 additions and 1488 deletions
+42
View File
@@ -0,0 +1,42 @@
# HEL-692 确认样本的正式功能回归
所有写入都使用独立本地后端 `127.0.0.1:8247`,数据在被忽略的 `e2e/shots/reference/data`。本脚本不连接测试服务器,不使用真实模型或 ComfyUI 服务。
从仓库根目录依次启动(测试结束后停止这些本地进程):
```sh
PYTHONPATH=calliope-backend/src python3 e2e/reference/server.py
python3 e2e/fake_comfy.py
python3 e2e/reference/fake_llm.py
npm --prefix calliope-web run dev
```
独立终端运行:
```sh
python3 e2e/seed.py
python3 e2e/reference/seed.py
PLAYWRIGHT_MODULE_PATH=/path/to/playwright-core CHROMIUM_EXECUTABLE_PATH=/path/to/chromium node e2e/reference/check.cjs
```
检查真实上传、任务、消息、技能引用、模型绑定、故事结果保存、取消/保存参数、工作流筛选、独立草稿、小窗口和手动播放。结果与截图写入 `e2e/shots/reference`。测试会暂改假 ComfyUI 的模式文件,退出时恢复。
## 已验证的范围
- 25 项浏览器回归通过;图像与视频输出由本地假服务提供,智能体回复来自本地兼容模型服务。正式功能仍调用现有后端接口。
- 引用限额由单条工作流改成一条工作流加最多四个技能;五项模型校验单测通过,第二条工作流仍拒绝。
- 项目保存使用现有 PATCH 故事草稿接口,由用户在工作台继续确认。其他阶段需要结构化字段,因此明确提供“复制内容并打开项目”,不把自由文本伪装成结构化结果。
- 实际外部模型质量、真实 GPU 性能和参考站完整成片流程不在这个隔离回归中验证。
## 界面与动效变化
| 修改前 | 修改后 |
| --- | --- |
| 工作流在另一层挑选台,填写和结果横排 | 左侧常驻列表、右侧结果、下方提示词与参数 |
| 参数窗即时改值 | 在独立草稿中修改,保存时只合并参数,取消不改值 |
| 五个智能体横排,技能和对话三栏 | 有主题主视觉的独立智能体页、侧栏选择、大输入框与集中弹窗 |
| Enter 直接发出长故事 | Enter 换行,Ctrl/Cmd + Enter 发送 |
| 项目阶段竖排 | 五阶段横排,保留原确认和回流接口 |
| 通用悬停色 | 跟随鼠标的蜂窝高亮,选中态独立,置顶按钮独立 |
主视觉和风格参考图来自用户指定参考站的公开素材,来源见 `calliope-web/src/lib/referenceAgent.ts`。没有收录账号截图、账号历史或登录资料。动效采用实测源站进入曲线与明确的按压/聚焦反馈,系统及手动减少动效都生效。
+362
View File
@@ -0,0 +1,362 @@
const { chromium } = require(
process.env.PLAYWRIGHT_MODULE_PATH || "playwright",
);
const assert = require("node:assert/strict"),
fs = require("fs"),
path = require("path");
const root = path.resolve(__dirname, "../.."),
runtime = path.join(root, "e2e/shots/reference");
fs.mkdirSync(runtime, { recursive: true });
const f = JSON.parse(fs.readFileSync(path.join(runtime, "fixtures.json"))),
API = "http://127.0.0.1:8247",
WEB = "http://127.0.0.1:5173";
const modepath = path.join(root, "e2e/fake_mode.json"),
savedMode = fs.existsSync(modepath) ? fs.readFileSync(modepath) : null;
const checks = [],
errors = [];
const ok = (name, value) => {
assert(value, name);
checks.push(name);
console.log("PASS", name);
};
async function api(url, body, method) {
const r = await fetch(API + url, {
method: method || (body ? "POST" : "GET"),
headers: { "Content-Type": "application/json" },
body: body ? JSON.stringify(body) : undefined,
});
if (!r.ok) throw Error(url + " " + r.status + " " + (await r.text()));
return r.json();
}
async function wait(fn) {
const end = Date.now() + 18000;
while (Date.now() < end) {
const value = await fn();
if (value) return value;
await new Promise((r) => setTimeout(r, 150));
}
throw Error("condition timeout");
}
function mode(videos = false) {
fs.writeFileSync(
modepath,
JSON.stringify({
mode: "ok",
delay_sec: 0,
unique_filename: true,
videos,
image_file: path.join(root, "calliope-web/static/refract/coast.jpg"),
}),
);
}
(async () => {
let b;
try {
const config = await api("/api/settings");
assert.equal(
path.resolve(config.data_dir),
path.join(runtime, "data"),
"Run the dedicated e2e/reference/server.py before this writing test.",
);
b = await chromium.launch({
executablePath: process.env.CHROMIUM_EXECUTABLE_PATH,
args: ["--no-sandbox", "--disable-dev-shm-usage"],
});
const p = await b.newPage({ viewport: { width: 1440, height: 900 } });
p.on("pageerror", (e) => errors.push(e.message));
p.setDefaultTimeout(12000);
await p.goto(WEB + "/image?wf=" + f.dual);
await p.locator("#desk-negative").waitFor();
ok(
"真实工作流显示正反向左右分栏",
await p
.locator(".prompt-pair")
.evaluate(
(e) =>
getComputedStyle(e).gridTemplateColumns.split(" ").length === 2,
),
);
await p.locator("#desk-prompt").fill("正向草稿");
await p.locator("#desk-negative").fill("反向草稿");
ok(
"工作流列表可应对超过 48 项",
(await p.locator(".workflow-pick").count()) >= 48,
);
await p.locator(".rail-tools input").fill("Qwen");
ok(
"列表搜索过滤真实元数据",
(await p.locator(".workflow-pick").count()) === 1,
);
await p.locator(".row-actions button").first().click();
ok(
"置顶不切换工作流、不清空草稿",
(await p.locator("#desk-prompt").inputValue()) === "正向草稿",
);
await p
.getByRole("button", { name: "创作设置", exact: true })
.first()
.click();
await p.locator(".modal-panel input[type=number]").first().fill("99");
await p.getByRole("button", { name: "取消", exact: true }).click();
await p
.getByRole("button", { name: "创作设置", exact: true })
.first()
.click();
ok(
"参数取消不改当前值",
(await p
.locator(".modal-panel input[type=number]")
.first()
.inputValue()) === "42",
);
await p.locator(".modal-panel input[type=number]").first().fill("101");
await p.getByRole("button", { name: "保存设置", exact: true }).click();
await p
.getByRole("button", { name: "创作设置", exact: true })
.first()
.click();
ok(
"参数保存应用到当前工作流",
(await p
.locator(".modal-panel input[type=number]")
.first()
.inputValue()) === "101",
);
await p.keyboard.press("Escape");
const beforeImage = Math.max(
0,
...(await api("/api/playground/jobs")).map((j) => j.id),
);
mode();
await p.locator(".gen").click();
const job = await wait(async () => {
const rows = await api("/api/playground/jobs");
return rows.find(
(j) =>
j.id > beforeImage && j.workflow_id === f.dual && j.status === "done",
);
});
ok("真实生成请求提交且取得结果", !!job.output_paths[0]);
ok(
"正反向与种子写入任务",
JSON.stringify(job.payload).includes("正向草稿") &&
JSON.stringify(job.payload).includes("反向草稿") &&
JSON.stringify(job.payload).includes("101"),
);
await p.locator(".result-item").first().click();
await p.screenshot({ path: path.join(runtime, "正式施工-创作台.png") });
await p.goto(WEB + "/video?wf=" + f.h3);
await p.locator(".a-slot").filter({ hasText: "首帧" }).waitFor();
const first = p
.locator(".a-slot")
.filter({ has: p.getByText("首帧", { exact: true }) }),
last = p
.locator(".a-slot")
.filter({ has: p.getByText("尾帧", { exact: true }) });
await first
.locator("input[type=file]")
.setInputFiles(path.join(root, "calliope-web/static/refract/coast.jpg"));
await last
.locator("input[type=file]")
.setInputFiles(path.join(root, "calliope-web/static/refract/arch.jpg"));
await wait(
async () =>
(await first.locator("img").count()) &&
(await last.locator("img").count()),
);
ok("H3 首尾帧真实上传保留", true);
const beforeVideo = Math.max(
0,
...(await api("/api/playground/jobs")).map((j) => j.id),
);
mode(true);
await p.locator(".gen").click();
const video = await wait(async () => {
const rows = await api("/api/playground/jobs");
return rows.find(
(j) =>
j.id > beforeVideo && j.workflow_id === f.h3 && j.status === "done",
);
});
await p.locator(".result-item").first().click();
await p.locator(".main video").waitFor();
ok(
"视频默认暂停且不自动播放",
await p.locator(".main video").evaluate((v) => v.paused && !v.autoplay),
);
ok(
"播放按钮明确可见",
await p
.getByRole("button", { name: "播放视频", exact: true })
.isVisible(),
);
await p.setViewportSize({ width: 1280, height: 720 });
ok(
"小窗口播放键仍完整可见",
await p
.getByRole("button", { name: "播放视频", exact: true })
.evaluate((e) => {
const r = e.getBoundingClientRect();
return r.top >= 0 && r.bottom <= innerHeight && r.right <= innerWidth;
}),
);
await p.screenshot({ path: path.join(runtime, "正式施工-首尾帧视频.png") });
await p.goto(WEB + "/agents");
await p.getByRole("button", { name: /新任务/ }).click();
await p.locator(".agent-intro").waitFor();
ok(
"智能体独立主题页面",
await p
.locator(".agent-scene img")
.evaluate((e) => e.complete && e.naturalWidth > 0),
);
await p.locator(".agent-composer textarea").fill("故事草稿 A");
await p.locator(".agent-row").filter({ hasText: "视觉设计" }).click();
await p.locator(".agent-composer textarea").fill("视觉草稿 B");
await p.locator(".agent-row").filter({ hasText: "剧本创作" }).click();
ok(
"五个智能体各自保留草稿",
(await p.locator(".agent-composer textarea").inputValue()) ===
"故事草稿 A",
);
await p.locator(".agent-controls .agent-option").first().click();
await p.locator(".style-card").filter({ hasText: "日系动画" }).click();
await p.getByRole("button", { name: "取消", exact: true }).click();
ok(
"风格取消不应用",
(await p.locator(".agent-controls .agent-option").first().innerText()) ===
"治愈绘本",
);
await p.locator(".agent-controls .agent-option").first().click();
await p.locator(".style-card").filter({ hasText: "日系动画" }).click();
await p.getByRole("button", { name: "应用风格", exact: true }).click();
ok(
"风格应用保留任务",
(await p.locator(".agent-composer textarea").inputValue()) ===
"故事草稿 A",
);
await p
.getByRole("button", { name: /默认大模型⌄|隔离测试模型 B⌄/ })
.click();
await p
.locator(".model-choice")
.filter({ hasText: "隔离测试模型 B" })
.click();
await p.getByRole("button", { name: "应用模型", exact: true }).click();
await p.getByRole("button", { name: /隔离测试模型 B⌄/ }).waitFor();
ok(
"模型选择通过真实设置接口绑定",
Object.values(
(await api("/api/settings")).agent_llm_assignments,
).includes("reference-model-b"),
);
await p.getByRole("button", { name: /选择技能/ }).click();
await p.locator(".skill-choice").nth(1).click();
await p.getByRole("button", { name: "应用技能", exact: true }).click();
await p
.locator('select[aria-label="智能体关联项目"]')
.selectOption(String(f.project));
await p
.locator(".agent-composer input[type=file]")
.setInputFiles(path.join(root, "calliope-web/static/refract/coast.jpg"));
await p.locator(".agent-attachments img").waitFor();
await p.getByRole("button", { name: /引用工作流/ }).click();
await p
.locator(".modal-panel .model-choice")
.filter({ hasText: "Qwen·正反向测试" })
.click();
await p.locator(".agent-send").click();
const session = await wait(async () => {
const sessions = await api("/api/agent/sessions?agent_key=script");
return sessions
.filter((s) => s.project_id === f.project)
.sort((a, b) => b.id - a.id)[0];
});
const detail = await wait(async () => {
const d = await api("/api/agent/sessions/" + session.id);
return d.messages.some((m) => m.role === "assistant") ? d : null;
});
const message = detail.messages.find((m) => m.role === "user");
ok(
"真实消息包含风格与技能引用",
message.content.includes("日系动画") &&
message.mentions.some((m) => m.type === "skill") &&
message.mentions.some((m) => m.type === "workflow"),
);
ok("参考材料真实上传并随任务发送", message.attachments.length === 1);
ok(
"后端智能体回复呈现在对话",
detail.messages.some((m) => m.content.includes("隔离测试模型回复")),
);
await p
.getByText(/隔离测试模型回复/)
.first()
.waitFor();
await p.screenshot({ path: path.join(runtime, "正式施工-智能体对话.png") });
await p.getByRole("button", { name: /编辑内容并带回项目/ }).click();
await p
.locator("#agent-result-editor")
.fill(
"这是编辑后带回项目的故事文稿。小女孩把折好的纸船放进海面,海风吹了一整夜,第二天纸船带回一片银色的树叶。",
);
await p
.getByRole("button", { name: "保存到项目草稿", exact: true })
.click();
await p.waitForURL("**/workbench/" + f.project + "?stage=script");
const wb = await api("/api/workbench/projects/" + f.project);
ok(
"智能体结果真实保存为待确认项目草稿",
wb.stages
.find((s) => s.stage_key === "script")
.content.text.includes("编辑后带回项目") &&
wb.stages.find((s) => s.stage_key === "script").status ===
"awaiting_confirm",
);
await p.goto(WEB + "/agents");
await p.getByRole("button", { name: /新任务/ }).click();
await p.locator(".agent-intro").waitFor();
await p.setViewportSize({ width: 1600, height: 900 });
await p.screenshot({ path: path.join(runtime, "正式施工-智能体首页.png") });
await p.locator(".agent-controls .agent-option").first().click();
await p.screenshot({ path: path.join(runtime, "正式施工-风格选择.png") });
await p.keyboard.press("Escape");
await p.getByRole("button", { name: "智能体设置", exact: true }).click();
ok(
"技能管理和自定义编辑可访问",
await p
.getByRole("button", { name: "+ 自定义技能", exact: true })
.isVisible(),
);
await p.getByRole("button", { name: "+ 自定义技能", exact: true }).click();
await p.screenshot({ path: path.join(runtime, "正式施工-自定义技能.png") });
await p.keyboard.press("Escape");
await p.goto(WEB + "/workbench/" + f.project);
await p.locator("[data-testid=workbench-page]").waitFor();
ok(
"五阶段横向排列",
await p
.locator(".stepper")
.evaluate((e) => getComputedStyle(e).flexDirection === "row"),
);
ok(
"项目上下文与真实任务区保留",
(await p.locator(".side-col .side-card").count()) >= 2,
);
await p.screenshot({ path: path.join(runtime, "正式施工-项目工作台.png") });
await p.goto(WEB + "/");
await p.screenshot({ path: path.join(runtime, "正式施工-工作室.png") });
ok("没有页面脚本错误", errors.length === 0);
fs.writeFileSync(
path.join(runtime, "results.json"),
JSON.stringify({ checks, errors }, null, 2),
);
console.log("PASS TOTAL", checks.length);
} finally {
if (b) await b.close();
if (savedMode) fs.writeFileSync(modepath, savedMode);
else if (fs.existsSync(modepath)) fs.unlinkSync(modepath);
}
})().catch((e) => {
console.error(e);
process.exitCode = 1;
});
+21
View File
@@ -0,0 +1,21 @@
import json,time
from pathlib import Path
from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer
root=Path(__file__).resolve().parents[1]/'shots/reference'
root.mkdir(parents=True,exist_ok=True)
class Handler(BaseHTTPRequestHandler):
def log_message(self,*args):pass
def do_POST(self):
payload=json.loads(self.rfile.read(int(self.headers.get('Content-Length','0'))))
with (root/'llm-requests.jsonl').open('a') as f:f.write(json.dumps(payload,ensure_ascii=False)+'\n')
content='【隔离测试模型回复】\n纸船带回了一片树叶。女孩望向海面,知道故事才刚刚开始。\n\n已收到任务与指定技能,后续可以继续修改。'
if payload.get('stream'):
self.send_response(200);self.send_header('Content-Type','text/event-stream');self.end_headers()
for chunk in [content[:16],content[16:]]:
body={'id':'reference-check','choices':[{'index':0,'delta':{'content':chunk},'finish_reason':None}]}
self.wfile.write(('data: '+json.dumps(body,ensure_ascii=False)+'\n\n').encode());self.wfile.flush();time.sleep(.05)
self.wfile.write(b'data: [DONE]\n\n')
else:
body={'id':'reference-check','choices':[{'index':0,'message':{'role':'assistant','content':content},'finish_reason':'stop'}]}
data=json.dumps(body,ensure_ascii=False).encode();self.send_response(200);self.send_header('Content-Type','application/json');self.end_headers();self.wfile.write(data)
ThreadingHTTPServer(('127.0.0.1',18189),Handler).serve_forever()
+21
View File
@@ -0,0 +1,21 @@
import json,urllib.request
from pathlib import Path
BASE='http://127.0.0.1:8247'
def api(path,payload=None,method=None):
req=urllib.request.Request(BASE+path,data=json.dumps(payload).encode() if payload is not None else None,method=method or ('POST' if payload is not None else 'GET'),headers={'Content-Type':'application/json'})
with urllib.request.urlopen(req) as r:return json.load(r)
image={ '1':{'class_type':'CLIPTextEncode','inputs':{'text':'海边的小女孩'},'_meta':{'title':'(Input:prompt) 正向提示词'}},'2':{'class_type':'CLIPTextEncode','inputs':{'text':'模糊'},'_meta':{'title':'(Input:negative) 反向提示词'}},'3':{'class_type':'PrimitiveInt','inputs':{'value':42},'_meta':{'title':'(Input:seed) 种子'}},'9':{'class_type':'SaveImage','inputs':{'images':'x'},'_meta':{'title':'(Output:image) 图片输出'}}}
h3={ '1':{'class_type':'CLIPTextEncode','inputs':{'text':'缓慢推镜'},'_meta':{'title':'(Input:prompt) 提示词'}},'2':{'class_type':'LoadImage','inputs':{'image':''},'_meta':{'title':'(Input:first_frame) 首帧'}},'3':{'class_type':'LoadImage','inputs':{'image':''},'_meta':{'title':'(Input:last_frame) 尾帧'}},'9':{'class_type':'VHS_VideoCombine','inputs':{'images':'x'},'_meta':{'title':'(Output:video) 视频输出'}}}
expected=Path(__file__).resolve().parents[1]/'shots/reference/data'
assert Path(api('/api/settings')['data_dir']).resolve()==expected.resolve(), 'Start the isolated reference server first'
rows=api('/api/workflows?view=meta');names={w['name']:w['id'] for w in rows}
def wf(name,kind,body):
if name in names:return names[name]
return api('/api/workflows',{'name':name,'kind':kind,'workflow_json':body})['id']
ids={'dual':wf('Qwen·正反向测试','image',image),'h3':wf('H3·首尾帧测试','video',h3)}
for i in range(60):wf('列表规模测试 '+str(i).zfill(3),'image',image)
project=api('/api/projects',{'title':'HEL692·隔离测试项目','idea':'纸船的故事'})
ids['project']=project['id']
profiles=[{k:v for k,v in p.items() if k in ('id','name','base_url','model')} for p in api('/api/settings')['llm_profiles']];profiles.append({'id':'reference-model-b','name':'隔离测试模型 B','base_url':'http://127.0.0.1:18189/v1','model':'reference-test-b','api_key':''});api('/api/settings',{'llm_profiles':profiles})
(Path(__file__).resolve().parents[1]/'shots/reference/fixtures.json').write_text(json.dumps(ids))
print(ids)
+13
View File
@@ -0,0 +1,13 @@
from pathlib import Path
from calliope import config
root=Path(__file__).resolve().parents[1]/'shots/reference'
root.mkdir(parents=True,exist_ok=True)
config.CONFIG_FILE=root/'settings.json'
config.settings=config.Settings(data_dir=root/'data',assets_dir=root/'data/assets',llm_base_url='http://127.0.0.1:18189/v1',llm_model='reference-test',dry_run=False)
if config.CONFIG_FILE.exists():config.settings.load_config_file()
config.settings.ensure_storage_dirs()
config.settings.ensure_llm_profiles()
config.settings.save_config_file()
from calliope.main import create_app
import uvicorn
uvicorn.run(create_app(),host='127.0.0.1',port=8247)