Merge origin/master into codex/rpg-creation-cg-fix
This commit is contained in:
16
.codegraph/.gitignore
vendored
Normal file
16
.codegraph/.gitignore
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# CodeGraph data files
|
||||
# These are local to each machine and should not be committed
|
||||
|
||||
# Database
|
||||
*.db
|
||||
*.db-wal
|
||||
*.db-shm
|
||||
|
||||
# Cache
|
||||
cache/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Hook markers
|
||||
.dirty
|
||||
143
.codegraph/config.json
Normal file
143
.codegraph/config.json
Normal file
@@ -0,0 +1,143 @@
|
||||
{
|
||||
"version": 1,
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.jsx",
|
||||
"**/*.py",
|
||||
"**/*.go",
|
||||
"**/*.rs",
|
||||
"**/*.java",
|
||||
"**/*.c",
|
||||
"**/*.h",
|
||||
"**/*.cpp",
|
||||
"**/*.hpp",
|
||||
"**/*.cc",
|
||||
"**/*.cxx",
|
||||
"**/*.cs",
|
||||
"**/*.php",
|
||||
"**/*.rb",
|
||||
"**/*.swift",
|
||||
"**/*.kt",
|
||||
"**/*.kts",
|
||||
"**/*.dart",
|
||||
"**/*.svelte",
|
||||
"**/*.vue",
|
||||
"**/*.liquid",
|
||||
"**/*.pas",
|
||||
"**/*.dpr",
|
||||
"**/*.dpk",
|
||||
"**/*.lpr",
|
||||
"**/*.dfm",
|
||||
"**/*.fmx",
|
||||
"**/*.scala",
|
||||
"**/*.sc"
|
||||
],
|
||||
"exclude": [
|
||||
"**/.git/**",
|
||||
"**/node_modules/**",
|
||||
"**/vendor/**",
|
||||
"**/Pods/**",
|
||||
"**/dist/**",
|
||||
"**/build/**",
|
||||
"**/out/**",
|
||||
"**/bin/**",
|
||||
"**/obj/**",
|
||||
"**/target/**",
|
||||
"**/*.min.js",
|
||||
"**/*.bundle.js",
|
||||
"**/.next/**",
|
||||
"**/.nuxt/**",
|
||||
"**/.svelte-kit/**",
|
||||
"**/.output/**",
|
||||
"**/.turbo/**",
|
||||
"**/.cache/**",
|
||||
"**/.parcel-cache/**",
|
||||
"**/.vite/**",
|
||||
"**/.astro/**",
|
||||
"**/.docusaurus/**",
|
||||
"**/.gatsby/**",
|
||||
"**/.webpack/**",
|
||||
"**/.nx/**",
|
||||
"**/.yarn/cache/**",
|
||||
"**/.pnpm-store/**",
|
||||
"**/storybook-static/**",
|
||||
"**/.expo/**",
|
||||
"**/web-build/**",
|
||||
"**/ios/Pods/**",
|
||||
"**/ios/build/**",
|
||||
"**/android/build/**",
|
||||
"**/android/.gradle/**",
|
||||
"**/__pycache__/**",
|
||||
"**/.venv/**",
|
||||
"**/venv/**",
|
||||
"**/site-packages/**",
|
||||
"**/dist-packages/**",
|
||||
"**/.pytest_cache/**",
|
||||
"**/.mypy_cache/**",
|
||||
"**/.ruff_cache/**",
|
||||
"**/.tox/**",
|
||||
"**/.nox/**",
|
||||
"**/*.egg-info/**",
|
||||
"**/.eggs/**",
|
||||
"**/go/pkg/mod/**",
|
||||
"**/target/debug/**",
|
||||
"**/target/release/**",
|
||||
"**/.gradle/**",
|
||||
"**/.m2/**",
|
||||
"**/generated-sources/**",
|
||||
"**/.kotlin/**",
|
||||
"**/.dart_tool/**",
|
||||
"**/.vs/**",
|
||||
"**/.nuget/**",
|
||||
"**/artifacts/**",
|
||||
"**/publish/**",
|
||||
"**/cmake-build-*/**",
|
||||
"**/CMakeFiles/**",
|
||||
"**/bazel-*/**",
|
||||
"**/vcpkg_installed/**",
|
||||
"**/.conan/**",
|
||||
"**/Debug/**",
|
||||
"**/Release/**",
|
||||
"**/x64/**",
|
||||
"**/.pio/**",
|
||||
"**/release/**",
|
||||
"**/*.app/**",
|
||||
"**/*.asar",
|
||||
"**/DerivedData/**",
|
||||
"**/.build/**",
|
||||
"**/.swiftpm/**",
|
||||
"**/xcuserdata/**",
|
||||
"**/Carthage/Build/**",
|
||||
"**/SourcePackages/**",
|
||||
"**/__history/**",
|
||||
"**/__recovery/**",
|
||||
"**/*.dcu",
|
||||
"**/.composer/**",
|
||||
"**/storage/framework/**",
|
||||
"**/bootstrap/cache/**",
|
||||
"**/.bundle/**",
|
||||
"**/tmp/cache/**",
|
||||
"**/public/assets/**",
|
||||
"**/public/packs/**",
|
||||
"**/.yardoc/**",
|
||||
"**/coverage/**",
|
||||
"**/htmlcov/**",
|
||||
"**/.nyc_output/**",
|
||||
"**/test-results/**",
|
||||
"**/.coverage/**",
|
||||
"**/.idea/**",
|
||||
"**/logs/**",
|
||||
"**/tmp/**",
|
||||
"**/temp/**",
|
||||
"**/_build/**",
|
||||
"**/docs/_build/**",
|
||||
"**/site/**"
|
||||
],
|
||||
"languages": [],
|
||||
"frameworks": [],
|
||||
"maxFileSize": 1048576,
|
||||
"extractDocstrings": true,
|
||||
"trackCallSites": true
|
||||
}
|
||||
23
.codex/config.toml
Normal file
23
.codex/config.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
# Genarrative 项目级 Codex 配置。
|
||||
# 这里仅保存可进入仓库的 hook 配置与脚本;个人 token、MCP server、模型路由仍放在个人 ~/.codex/config.toml。
|
||||
|
||||
[features]
|
||||
hooks = true
|
||||
|
||||
# Codex 准备执行 git commit 前检查 TypeScript / admin-web / api-server 编译错误。
|
||||
# 脚本也可手动运行:
|
||||
# node .codex/hooks/pre-submit-compile-check.mjs
|
||||
[[hooks.PreToolUse]]
|
||||
matcher = "Bash|shell_command|functions.shell_command"
|
||||
command = "node .codex/hooks/pre-submit-compile-check.mjs"
|
||||
timeout = 180
|
||||
statusMessage = "提交前检查编译错误"
|
||||
|
||||
# Codex 每次工具修改文件后执行:同步 CodeGraph 索引。
|
||||
# 脚本也可手动运行:
|
||||
# node .codex/hooks/post-edit-codegraph-sync.mjs
|
||||
[[hooks.PostToolUse]]
|
||||
matcher = "Bash|Edit|MultiEdit|Write|apply_patch|shell_command|functions.shell_command|functions.apply_patch"
|
||||
command = "node .codex/hooks/post-edit-codegraph-sync.mjs"
|
||||
timeout = 60
|
||||
statusMessage = "更新 CodeGraph 索引"
|
||||
51
.codex/hooks/post-edit-codegraph-sync.mjs
Normal file
51
.codex/hooks/post-edit-codegraph-sync.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { existsSync, mkdirSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||
const repoRoot = resolve(scriptDir, '..', '..');
|
||||
const logDir = resolve(repoRoot, '.codex', 'logs');
|
||||
const hasCodegraphConfig = existsSync(resolve(repoRoot, '.codegraph', 'config.json'));
|
||||
const npmCommand = process.platform === 'win32' ? 'cmd' : 'npm';
|
||||
|
||||
if (!hasCodegraphConfig) {
|
||||
console.log('[codex-hook] 未发现 .codegraph/config.json,跳过 CodeGraph 同步。');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const result = spawnSync(npmCommand, process.platform === 'win32' ? ['/d', '/s', '/c', 'npm run codegraph:sync'] : ['run', 'codegraph:sync'], {
|
||||
cwd: repoRoot,
|
||||
shell: false,
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
NO_COLOR: process.env.NO_COLOR ?? '1',
|
||||
},
|
||||
});
|
||||
|
||||
mkdirSync(logDir, { recursive: true });
|
||||
if (result.stdout) {
|
||||
process.stdout.write(result.stdout);
|
||||
}
|
||||
if (result.stderr) {
|
||||
process.stderr.write(result.stderr);
|
||||
}
|
||||
|
||||
if (result.error) {
|
||||
console.error(`[codex-hook] CodeGraph 同步启动失败:${result.error.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (result.signal) {
|
||||
console.error(`[codex-hook] CodeGraph 同步被信号终止:${result.signal}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if ((result.status ?? 0) !== 0) {
|
||||
console.error('[codex-hook] CodeGraph 同步失败,请手动运行 npm run codegraph:sync 查看详情。');
|
||||
process.exit(result.status ?? 1);
|
||||
}
|
||||
|
||||
console.log('[codex-hook] CodeGraph 已同步。');
|
||||
122
.codex/hooks/pre-submit-compile-check.mjs
Normal file
122
.codex/hooks/pre-submit-compile-check.mjs
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||
const repoRoot = resolve(scriptDir, '..', '..');
|
||||
const npmCommand = process.platform === 'win32' ? 'cmd' : 'npm';
|
||||
const hookInput = readHookInput();
|
||||
|
||||
if (hookInput && !isGitCommitCommand(extractShellCommand(hookInput))) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const validationSteps = [
|
||||
{
|
||||
label: 'TypeScript typecheck',
|
||||
command: npmCommand,
|
||||
args: process.platform === 'win32' ? ['/d', '/s', '/c', 'npm run typecheck'] : ['run', 'typecheck'],
|
||||
},
|
||||
{
|
||||
label: 'Admin web typecheck',
|
||||
command: npmCommand,
|
||||
args: process.platform === 'win32' ? ['/d', '/s', '/c', 'npm run admin-web:typecheck'] : ['run', 'admin-web:typecheck'],
|
||||
},
|
||||
{
|
||||
label: 'Rust api-server compile check',
|
||||
command: 'cargo',
|
||||
args: ['check', '-p', 'api-server', '--manifest-path', 'server-rs/Cargo.toml'],
|
||||
},
|
||||
];
|
||||
|
||||
for (const step of validationSteps) {
|
||||
const result = runStep(step);
|
||||
if (!result.ok) {
|
||||
const reason = `[codex-hook] 提交前编译检查失败:${step.label}。请修复编译错误后再提交。`;
|
||||
console.error(reason);
|
||||
if (hookInput) {
|
||||
console.log(JSON.stringify({ decision: 'block', reason }));
|
||||
process.exit(0);
|
||||
}
|
||||
process.exit(result.status ?? 1);
|
||||
}
|
||||
}
|
||||
|
||||
console.error('[codex-hook] 提交前编译检查通过。');
|
||||
|
||||
function runStep(step) {
|
||||
console.error(`[codex-hook] ${step.label}`);
|
||||
const result = spawnSync(step.command, step.args, {
|
||||
cwd: repoRoot,
|
||||
shell: false,
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
NO_COLOR: process.env.NO_COLOR ?? '1',
|
||||
},
|
||||
});
|
||||
|
||||
if (result.stdout) {
|
||||
process.stderr.write(result.stdout);
|
||||
}
|
||||
if (result.stderr) {
|
||||
process.stderr.write(result.stderr);
|
||||
}
|
||||
|
||||
if (result.error) {
|
||||
console.error(`[codex-hook] ${step.label} 启动失败:${result.error.message}`);
|
||||
return { ok: false, status: 1 };
|
||||
}
|
||||
|
||||
if (result.signal) {
|
||||
console.error(`[codex-hook] ${step.label} 被信号终止:${result.signal}`);
|
||||
return { ok: false, status: 1 };
|
||||
}
|
||||
|
||||
return {
|
||||
ok: (result.status ?? 0) === 0,
|
||||
status: result.status ?? 1,
|
||||
};
|
||||
}
|
||||
|
||||
function readHookInput() {
|
||||
try {
|
||||
const rawInput = readFileSync(0, 'utf8').trim();
|
||||
if (!rawInput) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parse(rawInput);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function extractShellCommand(input) {
|
||||
const candidates = [
|
||||
input?.tool_input?.command,
|
||||
input?.toolInput?.command,
|
||||
input?.tool_args?.command,
|
||||
input?.toolArgs?.command,
|
||||
input?.arguments?.command,
|
||||
input?.params?.command,
|
||||
input?.command,
|
||||
];
|
||||
|
||||
const command = candidates.find(value => typeof value === 'string' && value.trim().length > 0);
|
||||
if (command) {
|
||||
return command;
|
||||
}
|
||||
|
||||
const shellCommand = input?.tool_input?.cmd ?? input?.toolInput?.cmd ?? input?.arguments?.cmd;
|
||||
if (Array.isArray(shellCommand)) {
|
||||
return shellCommand.join(' ');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function isGitCommitCommand(command) {
|
||||
return /(^|[;&|]\s*)git(?:\.exe)?\b[\s\S]{0,200}\bcommit\b/iu.test(command);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ description: Generate or inspect project image assets through this repository's
|
||||
|
||||
# gpt-image-2 VectorEngine
|
||||
|
||||
Use this skill for project-local image asset generation that must match the repository's `server-rs` VectorEngine `gpt-image-2-all` path. The folder still contains `apimart` in its name for compatibility with existing local plugin references.
|
||||
Use this skill for project-local image asset generation that must match the repository's `server-rs` VectorEngine `gpt-image-2` path. The folder still contains `apimart` in its name for compatibility with existing local plugin references.
|
||||
|
||||
## Workflow
|
||||
|
||||
@@ -40,22 +40,14 @@ Default body:
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "gpt-image-2-all",
|
||||
"model": "gpt-image-2",
|
||||
"prompt": "<prompt>",
|
||||
"n": 1,
|
||||
"size": "1024x1024"
|
||||
}
|
||||
```
|
||||
|
||||
For weak visual references in text-to-image generation, add:
|
||||
|
||||
```json
|
||||
{
|
||||
"image": ["data:image/png;base64,..."]
|
||||
}
|
||||
```
|
||||
|
||||
For image-to-image work that must follow a reference image closely, use the VectorEngine edits endpoint instead of the generations `image` array:
|
||||
For visual references, use the edit endpoint instead of the create endpoint:
|
||||
|
||||
```text
|
||||
POST {VECTOR_ENGINE_BASE_URL}/v1/images/edits
|
||||
@@ -73,9 +65,9 @@ size=1024x1024
|
||||
image=@reference.png
|
||||
```
|
||||
|
||||
Prefer edits for workflows where the reference image controls composition, pose, container shape, or layout. In this repository, Match3D container UI generation uses edits with `public/match3d-background-references/pot-fused-reference.png` as the `image` part.
|
||||
In this repository, calls with no reference images use `POST /v1/images/generations`; calls with any reference image use `POST /v1/images/edits` and pass references as one or more `image` form parts. Match3D container UI generation embeds `public/match3d-background-references/pot-fused-reference.png` into the edit request as an `image` part.
|
||||
|
||||
Accept image output from `data[].url`, `data[].b64_json`, or direct nested `url` fields. VectorEngine GPT-image-2-all currently returns synchronously; do not poll APIMart task endpoints.
|
||||
Accept image output from `data[].url`, `data[].b64_json`, or direct nested `url` fields. VectorEngine GPT-image-2 currently returns synchronously; do not poll APIMart task endpoints.
|
||||
|
||||
## Environment
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ async function downloadUrl(url, timeoutMs) {
|
||||
|
||||
async function generateOne(env, entry, outDir) {
|
||||
const requestBody = {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: buildPrompt(entry),
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
@@ -305,7 +305,7 @@ if (dryRun) {
|
||||
id: entry.id,
|
||||
title: entry.title,
|
||||
body: {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: buildPrompt(entry),
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
|
||||
@@ -211,7 +211,7 @@ async function downloadUrl(url, timeoutMs) {
|
||||
|
||||
async function generateOne(env, template, outDir) {
|
||||
const requestBody = {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: buildPrompt(template),
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
@@ -275,7 +275,7 @@ if (dryRun) {
|
||||
id: template.id,
|
||||
title: template.title,
|
||||
body: {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: buildPrompt(template),
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
|
||||
@@ -16,6 +16,41 @@
|
||||
|
||||
---
|
||||
|
||||
## 2026-05-21 外部 API 失败必须 OTLP 上报并落库
|
||||
|
||||
- 背景:图片生成等外部供应商调用失败时,仅返回 502/504 或普通日志无法支持后续按 provider、阶段和重试属性聚合排障。
|
||||
- 决策:外部 API 调用未成功时,`api-server` 必须同时发送 OTLP 失败观测并写入 `tracking_event`。当前通用 VectorEngine `gpt-image-2` 图片生成 / 编辑适配器记录 `external_api_call_failure`,`scope_kind = module`、`scope_id = provider`、`module_key = external-api`,metadata 包含 endpoint、operation、failureStage、statusCode、statusClass、timeout、retryable、errorMessage、latencyMs、promptChars、referenceImageCount、imageModel 和 rawExcerpt。
|
||||
- 落库方式:优先复用 tracking outbox 异步批量写入;outbox 不可写或因保护阈值拒绝时回退同步直写 SpacetimeDB。不新增 SpacetimeDB 表,不让 reducer 做外部 I/O。
|
||||
- 影响范围:`server-rs/crates/api-server/src/external_api_audit.rs`、`server-rs/crates/api-server/src/openai_image_generation.rs`、`server-rs/crates/api-server/src/telemetry.rs`、tracking outbox、后端架构文档和开发运维文档。
|
||||
- 验证方式:执行 `cargo test -p api-server external_api_audit --manifest-path server-rs/Cargo.toml -- --nocapture`、`cargo test -p api-server openai_image_generation --manifest-path server-rs/Cargo.toml -- --nocapture`、`cargo check -p api-server --manifest-path server-rs/Cargo.toml`、`npm run check:encoding`。
|
||||
- 关联文档:`docs/【后端架构】server-rs与SpacetimeDB数据契约-2026-05-15.md`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
## 2026-05-21 拼图参考图主链改为 OSS assetObjectId 与只读签名 URL
|
||||
|
||||
- 背景:release 上拼图图生图生成草稿时,旧链路把上传图转成 Data URL/base64 放进创作 action JSON body,容易先触发 Nginx `413 Request Entity Too Large`,也让外部模型调用前的 HTTP body 过大。
|
||||
- 决策:浏览器参考图先通过资产直传票据上传 OSS,并确认 `asset_object`;拼图 action 主链只提交 `referenceImageAssetObjectId(s)`。`api-server` 按当前登录用户校验 asset owner、bucket、kind、图片 MIME 和大小后签发 OSS 只读 URL,传给 VectorEngine 的 generation fallback 使用;需要 edits multipart 时由后端用该签名 URL 拉取字节,不再让前端把图片塞进 JSON body。
|
||||
- 兼容边界:旧 `referenceImageSrc(s)` Data URL 与历史 `/generated-*` 路径仅保留给旧草稿、旧入口和迁移期请求;调大 Nginx `client_max_body_size` 只作为兼容兜底,不是长期创作主链。
|
||||
- 影响范围:拼图创作前端、`packages/shared` / `shared-contracts` action DTO、`api-server` 拼图 VectorEngine 编排、资产确认和 `spacetime-client` 资产读取 facade。
|
||||
- 验证方式:前端 payload 中 AI 重绘优先出现 `referenceImageAssetObjectId(s)` 且 `referenceImageSrc(s)` 不再携带 Data URL;后端 `puzzle_vector_engine_generation_prefers_signed_reference_url`、`puzzle_reference_image_sources_prefer_asset_object_ids`、`puzzle_asset_object_reference_requires_matching_owner` 通过。
|
||||
- 关联文档:`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`、`docs/【后端架构】server-rs与SpacetimeDB数据契约-2026-05-15.md`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
## 2026-05-21 Nginx 通用 API 入口放行创作参考图请求体
|
||||
|
||||
- 背景:release 上拼图结果页重绘动作携带参考图 Data URL 时,Nginx access log 出现 `413`、`request_time=0.000`、`upstream_status=-`,说明请求被反代层默认 1 MiB 上限拦截,未进入 `api-server`。
|
||||
- 决策:发布、开发服和容器 Nginx 模板的通用 `location ~ ^/api(?:/|$)` 统一设置 `client_max_body_size 64m`。该值只作为反代放行和旧 Data URL 请求兼容兜底,具体业务请求体和图片字节上限继续由 `api-server` 路由 `DefaultBodyLimit`、OSS asset 确认和业务校验控制,不能替代接口级限制;拼图参考图长期主链见同日 `OSS assetObjectId` 决策。
|
||||
- 影响范围:`deploy/nginx/genarrative.conf`、`deploy/nginx/genarrative-dev-http.conf`、`deploy/container/nginx.conf`、Nginx README、生产运维文档和 release 排障口径。
|
||||
- 验证方式:目标机 `nginx -T 2>/dev/null | grep client_max_body_size` 应看到 `client_max_body_size 64m;`;大于 1 MiB 的参考图请求不再在 Nginx 层直接 413,access log 应出现有效 `upstream_status`。
|
||||
- 关联文档:`deploy/nginx/README.md`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
## 2026-05-22 抓大鹅素材生成改为关卡整图派生三图
|
||||
|
||||
- 背景:旧抓大鹅素材链路按物品 5x5 sheet、纯背景和独立容器图分开生产,难以保证背景、UI、容器和物品风格一致,也让结果页继续暴露背景 / 容器重生成入口。
|
||||
- 决策:抓大鹅草稿生成先用 `gpt-image-2` 无参考图生成竖屏 `9:16` 完整关卡画面;关卡画面完成后,以它作为参考并发生成三张可运行资产:`1K 1:1` UI spritesheet、`1K 9:16` 关卡背景图、`2K 1:1` 物品 spritesheet。UI 与物品 spritesheet 都固定要求纯绿色绿幕背景,后端上传 OSS 前扣成真实透明 PNG。物品 spritesheet 固定 `10*10`,每行两种物品、每种五个形态。运行态和编辑器都按 alpha 连通域矩形检测解析 UI 和物品图集,不按固定像素坐标切图。
|
||||
- 兼容:新增字段继续存入现有 `generatedItemAssets[].backgroundAsset` / `generatedBackgroundAsset` JSON,不新增 SpacetimeDB schema 字段。历史 `containerImage*` 字段只作兼容;如果它与 `uiSpritesheetImage*` 同源,不得再作为运行态中心容器图。
|
||||
- 影响范围:`server-rs/crates/api-server/src/match3d/*`、`server-rs/crates/shared-contracts/src/match3d_*`、`packages/shared/src/contracts/match3dWorks.ts`、`src/components/match3d-result/Match3DResultView.tsx`、`src/components/match3d-runtime/Match3DRuntimeShell.tsx`、`src/services/match3dSpritesheetParser.ts`。
|
||||
- 验证方式:执行 `cargo test -p api-server match3d --manifest-path server-rs\Cargo.toml`、`npm run test -- src/components/match3d-result/Match3DResultView.test.tsx src/components/match3d-runtime/Match3DRuntimeShell.test.tsx src/services/match3dSpritesheetParser.test.ts src/services/match3dGeneratedModelCache.test.ts`、`npm run typecheck`、`npm run check:encoding`。
|
||||
- 关联文档:`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`。
|
||||
|
||||
|
||||
## 2026-05-18 Rust 手写模块入口统一不用 mod.rs
|
||||
|
||||
@@ -39,8 +74,9 @@
|
||||
|
||||
- 背景:`server-rs/crates/api-server/src/puzzle.rs` 已膨胀为数千行大文件,混合 Axum handler、草稿编译、图片生成、VectorEngine / OSS 持久化、DTO mapper、标签生成和测试;继续在单文件内迭代会降低定位和评审效率。
|
||||
- 决策:原超大 `puzzle.rs` 改为同名入口 `server-rs/crates/api-server/src/puzzle.rs` 加 `server-rs/crates/api-server/src/puzzle/` 子模块目录。`puzzle.rs` 只保留聚合入口和 handler re-export;`handlers.rs` 放 HTTP handler;`draft.rs` 放表单草稿 / 编译 / snapshot helper;`generation.rs` 放图片与 UI 背景生成编排;`vector_engine.rs` 放 VectorEngine、下载、OSS、asset object / binding 和错误归一;`mappers.rs` / `tags.rs` 保留映射和标签 / 错误 helper;`tests.rs` 承接原 puzzle 单测。
|
||||
- 2026-05-21 追加决策:拼图 HTTP/BFF handler 不再直接提取完整 `AppState`,统一通过 `PuzzleApiState` 暴露拼图能力需要的 SpacetimeDB facade、gallery cache、OSS、作者查询、LLM 和少量配置快照。`modules/puzzle.rs` 仍接收全局 `AppState` 以挂接鉴权和回到全局路由树,但内部路由先 `.with_state(PuzzleApiState::from_ref(&state))`,handler 使用 `State<PuzzleApiState>`。确需复用计费、外部失败审计等仍要求 `AppState` 的横切 helper 时,先经 `PuzzleApiState::root_state()` 显式过渡,后续再继续收窄。
|
||||
- 边界:本次只改变 `api-server` 内部文件组织,不改变 `/api/runtime/puzzle/*` 路由、DTO、error envelope、SpacetimeDB schema、公开 gallery cache 语义或计费语义。领域规则后续仍应逐步沉到 `module-puzzle`,SpacetimeDB 表、reducer、procedure 和 row shape 仍留在 `spacetime-module`。
|
||||
- 影响范围:`server-rs/crates/api-server/src/puzzle/`、`server-rs/crates/api-server/src/modules/puzzle.rs` 的 handler 引用、后端架构文档。
|
||||
- 影响范围:`server-rs/crates/api-server/src/state.rs`、`server-rs/crates/api-server/src/puzzle/`、`server-rs/crates/api-server/src/modules/puzzle.rs` 的 handler 引用、后端架构文档。
|
||||
- 验证方式:执行 `cargo check -p api-server --manifest-path server-rs\Cargo.toml`;后续若改动 puzzle API 行为,再按对应路由补充定向测试和 `npm run dev:api-server` `/healthz` smoke。
|
||||
- 关联文档:`docs/【后端架构】server-rs与SpacetimeDB数据契约-2026-05-15.md`。
|
||||
|
||||
@@ -204,6 +240,7 @@
|
||||
|
||||
## 2026-05-14 抓大鹅物品素材 sheet 改用 VectorEngine Gemini
|
||||
|
||||
- 状态:历史决策,已被 `2026-05-22 抓大鹅素材生成改为关卡整图派生三图` 取代;当前物品 spritesheet 走 `gpt-image-2` 参考关卡整图编辑生成 `2K 1:1`、`10*10` 绿幕图,上传 OSS 前扣成透明 PNG。
|
||||
- 背景:抓大鹅 2D 五视角物品素材仍沿用 5x5 sheet、绿幕去背、切图、OSS 转存和 `generatedItemAssets` 持久化,但用户要求物品素材图片生成步骤改用 VectorEngine Apifox `api-381740608` 对应的 Gemini 原生图片接口。
|
||||
- 决策:抓大鹅物品素材 sheet 生图固定走 VectorEngine `POST {VECTOR_ENGINE_BASE_URL}/v1beta/models/gemini-3-pro-image-preview:generateContent?key={VECTOR_ENGINE_API_KEY}`,请求体使用 `contents[].parts[].text` 与 `generationConfig.responseModalities = ["TEXT", "IMAGE"]`、`imageConfig.aspectRatio = "1:1"`;响应从 `candidates[].content.parts[].inlineData.data` / `inline_data.data` 读取 base64 图片。封面、9:16 纯背景图、1:1 容器 UI 图、切图、OSS、扣费和运行态消费链路保持不变;音频以后续“拼图与抓大鹅音频生成入口临时关闭”决策为准。
|
||||
- 影响范围:`server-rs/crates/api-server/src/match3d.rs`、`server-rs/crates/api-server/src/config.rs`、`deploy/env/api-server.env.example`、抓大鹅素材生成技术文档。
|
||||
@@ -255,7 +292,7 @@
|
||||
## 2026-05-12 抓大鹅入口素材风格改为 2D 常见素材风格
|
||||
|
||||
- 背景:抓大鹅草稿素材生成已经收敛为多视角 2D 图片素材,但入口页和旧参考图仍沿用黏土、低多边形、塑料、木雕、体素、金属等偏 3D 素材语言,容易让后续生成链路和用户预期继续漂移。
|
||||
- 决策:抓大鹅创作入口 `2D素材风格` 固定为 `扁平图标 / 赛璐璐卡通 / 像素复古 / 手绘水彩 / 贴纸描边 / 厚涂图标 / 自定义`;默认风格为 `flat-icon`。入口参考图统一由 `npm run assets:match3d-style-references -- --live` 调用 VectorEngine `gpt-image-2-all` 生成,输出到 `public/match3d-style-references/`。旧 3D 风格参考图不再保留为入口资产。
|
||||
- 决策:抓大鹅创作入口 `2D素材风格` 固定为 `扁平图标 / 赛璐璐卡通 / 像素复古 / 手绘水彩 / 贴纸描边 / 厚涂图标 / 自定义`;默认风格为 `flat-icon`。入口参考图统一由 `npm run assets:match3d-style-references -- --live` 调用 VectorEngine `gpt-image-2` 生成,输出到 `public/match3d-style-references/`。旧 3D 风格参考图不再保留为入口资产。
|
||||
- 影响范围:`Match3DAgentWorkspace`、抓大鹅入口交互测试、Match3D PRD、素材生成流水线技术文档、F1 入口文档和 `public/match3d-style-references/` 静态资产。
|
||||
- 验证方式:执行 `npm run test -- src\components\match3d-creation\Match3DAgentWorkspace.interaction.test.tsx`、`cargo test -p shared-contracts match3d --manifest-path server-rs\Cargo.toml`、`npm run typecheck`、`npm run check:encoding`,并人工抽查 `.tmp/match3d-style-preview.png`。
|
||||
- 关联文档:`docs/prd/AI_NATIVE_MATCH3D_CREATOR_AND_GAMEPLAY_SYSTEM_PRD_2026-04-30.md`、`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`、`docs/technical/MATCH3D_F1_CREATION_ENTRY_AND_AGENT_UI_2026-04-30.md`。
|
||||
@@ -271,8 +308,9 @@
|
||||
## 2026-05-12 拼图 UI 背景图复用 levels_json 持久化
|
||||
|
||||
- 背景:拼图草稿结果页需要像抓大鹅一样支持 UI 背景生成,但首版只需要作品级/首关背景,不应为图片生成结果新增 SpacetimeDB 表结构。
|
||||
- 决策:拼图 UI 背景字段存入首关 `levels_json`,字段为 `uiBackgroundPrompt`、`uiBackgroundImageSrc`、`uiBackgroundImageObjectKey`;`compile_puzzle_draft` 草稿编译阶段自动生成首关 UI 背景,自动草稿阶段必须拿到 `uiBackgroundImageSrc` 或 `uiBackgroundImageObjectKey` 才能返回成功;结果页新增 `UI` Tab,可编辑提示词并触发 `generate_puzzle_ui_background`,手动生成失败只展示在当前面板。`api-server` 读取 `public/ui-previews/puzzle-image-compact-ui-2026-05-08.png` 作为非拼图 UI 参考图,调用 VectorEngine `gpt-image-2-all` 生成 9:16 背景并要求中央正方形拼图区与外部 UI 背景边界清晰。SpacetimeDB 只保存结果,不做外部 I/O。
|
||||
- 决策:拼图 UI 背景字段存入首关 `levels_json`,字段为 `uiBackgroundPrompt`、`uiBackgroundImageSrc`、`uiBackgroundImageObjectKey`;`compile_puzzle_draft` 草稿编译阶段自动生成首关 UI 背景,自动草稿阶段必须拿到 `uiBackgroundImageSrc` 或 `uiBackgroundImageObjectKey` 才能返回成功;结果页新增 `UI` Tab,可编辑提示词并触发 `generate_puzzle_ui_background`,手动生成失败只展示在当前面板。`api-server` 读取 `public/ui-previews/puzzle-image-compact-ui-2026-05-08.png` 作为非拼图 UI 参考图,调用 VectorEngine `gpt-image-2` 生成 9:16 背景并要求中央正方形拼图区与外部 UI 背景边界清晰。SpacetimeDB 只保存结果,不做外部 I/O。
|
||||
- 2026-05-18 追加:为缩短首版草稿等待,`compile_puzzle_draft` 在首关命名和 `uiBackgroundPrompt` 稳定后并行启动首关关卡图生成与 UI 背景生成;上传主图且关闭 AI 重绘时,并行执行上传图持久化与 UI 背景生成。生成页预计完成时间按 5 分钟展示。
|
||||
- 2026-05-21 追加:拼图结果页独立“素材配置”Tab 已移除,UI spritesheet 与关卡纯背景收口到每关图片生成资产包。每次 `gpt-image-2` 预计 90 秒;草稿完整 AI 重绘路径约 298 秒,上传图且关闭 AI 重绘路径跳过首图生成约 208 秒。结果页关卡详情继续复用 `CreativeImageInputPanel`,本次上传/历史选择图优先成为主图卡片,正式图只作为无新参考图时的预览;仅有正式图时仍允许在画面描述框上传多张参考图。
|
||||
- 影响范围:拼图结果页、拼图运行态背景渲染、拼图 agent action、`module-puzzle` / `spacetime-module` / `spacetime-client` 的拼图关卡 JSON 映射、拼图流程技术文档。
|
||||
- 验证方式:执行 `npm run test -- src/components/puzzle-result/PuzzleResultView.test.tsx`、`cargo test -p api-server puzzle_ui_background --manifest-path server-rs/Cargo.toml`、`cargo check -p api-server --manifest-path server-rs/Cargo.toml`、`npm run typecheck`、`npm run check:encoding`。
|
||||
- 关联文档:`docs/technical/PUZZLE_FORM_CREATION_FLOW_2026-04-29.md`。
|
||||
@@ -280,7 +318,7 @@
|
||||
## 2026-05-12 抓大鹅结果页素材编辑统一走作品级资产面板
|
||||
|
||||
- 背景:抓大鹅结果页需要支持封面图上传 / AI 重绘、物品素材独立预览、单项删除和批量新增,且不能把素材编辑继续做成列表内联展开或前端临时状态。
|
||||
- 决策:结果页 `作品信息` 的封面图点击打开独立面板,封面图面板对齐拼图入口上传卡。已有上传主图时,请求体传 `uploadedImageSrc`,AI 重绘走 VectorEngine `/v1/images/edits`;关闭 AI 重绘时只写回上传图,不调用生图。没有上传主图时,请求体传 `referenceImageSrcs`,可混合本地上传、物品素材和 UI 素材,多参考图作为 `gpt-image-2-all` generations 的 `image` 数组传入。生成结果统一调用 `POST /api/creation/match3d/works/{profileId}/cover-image` 并转存到 `generated-match3d-assets`。`素材配置 > 物品` 列表项点击打开独立预览面板,不再提供单项重新生成按钮;单项删除和批量新增都写回同一份 `generated_item_assets_json`。批量新增调用 `POST /api/creation/match3d/works/{profileId}/item-assets`,复用草稿生成的 2D 素材图、5x5 切图、OSS 上传和可选点击音效链路,仅作用于新增物品,不新增 SpacetimeDB 表。
|
||||
- 决策:结果页 `作品信息` 的封面图点击打开独立面板,封面图面板对齐拼图入口上传卡。已有上传主图时,请求体传 `uploadedImageSrc`,AI 重绘走 VectorEngine `/v1/images/edits`,后端把上传图作为 multipart `image` part 传入 `gpt-image-2`;关闭 AI 重绘时只写回上传图,不调用生图。没有上传主图但存在 `referenceImageSrcs` 时,多参考图同样走 edits 的多个 `image` part;完全无参考图时走 `/v1/images/generations`。生成结果统一调用 `POST /api/creation/match3d/works/{profileId}/cover-image` 并转存到 `generated-match3d-assets`。`素材配置 > 物品` 列表项点击打开独立预览面板,不再提供单项重新生成按钮;单项删除和批量新增都写回同一份 `generated_item_assets_json`。批量新增调用 `POST /api/creation/match3d/works/{profileId}/item-assets`;该接口的物品 spritesheet 生成口径已被 2026-05-22 决策更新为关卡整图参考、`10*10` 绿幕图和上传前透明化。
|
||||
- 影响范围:Match3D 结果页、Match3D works shared contracts、`api-server` Match3D 作品路由、生成资产历史类型和草稿恢复路径。
|
||||
- 验证方式:执行 `npm run test -- src/components/match3d-result/Match3DResultView.test.tsx`、`npm run typecheck`、`cargo test -p api-server match3d --manifest-path server-rs/Cargo.toml`、`cargo check -p api-server --manifest-path server-rs/Cargo.toml`、`npm run check:encoding`。
|
||||
- 关联文档:`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`。
|
||||
@@ -303,7 +341,7 @@
|
||||
## 2026-05-13 宝贝爱画先作为寓教于乐独立本地 Demo 落地
|
||||
|
||||
- 背景:第三关 `宝贝爱画` 需要默认出现在“发现 / 寓教于乐”板块下方,但本阶段只验证画板、手部绘制、绘画魔法和本地保存闭环,不进入创作模板、公开作品或正式持久化。
|
||||
- 决策:`baby-love-drawing / 宝贝爱画` 先作为独立运行态接入,入口由发现页寓教于乐默认卡片打开,并支持 `/runtime/baby-love-drawing` 直达;关闭 `VITE_ENABLE_EDUTAINMENT_ENTRY` 时前端不展示频道/卡片且直达路由回落主应用。绘画魔法统一走 `POST /api/creation/edutainment/baby-love-drawing/magic` 后端安全代理,使用 VectorEngine `gpt-image-2-all` 与原始画布 Data URL 参考图生成绘本风图片;保存只写 localStorage,正式持久化后续再设计。
|
||||
- 决策:`baby-love-drawing / 宝贝爱画` 先作为独立运行态接入,入口由发现页寓教于乐默认卡片打开,并支持 `/runtime/baby-love-drawing` 直达;关闭 `VITE_ENABLE_EDUTAINMENT_ENTRY` 时前端不展示频道/卡片且直达路由回落主应用。绘画魔法统一走 `POST /api/creation/edutainment/baby-love-drawing/magic` 后端安全代理,使用 VectorEngine `gpt-image-2` 与原始画布 Data URL 参考图生成绘本风图片;保存只写 localStorage,正式持久化后续再设计。
|
||||
- 影响范围:`packages/shared/src/contracts/edutainmentBabyDrawing.ts`、`src/components/edutainment-runtime/BabyLoveDrawingRuntimeShell.tsx`、`src/services/edutainment-baby-drawing/`、`src/routing/appRoutes.tsx`、`src/components/rpg-entry/RpgEntryHomeView.tsx`、`server-rs/crates/api-server/src/edutainment_baby_drawing.rs`、`src/index.css`、宝贝爱画 PRD 与技术方案。
|
||||
- 验证方式:执行宝贝爱画 model/runtime/service/route 定向测试、`npm run typecheck`、定向 ESLint、`cargo test -p api-server edutainment_baby_drawing --manifest-path server-rs/Cargo.toml`、`cargo test -p api-server resolves_runtime_paths_to_creation_type_ids --manifest-path server-rs/Cargo.toml` 和编码检查;真实魔法生成需配置 `VECTOR_ENGINE_BASE_URL` 与 `VECTOR_ENGINE_API_KEY`。
|
||||
- 关联文档:`docs/prd/BABY_LOVE_DRAWING_EDUTAINMENT_LEVEL_PRD_2026-05-13.md`、`docs/technical/BABY_LOVE_DRAWING_RUNTIME_DEMO_IMPLEMENTATION_2026-05-13.md`。
|
||||
@@ -336,7 +374,7 @@
|
||||
## 2026-05-10 儿童动作 Demo 视觉资产统一为绘本草地舞台
|
||||
|
||||
- 背景:儿童动作 Demo 需要从暗色科技风切换到更适合儿童互动的卡通绘本草地风格,并且要让背景、地面、UI、地面指示环和用户轮廓使用同一套 image-2 资源口径。
|
||||
- 决策:热身舞台及后续儿童动作 Demo 场景、物品、UI 资源统一采用明亮卡通绘本草地视觉语言。真实资源默认输出到 `public/child-motion-demo/`。背景沿用 `picture-book-grass-stage.png`;地面、指示环、角色指示器和 UI 已拆分为用途专属资源:`picture-book-foreground-grass-v2.png`、`picture-book-ground-ring-v3.png`、`picture-book-character-outline-v4.png`、`picture-book-hud-strip-v2.png`、`picture-book-calibration-strip-v2.png`、`picture-book-start-panel-v2.png` 和 `picture-book-ui-button-v2.png`。其中角色指示器 v4 基于 v2 本地后处理为更细的白色描边样式,内部透明,耳朵、手指、脚趾等细节已弱化,页面显示尺寸相对上一版放大 50%。生成脚本固定为 `scripts/generate-child-motion-demo-assets.mjs`,并通过 `npm run assets:child-motion-demo` 调用 VectorEngine `gpt-image-2-all`;透明资源使用品红底生成后本地去背,中间源图仅保存在 `tmp/child-motion-demo-assets/`。在缺少 `VECTOR_ENGINE_BASE_URL` 或 `VECTOR_ENGINE_API_KEY` 时,只允许 dry-run 和 CSS 兜底,不伪造 live 生图结果。
|
||||
- 决策:热身舞台及后续儿童动作 Demo 场景、物品、UI 资源统一采用明亮卡通绘本草地视觉语言。真实资源默认输出到 `public/child-motion-demo/`。背景沿用 `picture-book-grass-stage.png`;地面、指示环、角色指示器和 UI 已拆分为用途专属资源:`picture-book-foreground-grass-v2.png`、`picture-book-ground-ring-v3.png`、`picture-book-character-outline-v4.png`、`picture-book-hud-strip-v2.png`、`picture-book-calibration-strip-v2.png`、`picture-book-start-panel-v2.png` 和 `picture-book-ui-button-v2.png`。其中角色指示器 v4 基于 v2 本地后处理为更细的白色描边样式,内部透明,耳朵、手指、脚趾等细节已弱化,页面显示尺寸相对上一版放大 50%。生成脚本固定为 `scripts/generate-child-motion-demo-assets.mjs`,并通过 `npm run assets:child-motion-demo` 调用 VectorEngine `gpt-image-2`;透明资源使用品红底生成后本地去背,中间源图仅保存在 `tmp/child-motion-demo-assets/`。在缺少 `VECTOR_ENGINE_BASE_URL` 或 `VECTOR_ENGINE_API_KEY` 时,只允许 dry-run 和 CSS 兜底,不伪造 live 生图结果。
|
||||
- 影响范围:`src/index.css`、`src/components/child-motion-demo/ChildMotionWarmupDemo.tsx` 的舞台视觉层、儿童动作 Demo 技术文档、后续 image-2 资产生成流程。
|
||||
- 验证方式:检查 `/child-motion-demo` 舞台是否在未生成资产时仍有可用草地绘本兜底;补齐 VectorEngine 私密配置后运行 `npm run assets:child-motion-demo -- --live` 或 `--live --only <asset-id>` 应能写出对应 PNG,并确认页面静态资源返回 `image/png`。若只调整透明去背、裁切或品红边缘,可运行 `npm run assets:child-motion-demo -- --live --postprocess-only --force --only <asset-id>` 复用源图后处理。页面接入时必须按资源原始比例等比使用,不得把方形软纸面板拉伸成 HUD、状态条或底部草坪。
|
||||
- 关联文档:`docs/technical/CHILD_MOTION_DEMO_WARMUP_IMPLEMENTATION_SPEC_2026-05-09.md`、`docs/technical/VECTOR_ENGINE_GPT_IMAGE_2_GENERATION_2026-05-09.md`。
|
||||
@@ -392,11 +430,19 @@
|
||||
## 2026-05-09 GPT-image-2 图片生成统一迁移到 VectorEngine
|
||||
|
||||
- 背景:仓库内 RPG、拼图、方洞和本地模板脚本的 GPT-image-2 生图此前依赖 APIMart 图片网关;团队要求参考 VectorEngine Apifox `api-448710071`,后续不再使用 APIMart 执行 GPT-image-2 图片生成。
|
||||
- 决策:所有 GPT-image-2 生图请求统一走 VectorEngine `POST /v1/images/generations`,基础配置读取 `VECTOR_ENGINE_BASE_URL` / `VECTOR_ENGINE_API_KEY` / `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`,上游模型使用 `gpt-image-2-all`,请求体不再携带 `official_fallback`,参考图字段改为 `image`。APIMart 只保留给创意 Agent 的 `gpt-5` Responses 文本/多模态链路。
|
||||
- 决策:所有 GPT-image-2 无参考图生图请求统一走 VectorEngine `POST /v1/images/generations`,有参考图请求走 `POST /v1/images/edits` multipart,基础配置读取 `VECTOR_ENGINE_BASE_URL` / `VECTOR_ENGINE_API_KEY` / `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`,上游模型使用 `gpt-image-2`,请求体不再携带 `official_fallback`。APIMart 只保留给创意 Agent 的 `gpt-5` Responses 文本/多模态链路。
|
||||
- 影响范围:`api-server` 共享图片 helper、拼图图片生成、角色主图、RPG 场景图、开局 CG 故事板、方洞视觉资产、生产环境示例、gpt-image-2 本地 skill 和相关技术文档。
|
||||
- 验证方式:执行 `npm run check:encoding`、`cargo test -p api-server openai_image --manifest-path server-rs/Cargo.toml`、`cargo test -p api-server puzzle --manifest-path server-rs/Cargo.toml`、`cargo test -p api-server custom_world_ai --manifest-path server-rs/Cargo.toml`、`cargo test -p api-server character_visual --manifest-path server-rs/Cargo.toml`,并用 `npm run dev:api-server` + `/healthz` 做后端 smoke。
|
||||
- 关联文档:`docs/technical/VECTOR_ENGINE_GPT_IMAGE_2_GENERATION_2026-05-09.md`、`docs/technical/API_SERVER_EXTERNAL_SERVICE_ENV_CONFIG_2026-05-07.md`。
|
||||
|
||||
## 2026-05-21 GPT-image-2 参考图统一走 edits multipart
|
||||
|
||||
- 背景:VectorEngine Apifox 创建 `api-446794806` 与编辑 `api-446794807` 明确区分无参考图创建和有参考图编辑;仓库旧实现曾把参考图塞入 `gpt-image-2` generations 的 `image` 数组,导致与供应商当前契约不一致。
|
||||
- 决策:所有 GPT-image-2 无参考图生成调用 `POST /v1/images/generations`,所有有参考图生成调用 `POST /v1/images/edits`,模型固定 `gpt-image-2`,参考图作为 multipart `image` part 传入;仓库不再调用 `gpt-image-2-all`。
|
||||
- 影响范围:`api-server` 共享图片 helper、拼图图片生成、Match3D 封面重绘和容器 UI 图、gpt-image-2 本地 skill、玩法链路文档和后端架构文档。
|
||||
- 验证方式:搜索仓库不应再出现 VectorEngine 图片编辑路径调用;执行 `cargo test -p api-server openai_image_generation --manifest-path server-rs/Cargo.toml`、`cargo test -p api-server puzzle_vector_engine --manifest-path server-rs/Cargo.toml`、`cargo test -p api-server match3d_background --manifest-path server-rs/Cargo.toml`。
|
||||
- 关联文档:`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`、`docs/【后端架构】server-rs与SpacetimeDB数据契约-2026-05-15.md`。
|
||||
|
||||
## 2026-05-08 Hyper3D Rodin Gen-2 只通过后端安全代理接入
|
||||
|
||||
- 背景:需要接入 Hyper3D Rodin Gen-2 的文生 3D 模型与图生 3D 模型,但供应商 API Key 不能进入前端、文档或 Git;本次只是外部副作用代理,不需要新增平台真相表。
|
||||
@@ -570,7 +616,7 @@
|
||||
## 2026-05-10 视觉小说入口收敛为单句创作 + 画风选择
|
||||
|
||||
- 背景:视觉小说入口页要对齐抓大鹅式的线性创作入口,只保留最小可用输入,避免再暴露文档 / 空白 / 对话式工作台。
|
||||
- 决策:入口页只展示一句话创作输入框和横向视觉画风卡片;画风通过 `seedText` 追加 `视觉画风` 和 `画风要求` 两行透传给既有创作链路;点击生成后先进入 `visual-novel-generating` 过程页,再自动进入 `visual-novel-result`。画风卡片主视觉固定消费 `public/visual-novel-style-references/` 下由 VectorEngine `gpt-image-2-all` 生成的静态参考图,不在前端运行时现场调用生图接口。
|
||||
- 决策:入口页只展示一句话创作输入框和横向视觉画风卡片;画风通过 `seedText` 追加 `视觉画风` 和 `画风要求` 两行透传给既有创作链路;点击生成后先进入 `visual-novel-generating` 过程页,再自动进入 `visual-novel-result`。画风卡片主视觉固定消费 `public/visual-novel-style-references/` 下由 VectorEngine `gpt-image-2` 生成的静态参考图,不在前端运行时现场调用生图接口。
|
||||
- 影响范围:`VisualNovelAgentWorkspace`、`visualNovelEntryGeneration`、`PlatformEntryFlowShellImpl`、视觉小说 PRD 和创作 Tab 设计文档;不新增后端字段或数据库结构。
|
||||
- 验证方式:执行 `npm run test -- VisualNovelAgentWorkspace`、视觉小说工作台相关 ESLint、`npx prettier --check` 和 `npm run check:encoding`;`npm run typecheck` 若失败需先区分是否来自无关 Match3D / RPG 既有改动。
|
||||
- 关联文档:`docs/prd/AI_NATIVE_VISUAL_NOVEL_TEMPLATE_PRD_2026-05-05.md`、`docs/design/PLATFORM_CREATE_TAB_CREATIVE_AGENT_HOME_2026-05-05.md`。
|
||||
@@ -594,7 +640,7 @@
|
||||
## 2026-05-12 抓大鹅物品种类从消除次数中拆出并改为 2D 五视角素材
|
||||
|
||||
- 背景:结果页草稿素材已经能生成和预览,但标准 / 硬核难度仍可能按 `clearCount` 误判需要 12 / 20 种素材,且继续生产 GLB 会拉长草稿生成耗时。
|
||||
- 决策:难度配置统一使用 `物品种类`:轻松 3、标准 9、进阶 15、硬核 21;历史硬核 `clearCount=20` 在运行态升为 21 组三消。新草稿和批量新增不再调用 Rodin、不再生成 GLB。每个物品生成 5 个不同 2D 视角,单张 1K 素材图固定按 5x5 切割,最多承载 5 个物品;超过 5 个物品时由 `api-server` 自动分批并行生图。发布必须校验已生成 `image_ready` 且有 `imageViews[]` 或首图引用的素材数量满足当前难度;试玩通过 `itemTypeCountOverride` 自动降到可用 2D 素材数量。历史模型字段只作为旧数据兼容,不再进入新生产链路。
|
||||
- 决策:难度配置统一使用运行态 `物品种类`:轻松 3、标准 9、进阶 15、硬核 20;历史硬核 `clearCount=20` 在运行态仍升为 21 组三消,但类型池最多 20 种。新草稿和批量新增不再调用 Rodin、不再生成 GLB。每次固定从 `2K 1:1`、`10*10` 物品 spritesheet 解析并持久化 20 个物品、每个 5 个不同 2D 形态,物品信息列表全部展示 20 个;持久化行列索引按每行两种物品计算,不能超过 `1..=10`。发布必须校验已生成 `image_ready` 且有 `imageViews[]`、首图引用或可解析的物品 spritesheet 满足当前难度;试玩通过 `itemTypeCountOverride` 自动降到可用 2D 素材数量。历史模型字段只作为旧数据兼容,不再进入新生产链路。
|
||||
- 影响范围:Match3D 结果页、运行态启动契约、`module-match3d` 初始 run 生成、SpacetimeDB start input / restart、发布校验和 Match3D 技术文档。
|
||||
- 验证方式:`npm run test -- src/components/match3d-result/Match3DResultView.test.tsx`、`cargo test -p module-match3d --manifest-path server-rs\Cargo.toml`、相关后端 check / tests。
|
||||
- 关联文档:`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`。
|
||||
@@ -694,3 +740,11 @@
|
||||
- 影响范围:平台入口、推荐流、公开详情、试玩启动、跳一跳运行态、`api-server` / SpacetimeDB 公开投影和 shared contracts。
|
||||
- 验证方式:从平台推荐或公开详情进入跳一跳作品时,路由 source type 为 `jump-hop`、public code 为 `JH-*`,运行态启动消费后端返回的完整 profile / run 数据;后端 smoke 统一使用 `npm run dev:api-server` 启动并检查 `/healthz`。
|
||||
- 关联文档:`docs/prd/【玩法创作】跳一跳俯视角玩法模板PRD-2026-05-19.md`、`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
# 2026-05-20 陶泥儿主视觉配色回收为暖白/陶土橙
|
||||
|
||||
- 背景:用户要求只替换产品各界面的 UI 颜色,不改布局,并以两张陶泥儿主视觉图作为配色依据。
|
||||
- 决策:平台亮色主题的主色回收到暖白 / 米杏底、陶土橙主按钮、深棕正文与浅杏边框;后台管理也同步切换到同一暖橙体系。主题变量优先通过 `src/index.css` 的 `--platform-*` token 统一控制,零散组件只做必要的局部替换。
|
||||
- 影响范围:主站平台壳层、常用表单 / 按钮 / 卡片 / 背景、后台管理 UI、业务进度条和小游戏结果条的通用强调色。
|
||||
- 验证方式:优先检查 `src/index.css` 与 `apps/admin-web/src/styles/admin.css` 是否还存在旧粉色主色;再用编码检查和可执行的本地 typecheck / build 验证。
|
||||
- 关联文档:`docs/【项目基线】当前产品与工程约束-2026-05-15.md`。
|
||||
|
||||
@@ -112,6 +112,24 @@ SpacetimeDB bindings 生成:
|
||||
npm run spacetime:generate
|
||||
```
|
||||
|
||||
CodeGraph 本地语义索引:
|
||||
|
||||
```bash
|
||||
npm run codegraph:init
|
||||
npm run codegraph:status
|
||||
npm run codegraph:sync
|
||||
npm run codegraph:index
|
||||
```
|
||||
|
||||
`.codegraph/config.json` 可随仓库共享;`.codegraph/codegraph.db`、缓存和日志为本机生成物,不提交。
|
||||
|
||||
Codex 项目级 hook 保存在 `.codex/config.toml` 与 `.codex/hooks/`:
|
||||
|
||||
- `PreToolUse` hook:`node .codex/hooks/pre-submit-compile-check.mjs`,Codex 准备执行 `git commit` 前检查 `npm run typecheck`、`npm run admin-web:typecheck`、`cargo check -p api-server --manifest-path server-rs/Cargo.toml`。
|
||||
- `PostToolUse` hook:`node .codex/hooks/post-edit-codegraph-sync.mjs`,工具修改文件后执行 `npm run codegraph:sync`。
|
||||
|
||||
个人 token、模型路由、MCP server 仍属于个人环境;需要时由成员本机执行 `codegraph install` 或查看 `codegraph install --print-config codex`,不要提交个人全局配置。
|
||||
|
||||
## 常用检查命令
|
||||
|
||||
- 后端通用用户行为埋点统一通过 `record_tracking_event_and_return` procedure、`SpacetimeRuntimeClient::record_tracking_event(...)` 与 api-server `tracking` 中间件写入 `tracking_event` / `tracking_daily_stat`;后台、RPG、大鱼吃小鱼、Visual Novel、Story、Combat 默认排除;作品级游玩埋点统一使用 `work_play_start`,详细事件清单见 `docs/technical/BACKEND_TRACKING_EVENT_COVERAGE_2026-05-09.md`。
|
||||
|
||||
@@ -14,6 +14,32 @@
|
||||
- 关联:相关文件、文档、提交或 Issue
|
||||
```
|
||||
|
||||
## 抓大鹅新 UI spritesheet 不要回退成中心容器图
|
||||
|
||||
- 现象:新素材流程生成后,运行态棋盘中心可能叠出一整张 UI spritesheet,导致按钮素材、方格和空白图集覆盖容器区域。
|
||||
- 原因:为了兼容旧 DTO,后端可能把 `uiSpritesheetImage*` 同步写入历史 `containerImage*` 字段;旧前端只看 `containerImage*`,会误把 UI 图集当透明中心容器。
|
||||
- 处理:读取中心容器图时先比较归一化后的 `containerImage*` 与 `uiSpritesheetImage*`。两者同源时忽略 `containerImage*`,只把它作为旧数据兼容字段;新流程背景图本身已经保留容器,运行态只需加载背景和解析 UI / 物品 spritesheet。
|
||||
- 验证:`npm run test -- src/components/match3d-runtime/Match3DRuntimeShell.test.tsx` 应覆盖“运行态不把兼容写入的UI spritesheet当中心容器图”。
|
||||
- 关联:`src/components/match3d-runtime/Match3DRuntimeShell.tsx`、`server-rs/crates/api-server/src/match3d/mappers.rs`、`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`。
|
||||
|
||||
## UI spritesheet 不要依赖模型直接生成透明背景
|
||||
|
||||
- 现象:拼图或抓大鹅运行态解析 UI spritesheet 时,把整张背景图、棋盘格、叶子或装饰图也当作 UI 素材区域,按钮映射错乱;截图里常表现为底部按钮区只剩透明棋盘格或素材碎片。
|
||||
- 原因:前端解析依赖 alpha 连通域检测,透明背景是前提;但生图模型收到“透明背景 spritesheet”提示后仍可能输出带实景背景或伪透明棋盘格的普通不透明 PNG,OSS 中保存的图没有真实 alpha。
|
||||
- 处理:UI spritesheet 提示词应要求统一纯绿色绿幕背景,而不是让模型直接产透明背景;后端在上传 OSS 前复用 `generated_asset_sheets::apply_generated_asset_sheet_green_screen_alpha(...)` 把绿幕扣成真实透明 PNG,再把透明图写入 `uiSpritesheetImageSrc/uiSpritesheetImageObjectKey`。
|
||||
- 验证:`cargo test -p api-server puzzle_ui_spritesheet_postprocess_turns_green_screen_transparent --manifest-path server-rs\Cargo.toml`、`cargo test -p api-server puzzle_level_scene_spritesheet_and_background_requests_use_references --manifest-path server-rs\Cargo.toml`、`cargo test -p api-server match3d_derived_asset_prompts_match_three_sheet_pipeline --manifest-path server-rs\Cargo.toml`。
|
||||
- 关联:`server-rs/crates/api-server/src/puzzle/generation.rs`、`server-rs/crates/api-server/src/match3d/works.rs`、`server-rs/crates/api-server/src/generated_asset_sheets.rs`、`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`。
|
||||
|
||||
## 拼图 UI spritesheet 运行态不要二次包圆底或拉伸比例
|
||||
|
||||
- 现象:拼图运行态左上返回和右上设置按钮外面出现白色圆圈;底部“提示 / 原图 / 冻结”三枚素材被压扁、拉宽或拉成正圆,和图集原始按钮比例不一致。
|
||||
- 原因:UI spritesheet 已经包含按钮视觉本体,但运行态仍给顶部按钮套默认圆形 icon 容器;底部三枚素材用 `h-full w-full rounded-full` 铺满按钮格,覆盖了自动检测矩形的真实宽高比。
|
||||
- 处理:有 `uiSpritesheetImage*` 时,顶部返回 / 设置按钮容器只保留透明点击区和 focus 状态,不再叠加默认圆形底;`buildPuzzleUiSpriteBackgroundStyle(...)` 对检测到的矩形写入 `aspectRatio`,底部三枚素材按原始宽高比和最大尺寸渲染,不强制 `w-full`。
|
||||
- 验证:`npm run test -- src/components/puzzle-runtime/PuzzleRuntimeShell.test.tsx`、`npm run test -- src/services/puzzle-runtime/puzzleUiSpritesheetParser.test.ts`。
|
||||
- 关联:`src/components/puzzle-runtime/PuzzleRuntimeShell.tsx`、`src/services/puzzle-runtime/puzzleUiSpritesheetParser.ts`、`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`。
|
||||
|
||||
2026-05-22 补充:展示矩形和点击热区要分开处理。`puzzleUiSpritesheetParser` 的 `regions` 保留完整视觉裁切矩形,`hitRegions` 用较高 alpha 阈值只包住实心按钮主体;运行态底部 spritesheet 道具按钮启用 `puzzle-runtime-sprite-tool-button--precise-hit`,父按钮不吃整块透明留白,内部 `puzzle-runtime-ui-sprite-hit-zone` 才接收指针事件,避免透明区域成为点击热区。
|
||||
|
||||
## 图像输入组件不要把业务状态藏在页面内联实现里
|
||||
|
||||
- 现象:拼图页把参考图上传、缩略图、主图删除确认和 AI 重绘开关内联实现后,后续想复用到其它创作页时,页面级状态和通用 UI 状态混在一起,容易出现多套上传卡和参考图展示口径。
|
||||
@@ -62,6 +88,14 @@
|
||||
- 验证:`npm run test -- src/components/game-canvas/GameCanvasEntityLayer.test.tsx` 覆盖伤害/治疗飘字样式策略;运行态截图中敌方头顶伤害数字应能在暗场景上辨认。
|
||||
- 关联:`src/components/game-canvas/GameCanvasEntityLayer.tsx`、`docs/【项目基线】当前产品与工程约束-2026-05-15.md`。
|
||||
|
||||
## 弹窗里复用 CreativeImageInputPanel 要保留画面卡高度
|
||||
|
||||
- 现象:拼图草稿结果页的关卡详情弹窗中仍能看到“画面图”标题、画面描述和生成按钮,但实际画面图卡片视觉上消失。
|
||||
- 原因:`CreativeImageInputPanel` 内部依赖 `flex-1`、`h-full` 和 `max-h-full` 撑开正方形画面卡;放进弹窗里的普通 `section` 后,父级没有可计算高度,卡片会被压到不可见。
|
||||
- 处理:通用画面卡 `puzzle-image-upload-card` 保持 `aspect-square` 的同时设置稳定 `min-height`,让入口页和关卡详情弹窗都能显示主图/上传区。
|
||||
- 验证:`npm run test -- src/components/puzzle-result/PuzzleResultView.test.tsx -t "opens an independent level detail dialog"` 应断言关卡详情中的 `.puzzle-image-upload-card` 具备最小高度类;`npm run test -- src/components/common/CreativeImageInputPanel.test.tsx` 应继续通过。
|
||||
- 关联:`src/components/common/CreativeImageInputPanel.tsx`、`src/components/puzzle-result/PuzzleResultView.tsx`、`src/components/puzzle-result/PuzzleResultView.test.tsx`。
|
||||
|
||||
## Windows provision 下载截断要断点续传而不是回退目标机下载
|
||||
|
||||
- 现象:`Genarrative-Server-Provision` 在 `Download Provision Tool Archives` 阶段出现 `curl: (18) end of response ... bytes missing`,常见于 `otelcol-contrib_0.151.0_linux_amd64.tar.gz` 等 GitHub release 大文件。
|
||||
@@ -86,6 +120,30 @@
|
||||
- 验证:普通 route 请求在 SpacetimeDB 不可用时仍能返回,恢复后 sealed 文件会继续被清理。
|
||||
- 关联:`server-rs/crates/api-server/src/tracking_outbox.rs`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
## release tracking outbox 权限错误先查 env 缺失
|
||||
|
||||
- 现象:release 机器 `journalctl -u genarrative-api.service` 每秒刷 `tracking outbox 定时封存 active 文件失败 error=Permission denied (os error 13)` 和 `tracking outbox 批量写入 SpacetimeDB 失败`。
|
||||
- 原因:旧 `/etc/genarrative/api-server.env` 没有 `GENARRATIVE_TRACKING_OUTBOX_DIR` 时,api-server 会回退到本地开发默认相对路径 `server-rs/.data/tracking-outbox`;systemd 工作目录是只读发布目录 `/opt/genarrative/releases/<version>`,`genarrative` 用户不能在其中创建 `server-rs`。
|
||||
- 处理:补齐 `GENARRATIVE_TRACKING_OUTBOX_DIR=/var/lib/genarrative/tracking-outbox` 及 batch/flush/max 配置,创建并授权 `/var/lib/genarrative/tracking-outbox` 给 `genarrative:genarrative`,再重启 `genarrative-api.service`。Server-Provision 与 API-Deploy 会保留旧 env 但自动补缺这些运行态路径。
|
||||
- 验证:`tr '\0' '\n' < /proc/$(systemctl show genarrative-api.service -p MainPID --value)/environ | grep GENARRATIVE_TRACKING_OUTBOX_DIR` 应指向 `/var/lib/genarrative/tracking-outbox`;重启后当前 PID 不再出现 `Permission denied (os error 13)`。
|
||||
- 关联:`scripts/deploy/production-api-deploy.sh`、`scripts/jenkins-server-provision.sh`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
## 外部 API 失败没法追溯先查 external_api_call_failure
|
||||
|
||||
- 现象:VectorEngine 图片生成 / 编辑接口对前端只表现为 `502` / `504` 或“上游服务请求失败”,但难以区分是请求发送失败、上游 429/5xx、响应解析失败、未返回图片,还是下载图片失败。
|
||||
- 原因:外部 API 失败如果只靠普通日志,不一定能和 OTLP 指标、trace 与 SpacetimeDB 历史查询稳定关联;重启后也容易丢失上下文。
|
||||
- 处理:先查 OTLP 指标 `genarrative.external_api.failures{provider,failure_stage,status_class,retryable}`,再查 `tracking_event` 中 `event_key = 'external_api_call_failure'` 的 `metadata_json`。当前通用 VectorEngine `gpt-image-2-all` 适配器会记录 provider、endpoint、operation、failureStage、statusCode、statusClass、timeout、retryable、errorMessage、latencyMs、promptChars、referenceImageCount、imageModel 和 rawExcerpt。
|
||||
- 验证:`SELECT event_id, scope_id AS provider, metadata_json, occurred_at FROM tracking_event WHERE event_key = 'external_api_call_failure' ORDER BY occurred_at DESC LIMIT 50;`;如果查不到同时看 tracking outbox 目录权限和 sealed 文件是否堆积。
|
||||
- 关联:`server-rs/crates/api-server/src/external_api_audit.rs`、`server-rs/crates/api-server/src/openai_image_generation.rs`、`docs/【后端架构】server-rs与SpacetimeDB数据契约-2026-05-15.md`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
## release 创作接口 413 先查是否还在提交 Data URL
|
||||
|
||||
- 现象:release 上 `POST /api/runtime/puzzle/agent/sessions/{session_id}/actions` 携带参考图 Data URL 时返回 `413 Request Entity Too Large`,access log 显示 `request_time=0.000`、`upstream_status=-`。
|
||||
- 原因:Nginx 默认 `client_max_body_size` 只有 1 MiB,请求在反代层被拒绝,根本没有到达 `api-server`;即使模板放宽到 `64m`,把图片 base64 放进创作 JSON body 仍会放大请求体并把上限问题推给下一层。
|
||||
- 处理:长期修复不是继续调大 Nginx,而是让浏览器先走 `/api/assets/direct-upload-tickets` 直传 OSS,再 `/api/assets/objects/confirm` 确认 `asset_object`,拼图 action 只提交 `referenceImageAssetObjectId(s)`;后端校验 owner / bucket / kind / MIME / size 后签只读 URL 给 VectorEngine。Nginx `client_max_body_size 64m` 只保留为旧客户端和兼容输入兜底,发布后仍需 `nginx -t && nginx -s reload`。
|
||||
- 验证:前端 action payload 不应再出现大段 `data:image/...;base64`;`nginx -T 2>/dev/null | grep client_max_body_size` 可确认反代兜底;再次提交参考图时 access log 应有正常 `upstream_status`,后端测试 `puzzle_reference_image_sources_prefer_asset_object_ids` / `puzzle_asset_object_reference_requires_matching_owner` 应通过。
|
||||
- 关联:`src/services/puzzle-works/puzzleAssetClient.ts`、`server-rs/crates/api-server/src/puzzle/vector_engine.rs`、`deploy/nginx/genarrative.conf`、`deploy/nginx/genarrative-dev-http.conf`、`deploy/container/nginx.conf`、`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。
|
||||
|
||||
## 汪汪声浪入口不要再回到独立配置阶段
|
||||
|
||||
- 现象:汪汪声浪入口如果继续切换到独立配置阶段,会和拼图、抓大鹅的创作页内嵌结构不一致,用户会感觉入口跳页。
|
||||
@@ -205,7 +263,7 @@
|
||||
|
||||
## 陶泥儿 logo 生图慢请求先缩短 prompt 并单张串行
|
||||
|
||||
- 现象:使用 VectorEngine `gpt-image-2-all` 生成陶泥儿 logo 概念图时,部分 prompt 会超过 10 分钟仍无响应,或返回 `429` / `当前分组上游负载已饱和`;同一批次里后续图片会被前面的慢请求拖住。
|
||||
- 现象:使用 VectorEngine `gpt-image-2` 生成陶泥儿 logo 概念图时,部分 prompt 会超过 10 分钟仍无响应,或返回 `429` / `当前分组上游负载已饱和`;同一批次里后续图片会被前面的慢请求拖住。
|
||||
- 原因:复杂抽象 logo prompt 同时包含品牌解释、禁用元素、中文结构和多重隐喻时,上游排队与生成时长不稳定;并发或批量运行会放大单条慢请求的影响。
|
||||
- 处理:先 `--dry-run` 看请求体;真实生成时优先短 prompt、单一造型、单张串行或小批量。失败后不要反复重试同一长 prompt,先压缩到“一个主体 + 一个负形 + 颜色 + 禁用文字/播放键/聊天气泡”再跑。联系表中的中文标签不要通过 PowerShell 管道内联 Python 写入,容易因编码链路显示为问号,可改用英文标签或脚本文件方式。
|
||||
- 验证:生成文件落在 `public/branding/taonier-logo-*/`,用 Pillow 检查图片尺寸和非空;执行 `node --check scripts/generate-taonier-logo-concepts.mjs`、`npm run check:encoding`、`git diff --check`。
|
||||
@@ -223,11 +281,11 @@
|
||||
|
||||
- 现象:点击生成抓大鹅草稿后,页面只提示“服务暂不可用”,或者本地 `npm run dev:api-server` 看似启动但生成接口不可用。
|
||||
- 原因:配置缺失类错误通常在后端 `error.details.reason` 中给出具体缺项,前端如果只读 `details.message` 会吞掉原因;本地只配置 `ALIYUN_OSS_BUCKET` / `ALIYUN_OSS_ENDPOINT` 时,旧逻辑还会在启动期构造空 AccessKey 的 OSS 客户端并失败。抓大鹅新链路仍是 2D 生图切割,不需要也不应回退 Rodin/GLB。
|
||||
- 处理:前端 API 错误展示优先读取 `details.reason`,再读取 `details.message`,避免底层 `error sending request` 覆盖真正可操作的配置或网络原因;`api-server` 只有在 OSS 四件套齐全时初始化 OSS 客户端,部分缺失只记 warning 并让具体 generated 上传/换签接口返回 `OSS 未完成环境变量配置`。抓大鹅素材、封面和背景生成在调用 VectorEngine 前先预检 OSS,并通过 `details.missingEnv` 列出缺项;真实生成需补齐 `VECTOR_ENGINE_BASE_URL`、`VECTOR_ENGINE_API_KEY` 和完整 `ALIYUN_OSS_*` 四件套。抓大鹅 `5*5` 素材图提示词还必须要求相邻物体主体至少保留 `1/4` 单格宽度空白间距,避免切割后相邻格内容污染。
|
||||
- 处理:前端 API 错误展示优先读取 `details.reason`,再读取 `details.message`,避免底层 `error sending request` 覆盖真正可操作的配置或网络原因;`api-server` 只有在 OSS 四件套齐全时初始化 OSS 客户端,部分缺失只记 warning 并让具体 generated 上传/换签接口返回 `OSS 未完成环境变量配置`。抓大鹅素材、封面和背景生成在调用 VectorEngine 前先预检 OSS,并通过 `details.missingEnv` 列出缺项;真实生成需补齐 `VECTOR_ENGINE_BASE_URL`、`VECTOR_ENGINE_API_KEY` 和完整 `ALIYUN_OSS_*` 四件套。抓大鹅 UI spritesheet 和物品 spritesheet 的提示词必须要求纯绿色绿幕背景,后端上传 OSS 前统一扣成透明 PNG,避免运行态 alpha 连通域解析失败。
|
||||
- 验证:`npm run test -- src/services/apiClient.test.ts` 覆盖 `details.reason`;`cargo test -p api-server state --manifest-path server-rs/Cargo.toml` 覆盖半配置 OSS 不阻断启动;`npm run dev:api-server` 后按实际 `GENARRATIVE_API_PORT` 请求 `/healthz`,不要默认打 `3100`。
|
||||
- 关联:`packages/shared/src/http.ts`、`server-rs/crates/api-server/src/state.rs`、`docs/technical/API_SERVER_EXTERNAL_SERVICE_ENV_CONFIG_2026-05-07.md`、`docs/technical/AUTH_SNAPSHOT_AND_MATCH3D_LOCAL_DEV_FIX_2026-05-01.md`。
|
||||
|
||||
2026-05-14 补充:抓大鹅“物品素材 sheet”已改用 VectorEngine Gemini `gemini-3-pro-image-preview` 原生 `generateContent`,真实生成读取 `VECTOR_ENGINE_BASE_URL`、`VECTOR_ENGINE_API_KEY` 和 `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`;封面和 `9:16` 背景图走 VectorEngine `/v1/images/generations`,`1:1` 容器 UI 走 VectorEngine `/v1/images/edits` multipart 参考图链路。排查素材 sheet 时看请求路径是否为 `/v1beta/models/gemini-3-pro-image-preview:generateContent?key=...`,响应图片在 `candidates[].content.parts[].inlineData.data` / `inline_data.data`,不要再按 APIMart `/images/generations` 或 `/tasks/{task_id}` 排查。
|
||||
2026-05-22 补充:抓大鹅“物品 spritesheet”不再按旧 Gemini `generateContent` / `5*5` sheet 路径排查;当前链路先用 `gpt-image-2` 无参考图生成 `9:16` 关卡整图,再以该关卡整图作为 multipart `image` 参考并发编辑生成 `1K 1:1` UI spritesheet、`1K 9:16` 背景图和 `2K 1:1` 物品 spritesheet。UI 与物品 spritesheet 都要求纯绿色绿幕背景,上传 OSS 前通过后端透明化处理写入真实 alpha PNG。
|
||||
|
||||
## 抓大鹅发布按钮要先开发布面板,封面编辑收口到发布面板内
|
||||
|
||||
@@ -321,7 +379,7 @@
|
||||
## 儿童动作 Demo 绘本风资源未生成先查 VectorEngine 配置
|
||||
|
||||
- 现象:`/child-motion-demo` 已经呈现绘本草地风格,但 `public/child-motion-demo/picture-book-grass-stage.png`、`picture-book-grass-floor.png`、`picture-book-ground-ring.png`、`picture-book-character-outline.png`、`picture-book-ui-panel.png` 或 `picture-book-ui-button.png` 不存在,Network 里对应图片返回 404,或运行 `npm run assets:child-motion-demo -- --live` 返回缺少 VectorEngine 配置。
|
||||
- 原因:儿童动作 Demo 的真实背景、地面、UI、地面指示环和角色轮廓资源都使用 VectorEngine `gpt-image-2-all` 生成,脚本只读取 `VECTOR_ENGINE_BASE_URL`、`VECTOR_ENGINE_API_KEY` 和可选 `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`;仓库内不能提交真实 key,缺配置时页面只能使用 CSS 草地绘本兜底。
|
||||
- 原因:儿童动作 Demo 的真实背景、地面、UI、地面指示环和角色轮廓资源都使用 VectorEngine `gpt-image-2` 生成,脚本只读取 `VECTOR_ENGINE_BASE_URL`、`VECTOR_ENGINE_API_KEY` 和可选 `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`;仓库内不能提交真实 key,缺配置时页面只能使用 CSS 草地绘本兜底。
|
||||
- 处理:在本地私密环境补齐 `VECTOR_ENGINE_BASE_URL=https://api.vectorengine.ai` 与 `VECTOR_ENGINE_API_KEY`,不要把 key 写入 Git;先运行 `npm run assets:child-motion-demo -- --dry-run` 核对 prompt,再运行 `npm run assets:child-motion-demo -- --live` 或 `npm run assets:child-motion-demo -- --live --only ui-panel` 等小批量命令生成资源。透明资源的品红底源图写入 `tmp/child-motion-demo-assets/`,不要把源图或预览图放入 `public/child-motion-demo/` 作为正式资产。
|
||||
- 验证:生成后确认 `public/child-motion-demo/` 只保留页面引用的最终 PNG,重新打开 `/child-motion-demo` 可看到真实绘本草地背景、地面、圆环、角色轮廓和 UI 资源;`npm run check:encoding` 仍通过。
|
||||
- 关联:`scripts/generate-child-motion-demo-assets.mjs`、`src/index.css`、`docs/technical/CHILD_MOTION_DEMO_WARMUP_IMPLEMENTATION_SPEC_2026-05-09.md`。
|
||||
@@ -345,8 +403,8 @@
|
||||
## GPT-image-2 不再读 APIMart 图片配置
|
||||
|
||||
- 现象:配置了 `APIMART_BASE_URL` / `APIMART_API_KEY` 后,RPG、拼图或方洞的 GPT-image-2 生图仍返回缺配置,或请求体里还出现 `official_fallback` / `image_urls`。
|
||||
- 原因:2026-05-09 后 GPT-image-2 图片生成已切到 VectorEngine `gpt-image-2-all`,APIMart 只保留给创意 Agent 的 `gpt-5` Responses 文本/多模态链路。
|
||||
- 处理:为图片生成配置 `VECTOR_ENGINE_BASE_URL=https://api.vectorengine.ai`、`VECTOR_ENGINE_API_KEY`、`VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`;排查请求体时确认路径为 `/v1/images/generations`、模型为 `gpt-image-2-all`、参考图字段为 `image`。
|
||||
- 原因:2026-05-21 后 GPT-image-2 图片生成按 VectorEngine 创建/编辑接口分流,APIMart 只保留给创意 Agent 的 `gpt-5` Responses 文本/多模态链路。
|
||||
- 处理:为图片生成配置 `VECTOR_ENGINE_BASE_URL=https://api.vectorengine.ai`、`VECTOR_ENGINE_API_KEY`、`VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`;排查请求体时确认无参考图路径为 `/v1/images/generations`、有参考图路径为 `/v1/images/edits`,模型为 `gpt-image-2`。
|
||||
- 验证:运行 `cargo test -p api-server openai_image --manifest-path server-rs/Cargo.toml` 和相关玩法图片生成测试;真实联调只在本地私密环境放置 VectorEngine key。
|
||||
- 关联:`docs/technical/VECTOR_ENGINE_GPT_IMAGE_2_GENERATION_2026-05-09.md`、`server-rs/crates/api-server/src/openai_image_generation.rs`。
|
||||
|
||||
@@ -366,19 +424,19 @@
|
||||
- 验证:后端单测覆盖 `build_puzzle_levels_with_primary_update` 和 `apply_generated_puzzle_candidates_to_session_snapshot`;结果页重新生成应在未重新上传时继续带入 `level.pictureReference`。
|
||||
- 关联:`server-rs/crates/api-server/src/puzzle.rs`、`src/components/puzzle-result/PuzzleResultView.tsx`。
|
||||
|
||||
## 拼图图生图仍不像参考图时先看是否走了 edits
|
||||
## 拼图参考图不像时先看 edits multipart image
|
||||
|
||||
- 现象:Network payload 已带 `referenceImageSrc`,但 VectorEngine 生成结果仍明显不像上传图。
|
||||
- 原因:`gpt-image-2-all` 的 `/v1/images/generations` 更适合纯文生图;有参考图且需要重绘时应切到 `/v1/images/edits` 的 multipart 图生图接口。
|
||||
- 处理:`referenceImageSrc` 存在且 `aiRedraw = true` 时直接走 edits,prompt 仍保留参考图强约束;入口页关闭 AI 重绘时直接应用上传图,不调用图片生成;前端把参考图压到单边 1024 内,后端解析后拒绝超过 8MB 的参考图字节。
|
||||
- 验证:后端单测应覆盖 `images/edits` 路由、`b64_json` 响应解码和参考图强提示;真实联调先看日志里是否命中 `拼图 VectorEngine 图片编辑 HTTP 返回`。
|
||||
- 原因:参考图只在 `aiRedraw = true` 时由后端解析并传给 `gpt-image-2` `/v1/images/edits` 的 multipart `image` part;若前端没传 `referenceImageSrc`、后端解析失败或 prompt 缺少参考图强约束,生成会退化为纯文生图。
|
||||
- 处理:`referenceImageSrc` 存在且 `aiRedraw = true` 时走 edits multipart,prompt 保留参考图强约束;入口页关闭 AI 重绘时直接应用上传图,不调用图片生成;前端把参考图压到单边 1024 内,后端解析后拒绝超过 8MB 的参考图字节。
|
||||
- 验证:后端单测应覆盖 `/v1/images/edits` 路由、`b64_json` 响应解码和参考图强提示;真实联调看日志里是否命中 `拼图 VectorEngine 图片编辑 HTTP 返回`。
|
||||
- 关联:`server-rs/crates/api-server/src/puzzle.rs`、`src/services/puzzleReferenceImage.ts`、`docs/technical/VECTOR_ENGINE_GPT_IMAGE_2_GENERATION_2026-05-09.md`。
|
||||
|
||||
## 拼图 edits 报 error sending request 先看网络分类
|
||||
|
||||
- 现象:拼图有参考图时返回 `拼图图片生成失败:创建拼图 VectorEngine 图片编辑任务失败:error sending request for url (https://api.vectorengine.ai/v1/images/edits)`,后端没有 `拼图 VectorEngine 图片编辑 HTTP 返回` 日志。
|
||||
- 原因:这是 `reqwest` 在 `send()` 阶段失败,尚未收到 VectorEngine HTTP 响应;常见原因是服务器网络 / DNS / 防火墙 / 代理问题,或上游网关中断 multipart 连接。
|
||||
- 处理:查看错误响应 `details.reason/source/connect/body/timeout/endpoint` 和 `拼图 VectorEngine 请求发送失败` 日志。拼图图片客户端已强制 HTTP/1.1,降低 multipart HTTP/2 兼容风险;若 `connect=true` 先查网络出口,若 `body=true` 先查参考图大小和 multipart 发送。
|
||||
- 处理:查看错误响应和 `拼图 VectorEngine 图片编辑` 相关日志;若请求发送阶段失败,先查网络出口、DNS、防火墙、代理、参考图大小和 `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`。
|
||||
- 验证:`curl --http1.1 -i -X POST https://api.vectorengine.ai/v1/images/edits -H "Authorization: Bearer invalid" -F "model=gpt-image-2" -F "prompt=test" -F "n=1" -F "size=1024x1024" -F "image=@public/match3d-background-references/pot-fused-reference.png;type=image/png"` 至少应返回 HTTP `401`,说明域名、TLS、路径和 multipart 上传可达;执行 `cargo test -p api-server puzzle_vector_engine --manifest-path server-rs/Cargo.toml`。
|
||||
- 关联:`server-rs/crates/api-server/src/puzzle.rs`、`docs/technical/VECTOR_ENGINE_GPT_IMAGE_2_GENERATION_2026-05-09.md`、`docs/technical/API_SERVER_EXTERNAL_SERVICE_ENV_CONFIG_2026-05-07.md`。
|
||||
|
||||
@@ -409,7 +467,7 @@
|
||||
## 拼图草稿生成 180 秒后 502/504 先查 VectorEngine 超时与前端重试
|
||||
|
||||
- 现象:点击“生成拼图游戏草稿”后,`POST /api/runtime/puzzle/agent/sessions/{sessionId}/actions` 等待约 180 秒返回 `502 Bad Gateway` 或 `504 Gateway Timeout`;钱包流水里同一 session 可能出现连续两组 `puzzle_initial_image` 扣费后退款。
|
||||
- 原因:首图生成走 VectorEngine `gpt-image-2-all`,默认 `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS=1000000`;若上游在该窗口内未返回,后端退款并返回超时错误。旧前端 action 写请求会对 502/503/504 自动重试一次,导致同一次点击重复触发生图与扣退费。
|
||||
- 原因:首图生成走 VectorEngine `gpt-image-2`,默认 `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS=1000000`;若上游在该窗口内未返回,后端退款并返回超时错误。旧前端 action 写请求会对 502/503/504 自动重试一次,导致同一次点击重复触发生图与扣退费。
|
||||
- 处理:拼图/创作 Agent 的 `executeAction` 默认不做前端自动重试;后端将 VectorEngine / 图片请求超时映射为 `504 Gateway Timeout`,`error.details.provider=vector-engine` 且 `timeout=true`。真实排障按日志同一 `session_id` 查 `拼图 VectorEngine 图片生成 HTTP 返回` 是否缺失,以及钱包流水扣费到退款的时间差是否接近 `VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS`。
|
||||
- 验证:运行 `npm run test -- src/services/creation-agent/creationAgentClientFactory.test.ts src/services/apiClient.test.ts`、`cargo test -p api-server puzzle_vector_engine --manifest-path server-rs/Cargo.toml`,真实联调重启 `npm run dev:api-server` 后检查 `/healthz`。
|
||||
- 关联:`src/services/creation-agent/creationAgentClientFactory.ts`、`server-rs/crates/api-server/src/puzzle.rs`、`docs/technical/API_SERVER_EXTERNAL_SERVICE_ENV_CONFIG_2026-05-07.md`。
|
||||
@@ -443,7 +501,7 @@
|
||||
- 现象:用 Node `fetch` 直接请求 `POST /v1/images/generations`,已经设置较长的 AbortController 超时,但仍在约 180 到 300 秒后抛 `AbortError`、`TypeError: fetch failed` 或 `UND_ERR_HEADERS_TIMEOUT`;同一 prompt 改用原生 `https.request` 可以在较短时间内成功返回图片。
|
||||
- 原因:Node/Undici 的默认 headers timeout 可能早于业务脚本期望的长生图等待窗口触发,表现上容易被误判成 VectorEngine 上游本身超时。
|
||||
- 处理:长期脚本优先复用后端 reqwest 或项目已有生成脚本;临时本地工具若必须用 Node,可改用原生 `http`/`https.request` 并显式设置 socket timeout,或为 Undici 单独配置 headers timeout。仍需隐藏 `VECTOR_ENGINE_API_KEY`,只报告配置是否存在。
|
||||
- 验证:同一 `gpt-image-2-all` 请求体、同一环境变量下,原生 HTTP 请求能返回 `url` / `b64_json` 并落盘;失败时错误里能区分请求发送、首部等待、下载和解码阶段。
|
||||
- 验证:同一 `gpt-image-2` 请求体、同一环境变量下,原生 HTTP 请求能返回 `url` / `b64_json` 并落盘;失败时错误里能区分请求发送、首部等待、下载和解码阶段。
|
||||
- 关联:`.codex/skills/gpt-image-2-apimart/SKILL.md`、`server-rs/crates/api-server/src/openai_image_generation.rs`。
|
||||
|
||||
## 旧后端路线文档造成判断漂移
|
||||
@@ -860,7 +918,7 @@
|
||||
|
||||
- 现象:修改抓大鹅素材时容易沿用旧 Rodin/GLB 方案,导致新草稿生成耗时变长、进度停在模型阶段,或运行态等待不存在的 GLB。
|
||||
- 原因:仓库里保留了 Hyper3D 通用代理和历史模型字段,旧文档也曾要求草稿阶段同步生成 GLB。当前产品口径已经改为 2D 多视角素材。
|
||||
- 处理:新 `match3d_compile_draft` 与批量新增只生成 2D 图片:每个物品 5 个视角,单张 1K 素材图固定 5x5,最多承载 5 个物品,一行对应一个物品,不足 5 个物品也补齐到完整 5 行;超过 5 个物品自动分批并行生图。素材图 prompt 固定要求纯绿色绿幕背景,切割前先把绿幕处理为透明 alpha,再做格内内容前景边界校准并带留白,避免固定内缩切掉贴近格线的主体。`generatedItemAssets[].status` 使用 `image_ready`,发布校验看 `imageViews[]` 或首图引用。`generated-models` 仅用于历史外部模型链接转存,不能作为新生产链路。
|
||||
- 处理:新 `match3d_compile_draft` 与批量新增只生成 2D 图片:每个物品 5 个形态,单张 `2K 1:1` 物品 spritesheet 固定 `10*10`,每行承载两种物品、每种五个形态,单张最多承载 20 种物品。素材图 prompt 固定要求纯绿色绿幕背景,上传 OSS 前先把整张 spritesheet 绿幕处理为透明 alpha,再由运行态和编辑器按 alpha 连通域解析;`generatedItemAssets[].status` 使用 `image_ready`,发布校验看 `imageViews[]`、首图引用或可解析的物品 spritesheet。`generated-models` 仅用于历史外部模型链接转存,不能作为新生产链路。
|
||||
- 验证:`cargo test -p api-server match3d --manifest-path server-rs/Cargo.toml`、`npm run test -- src\services\miniGameDraftGenerationProgress.test.ts src\components\match3d-result\Match3DResultView.test.tsx src\components\match3d-runtime\Match3DRuntimeShell.test.tsx`。
|
||||
- 关联:`server-rs/crates/api-server/src/match3d.rs`、`src/components/match3d-runtime/Match3DRuntimeShell.tsx`、`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`。
|
||||
|
||||
@@ -896,11 +954,11 @@
|
||||
- 验证:执行 `npm run test -- src/components/match3d-runtime/Match3DRuntimeShell.test.tsx` 和 `npm run test -- src/components/rpg-entry/RpgEntryFlowShell.agent.interaction.test.tsx -t "Match3D runtime"`;浏览器 Network 中背景和容器 generated path 应先请求 `/api/assets/read-url` 换签,局内出现 `match3d-background-image` 和 `match3d-container-image` 对应图片。
|
||||
- 关联:`src/components/match3d-runtime/Match3DRuntimeShell.tsx`、`src/components/platform-entry/PlatformEntryFlowShellImpl.tsx`、`src/components/rpg-entry/rpgEntryWorldPresentation.ts`、`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`。
|
||||
|
||||
## 抓大鹅容器参考图必须走 edits 并接管棋盘外观
|
||||
## 抓大鹅容器参考图必须进入 edits multipart image 并接管棋盘外观
|
||||
|
||||
- 现象:抓大鹅结果页看似有容器生成入口,但真实生成出的局内容器不像 `pot-fused-reference.png`,或进入试玩后仍被默认圆形锅壳、金色边框和径向底色覆盖/裁切。
|
||||
- 原因:`/v1/images/generations` 的 `image` 数组更适合弱参考文生图,难以稳定锁定大尺寸轻俯视容器构图;即使生成了容器图,如果运行态继续保留默认 `rounded-full` 锅壳和 `overflow-hidden`,生成图也会被默认视觉覆盖或裁掉。
|
||||
- 处理:抓大鹅 `1:1` 容器 UI 图必须用 VectorEngine `POST /v1/images/edits` multipart,参考 `public/match3d-background-references/pot-fused-reference.png` 的透明容器图作为 `image` part;该参考图属于后端生图协议输入,需通过 `include_bytes!` 编译进 `api-server`,不能在运行时按当前工作目录读取 `public/`。共享 GPT-image-2 HTTP client 承载 multipart 时强制 HTTP/1.1。`Match3DRuntimeShell` 在容器图换签并成功加载后,把棋盘外壳切为透明和 `overflow-visible`,只在容器缺失或加载失败时使用默认圆形容器。
|
||||
- 原因:容器参考图必须进入 `gpt-image-2` `/v1/images/edits` multipart `image` part,并配合强 prompt 锁定大尺寸轻俯视容器构图;即使生成了容器图,如果运行态继续保留默认 `rounded-full` 锅壳和 `overflow-hidden`,生成图也会被默认视觉覆盖或裁掉。
|
||||
- 处理:抓大鹅 `1:1` 容器 UI 图统一调用 VectorEngine `POST /v1/images/edits`,参考 `public/match3d-background-references/pot-fused-reference.png` 的透明容器图由后端作为 `image` part 上传;该参考图属于后端生图协议输入,需通过 `include_bytes!` 编译进 `api-server`,不能在运行时按当前工作目录读取 `public/`。`Match3DRuntimeShell` 在容器图换签并成功加载后,把棋盘外壳切为透明和 `overflow-visible`,只在容器缺失或加载失败时使用默认圆形容器。
|
||||
- 验证:执行 `cargo test -p api-server vector_engine --manifest-path server-rs/Cargo.toml`、`cargo test -p api-server match3d_background --manifest-path server-rs/Cargo.toml`、`npm run test -- src/components/match3d-runtime/Match3DRuntimeShell.test.tsx src/components/match3d-result/Match3DResultView.test.tsx`;真实联调看容器生成请求是否命中 `/v1/images/edits`,局内 `match3d-container-image` 是否渲染且 `match3d-board` 不再含默认 `rounded-full`。
|
||||
- 关联:`server-rs/crates/api-server/src/openai_image_generation.rs`、`server-rs/crates/api-server/src/match3d.rs`、`src/components/match3d-runtime/Match3DRuntimeShell.tsx`、`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`。
|
||||
|
||||
@@ -978,9 +1036,9 @@
|
||||
|
||||
## 抓大鹅难度配置的物品种类和消除次数必须分离
|
||||
|
||||
- 现象:历史草稿选择标准 / 硬核难度后,系统可能把 `clearCount` 当成局内物品种类数量,导致标准需要 12 种、硬核需要 20/21 种;素材不足时发布或试玩行为不一致。
|
||||
- 现象:历史草稿选择标准 / 硬核难度后,系统可能把 `clearCount` 当成局内物品种类数量,导致标准需要 12 种、硬核需要 20/21 种;或者把第 11 到 20 个物品持久化为第 11 到 20 行,触发“系列素材图集持久化的行列索引必须落在 n*n 范围内”。
|
||||
- 原因:旧运行态把消除次数和类型数量绑在一起,结果页文案又同时展示“素材图片 / 局内类型”,导致前端、发布校验和 run start 口径不一致。
|
||||
- 处理:统一使用 `物品种类` 口径:轻松 3、标准 9、进阶 15、硬核 21;历史 `clearCount=20` 且难度为硬核的运行态按新硬核升为 21 组三消,避免 20 组却要求 21 种素材。发布前按 `image_ready` 且有 `imageViews[]` 或 `imageSrc/imageObjectKey` 的生成素材数量阻断不足难度;试玩不阻断,但通过 `itemTypeCountOverride` 自动降到已生成 2D 素材数量。重启从已有 run 快照反推实际物品种类,保持同一局重开不变。
|
||||
- 处理:生成和持久化固定使用 20 个物品素材;运行态物品种类口径为轻松 3、标准 9、进阶 15、硬核 20,历史 `clearCount=20` 且难度为硬核的运行态仍可升为 21 组三消,但类型池不超过 20。10*10 sheet 每行两种物品、每种五个形态,持久化行列为 `row = itemIndex / 2 + 1`、`col = itemIndex % 2 * 5 + viewIndex + 1`。发布前按 `image_ready` 且有 `imageViews[]` 或 `imageSrc/imageObjectKey` 的生成素材数量阻断不足难度;试玩不阻断,但通过 `itemTypeCountOverride` 自动降到已生成 2D 素材数量。重启从已有 run 快照反推实际物品种类,保持同一局重开不变。
|
||||
- 验证:`npm run test -- src\components\match3d-result\Match3DResultView.test.tsx`、`cargo test -p module-match3d --manifest-path server-rs\Cargo.toml`,涉及发布 reducer 时补跑 `cargo test -p spacetime-module match3d --manifest-path server-rs\Cargo.toml`。
|
||||
- 关联:`src/components/match3d-result/Match3DResultView.tsx`、`src/services/match3d-runtime/match3dRuntimeClient.ts`、`server-rs/crates/module-match3d/src/application.rs`、`server-rs/crates/spacetime-module/src/match3d.rs`、`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`。
|
||||
|
||||
@@ -997,7 +1055,7 @@
|
||||
- 现象:抓大鹅生成的物品视角图裁剪后仍带白边,或者整块纯绿色绿幕背景没有被透明化,运行态看到绿色方块。
|
||||
- 原因:素材 sheet 可能是“每格内部绿幕、整张图外圈近白底”,内部绿幕不一定连通到 sheet 外边缘;旧 flood fill 只从外边缘找背景会漏掉这种绿幕块。白底抗锯齿如果不纳入抠像和边缘去污染,也会随裁剪输出成一圈白边。即使顺序已是先整张 sheet 去绿再裁剪,较厚的半透明或混色软绿边仍可能低于高置信绿幕阈值,被当作前景带进独立 PNG。
|
||||
- 处理:`api-server` 的 `slice_match3d_material_sheet` 必须先在整张 sheet 上做透明背景后处理:外边缘连通绿幕/近白底清 alpha,非连通但高置信纯绿块也清 alpha,沿整张 sheet 透明背景继续吃掉软绿边,边缘近白和绿幕抗锯齿做透明或去污染;同时保护不够纯的绿色主体像素。不要改成先裁剪单格再去绿。
|
||||
- 验证:`cargo test -p api-server match3d_material_sheet_slicing --manifest-path server-rs\Cargo.toml` 覆盖非连通绿幕、白边、贴边主体保留和固定 5x5 切图。
|
||||
- 验证:`cargo test -p api-server match3d_material_sheet_slicing --manifest-path server-rs\Cargo.toml` 覆盖非连通绿幕、白边、贴边主体保留和固定 `10*10` 切图;`cargo test -p api-server match3d_spritesheet_green_screen_postprocess_turns_background_transparent --manifest-path server-rs\Cargo.toml` 覆盖完整 spritesheet 上传前绿幕透明化。
|
||||
- 关联:`server-rs/crates/api-server/src/match3d.rs`、`docs/technical/MATCH3D_DRAFT_ASSET_GENERATION_PIPELINE_2026-05-10.md`。
|
||||
|
||||
## 抓大鹅物品详情大方格只做单张大图查看
|
||||
@@ -1064,6 +1122,14 @@
|
||||
- 验证:运行 `npm run test -- src/components/puzzle-runtime/PuzzleRuntimeShell.test.tsx -t "拖拽合并大块时底层单格不显示选中色块"`,并确认合并块拖拽时底层 `[data-piece-id]` 仍为 `puzzle-runtime-piece--merged`。
|
||||
- 关联:`src/components/puzzle-runtime/PuzzleRuntimeShell.tsx`、`src/components/puzzle-runtime/PuzzleRuntimeShell.test.tsx`、`docs/technical/PUZZLE_FORM_CREATION_FLOW_2026-04-29.md`。
|
||||
|
||||
## 推荐页嵌入拼图通关结算不要放在运行态内部 absolute 层
|
||||
|
||||
- 现象:推荐页里玩拼图通关后,结算面板只显示上半部分,排行榜、下一关按钮或相似作品卡被截断。
|
||||
- 原因:推荐页把运行态放在滑动作品卡的视觉区内,`platform-recommend-swipe-page`、`platform-recommend-swipe-card__visual` 和 `platform-recommend-runtime-viewport` 都是 `overflow: hidden`;拼图通关结算如果仍是运行态内部 `absolute inset-0` 弹层,就只能在半屏卡片区域里显示。
|
||||
- 处理:`PuzzleRuntimeShell` 在 `embedded` 模式下把通关结算层通过 portal 挂到 `document.body`,使用 `puzzle-runtime-modal-overlay--fixed` 页面级 fixed 浮层;非嵌入态继续使用运行态内部覆盖层。
|
||||
- 验证:运行 `npm run test -- src/components/puzzle-runtime/PuzzleRuntimeShell.test.tsx -t "推荐页嵌入拼图通关结算使用页面级浮层避免卡片裁剪"`,确认弹层不再位于 `.platform-recommend-runtime-viewport` 内。
|
||||
- 关联:`src/components/puzzle-runtime/PuzzleRuntimeShell.tsx`、`src/index.css`、`src/components/rpg-entry/RpgEntryHomeView.tsx`。
|
||||
|
||||
## 拼图历史图片列表不要把账号归属当图片名
|
||||
|
||||
- 现象:拼图创作页或结果页打开“选择历史图片”后,历史列表显示 `账号 user-1` 之类归属文案而不是图片名;`1713686400.000000Z` 这类时间显示为未知;选中后预览或生成参考图可能被怀疑不可用。
|
||||
@@ -1082,12 +1148,22 @@
|
||||
|
||||
## 拼图结果页局部生图不要污染草稿生成态
|
||||
|
||||
- 现象:拼图草稿已经生成完成后,在结果页重新生成 UI 背景或追加关卡生成图片,草稿页仍显示整卡“生成中”,点击草稿会回到生成过程页,无法查看已有结果;UI 背景生成中还会禁用“新增关卡”和关卡图生成。
|
||||
- 现象:拼图草稿已经生成完成后,在结果页重新生成关卡图片或追加关卡生成图片,草稿页仍显示整卡“生成中”,点击草稿会回到生成过程页,无法查看已有结果;关卡图片生成中还会禁用“新增关卡”和其它关卡详情编辑。
|
||||
- 原因:结果页局部 action 复用了全局 `isPuzzleBusy` / 持久化 `generationStatus=generating` 语义,作品架没有区分“初始草稿不可查看”和“已有结果上的局部关卡生成”。
|
||||
- 处理:作品架只在拼图没有可用封面、首关候选图或任一可查看关卡时才把 `generationStatus=generating` 解释为初始草稿生成;结果页 UI 背景和关卡图走 background action,不设置全局 busy,UI 背景只禁用自己的按钮;SpacetimeDB/API mapper 读写时把已有图片但状态仍是 `generating` 的历史关卡归一为 `ready`。
|
||||
- 处理:作品架只在拼图没有可用封面、首关候选图或任一可查看关卡时才把 `generationStatus=generating` 解释为初始草稿生成;结果页关卡图走 background action,不设置全局 busy,只标记对应关卡局部生成进度;SpacetimeDB/API mapper 读写时把已有图片但状态仍是 `generating` 的历史关卡归一为 `ready`。
|
||||
- 验证:`npm run test -- src/components/custom-world-home/CustomWorldCreationHub.test.tsx src/components/puzzle-result/PuzzleResultView.test.tsx`、`cargo test -p api-server puzzle --manifest-path server-rs\Cargo.toml`。
|
||||
- 关联:`src/components/custom-world-home/creationWorkShelf.ts`、`src/components/platform-entry/PlatformEntryFlowShellImpl.tsx`、`src/components/puzzle-result/PuzzleResultView.tsx`、`server-rs/crates/api-server/src/puzzle/mappers.rs`、`server-rs/crates/spacetime-module/src/puzzle.rs`。
|
||||
|
||||
2026-05-22 补充:结果页关卡详情的“关卡测试”不能把单关 `draft` 传给父级再调用 `updatePuzzleWork`。`updatePuzzleWork` 会同步 `puzzle_work_profile.levels_json` 和 source session 草稿,单关快照会把整份多关卡草稿覆盖成一个关卡,退出重进后只剩最后测试的关卡且序号表现为第一关。修复口径是 `PuzzleResultView` 始终传完整 `syncedDraft`,额外用 `{ levelId }` 指定起始关卡;父级持久化完整 levels 后调用 `startLocalPuzzleRun(item, levelId)`。
|
||||
|
||||
## 拼图上传图关闭 AI 重绘不要走首图生图
|
||||
|
||||
- 现象:用户在拼图入口页或结果页关卡详情上传图片并关闭 AI 重绘后,生成页仍显示“生成拼图首图”,或者后端仍调用 `generate_puzzle_image_candidates` 生成第一张 1:1 候选图。
|
||||
- 原因:上传图直用路径应把 Data URL 或 `/generated-*` 历史图解析后持久化为 `sourceType=uploaded` 的正式候选,再继续生成 9:16 关卡画面、UI spritesheet 和纯背景;如果只把 `aiRedraw=false` 当作“不参考图片生成”,就会误走首图生成。
|
||||
- 处理:入口页用 payload 的 `aiRedraw` 写入生成页 metadata,`puzzleAiRedraw=false` 时进度跳过 `生成拼图首图`;后端 `compile_puzzle_draft` 和结果页 `generate_puzzle_images` 都在 `aiRedraw=false && referenceImageSrc 非空` 时走上传图直用候选。结果页关卡详情必须复用 `CreativeImageInputPanel`,不要把正式图当成可重绘参考图;本次上传或历史选择的图才显示 AI 重绘开关并可删除。
|
||||
- 验证:`npm run test -- src/services/miniGameDraftGenerationProgress.test.ts src/components/puzzle-result/PuzzleResultView.test.tsx`、`cargo test -p api-server puzzle_result_level_direct_upload_skips_cover_image_generation --manifest-path server-rs\Cargo.toml`。
|
||||
- 关联:`src/services/miniGameDraftGenerationProgress.ts`、`src/components/puzzle-agent/PuzzleAgentWorkspace.tsx`、`src/components/puzzle-result/PuzzleResultView.tsx`、`server-rs/crates/api-server/src/puzzle/draft.rs`、`server-rs/crates/api-server/src/puzzle/generation.rs`。
|
||||
|
||||
## Jenkins 数据库导入导出脚本先补 Node 工具链 PATH
|
||||
|
||||
- 现象:`Genarrative-Database-Import` 或 `Genarrative-Database-Export` 运行到迁移脚本时,`bash` 报 `node: command not found`,常见在日志里表现为某个 `sh` 块内第 61 行直接调用 `node` 失败。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
:root {
|
||||
color: #17212b;
|
||||
background: #eef3f6;
|
||||
color: #3d1f10;
|
||||
background: #f8efe7;
|
||||
font-family:
|
||||
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
|
||||
"Segoe UI", sans-serif;
|
||||
@@ -16,7 +16,7 @@ body {
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
background: #eef3f6;
|
||||
background: #f8efe7;
|
||||
}
|
||||
|
||||
button,
|
||||
@@ -49,31 +49,31 @@ button:disabled {
|
||||
|
||||
.admin-loading-screen {
|
||||
gap: 12px;
|
||||
color: #5c6b77;
|
||||
color: #7b6150;
|
||||
}
|
||||
|
||||
.admin-loading-mark {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 3px solid #d1dde6;
|
||||
border-top-color: #126e82;
|
||||
border: 3px solid #e1ccbb;
|
||||
border-top-color: #b6623f;
|
||||
border-radius: 50%;
|
||||
animation: admin-spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
.admin-login-screen {
|
||||
background:
|
||||
linear-gradient(145deg, rgba(18, 110, 130, 0.12), transparent 36%),
|
||||
linear-gradient(315deg, rgba(165, 94, 54, 0.12), transparent 34%),
|
||||
#eef3f6;
|
||||
linear-gradient(145deg, rgba(204, 117, 76, 0.14), transparent 36%),
|
||||
linear-gradient(315deg, rgba(226, 171, 134, 0.16), transparent 34%),
|
||||
#f8efe7;
|
||||
}
|
||||
|
||||
.admin-login-panel,
|
||||
.admin-panel {
|
||||
border: 1px solid #d8e2e8;
|
||||
border: 1px solid #e1ccbb;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 12px 36px rgba(23, 33, 43, 0.08);
|
||||
box-shadow: 0 12px 36px rgba(112, 57, 30, 0.08);
|
||||
}
|
||||
|
||||
.admin-login-panel {
|
||||
@@ -92,14 +92,14 @@ button:disabled {
|
||||
|
||||
.admin-login-brand h1 {
|
||||
margin: 0;
|
||||
color: #17212b;
|
||||
color: #3d1f10;
|
||||
font-size: 26px;
|
||||
line-height: 1.16;
|
||||
}
|
||||
|
||||
.admin-login-brand span,
|
||||
.admin-brand span {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@@ -108,10 +108,10 @@ button:disabled {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
place-items: center;
|
||||
border: 1px solid #bcd2db;
|
||||
border: 1px solid #dfc8b7;
|
||||
border-radius: 8px;
|
||||
color: #126e82;
|
||||
background: #e7f3f5;
|
||||
color: #b6623f;
|
||||
background: #f4e5d7;
|
||||
}
|
||||
|
||||
.admin-brand-icon-large {
|
||||
@@ -129,7 +129,7 @@ button:disabled {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
border-right: 1px solid #d8e2e8;
|
||||
border-right: 1px solid #e1ccbb;
|
||||
background: #ffffff;
|
||||
padding: 22px 18px;
|
||||
}
|
||||
@@ -164,13 +164,13 @@ button:disabled {
|
||||
gap: 10px;
|
||||
min-height: 42px;
|
||||
padding: 0 12px;
|
||||
color: #52616d;
|
||||
color: #755a49;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.admin-nav-button[data-active="true"] {
|
||||
color: #0f5666;
|
||||
background: #e7f3f5;
|
||||
color: #8f3f27;
|
||||
background: #f4e5d7;
|
||||
}
|
||||
|
||||
.admin-main {
|
||||
@@ -184,7 +184,7 @@ button:disabled {
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
border-bottom: 1px solid #d8e2e8;
|
||||
border-bottom: 1px solid #e1ccbb;
|
||||
background: rgba(255, 255, 255, 0.86);
|
||||
padding: 0 24px;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-user small {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
@@ -232,7 +232,7 @@ button:disabled {
|
||||
.admin-page-heading h2,
|
||||
.admin-panel-heading h3 {
|
||||
margin: 0;
|
||||
color: #17212b;
|
||||
color: #3d1f10;
|
||||
}
|
||||
|
||||
.admin-page-heading h2 {
|
||||
@@ -241,7 +241,7 @@ button:disabled {
|
||||
|
||||
.admin-page-heading p {
|
||||
margin: 3px 0 0;
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
}
|
||||
|
||||
.admin-panel {
|
||||
@@ -256,7 +256,7 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-panel-heading span {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
@@ -314,12 +314,12 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-table tbody tr[data-clickable="true"]:hover {
|
||||
background: #f5fafb;
|
||||
background: #fff7f0;
|
||||
}
|
||||
|
||||
.admin-text-button:hover,
|
||||
.admin-text-button:focus-visible {
|
||||
color: #126e82;
|
||||
color: #b6623f;
|
||||
text-decoration: underline;
|
||||
outline: none;
|
||||
}
|
||||
@@ -345,7 +345,7 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-query-summary {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 12px;
|
||||
font-weight: 650;
|
||||
}
|
||||
@@ -354,7 +354,7 @@ button:disabled {
|
||||
display: grid;
|
||||
min-width: 0;
|
||||
gap: 7px;
|
||||
color: #4c5c68;
|
||||
color: #6f5848;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
}
|
||||
@@ -372,16 +372,16 @@ button:disabled {
|
||||
.admin-field textarea {
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
border: 1px solid #cbd8e0;
|
||||
border: 1px solid #dfc8b7;
|
||||
border-radius: 8px;
|
||||
color: #17212b;
|
||||
background: #fbfdfe;
|
||||
color: #3d1f10;
|
||||
background: #fffdf9;
|
||||
padding: 9px 11px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.admin-field-note {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
line-height: 1.45;
|
||||
@@ -395,8 +395,8 @@ button:disabled {
|
||||
.admin-field input:focus,
|
||||
.admin-field select:focus,
|
||||
.admin-field textarea:focus {
|
||||
border-color: #126e82;
|
||||
box-shadow: 0 0 0 3px rgba(18, 110, 130, 0.16);
|
||||
border-color: #b6623f;
|
||||
box-shadow: 0 0 0 3px rgba(204, 117, 76, 0.16);
|
||||
}
|
||||
|
||||
.admin-combobox {
|
||||
@@ -419,16 +419,16 @@ button:disabled {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 42px;
|
||||
border: 1px solid #cbd8e0;
|
||||
border: 1px solid #dfc8b7;
|
||||
border-left: 0;
|
||||
border-radius: 0 8px 8px 0;
|
||||
color: #52616d;
|
||||
background: #fbfdfe;
|
||||
color: #755a49;
|
||||
background: #fffdf9;
|
||||
}
|
||||
|
||||
.admin-combobox:focus-within .admin-combobox-toggle {
|
||||
border-color: #126e82;
|
||||
box-shadow: 0 0 0 3px rgba(18, 110, 130, 0.16);
|
||||
border-color: #b6623f;
|
||||
box-shadow: 0 0 0 3px rgba(204, 117, 76, 0.16);
|
||||
}
|
||||
|
||||
.admin-combobox-menu {
|
||||
@@ -440,10 +440,10 @@ button:disabled {
|
||||
display: grid;
|
||||
max-height: 260px;
|
||||
overflow: auto;
|
||||
border: 1px solid #cbd8e0;
|
||||
border: 1px solid #dfc8b7;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 16px 40px rgba(23, 33, 43, 0.14);
|
||||
box-shadow: 0 16px 40px rgba(112, 57, 30, 0.14);
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ button:disabled {
|
||||
width: 100%;
|
||||
border: 0;
|
||||
border-radius: 7px;
|
||||
color: #17212b;
|
||||
color: #3d1f10;
|
||||
background: transparent;
|
||||
padding: 9px 10px;
|
||||
text-align: left;
|
||||
@@ -461,12 +461,12 @@ button:disabled {
|
||||
|
||||
.admin-combobox-option:hover,
|
||||
.admin-combobox-option:focus-visible {
|
||||
background: #e7f3f5;
|
||||
background: #f4e5d7;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.admin-combobox-option span {
|
||||
color: #0f5666;
|
||||
color: #8f3f27;
|
||||
font-family:
|
||||
"SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
||||
font-size: 12px;
|
||||
@@ -475,7 +475,7 @@ button:disabled {
|
||||
|
||||
.admin-combobox-option small,
|
||||
.admin-combobox-empty {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
line-height: 1.45;
|
||||
@@ -495,7 +495,7 @@ button:disabled {
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
color: #4c5c68;
|
||||
color: #6f5848;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
}
|
||||
@@ -503,7 +503,7 @@ button:disabled {
|
||||
.admin-switch-field input {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
accent-color: #126e82;
|
||||
accent-color: #b6623f;
|
||||
}
|
||||
|
||||
.admin-primary-button,
|
||||
@@ -522,7 +522,7 @@ button:disabled {
|
||||
z-index: 80;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: rgba(23, 33, 43, 0.42);
|
||||
background: rgba(61, 31, 16, 0.34);
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
@@ -530,10 +530,10 @@ button:disabled {
|
||||
display: grid;
|
||||
width: min(100%, 420px);
|
||||
gap: 16px;
|
||||
border: 1px solid #d8e2e8;
|
||||
border: 1px solid #e1ccbb;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(23, 33, 43, 0.24);
|
||||
box-shadow: 0 22px 60px rgba(112, 57, 30, 0.24);
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
@@ -543,10 +543,10 @@ button:disabled {
|
||||
max-height: min(90dvh, 760px);
|
||||
gap: 16px;
|
||||
overflow: auto;
|
||||
border: 1px solid #d8e2e8;
|
||||
border: 1px solid #e1ccbb;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(23, 33, 43, 0.24);
|
||||
box-shadow: 0 22px 60px rgba(112, 57, 30, 0.24);
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
@@ -557,7 +557,7 @@ button:disabled {
|
||||
.admin-confirm-warning {
|
||||
border: 1px solid #efc894;
|
||||
border-radius: 8px;
|
||||
color: #8a5a1b;
|
||||
color: #8f4b26;
|
||||
background: #fffaf3;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
@@ -576,26 +576,26 @@ button:disabled {
|
||||
|
||||
.admin-primary-button {
|
||||
color: #ffffff;
|
||||
background: #126e82;
|
||||
background: #b6623f;
|
||||
}
|
||||
|
||||
.admin-secondary-button,
|
||||
.admin-icon-button {
|
||||
border: 1px solid #cbd8e0;
|
||||
color: #2f4550;
|
||||
border: 1px solid #dfc8b7;
|
||||
color: #4b2412;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.admin-danger-button {
|
||||
color: #ffffff;
|
||||
background: #a44242;
|
||||
background: #a6402f;
|
||||
}
|
||||
|
||||
.admin-ghost-button {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
color: #52616d;
|
||||
background: #eef3f6;
|
||||
color: #755a49;
|
||||
background: #f8efe7;
|
||||
}
|
||||
|
||||
.admin-ghost-button.admin-query-reset-button {
|
||||
@@ -608,7 +608,7 @@ button:disabled {
|
||||
.admin-text-button {
|
||||
display: inline;
|
||||
border: 0;
|
||||
color: #0f5666;
|
||||
color: #8f3f27;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
@@ -616,9 +616,9 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-alert {
|
||||
border: 1px solid #efc0bd;
|
||||
border: 1px solid #e2b9a4;
|
||||
border-radius: 8px;
|
||||
color: #8a2f2f;
|
||||
color: #8f3f27;
|
||||
background: #fff4f3;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
@@ -638,7 +638,7 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-info-list dt {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@@ -646,7 +646,7 @@ button:disabled {
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
color: #17212b;
|
||||
color: #3d1f10;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
}
|
||||
@@ -666,26 +666,26 @@ button:disabled {
|
||||
|
||||
.admin-table th,
|
||||
.admin-table td {
|
||||
border-bottom: 1px solid #e4edf2;
|
||||
border-bottom: 1px solid #eaded2;
|
||||
padding: 10px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.admin-table th {
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.admin-table td small {
|
||||
display: block;
|
||||
margin-top: 3px;
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.admin-muted-text {
|
||||
color: #86939c;
|
||||
color: #a38f80;
|
||||
}
|
||||
|
||||
.admin-tag-list {
|
||||
@@ -699,10 +699,10 @@ button:disabled {
|
||||
display: inline-flex;
|
||||
max-width: 100%;
|
||||
align-items: center;
|
||||
border: 1px solid #cbdfe6;
|
||||
border: 1px solid #dfc8b7;
|
||||
border-radius: 999px;
|
||||
background: #eef7f8;
|
||||
color: #0f5666;
|
||||
background: #f7eadf;
|
||||
color: #8f3f27;
|
||||
padding: 3px 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 750;
|
||||
@@ -744,7 +744,7 @@ button:disabled {
|
||||
gap: 6px;
|
||||
max-width: 100%;
|
||||
border: 0;
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
@@ -773,7 +773,7 @@ button:disabled {
|
||||
.admin-table-sort-button:hover,
|
||||
.admin-table-sort-button:focus-visible,
|
||||
.admin-table-sort-button[data-active="true"] {
|
||||
color: #0f5666;
|
||||
color: #8f3f27;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@@ -782,7 +782,7 @@ button:disabled {
|
||||
max-height: 160px;
|
||||
margin: 0;
|
||||
overflow: auto;
|
||||
color: #2f4550;
|
||||
color: #4b2412;
|
||||
font-family:
|
||||
"SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
||||
font-size: 12px;
|
||||
@@ -801,18 +801,18 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-status-ok {
|
||||
color: #17623c;
|
||||
background: #e6f5ed;
|
||||
color: #2f7b46;
|
||||
background: #edf8ef;
|
||||
}
|
||||
|
||||
.admin-status-pending {
|
||||
color: #8a5a1b;
|
||||
background: #fff4df;
|
||||
color: #8f4b26;
|
||||
background: #fdf1e5;
|
||||
}
|
||||
|
||||
.admin-status-error {
|
||||
color: #8a2f2f;
|
||||
background: #fff1ef;
|
||||
color: #8f3f27;
|
||||
background: #fff0e9;
|
||||
}
|
||||
|
||||
.admin-error-list {
|
||||
@@ -820,7 +820,7 @@ button:disabled {
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
padding-left: 18px;
|
||||
color: #8a5a1b;
|
||||
color: #8f4b26;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
@@ -830,7 +830,7 @@ button:disabled {
|
||||
}
|
||||
|
||||
.admin-subsection-heading {
|
||||
color: #4c5c68;
|
||||
color: #6f5848;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
}
|
||||
@@ -850,7 +850,7 @@ button:disabled {
|
||||
.admin-header-row input {
|
||||
min-width: 0;
|
||||
min-height: 38px;
|
||||
border: 1px solid #cbd8e0;
|
||||
border: 1px solid #dfc8b7;
|
||||
border-radius: 8px;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
@@ -863,10 +863,10 @@ button:disabled {
|
||||
max-height: 520px;
|
||||
margin: 0;
|
||||
overflow: auto;
|
||||
border: 1px solid #dce6ec;
|
||||
border: 1px solid #eaded2;
|
||||
border-radius: 8px;
|
||||
background: #17212b;
|
||||
color: #e9f2f4;
|
||||
background: #3d1f10;
|
||||
color: #fdf9f5;
|
||||
padding: 14px;
|
||||
font-family:
|
||||
"SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
||||
@@ -880,19 +880,19 @@ button:disabled {
|
||||
display: grid;
|
||||
min-height: 140px;
|
||||
place-items: center;
|
||||
border: 1px dashed #cbd8e0;
|
||||
border: 1px dashed #dfc8b7;
|
||||
border-radius: 8px;
|
||||
color: #667682;
|
||||
background: #fbfdfe;
|
||||
color: #8f7868;
|
||||
background: #fffdf9;
|
||||
}
|
||||
|
||||
.admin-segmented-control {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 6px;
|
||||
border: 1px solid #d8e2e8;
|
||||
border: 1px solid #e1ccbb;
|
||||
border-radius: 8px;
|
||||
background: #eef3f6;
|
||||
background: #f8efe7;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
@@ -900,15 +900,15 @@ button:disabled {
|
||||
min-height: 36px;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
color: #52616d;
|
||||
color: #755a49;
|
||||
background: transparent;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.admin-segmented-control button[data-active="true"] {
|
||||
color: #0f5666;
|
||||
color: #8f3f27;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 2px 8px rgba(23, 33, 43, 0.08);
|
||||
box-shadow: 0 2px 8px rgba(112, 57, 30, 0.08);
|
||||
}
|
||||
|
||||
.admin-bottom-nav {
|
||||
@@ -964,7 +964,7 @@ button:disabled {
|
||||
z-index: 20;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
|
||||
border-top: 1px solid #d8e2e8;
|
||||
border-top: 1px solid #e1ccbb;
|
||||
background: rgba(255, 255, 255, 0.94);
|
||||
padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
|
||||
backdrop-filter: blur(10px);
|
||||
@@ -974,15 +974,15 @@ button:disabled {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
min-height: 48px;
|
||||
color: #667682;
|
||||
color: #8f7868;
|
||||
background: transparent;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.admin-bottom-nav-button[data-active="true"] {
|
||||
color: #0f5666;
|
||||
background: #e7f3f5;
|
||||
color: #8f3f27;
|
||||
background: #f4e5d7;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,8 @@ http {
|
||||
|
||||
location ~ ^/api(?:/|$) {
|
||||
default_type application/json;
|
||||
# 中文注释:创作接口会携带参考图 Data URL,Nginx 只放行到 api-server;真实大小限制仍由路由 DefaultBodyLimit 和业务字节校验负责。
|
||||
client_max_body_size 64m;
|
||||
limit_conn genarrative_api_conn 64;
|
||||
limit_req zone=genarrative_api_rps burst=64 nodelay;
|
||||
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
本配置片段由 `scripts/jenkins-server-provision.sh` 在安装 Nginx 站点配置时展开。
|
||||
|
||||
## 请求体大小
|
||||
|
||||
- 生产、开发服和容器模板都在通用 `location ~ ^/api(?:/|$)` 内设置 `client_max_body_size 64m`。
|
||||
- 该值只用于让携带参考图 Data URL 的创作接口抵达 `api-server`;不要把它当作业务上传上限。Rust 路由仍通过 `DefaultBodyLimit` 和解码后字节校验限制具体接口,例如拼图参考图路由只放宽到 12 MiB 请求体,图片字节继续按业务规则拒绝。
|
||||
- 若线上看到 `413 Request Entity Too Large`,并且 access log 里 `request_time=0.000 upstream_status=-`,通常是 Nginx 没有加载该模板或未 reload;先执行 `nginx -T | grep client_max_body_size` 和 `nginx -t` 再检查 `api-server`。
|
||||
|
||||
## gzip
|
||||
|
||||
- `deploy/nginx/genarrative.conf` 与 `deploy/nginx/genarrative-dev-http.conf` 默认开启 gzip。
|
||||
|
||||
@@ -190,6 +190,8 @@ server {
|
||||
# 临时兼容主站仍在使用的 /api/* HTTP facade;前端完成 SpacetimeDB SDK 迁移后删除。
|
||||
location ~ ^/api(?:/|$) {
|
||||
default_type application/json;
|
||||
# 中文注释:创作接口会携带参考图 Data URL,Nginx 只放行到 api-server;真实大小限制仍由路由 DefaultBodyLimit 和业务字节校验负责。
|
||||
client_max_body_size 64m;
|
||||
limit_conn genarrative_api_conn 64;
|
||||
limit_req zone=genarrative_api_rps burst=64 nodelay;
|
||||
|
||||
|
||||
@@ -210,6 +210,8 @@ server {
|
||||
# 临时兼容主站仍在使用的 /api/* HTTP facade;前端完成 SpacetimeDB SDK 迁移后删除。
|
||||
location ~ ^/api(?:/|$) {
|
||||
default_type application/json;
|
||||
# 中文注释:创作接口会携带参考图 Data URL,Nginx 只放行到 api-server;真实大小限制仍由路由 DefaultBodyLimit 和业务字节校验负责。
|
||||
client_max_body_size 64m;
|
||||
limit_conn genarrative_api_conn 64;
|
||||
limit_req zone=genarrative_api_rps burst=64 nodelay;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 宝贝识物寓教于乐模板 PRD 2026-05-11
|
||||
# 宝贝识物寓教于乐模板 PRD 2026-05-11
|
||||
|
||||
## 1. 目标
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
5. 游戏视觉主题包;
|
||||
6. 作品标签。
|
||||
|
||||
素材使用 VectorEngine `gpt-image-2-all` / image-2 生成。图片生成只能走后端接口,前端不得读取、拼接或暴露 `VECTOR_ENGINE_API_KEY`。
|
||||
素材使用 VectorEngine `gpt-image-2` / image-2 生成。图片生成只能走后端接口,前端不得读取、拼接或暴露 `VECTOR_ENGINE_API_KEY`。
|
||||
|
||||
为降低生成成本,创作提交后只生成两张原始图片:一张 `2x2` 素材 sheet 和一张单独场景背景图。`2x2` 素材 sheet 固定包含左上物品 A、右上物品 B、左下篮子、右下礼物盒。服务端必须按固定格切图,并把物品、篮子和礼物盒转成透明 PNG。只有透明抠图后的两个物品素材才允许写入草稿 `itemAssets` 并进入游戏运行态。左右手位置指示器属于运行态默认规则,使用项目内置静态素材,不在每次创作时生成。
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 宝贝识物创作发布实现方案 2026-05-11
|
||||
# 宝贝识物创作发布实现方案 2026-05-11
|
||||
|
||||
## 1. 范围
|
||||
|
||||
@@ -144,7 +144,7 @@ PUT /api/creation/edutainment/baby-object-match/drafts/{draftId}
|
||||
POST /api/creation/edutainment/baby-object-match/drafts/{draftId}/publish
|
||||
```
|
||||
|
||||
图片生成必须在后端调用 VectorEngine `gpt-image-2-all`,不得从前端直接调用外部图片接口。
|
||||
图片生成必须在后端调用 VectorEngine `gpt-image-2`,不得从前端直接调用外部图片接口。
|
||||
|
||||
后端 `2x2` 素材 sheet prompt 约束:
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 儿童动作识别互动玩法 Demo 热身关开发规格文档
|
||||
# 儿童动作识别互动玩法 Demo 热身关开发规格文档
|
||||
|
||||
> 日期:2026-05-09
|
||||
> 关联设计文档:[CHILD_MOTION_DEMO_WARMUP_LEVEL_DESIGN_2026-05-09.md](../design/CHILD_MOTION_DEMO_WARMUP_LEVEL_DESIGN_2026-05-09.md)
|
||||
@@ -684,7 +684,7 @@
|
||||
1. 舞台主环境采用卡通绘本风格、明亮草地、天空、小山坡和树木的组合,默认背景环境需要保证中心与下方前景留空,便于角色轮廓和地面指示环叠加。
|
||||
2. 该卡通绘本草地风格是儿童动作 Demo 后续场景、物品、UI 资源的全局风格要求;新增资源不得切回暗色科技风、真实照片风或后台面板风。
|
||||
3. `src/index.css` 中的热身舞台、摄像头背景层、地面、角色轮廓、地面圆环、开始按钮和横屏提示均按绘本草地风格接入真实资源;资源加载失败时保留 CSS 兜底。
|
||||
4. 生成脚本固定为 `scripts/generate-child-motion-demo-assets.mjs`,并通过 `npm run assets:child-motion-demo` 触发;脚本使用 `gpt-image-2-all` 调用 VectorEngine `POST /v1/images/generations`,透明资源先生成品红底源图,再在本地移除色键,源图写入 `tmp/child-motion-demo-assets/`。
|
||||
4. 生成脚本固定为 `scripts/generate-child-motion-demo-assets.mjs`,并通过 `npm run assets:child-motion-demo` 触发;脚本使用 `gpt-image-2` 调用 VectorEngine `POST /v1/images/generations`,透明资源先生成品红底源图,再在本地移除色键,源图写入 `tmp/child-motion-demo-assets/`。
|
||||
5. 当前已生成并接入以下正式 Demo 资源:
|
||||
- `public/child-motion-demo/picture-book-grass-stage.png`:默认草地舞台背景。
|
||||
- `public/child-motion-demo/picture-book-foreground-grass-v2.png`:底部前景草坪条,只覆盖舞台下沿,不作为整块地板拉伸。
|
||||
|
||||
@@ -214,7 +214,7 @@ Handler 主要在 `story.rs`、`combat.rs`、`runtime_inventory.rs`:
|
||||
| Big Fish 正式图 | DashScope `wan2.2-t2i-flash` | 轮询 task 后 HTTP GET 图片 URL | `LegacyAssetPrefix::BigFishAssets` | 由 assetKind 映射主图/动作图/舞台背景等 | `big_fish_session` + session/entity id + slot | `big_fish.rs` 调用方 `execute_billable_asset_operation` | 配置缺失/上游失败直接错误;gallery 对部分 Spacetime 运行错误软降级 |
|
||||
| Square Hole 图片重生成 | OpenAI/VectorEngine GPT image helper | URL 下载或 base64/data URL 解码 | `LegacyAssetPrefix::SquareHoleAssets` | 方洞作品图片槽位相关 kind | profile/work + image slot | 调用方包裹 | 生成成功但入库失败保留 Data URL 回包 |
|
||||
| Custom World 场景/封面 | VectorEngine GPT image 2 / OpenAI helper | URL 下载或 base64 解码 | `LegacyAssetPrefix::CustomWorldScenes` 等 | scene/cover/opening storyboard | `custom_world_profile` 或 profile/landmark/scene slot | `custom_world_ai.rs` 调用方包裹 | entity/scene 生成存在 LLM fallback;资产持久化失败按当前错误口径返回 |
|
||||
| Puzzle 图片 | GPT image 2 generations/edits | multipart/base64/URL 结果归一 | `LegacyAssetPrefix::PuzzleAssets` | puzzle level/background/generated image,另有 `puzzle_background_music` | puzzle profile/run/level slot | `puzzle.rs` 调用方包裹 | connectivity 可按既有规则跳过部分计费;运行态 fallback 保持原逻辑 |
|
||||
| Puzzle 图片 | GPT image 2 generations/edits | 无参考图 JSON 创建;有参考图 multipart 编辑;base64/URL 结果归一 | `LegacyAssetPrefix::PuzzleAssets` | puzzle level/background/generated image,另有 `puzzle_background_music` | puzzle profile/run/level slot | `puzzle.rs` 调用方包裹 | connectivity 可按既有规则跳过部分计费;运行态 fallback 保持原逻辑 |
|
||||
| Match3D 图片 | APIMart/VectorEngine/OpenAI image helper | 下载、切图、透明化、校准后入库 | `LegacyAssetPrefix::Match3DAssets` | cover/background/item material sheet,音频 kind 另列 | match3d profile/session slot | `match3d.rs` 调用方包裹 | 新草稿不回退 Rodin/GLB;部分连接错误按现有计费跳过规则处理 |
|
||||
| Visual Novel 音频 | VectorEngine Suno/Vidu | 任务提交后按 task publish 下载音频 | 视觉小说/creation audio scope | `visual_novel_music`、`visual_novel_ambient_sound` | `visual_novel_scene` + scene id + `music`/`ambient_sound` | `vector_engine_audio_generation.rs` 调用方包裹 | 上游/下载失败显式错误,不混入图片 Adapter |
|
||||
| 通用音频 | VectorEngine Suno/Vidu | 同上 | creation audio scope | background_music/sound_effect 由调用方目标指定 | creation target entity/slot | 调用方包裹 | 不与 VN 场景语义混用 |
|
||||
|
||||
@@ -77,13 +77,16 @@ npm run check:server-rs-ddd
|
||||
|
||||
1. 每个能力 Module 只暴露 `router(state) -> Router<AppState>`,由 `app.rs` 统一 `.merge(...)`。
|
||||
2. `app.rs` 只保留全局 middleware、TraceLayer、request context、tracking middleware、入口开关和少量顶层 glue。
|
||||
3. 路由迁移和业务重构分阶段处理;先移动路由装配,再拆 handler 内部实现。
|
||||
4. 大 handler 拆分时优先按 `router.rs`、`handlers.rs`、`application.rs`、`assets.rs`、`mapper.rs`、`errors.rs` 分层。`handlers.rs` 只做 Axum extract、鉴权和 request/response,业务规则继续下沉到 `module-*`。
|
||||
5. 手写 Rust 模块入口统一使用同名 `.rs` 文件,例如 `puzzle.rs` + `puzzle/*.rs`、`match3d.rs` + `match3d/*.rs`;不要再新增 `mod.rs` 入口。生成的 SpacetimeDB Rust bindings 也由生成脚本同步为 `module_bindings.rs` + `module_bindings/*.rs` 布局。
|
||||
3. 能力 Module 可在路由内部用 `FromRef<AppState>` 派生自己的 Feature State,例如 `PuzzleApiState`。全局 `AppState` 仍作为进程组合根、鉴权层和全局中间件状态,但业务 handler 优先只提取对应 Feature State,不直接暴露完整 `AppState`。
|
||||
4. Feature State 只暴露该能力实际需要的 facade / adapter / 配置快照;若必须复用仍要求 `AppState` 的横切 helper(例如计费、外部失败审计或通用 tracking),应通过 Feature State 的窄方法或显式 `root_state()` 过渡,并在后续继续收窄。
|
||||
5. 路由迁移和业务重构分阶段处理;先移动路由装配,再拆 handler 内部实现,再收窄 handler 可见状态。
|
||||
6. 大 handler 拆分时优先按 `router.rs`、`handlers.rs`、`application.rs`、`assets.rs`、`mapper.rs`、`errors.rs` 分层。`handlers.rs` 只做 Axum extract、鉴权和 request/response,业务规则继续下沉到 `module-*`。
|
||||
7. 手写 Rust 模块入口统一使用同名 `.rs` 文件,例如 `puzzle.rs` + `puzzle/*.rs`、`match3d.rs` + `match3d/*.rs`;不要再新增 `mod.rs` 入口。生成的 SpacetimeDB Rust bindings 也由生成脚本同步为 `module_bindings.rs` + `module_bindings/*.rs` 布局。
|
||||
|
||||
拼图 `api-server` 内部拆分:
|
||||
|
||||
- `server-rs/crates/api-server/src/modules/puzzle.rs` 只负责路由装配、鉴权层和参考图 body limit;对外继续引用同一批 handler 名称。
|
||||
- `server-rs/crates/api-server/src/state.rs` 中的 `PuzzleApiState` 是拼图 HTTP/BFF 的 Feature State,集中暴露 `SpacetimeClient`、`PuzzleGalleryCache`、OSS client、作者查询所需认证服务、拼图 LLM client 和少量 VectorEngine / Agent 配置快照。拼图 handler 只提取 `State<PuzzleApiState>`,不得重新改回 `State<AppState>`。
|
||||
- `server-rs/crates/api-server/src/puzzle.rs` 只作为聚合入口,保留共享 import / 常量、内部模块声明和 handler re-export,不继续承载大段实现。
|
||||
- `server-rs/crates/api-server/src/puzzle/handlers.rs` 承接 Axum handler,负责 extract、鉴权上下文、调用 SpacetimeDB facade / 编排 helper,并返回 HTTP/SSE 响应。
|
||||
- `server-rs/crates/api-server/src/puzzle/draft.rs` 承接表单草稿保存、草稿编译、首关命名、UI 背景 prompt、降级 snapshot 和初始资产就绪校验。
|
||||
@@ -102,7 +105,7 @@ npm run check:server-rs-ddd
|
||||
- `server-rs/crates/api-server/src/match3d/draft.rs` 承接 Agent session、草稿编译、题材 / 难度 / 物品计划和草稿持久化编排。
|
||||
- `server-rs/crates/api-server/src/match3d/works.rs` 承接作品 CRUD、封面 / 背景 / 容器资产生成入口、发布 / Remix / 点赞 / 游玩记录和作品级 helper。
|
||||
- `server-rs/crates/api-server/src/match3d/item_assets.rs` 承接物品生成批次编排、append / replace / delete / sort / merge、计费外层和草稿素材映射;sheet prompt、绿幕 / 近白底透明化、切图和切片持久化复用 `generated_asset_sheets` 通用模块。
|
||||
- `server-rs/crates/api-server/src/match3d/vector_engine_gemini.rs` 承接 VectorEngine Gemini 请求体、响应解析、base64 图片下载和上游错误归一。
|
||||
- `server-rs/crates/api-server/src/match3d/vector_engine_gemini.rs` 仅保留历史 VectorEngine Gemini 物品 sheet helper;当前草稿物品 spritesheet 以关卡整图为参考走 `gpt-image-2` 编辑链路,提示词、绿幕透明化和 OSS 持久化由 `item_assets.rs` / `works.rs` 约束。
|
||||
- `server-rs/crates/api-server/src/match3d/runtime.rs` 保留运行态轻量归一 helper;`mappers.rs` / `tags.rs` / `tests.rs` 分别承接 DTO 映射、标签 / 通用错误 helper 和原有单测。
|
||||
|
||||
该拆分只改变 `api-server` 文件组织,不改变 `/api/creation/match3d/*`、`/api/runtime/match3d/*` route、DTO、error envelope、SpacetimeDB schema、公开 gallery cache 语义、VectorEngine / OSS 副作用边界或计费语义;后续继续细分时也必须先保持行为不变,再单独讨论领域规则下沉到 `module-match3d`。
|
||||
@@ -114,7 +117,8 @@ npm run check:server-rs-ddd
|
||||
3. Adapter 输出应保留 legacy public path、object key、asset object id、MIME、extension、task id 和实际 prompt。
|
||||
4. Adapter 不负责扣费、退款或钱包读取;计费仍由调用方显式包裹。
|
||||
5. Puzzle、Match3D、音频、GLB、视频等复杂媒体可以复用 OSS + asset object + binding 的底层持久化能力,但玩法专属处理规则留在各自编排层,不塞进公共接口。
|
||||
6. 系列素材图集使用 `server-rs/crates/api-server/src/generated_asset_sheets.rs`:调用方必须传入 `grid_size` 作为 `n*n` 的 `n`,可选传入物品名称 prompt 模板和特殊设定 prompt;模块负责 sheet prompt 组装、按 `n*n` 切片、透明化、PNG 输出、OSS private upload 请求构造和 sheet / item / special prompt 元数据持久化。玩法只负责规划 slot、调用具体生图 provider、计费、失败回写,以及把通用切片结果映射回自己的 DTO / 草稿 / runtime 字段。
|
||||
6. 拼图图生图参考图主链不得再把大图 Data URL 塞进创作 JSON body;前端先直传 OSS 并提交 `referenceImageAssetObjectId(s)`,`api-server` 校验 `asset_object` 的 bucket、kind、图片 MIME、大小和 owner 后签发只读 URL 给 VectorEngine 读取,Data URL / `/generated-*` 仅作为旧请求兼容。
|
||||
7. 系列素材图集使用 `server-rs/crates/api-server/src/generated_asset_sheets.rs`:调用方必须传入 `grid_size` 作为 `n*n` 的 `n`,可选传入物品名称 prompt 模板和特殊设定 prompt;模块负责 sheet prompt 组装、按 `n*n` 切片、透明化、PNG 输出、OSS private upload 请求构造和 sheet / item / special prompt 元数据持久化。玩法只负责规划 slot、调用具体生图 provider、计费、失败回写,以及把通用切片结果映射回自己的 DTO / 草稿 / runtime 字段。
|
||||
|
||||
## SpacetimeDB schema 变更规则
|
||||
|
||||
@@ -152,12 +156,12 @@ npm run check:server-rs-ddd
|
||||
|
||||
- LLM:`GENARRATIVE_LLM_*`,创意 Agent 另用 `APIMART_BASE_URL` / `APIMART_API_KEY`。
|
||||
- 图片生成:VectorEngine / APIMart / DashScope,密钥只在后端环境变量中。
|
||||
- Match3D 物品 sheet:VectorEngine Gemini `gemini-3-pro-image-preview` 原生 `generateContent`;图集 prompt、切图、透明化和切片持久化走 `generated_asset_sheets` 通用模块,Match3D 只补题材 / 风格 / 五视角设定和字段映射。
|
||||
- Match3D 封面和 9:16 纯背景:VectorEngine `/v1/images/generations`。
|
||||
- Match3D 1:1 容器 UI:VectorEngine `/v1/images/edits` multipart 参考图。该容器参考图是后端生图协议输入,必须通过 `include_bytes!` 随 `api-server` 编译进二进制,避免 API 单独发布或运行目录缺少 `public/` 时生成失败。
|
||||
- Match3D 物品 sheet:关卡整图完成后走 VectorEngine `/v1/images/edits` multipart `image`,模型为 `gpt-image-2`,`2K 1:1` 输出 `10*10` spritesheet;物品 sheet prompt 固定要求纯绿色绿幕背景,后端上传 OSS 前必须把绿幕扣成透明 PNG,并把透明整图写入 `itemSpritesheetImageSrc/itemSpritesheetImageObjectKey`。后端固定从该 sheet 解析并持久化 20 个物品、每个 5 个形态;通用系列素材图集的行列索引按每行 2 个物品计算,必须落在 `1..=10`,难度只决定运行态加载 3 / 9 / 15 / 20 种。
|
||||
- Match3D UI spritesheet 和背景派生图:关卡整图作为参考图并发生成 `1K 1:1` UI spritesheet 与 `1K 9:16` 背景图,模型均为 `gpt-image-2`。UI spritesheet prompt 固定要求纯绿色绿幕背景,后端上传 OSS 前必须把绿幕扣成透明 PNG;背景图必须合成为全画幅不透明 PNG。
|
||||
- Hyper3D / Rodin:只保留后端安全代理和旧数据兼容;新 Match3D 草稿和批量新增不再生成 GLB。
|
||||
- 音频:视觉小说专用音频路由保留;拼图和抓大鹅生成入口暂时关闭,通用 `/api/creation/audio/*` 对相关目标返回 `410 Gone`。
|
||||
- OSS:私有 generated legacy path 进入浏览器前必须通过 `/api/assets/read-url` 换签;不要裸请求 `/generated-*`。
|
||||
- 外部 API 失败审计:外部供应商调用未成功时,`api-server` 必须发送 OTLP 失败事件并写入 `tracking_event`。当前通用 VectorEngine `gpt-image-2-all` 图片生成 / 编辑适配器在 `request_send`、`response_body`、`upstream_status`、`response_parse`、`missing_image` 和 `image_download` 阶段失败时记录 `external_api_call_failure`,`scope_kind = module`、`scope_id = provider`、`module_key = external-api`;metadata 固定包含 provider、endpoint、operation、failureStage、statusCode、statusClass、timeout、retryable、errorMessage、latencyMs、promptChars、referenceImageCount 和 imageModel。入库优先复用 tracking outbox,outbox 不可写或保护阈值拒绝时回退同步写 SpacetimeDB;不得新增前端兜底或在 SpacetimeDB reducer 内做外部 I/O。
|
||||
|
||||
## SpacetimeDB 表目录
|
||||
|
||||
@@ -677,6 +681,7 @@ RPG 创作入口的配置 ID 是 `rpg`,当前 `visible=true`、`open=true`;
|
||||
- Rust 结构体:`TrackingEvent`
|
||||
- 源码:`server-rs/crates/spacetime-module/src/runtime/profile.rs`
|
||||
- 写入:关键业务埋点同步调用单条 procedure;普通 HTTP route tracking 由 `api-server` 本机 outbox 批量调用 `record_tracking_events_and_return`。outbox 到达批量阈值时先封存 active 文件并切新 active,后台 worker 异步 flush sealed 文件,HTTP 请求线程不等待 SpacetimeDB。`FLUSH_INTERVAL_MS` 只负责兜底封存长时间未满批的 active 文件,`MAX_BYTES` 只做磁盘保护阈值。`event_id` 必须稳定且全局唯一,批量重试时用唯一索引做幂等跳过。
|
||||
- 外部 API 失败:`event_key = external_api_call_failure` 使用同一张表落库;它是供应商失败审计事实,不新增 SpacetimeDB 表,查询时按 `module_key = 'external-api'` 或 `scope_kind = module AND scope_id = '<provider>'` 过滤。
|
||||
|
||||
### `treasure_record`
|
||||
|
||||
|
||||
@@ -96,6 +96,33 @@ SpacetimeDB bindings:
|
||||
npm run spacetime:generate
|
||||
```
|
||||
|
||||
## CodeGraph 本地代码索引
|
||||
|
||||
项目已安装 `@colbymchenry/codegraph` 作为开发期依赖,用于在本地生成语义代码索引,辅助 AI / IDE 做符号搜索、调用关系和影响范围分析。索引目录为 `.codegraph/`,其中 `config.json` 可提交,数据库、缓存和日志由 `.codegraph/.gitignore` 保持本机私有。
|
||||
|
||||
首次拉取或需要重建索引时:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run codegraph:init
|
||||
```
|
||||
|
||||
日常使用:
|
||||
|
||||
```bash
|
||||
npm run codegraph:status
|
||||
npm run codegraph:sync
|
||||
npm run codegraph:index
|
||||
```
|
||||
|
||||
Codex 项目级 hook 已放在 `.codex/config.toml` 与 `.codex/hooks/`:
|
||||
|
||||
- `PreToolUse` hook 会在 Codex 准备执行 `git commit` 前运行 `node .codex/hooks/pre-submit-compile-check.mjs`,依次执行 `npm run typecheck`、`npm run admin-web:typecheck`、`cargo check -p api-server --manifest-path server-rs/Cargo.toml`,发现编译错误会阻止本次提交。
|
||||
- `PostToolUse` hook 会在 Codex 工具修改文件后运行 `node .codex/hooks/post-edit-codegraph-sync.mjs`,执行 `npm run codegraph:sync` 刷新本地语义索引。
|
||||
- 如果某个 Codex 客户端版本尚未自动加载项目级 hook,可先手动运行 `node .codex/hooks/pre-submit-compile-check.mjs` 与 `node .codex/hooks/post-edit-codegraph-sync.mjs`;个人模型、token、MCP server 仍放在个人 `~/.codex/config.toml`,不要提交。
|
||||
|
||||
若要把 CodeGraph 接到 Codex CLI / Cursor / Claude Code 等 MCP 客户端,按本机 agent 配置执行 `codegraph install` 或参考 `codegraph install --print-config codex` 输出;不要把个人全局 agent 配置、token 或本机绝对路径提交到仓库。
|
||||
|
||||
## 后端改动验收
|
||||
|
||||
后端代码修改后,按变更范围选择:
|
||||
@@ -155,7 +182,7 @@ Windows Stdb module 构建流水线运行在 Jenkins `windows` 节点上。该
|
||||
|
||||
生产环境变量模板:`deploy/env/api-server.env.example`。真实密钥只放服务器,不提交 Git,不写入文档示例。
|
||||
|
||||
`Genarrative-Server-Provision` 会安装基础构建依赖、systemd 模板和 Nginx 站点模板。Ubuntu / apt 目标机会额外安装 `libnginx-mod-http-brotli-filter` 与 `libnginx-mod-http-brotli-static`,随后由 `scripts/jenkins-server-provision.sh` 通过临时 `nginx -t` 配置探测 Brotli 指令是否可用;该临时配置必须先 `include /etc/nginx/modules-enabled/*.conf`,因为 apt 安装的 Brotli 是动态模块,不会出现在普通 `nginx -V` 编译参数里。探测成功才在渲染后的 `deploy/nginx/genarrative.conf` / `genarrative-dev-http.conf` 中启用 Brotli,避免未安装模块的机器直接写入无效配置。
|
||||
`Genarrative-Server-Provision` 会安装基础构建依赖、systemd 模板和 Nginx 站点模板。Ubuntu / apt 目标机会额外安装 `libnginx-mod-http-brotli-filter` 与 `libnginx-mod-http-brotli-static`,随后由 `scripts/jenkins-server-provision.sh` 通过临时 `nginx -t` 配置探测 Brotli 指令是否可用;该临时配置必须先 `include /etc/nginx/modules-enabled/*.conf`,因为 apt 安装的 Brotli 是动态模块,不会出现在普通 `nginx -V` 编译参数里。探测成功才在渲染后的 `deploy/nginx/genarrative.conf` / `genarrative-dev-http.conf` 中启用 Brotli,避免未安装模块的机器直接写入无效配置。Provision 写入 Genarrative Nginx 站点时会把 `/etc/nginx/sites-enabled/default*` 移到 `/etc/nginx/sites-disabled/`,避免 Debian / Certbot 默认站点继续占用 `genarrative.world` / `www.genarrative.world` 并在 `nginx -T` 中出现 `conflicting server name ... ignored`。如果 `nginx -t` 失败,脚本会恢复写入前的 Genarrative 配置和被移动的默认站点。
|
||||
|
||||
50 HTTP req/s 首版压测优化口径:
|
||||
|
||||
@@ -166,7 +193,7 @@ Windows Stdb module 构建流水线运行在 Jenkins `windows` 节点上。该
|
||||
- Windows 下载阶段如果出现 `curl: (18)` 或响应体截断,流水线会保留同名 `.download` 临时文件并用 `curl -C -` 断点续传;只有完整返回但 SHA256 digest 仍不匹配时才删除临时文件后重新下载。目标 Linux 节点仍只接收 `stash/unstash` 带过去的本地下载件,不回退外网下载。
|
||||
- Windows 下载阶段如果走代理,在 `Genarrative-Server-Provision` 参数 `PROVISION_DOWNLOAD_PROXY` 填写 Windows Jenkins 节点可访问的 HTTP 代理,例如 `http://127.0.0.1:7890`;不要填写目标 release 机器视角的 `127.0.0.1`,除非代理确实运行在该 Windows 节点本机。Linux 目标机阶段会强制要求使用本地下载件,缺少文件直接失败,不再回退到外网下载。
|
||||
- `otelcol-contrib.service` 作为可选系统服务加入 provision,默认监听 `127.0.0.1:4317/4318` 并使用 `deploy/otelcol/genarrative-debug.yaml`。api-server 是否发送 OTLP 仍由 `GENARRATIVE_OTEL_ENABLED` 控制,服务 unit 见 `deploy/systemd/otelcol-contrib.service`。
|
||||
- Nginx `/api/` 与 `/admin/api/` 通过 `genarrative_api` upstream 代理到 `127.0.0.1:8082`,upstream keepalive 为 64;`limit_conn` 负责连接 / 并发保护,`limit_req` 负责入口 RPS 快拒绝。当前模板把公开 gallery list 单独放到 `genarrative_gallery_rps`,默认 `rate=5000r/s`、`burst=4096`、`limit_conn=320`;公开详情和普通 API 放到 `genarrative_api_rps`,后台 API 放到 `genarrative_admin_rps`。压测时看 `/var/log/nginx/genarrative.access.log` 中的 `request_time`、`upstream_connect_time`、`upstream_header_time`、`upstream_response_time`、`upstream_status`、`request_id`。
|
||||
- Nginx `/api/` 与 `/admin/api/` 通过 `genarrative_api` upstream 代理到 `127.0.0.1:8082`,upstream keepalive 为 64;`limit_conn` 负责连接 / 并发保护,`limit_req` 负责入口 RPS 快拒绝。当前模板把公开 gallery list 单独放到 `genarrative_gallery_rps`,默认 `rate=5000r/s`、`burst=4096`、`limit_conn=320`;公开详情和普通 API 放到 `genarrative_api_rps`,后台 API 放到 `genarrative_admin_rps`。通用 `/api` location 设置 `client_max_body_size 64m` 只是反代兜底,防止旧客户端或兼容请求在到达 `api-server` 前被默认 1 MiB 上限拦截;长期主链不得依赖大 JSON body 承载图片,拼图参考图应先直传 OSS,只向创作接口提交 `referenceImageAssetObjectId(s)`,由后端签只读 URL 给外部模型读取。真实业务上限仍由 Rust 路由 `DefaultBodyLimit`、资产确认时 OSS HEAD 和解码后字节校验控制。若线上出现 `413 Request Entity Too Large` 且 access log 中 `request_time=0.000`、`upstream_status=-`,说明请求在 Nginx 层被拦截,先用 `nginx -T | grep client_max_body_size` 检查 release 模板是否已渲染并 reload,同时检查前端是否仍在提交 Data URL 而不是 `assetObjectId`。`limit_conn_status 429` 和 `limit_req_status 429` 必须在 HTTP 与 HTTPS server 中同时生效;若线上压测看到 `limiting connections by zone "genarrative_api_conn"` 却返回 503,优先检查 `nginx -T` 里 HTTPS server 是否缺少这些状态码,以及 `/api/runtime/puzzle/gallery` 是否误落到通用 `location ~ ^/api` 的 `limit_conn=64`。压测时看 `/var/log/nginx/genarrative.access.log` 中的 `request_time`、`upstream_connect_time`、`upstream_header_time`、`upstream_response_time`、`upstream_status`、`request_id`。
|
||||
- 作品列表 K6 脚本一次 iteration 默认请求两个公开接口,因此约 50 HTTP req/s 的目标命令使用 `SCENARIO=spike START_RPS=5 PEAK_RPS=25 HOLD=60s END_RPS=5 DETAIL_RATIO=0 npm run loadtest:k6:works`。
|
||||
- 作品列表短期继续由 `api-server` / BFF 订阅 SpacetimeDB 公开 read model 后读本地 cache,不让浏览器前端直接订阅完整列表;未来如新增 `public_work_gallery_entry` 等专用公开作品列表 read model,前端只可订阅稳定、低基数、公开的专用投影,禁止订阅 `puzzle_work_profile`、`custom_world_profile` 等玩法源表后自行 join、聚合或判断权限。前端直订阅落地前必须先补齐权限、字段契约、排序 / 分页、埋点和 BFF 回退策略。
|
||||
- 50 HTTP req/s 验收目标为 `http_req_failed < 1%`、`p95 < 2s`、`dropped_iterations = 0`,同时压测窗口内 Nginx 无新增 502。2026-05-19 容器 2C / 2G 连续 10 轮不重启 SpacetimeDB 压测:`PEAK_RPS=2500` 等价约 5000 HTTP req/s,平均实际吞吐约 `4219 HTTP req/s`,10 轮总计 `1,897,357` 个 200、`212,542` 个 429、`0` 个 5xx,200 请求平均 `p95=123ms`、`p99=234ms`;该档会把 SpacetimeDB 容器内存从约 `366MiB` 推到约 `885MiB / 896MiB`,因此当前不要继续抬公开 gallery 入口并发,应优先处理 SpacetimeDB 侧连接 / 订阅 / tracking 写入后的内存高水位。
|
||||
@@ -195,6 +222,7 @@ OpenTelemetry 现阶段默认开启 OTLP traces / metrics / logs,但本地日
|
||||
- debug exporter / Rider 转发都会同时接收 traces、metrics 和 logs。
|
||||
- api-server 会随 metrics 发送进程级指标:`process.memory.usage`、`process.memory.virtual`、`process.cpu.time`、`genarrative.process.cpu.usage_percent`、`process.thread.count`、`genarrative.process.memory.private`;Windows 额外发送 `process.windows.handle.count`,Linux 额外发送 `process.unix.file_descriptor.count`。这些指标只描述当前进程,不携带请求、用户或作品 label。
|
||||
- HTTP 运行态补充发送 `genarrative.http.server.response_bodies.in_flight` 与 `genarrative.http.server.request_permits.available`,后者带低基数 `pool=default|gallery|detail|admin` label,用于区分业务 handler / 背压 permit 是否仍被占用;拼图广场热点缓存补充发送 `genarrative.puzzle_gallery.cache.*` 指标,记录 fresh hit、stale hit、未命中、后台刷新开始 / 失败、重建耗时和预序列化 data JSON 字节数。
|
||||
- 外部 API 失败统一发送 OTLP 并落库。当前 VectorEngine `gpt-image-2-all` 图片生成 / 编辑失败会输出 `外部 API 调用失败` trace/log,并记录指标 `genarrative.external_api.failures{provider,failure_stage,status_class,retryable}`;同时写入 `tracking_event`,`event_key = external_api_call_failure`、`module_key = external-api`、`scope_kind = module`、`scope_id = provider`。排障时先按 provider / failureStage 聚合,再结合 request 日志和上游响应 excerpt 判断是限流、超时、解析失败还是未返回图片。
|
||||
- SpacetimeDB 观测分为两类:procedure / reducer 调用继续用 `genarrative.spacetime.procedure.*`,订阅本地 cache 读使用 `genarrative.spacetime.read.*`。`read=list_puzzle_gallery` 表示拼图广场当前从 `puzzle_gallery_card_view` 本地 cache 读取,不再每个 HTTP 请求调用 `list_puzzle_gallery` procedure。
|
||||
- 本地 Windows 直连压测的内存高水位要结合 K6 VU / 连接数解释。250 RPS 下过高 `PREALLOCATED_VUS` 可能让 300 个本地 Established 连接把 `api-server` private memory 瞬时推到 GB 级,且 `/healthz` 小响应也能复现;若压测结束后回落、`response_bodies.in_flight` 和背压 permit 未显示业务积压,应优先按连接 / 发送链路高水位处理,而不是判断为 SpacetimeDB 或 JSON 缓存泄漏。
|
||||
- Rider 的 Logs 面板只展示 log event 自身字段,不会自动展开父 span 的全部 attributes;请求完成日志会直接带 `request_id`、`http.request.method`、`http.route`、`url.scheme`、`url.path`、`http.response.status_code`、`status_class`、`latency_ms` 和 `slow_request`,完整链路继续到 Traces 面板按 trace/span 查看。
|
||||
@@ -252,6 +280,16 @@ cargo test -p platform-auth --manifest-path server-rs/Cargo.toml aliyun_send_sms
|
||||
|
||||
个人任务首版 scope 仅支持 `user`。后台、RPG、大鱼吃小鱼、Visual Novel、Story、Combat 等特定链路按 tracking 中间件排除规则处理;作品游玩统一使用 `work_play_start`。
|
||||
|
||||
外部 API 失败审计复用 `tracking_event`,不新增表。失败事件优先写入本机 tracking outbox,再由后台 worker 批量落库;如果 outbox 因权限、磁盘或保护阈值不可写,会回退同步直写 SpacetimeDB。`metadata_json` 包含 endpoint、operation、failureStage、statusCode、statusClass、timeout、retryable、errorMessage、latencyMs、promptChars、referenceImageCount、imageModel 和 rawExcerpt。常用查询:
|
||||
|
||||
```sql
|
||||
SELECT event_id, scope_id AS provider, metadata_json, occurred_at
|
||||
FROM tracking_event
|
||||
WHERE event_key = 'external_api_call_failure'
|
||||
ORDER BY occurred_at DESC
|
||||
LIMIT 50;
|
||||
```
|
||||
|
||||
tracking outbox 默认配置:
|
||||
|
||||
```env
|
||||
@@ -264,6 +302,17 @@ GENARRATIVE_TRACKING_OUTBOX_MAX_BYTES=268435456
|
||||
|
||||
outbox 采用 NDJSON 文件保存原始事件。达到 `BATCH_SIZE` 时会立刻把当前 active 文件原子封存为 sealed 文件,并马上切到新的 active 继续写入;后台 worker 异步 flush sealed 文件,HTTP 请求线程不等待 SpacetimeDB。`FLUSH_INTERVAL_MS` 只负责兜底封存长时间未满批的 active 文件。SpacetimeDB 批量 procedure 返回成功后删除 sealed 文件,失败则保留文件并重试。`MAX_BYTES` 是磁盘保护阈值,不是 flush 阈值;超过后低价值 route tracking 可以被丢弃并记录日志 / 指标,关键同步事件不进入该丢弃路径。sealed 文件若出现无法解析的坏行,会重命名为 `corrupt-*` 隔离并记录 `genarrative.tracking_outbox.files.corrupt` 指标,避免一个坏文件阻塞后续批量入库。该机制提供至少一次投递语义,依赖 `tracking_event.event_id` 幂等跳过重复事件。
|
||||
|
||||
release 机器如果日志每秒刷 `tracking outbox ... Permission denied (os error 13)`,先检查 `/etc/genarrative/api-server.env` 是否缺少 `GENARRATIVE_TRACKING_OUTBOX_DIR`。缺少时 `api-server` 会回退到本地开发默认相对路径 `server-rs/.data/tracking-outbox`,而 systemd 的工作目录是只读发布目录 `/opt/genarrative/releases/<version>`,`genarrative` 用户无法在其中创建 `server-rs`。修复顺序:
|
||||
|
||||
```bash
|
||||
install -d -o genarrative -g genarrative -m 0750 /var/lib/genarrative/tracking-outbox
|
||||
grep -n '^GENARRATIVE_TRACKING_OUTBOX' /etc/genarrative/api-server.env
|
||||
systemctl restart genarrative-api.service
|
||||
journalctl -u genarrative-api.service --since '30 seconds ago' --no-pager | grep -E 'tracking outbox|Permission denied|os error 13'
|
||||
```
|
||||
|
||||
`Genarrative-Server-Provision` 和 `Genarrative-Api-Deploy` 会在保留旧 `/etc/genarrative/api-server.env` 的前提下补齐缺失的 tracking outbox 与 auth-store 运行态路径,并确保 `/var/lib/genarrative/tracking-outbox`、`/var/lib/genarrative/auth` 归属 `genarrative:genarrative`。
|
||||
|
||||
常用检查思路:
|
||||
|
||||
```sql
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
`PlatformEntryFlowShellImpl.tsx` 仍是平台入口编排壳,后续维护时应优先把独立 UI 片段、公开作品映射、草稿生成 notice 和运行态状态 helper 拆到 `src/components/platform-entry/PlatformEntryFlowShellImpl/` 或同目录紧邻 helper 文件。拆分只允许改变文件组织,不改变入口配置事实源、默认导出、props、页面阶段、UI 文案或现有交互;其中拼图首访 onboarding 已拆为 `PlatformEntryFlowShellImpl/PuzzleOnboardingView.tsx`。
|
||||
|
||||
移动端底部一级导航是全局平台样式,不按单一玩法分叉。当前视觉统一为米白浮动胶囊底座、浅棕分隔线、棕色线性图标、橘色选中态和底部短下划线;中间 `创作` 入口保持凸起圆形主按钮,但凸起位移只能作用在按钮内容层,不能移动承载分隔线的 Tab 按钮容器,确保创作左右分隔线与其他分隔线垂直位置一致。Tab 名称和可见性仍由现有 `PlatformHomeTab` / 登录态规则决定,样式调整不得改写 Tab 文案或导航状态。
|
||||
|
||||
## 新增玩法创作工具平台 SOP
|
||||
|
||||
新增玩法默认采用表单/图片输入创作工作台,链路为:
|
||||
@@ -73,23 +75,26 @@ RPG / 拼图等运行态存档选择入口统一在个人中心 `常用功能 >
|
||||
当前口径:
|
||||
|
||||
- 图像输入复用 `CreativeImageInputPanel`。
|
||||
- 结果页每关画面编辑和素材配置里的 UI 背景生成也复用 `CreativeImageInputPanel`;三处只共享受控 UI 模块,不共享数据源、状态、action 或存储位置:入口页继续写 `formDraft` 与草稿编译 payload,关卡画面写 `levels[].pictureReference/pictureDescription` 并触发 `generate_puzzle_images`,UI 背景写 `levels[0].uiBackgroundPrompt/uiBackgroundImage*` 并触发 `generate_puzzle_ui_background`。通用图片面板的展示图和 AI 重绘参考图能力必须分开控制:结果页正式关卡图只作为预览图,不因存在 `displayImageSrc` 自动暴露 AI 重绘开关;只有本地上传、历史选择或已保存 `pictureReference` 可作为重绘参考图时,才显示 AI 重绘开关并把状态带入 `generate_puzzle_images`。
|
||||
- 支持画面描述生图、多参考图生图、上传或历史生成主图后 AI 重绘、上传或历史生成主图后不重绘;关闭 AI 重绘时,前端可提交本地上传 Data URL 或历史 `/generated-*` 图片路径,后端统一解析为首关正式图后再持久化。
|
||||
- 草稿生成会先持久化 `generationStatus=generating` 的作品摘要,生成完成并回写关卡图、UI 背景后再变为 `ready`;首关关卡图和 UI 背景在命名稳定后并行启动,当前不自动生成背景音乐。
|
||||
- 结果页每关画面编辑复用 `CreativeImageInputPanel`;入口页和关卡画面只共享受控 UI 模块,不共享数据源、状态、action 或存储位置:入口页继续写 `formDraft` 与草稿编译 payload,关卡画面写 `levels[].pictureReference/pictureDescription` 并触发 `generate_puzzle_images`。结果页删除独立“素材配置”Tab,不再提供单独 UI 背景生成入口。通用图片面板的展示图和 AI 重绘参考图能力必须分开控制:结果页正式关卡图只作为预览图,不因存在正式图自动暴露 AI 重绘开关;只有本地上传、历史选择或已保存 `pictureReference` 可作为重绘参考图时,才显示 AI 重绘开关并把状态带入 `generate_puzzle_images`。用户在本次编辑中上传或选择历史图后,该图优先占据主图卡片,可删除、切换 AI 重绘,也可关闭 AI 重绘直用;仅有正式图预览时,画面描述框仍可上传多张参考图。关卡详情弹窗应使用加宽面板,关卡名称、画面图和画面描述合并在同一个纵向列表中,名称输入和画面编辑模块外层不再包独立 `platform-subpanel`;画面图卡仍必须保留稳定最小高度,避免弹窗内 `flex-1` 布局坍缩后只剩标题、描述输入和操作按钮。
|
||||
- 支持画面描述生图、多参考图生图、上传或历史生成主图后 AI 重绘、上传或历史生成主图后不重绘;主链要求浏览器先经 `/api/assets/direct-upload-tickets` 直传 OSS 并确认 `asset_object`,创作 action 只提交 `referenceImageAssetObjectId(s)`,由后端校验 owner / bucket / kind / MIME / size 后签发 OSS 只读 URL 并下载为 VectorEngine `/v1/images/edits` 的 multipart `image` part。本地上传 Data URL 与历史 `/generated-*` 图片路径仅保留为旧草稿、旧入口或未迁移客户端的兼容输入;关闭 AI 重绘时,后端统一解析为首关或当前关卡正式图后再持久化,不调用第一段拼图首图生成。
|
||||
- 草稿生成会先持久化 `generationStatus=generating` 的作品摘要,生成完成并回写关卡拼图画面、关卡画面参考图、UI spritesheet 和关卡背景图后再变为 `ready`;当前不自动生成背景音乐。生成页进度不再按固定 5 分钟展示,而按实际开始时间和当前路径的分步骤预计时长推进;任一同步 action 回包到达时立即以真实完成/失败结果冻结进度。
|
||||
- 作品架拼图草稿的“生成中”遮罩只表示初始草稿还没有可查看结果;只要作品摘要、首关封面或任一关卡候选图已经可用,后续 UI 背景重生成和追加关卡生图都必须作为结果页局部生成态处理,不能阻止打开草稿结果页。
|
||||
- 拼图草稿编译是长耗时 action,前端 action 请求默认等待 `1_000_000ms` 且不自动重试,生成页预计完成时间按 `5` 分钟展示;生成页恢复时必须沿用作品摘要 `updatedAt` 作为原始 `startedAtMs`,失败/完成态用 `finishedAtMs` 冻结耗时,不能在锁屏或返回草稿页后重新从 0 计时。
|
||||
- 拼图草稿编译是长耗时 action,前端 action 请求默认等待 `1_800_000ms`(30 分钟)且不自动重试。每次 `gpt-image-2` 调用的预期用时按 90 秒计算;完整 AI 重绘路径为 `编译首关草稿` 8 秒、`生成关卡名称` 10 秒、`生成拼图首图` 90 秒、`生成关卡画面` 90 秒、`生成UI与背景` 90 秒、`写入正式草稿` 10 秒,合计约 298 秒。上传图且关闭 AI 重绘时必须跳过 `生成拼图首图`,直接进入 `生成关卡画面` 和 `生成UI与背景`,合计约 208 秒。生成页恢复时必须沿用作品摘要 `updatedAt` 作为原始 `startedAtMs`,失败/完成态用 `finishedAtMs` 冻结耗时,不能在锁屏或返回草稿页后重新从 0 计时。
|
||||
- 若浏览器锁屏、息屏或网络切换导致 compile 请求失败,前端在标记失败前必须先复读 `getPuzzleAgentSession(sessionId)`;只有最新 session 仍缺 `draft.coverImageSrc`、首关 `coverImageSrc` 或候选图时才展示失败,复读到已生成草稿时按成功收尾、刷新作品架并继续自动试玩/结果页链路。
|
||||
- 拼图参考图 AI 重绘优先走 VectorEngine `/v1/images/edits`;若编辑接口超时,`api-server` 会降级为 `/v1/images/generations`,并把同一参考图塞进 `image` 数组继续生成,避免参考图草稿整单失败。
|
||||
- 结果页素材配置当前只保留 UI 相关能力;旧背景音乐入口隐藏。
|
||||
- 拼图参考图 AI 重绘走 VectorEngine `/v1/images/edits`;无参考图时走 `/v1/images/generations`。两者模型都使用 `gpt-image-2`,参考图由后端作为 multipart `image` part 传入编辑接口。
|
||||
- 每次新建关卡生成或重新生成关卡图都必须由 `api-server` 串起当前关卡资产包:AI 重绘开启时第一段沿用草稿生成第一关的拼图主图提示词配置和模型 / 尺寸 / 参考图规则生成 `coverImageSrc/coverAssetId` 作为关卡拼图画面和结果页预览图,提示词来源同样按显式画面描述、关卡画面描述、草稿摘要顺序回退,且固定要求输出画面比例为 `1:1`;上传图且关闭 AI 重绘时跳过这一段,把上传图或历史图持久化为 `sourceType=uploaded` 的正式候选。随后用正式候选图作为参考,`9:16` 生成完整拼图游戏关卡画面并写入 `levelSceneImageSrc/levelSceneImageObjectKey`,提示词必须要求道具按钮上不要显示次数标注,且返回按钮和设置按钮旁禁止标注文字;UI spritesheet 与关卡纯背景在关卡画面完成后并发生成,spritesheet 用 `1:1`、`1k` 先生成纯绿色绿幕背景图,后端上传 OSS 前必须把绿幕扣成透明 PNG,再写入 `uiSpritesheetImageSrc/uiSpritesheetImageObjectKey`,按钮顺序固定为返回、设置、下一关、提示、原图、冻结,按钮素材自身保留对应中文文字,返回和设置按钮不得额外生成白色外圈、白底圆环或浮雕外框;纯背景用 `9:16`、`1k` 写入 `levelBackgroundImageSrc/levelBackgroundImageObjectKey`,提示词必须包含“禁止在背景中出现人像或和拼图画面中主体一致的内容”。运行态不直接使用第二段完整关卡画面,但必须持久化它用于追踪和后续再生成。结果页局部关卡生成进度按 AI 重绘开启约 270 秒、关闭 AI 重绘约 180 秒展示。
|
||||
- 结果页允许多关卡并行编辑和生成;某一关卡图片生成完成回包只静默更新该关卡素材与生成态,不得自动打开或切换关卡详情面板,避免打断用户正在编辑的其它关卡。
|
||||
- 结果页 UI 背景重生成只禁用 UI 背景自己的按钮和确认动作,不禁用“新增关卡”、关卡图片生成、关卡详情编辑和结果页导航;关卡图片生成也只标记对应关卡的局部生成进度。
|
||||
- 结果页关卡图片生成只标记对应关卡的局部生成进度,不禁用“新增关卡”、其它关卡详情编辑和结果页导航。
|
||||
- 结果页单关测试只能把完整草稿持久化,并通过 `levelId` 指定运行态起始关卡;不得把单关快照作为整份草稿调用 `updatePuzzleWork`,否则 source session 和作品 profile 的 `levels` 会被覆盖成单关,退出重进后其它关卡会丢失。
|
||||
- 结果页生成关卡图时若关卡名为空,前端必须传 `shouldAutoNameLevel=true`,后端复用首关命名契约先按画面描述生成关卡名,再在图片生成后用视觉命名结果精修,并把生成名和 UI 背景提示词随本次关卡快照写回。
|
||||
- 拼图 UI 背景是作品运行态背景,不只属于第一关;本地试玩、直达指定关卡和正式 `next-level` 推进时,目标关卡缺 `uiBackgroundImageSrc/uiBackgroundImageObjectKey` 必须继承同作品首个可用 UI 背景,仍缺失时才沿用当前运行态快照背景或默认 UI。
|
||||
- 拼图运行态背景优先读取当前关卡 `levelBackgroundImageSrc/levelBackgroundImageObjectKey`,旧数据才兼容 `uiBackgroundImageSrc/uiBackgroundImageObjectKey`;本地试玩、直达指定关卡和正式 `next-level` 推进时,目标关卡缺关卡背景时必须继承同作品首个可用关卡背景,仍缺失时才沿用当前运行态快照背景或默认 UI。运行态按钮视觉优先读取当前关卡 `uiSpritesheetImageSrc/uiSpritesheetImageObjectKey`,先按透明 alpha 自动边界检测识别 spritesheet 中的独立按钮展示矩形,再按原图位置从左到右、从上到下映射到返回、设置、下一关、提示、原图、冻结;同一组件还要按较高 alpha 阈值派生紧致点击热区,透明留白和柔边低 alpha 区域尽量不响应点击。检测失败时回退旧固定六格裁切,缺失时才用现有图标按钮兜底。有 spritesheet 时,返回和设置按钮的点击容器只提供透明点击区,不再叠加默认白色圆形底;底部提示、原图、冻结三枚素材按检测矩形的原始宽高比显示,不能强行拉伸成正圆或铺满整列。底部道具区不再使用连片胶囊背景,提示、原图、冻结三个按钮均匀分布;运行态只展示按钮素材本身,不额外叠加“提示 / 原图 / 冻结”文字。
|
||||
- 拼图运行态棋盘不叠加分块蒙版、描边、阴影、选中底色或合并块 SVG 轮廓;拼图片本体需要裁切为圆角形状,单块使用独立圆角裁切,合并块使用 SVG 原生 `clipPath` 裁切整体外轮廓,外凸角和内凹角分别计算半径,内凹角半径要比外凸角更明显以避免手机 WebView 中看起来仍是直角。原图道具只在用户主动确认后打开独立原图查看层,不在当前拼图棋盘上叠加原图。
|
||||
- 拼图运行态拖拽必须完全跟随手指或鼠标位置,`pointermove` 期间即时写入可见拼块的 transform,不依赖等待后端回包、React 重渲染或下一帧动画队列;进入拖动后不展示拼块选中态或“已选择”提示,松手后再提交目标格同步规则真相。
|
||||
- 拼图运行态的提示、设置等点击弹层跟随当前运行态主色主题,使用普通圆角主题面板,不复用像素九宫格素材框。
|
||||
- 拼图运行态壳层自身要补齐 `platform-ui-shell` / `platform-theme` / `platform-theme--light|dark`,不能依赖外层平台壳来提供主题变量;`/puzzle` 直达页和平台内嵌页都必须渲染同一套主题语义类。
|
||||
- 拼图运行态顶部关卡信息采用游戏化铭牌样式:橘棕横向关卡名牌承载 `第 N 关` 和关卡名,左侧固定使用 `media/logo.png` 卡通形象;倒计时作为下挂米白小牌独立显示,紧贴铭牌但不遮挡棋盘。该样式只改变运行态 HUD 视觉,不改变计时、暂停、失败同步或关卡推进规则。
|
||||
- 拼图运行态进行中关卡的 `elapsedMs` 仍是结算字段,设置面板的“当前用时”必须按 `startedAtMs`、暂停累计和冻结累计实时派生;不要直接把进行中的 `currentLevel.elapsedMs` 当作展示值。
|
||||
- 推荐页嵌入拼图运行态时,通关结算弹层必须挂到页面级 fixed 浮层,不能留在推荐卡片视觉区内的 absolute 覆盖层;推荐页滑动卡片和运行态视口都使用 `overflow: hidden`,半屏内容区会裁剪排行榜、下一关按钮和相似作品卡。
|
||||
- 推荐页里的拼图作品如果从运行态进入“改造”结果页,返回平台后要清掉推荐嵌入态的 `activeRecommendEntryKey` / `activeRecommendRuntimeKind` / `isStartingRecommendEntry`,再重新按推荐页自动启动逻辑进入作品,不能复用已经被清空的旧 `puzzleRun`。
|
||||
- 拼图运行态允许前端低延迟交互表现,但通关、排行榜、奖励和作品状态仍以后端确认为准。
|
||||
|
||||
@@ -122,9 +127,10 @@ RPG / 拼图等运行态存档选择入口统一在个人中心 `常用功能 >
|
||||
入口表单只展示:
|
||||
|
||||
- 题材主题。
|
||||
- `2D素材风格` 横向风格卡:扁平图标、赛璐璐卡通、像素复古、手绘水彩、贴纸描边、厚涂图标、自定义。
|
||||
- 难度:轻松、标准、进阶、硬核。
|
||||
|
||||
入口不再要求用户选择素材风格;历史草稿和旧接口中的 `assetStyleId` / `assetStyleLabel` / `assetStylePrompt` 仅作为兼容字段保留,新入口提交不再写入这些字段。
|
||||
|
||||
难度映射:
|
||||
|
||||
| 难度 | clearCount | difficulty | 总物品数 | 物品种类 |
|
||||
@@ -132,29 +138,27 @@ RPG / 拼图等运行态存档选择入口统一在个人中心 `常用功能 >
|
||||
| 轻松 | 8 | 2 | 24 | 3 |
|
||||
| 标准 | 12 | 4 | 36 | 9 |
|
||||
| 进阶 | 16 | 6 | 48 | 15 |
|
||||
| 硬核 | 21 | 8 | 63 | 21 |
|
||||
| 硬核 | 21 | 8 | 63 | 20 |
|
||||
|
||||
当前素材生成流水线:
|
||||
|
||||
1. 点击生成前弹出泥点确认,草稿生成固定消耗 `10` 泥点。
|
||||
2. 先写入可恢复草稿 profile,再执行文本计划、图片生成、切图、OSS 上传、背景和容器生成;作品摘要在素材或背景未完整时下发 `generationStatus=generating`,素材和背景完整后下发 `ready`,草稿完成条件不包含 `backgroundMusic`。
|
||||
3. 物品素材不再调用 Hyper3D Rodin,不再生成 GLB。新草稿和批量新增固定生成 2D 五视角素材。
|
||||
4. 物品 sheet 走 VectorEngine Gemini `gemini-3-pro-image-preview` 原生 `generateContent`,单张 `1:1` 图固定 `5*5`,每张承载 `5` 个物品、每个物品 `5` 个视角。
|
||||
5. 物品 sheet prompt、切图、透明化和五视角切片持久化复用 `generated_asset_sheets` 通用模块;Match3D 只传入题材 / 风格 subject、物品行 prompt 模板和“同一行五格必须是同一物品五个不同视角”的特殊设定,并把通用切片结果映射回 `generatedItemAssets[].imageViews[]`。
|
||||
6. 切图前先在整张 sheet 上做绿幕 / 近白底透明化和边缘去污染,再按格子导出独立 PNG;每个视角图再以扩大的 PNG 边界带为种子,把连通的浅绿 / 近白抗锯齿边直接改为透明,并对贴透明背景的弱绿 / 暗绿轮廓像素做去绿污染处理,最后按剩余可见主体二次收紧;不要先裁剪单格再各自去绿。
|
||||
7. `generatedItemAssets[].imageViews[]` 是新素材主字段,`imageSrc/imageObjectKey` 只兼容首张视角。
|
||||
2. 先写入可恢复草稿 profile,再执行文本计划、关卡整图生成、三张派生图生成、OSS 上传和素材解析;作品摘要在背景、UI spritesheet 或物品 spritesheet 未完整时下发 `generationStatus=generating`,完整后下发 `ready`,草稿完成条件不包含 `backgroundMusic`。
|
||||
3. 首次调用 VectorEngine `gpt-image-2`,无参考图,竖屏 `9:16`,生成完整抓大鹅关卡画面并持久化到 `generatedBackgroundAsset.levelSceneImageSrc/levelSceneImageObjectKey`。提示词必须包含用户主题描述、顶部返回 / 标题倒计时 / 设置按钮、中间与主题匹配且贴横向边缘的容器,以及底部“移出 / 凑齐 / 打乱”三个道具按钮。
|
||||
4. 关卡整图完成后并发发起三次 `gpt-image-2` 编辑请求,三者都以关卡整图作为参考图:`1K`、`1:1` 的 UI spritesheet 写入 `uiSpritesheetImageSrc/uiSpritesheetImageObjectKey`;`1K`、`9:16` 的背景图写入 `imageSrc/imageObjectKey`;`2K`、`1:1` 的物品 spritesheet 写入 `itemSpritesheetImageSrc/itemSpritesheetImageObjectKey`。
|
||||
5. UI spritesheet 提示词固定要求按从上到下、从左到右整理纯绿色绿幕背景素材:返回按钮、设置按钮、方格素材(不含边框,仅保留一个)、移出按钮、凑齐按钮、打乱按钮;后端上传 OSS 前必须把绿幕扣成透明 PNG。背景图提示词固定要求移除全部 UI 组件和容器内含物,完整保留容器和背景,并补全被 UI 覆盖的背景内容。
|
||||
6. 物品 spritesheet 固定 `10行*10列`、统一纯绿色绿幕背景,后端上传 OSS 前必须把绿幕扣成透明 PNG;素材间距严格均匀分布,每一行包含两种物品,每种物品五个不同形态,物品来自参考图中心容器中的 2D 素材,严禁高相似度物品。新流程每次固定解析并持久化 `20` 种物品,物品信息列表全部展示这 `20` 种;持久化单格映射必须按 `row = itemIndex / 2 + 1`、`col = itemIndex % 2 * 5 + viewIndex + 1` 写入通用系列素材图集,不能再用 `row = itemIndex + 1`。`generatedItemAssets[].imageViews[]` 仍兼容已切好的五视角图,缺失时运行态和编辑器按 spritesheet 自动解析结果回退。
|
||||
7. 前端和运行态统一使用 alpha 连通域矩形检测解析 spritesheet:UI 图按返回、设置、方格、移出、凑齐、打乱顺序映射回原 UI 位置;物品图按检测顺序每 `5` 个区域组成一个物品的五个形态,最多 `20` 个物品。透明背景是解析前提,不能在前端按固定像素坐标写死切片。
|
||||
8. 文本生成物品名称时必须同时生成 `itemSize`,只允许 `大`、`中`、`小`。该字段随 `generatedItemAssets[].itemSize` 持久化并下发;历史缺失字段的素材按 `大` 兼容,模型缺失或非法值按物品名本地推断。
|
||||
9. 局内 `9:16` 纯背景图和 `1:1` 中心容器 UI 图分开生成。纯背景不得包含锅、盘、托盘、HUD、按钮、文字或物品,且入库前必须合成为全画幅不透明图片,不允许出现透明区域;容器图走 `/v1/images/edits` 参考透明容器图。该容器参考图由后端内嵌到 `api-server`,不要依赖运行时当前目录下的 `public/` 文件。
|
||||
10. 当前抓大鹅音频生成关闭:入口无 `生成音效`,草稿不生成背景音乐或点击音效,结果页不展示背景音乐 Tab 或点击音效生成入口。历史 `backgroundMusic` / `clickSound` 字段继续兼容传递。
|
||||
11. UI 背景和容器资产的持久化真相仍在 `generatedItemAssets[].backgroundAsset`;Agent session、work summary/detail、结果页和运行态入口都必须把该字段提升为 `backgroundImageSrc/backgroundImageObjectKey/generatedBackgroundAsset` 读取。草稿编译后的 `draftJson` 自身也必须携带 `generatedItemAssets` 快照;HTTP facade 不能只依赖 work detail 回读补齐 UI 资产,外部回读为空时也不得清空草稿内已有的背景 / 容器图。平台壳层从作品架、广场、生成完成回调、结果页保存 / 发布 / 试玩回调进入 Match3D profile 时也要先归一化并提升,避免首次试玩、手动试玩、推荐流或公开详情运行态退回默认背景 / 默认容器。
|
||||
9. 当前抓大鹅音频生成关闭:入口无 `生成音效`,草稿不生成背景音乐或点击音效,结果页不展示背景音乐 Tab 或点击音效生成入口。历史 `backgroundMusic` / `clickSound` 字段继续兼容传递。
|
||||
10. 背景、UI spritesheet、物品 spritesheet 和历史容器兼容字段的持久化真相仍在 `generatedItemAssets[].backgroundAsset` 与提升后的 `generatedBackgroundAsset`;Agent session、work summary/detail、结果页和运行态入口都必须把该字段提升为 `backgroundImageSrc/backgroundImageObjectKey/generatedBackgroundAsset` 读取。草稿编译后的 `draftJson` 自身也必须携带 `generatedItemAssets` 快照;HTTP facade 不能只依赖 work detail 回读补齐 UI 资产,外部回读为空时也不得清空草稿内已有的背景 / 图集。平台壳层从作品架、广场、生成完成回调、结果页保存 / 发布 / 试玩回调进入 Match3D profile 时也要先归一化并提升,避免首次试玩、手动试玩、推荐流或公开详情运行态退回默认背景。
|
||||
|
||||
结果页当前结构:
|
||||
|
||||
- `作品信息`:名称、描述、标签;封面编辑收口到发布面板。
|
||||
- `难度配置`:四档离散拖动条,显示需要消除、总物品数、物品种类、已生成物品种类。
|
||||
- `素材配置 > 物品`:两列素材卡,点击打开独立五视角预览面板;支持删除、批量新增和批量重新生成。替换模式必须保留原 `itemId` 和列表顺序。
|
||||
- `素材配置 > UI`:纯背景图与运行态 UI 预览,重生成消耗 `2` 泥点;UI 预览必须复用运行态顶部 HUD、中央容器棋盘、容器图定位和底部槽位样式,不单独维护一套简化预览 UI。
|
||||
- `素材配置 > 容器形象`:单独预览和重生成中心容器,消耗 `2` 泥点。
|
||||
- `素材配置 > 物品`:两列素材卡固定展示 20 个物品,点击打开独立五视角预览面板;支持删除、批量新增和批量重新生成。替换模式必须保留原 `itemId` 和列表顺序。
|
||||
- `素材配置 > UI素材`:预览背景图、UI spritesheet 原图、物品 spritesheet 原图和物品 spritesheet 自动解析缩略图;背景图只支持预览,不提供重新生成入口。UI 预览必须复用运行态顶部 HUD、中央容器棋盘和底部槽位样式,不单独维护一套简化预览 UI。
|
||||
|
||||
运行态当前口径:
|
||||
|
||||
@@ -164,8 +168,9 @@ RPG / 拼图等运行态存档选择入口统一在个人中心 `常用功能 >
|
||||
- 初始物品坐标围绕容器口中心生成,并保留内缩安全距离,避免贴边和局部角落聚集。
|
||||
- 本地试玩与 Rust `module-match3d` 后端领域生成使用同一套中心铺开口径;生成点覆盖四象限且均值接近中心。
|
||||
- 运行态优先消费 2D 生成图;默认积木 / 程序化 3D 表现只作为视觉分支和兜底,不改变规则真相。
|
||||
- 运行态启动前要预加载 `generatedItemAssets[].imageViews[]`、顶层 `generatedBackgroundAsset`、物品挂载 `backgroundAsset` 中的背景和容器图;首次生成自动试玩、结果页手动试玩、推荐流和公开详情启动都必须传入提升后的 profile。卡片摘要缺 UI 背景或容器字段时,进入运行态前必须补读 work detail。补读后的 profile 也要再次提升 `generatedItemAssets[].backgroundAsset`,确保背景和容器字段传给 `Match3DRuntimeShell`。
|
||||
- 局内容器图在移动端宽度大于屏幕宽度并略向下压,当前运行态使用 `w-[min(116vw,42rem)]` 与 `top-[54%]` 放大和下移容器图本体,保持原图比例不拉伸且不改变后端物品布局、点击半径或消除规则;生成容器图加载成功后棋盘外壳透明且 `overflow-visible`,只有生成图缺失或加载失败时才显示透明参考容器兜底。
|
||||
- 难度只决定本局加载的物品种类数量:轻松 3、标准 9、进阶 15、硬核 20。硬核仍保留 21 次消除和 63 件总物品,运行态按 20 种素材循环复用,不要求生成第 21 种素材。
|
||||
- 运行态启动前要预加载 `generatedItemAssets[].imageViews[]`、顶层 `generatedBackgroundAsset`、物品挂载 `backgroundAsset` 中的背景、UI spritesheet 和物品 spritesheet;首次生成自动试玩、结果页手动试玩、推荐流和公开详情启动都必须传入提升后的 profile。卡片摘要缺图集字段时,进入运行态前必须补读 work detail。补读后的 profile 也要再次提升 `generatedItemAssets[].backgroundAsset`,确保背景和图集字段传给 `Match3DRuntimeShell`。
|
||||
- 背景图作为运行态全屏背景,图内已经保留容器;旧 `containerImage*` 只作为历史透明容器兼容字段。若 `containerImage*` 与 `uiSpritesheetImage*` 同源,运行态不得把 UI spritesheet 当中心容器图叠到棋盘上。
|
||||
- generated 私有图换签未完成时,局内物品先隐藏等待,不得短暂显示默认积木;同一批资源在重启 run 时保留已解析签名 URL,只有资源源列表变化或换签失败后才允许进入兜底视觉。
|
||||
- `itemSize` 只缩放生成 2D 图片本体:`大`、`中`、`小` 均按相对尺寸缩放,其中 `大` 也比原始图片略小,`中` 和 `小` 进一步缩小;不改变后端下发的布局半径、点击半径或三消规则。
|
||||
- 物品进入底部物品栏时按同类型插入:如果物品栏已有同类物品,新物品插到该类型最后一个物品后面,后续物品整体后移;没有同类时追加到当前末尾。达到三件同类时,在飞入物品栏动画结束后,左侧和右侧同类物品向中间合成,三件一起消失,播放合成音效,不展示星星图标,后面的物品再向前补位。该动效只是前端表现层,后端和本地试玩仍负责权威插入、指定点击类型清除与补位后的槽位快照。
|
||||
|
||||
@@ -95,6 +95,7 @@ server-rs + Axum + SpacetimeDB
|
||||
9. 发现页 `分类` 子频道的筛选必须打开独立 dialog / drawer / modal,至少支持玩法类型过滤与排序切换;筛选结果为空时显示空状态,不把筛选内容展开在当前列表下方。
|
||||
10. “我的”页泥点、游戏时长、玩过三张统计卡只展示各自标签和值,内容居中且不换行,不在统计区底部展示“更新于”时间。
|
||||
11. RPG 等运行态的战斗飘字、血量变化和即时反馈必须在暗色、噪声高的场景背景上保持可读:使用高亮文字、深色描边、强阴影或小面积半透明底,不只依赖红/绿文字本身表达伤害或治疗。
|
||||
11. 平台亮色 UI 配色以陶泥儿主视觉为准:暖白 / 米杏底、陶土橙主按钮、深棕正文与浅杏边框;新增界面优先复用 `src/index.css` 的 `--platform-*` 主题变量和 `apps/admin-web/src/styles/admin.css` 的同系色值,不再引入粉红、蓝绿等独立主色方案。
|
||||
|
||||
## 文案与编码
|
||||
|
||||
|
||||
BIN
media/logo.png
Normal file
BIN
media/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
1061
package-lock.json
generated
1061
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -57,7 +57,11 @@
|
||||
"check:data": "node scripts/run-tsx.cjs scripts/validate-content.ts",
|
||||
"check:overrides": "node scripts/run-tsx.cjs scripts/validate-overrides.ts",
|
||||
"check:smoke": "node scripts/run-tsx.cjs scripts/smoke-content.ts",
|
||||
"check:content": "npm run check:data && npm run check:overrides && npm run check:smoke"
|
||||
"check:content": "npm run check:data && npm run check:overrides && npm run check:smoke",
|
||||
"codegraph:init": "codegraph init -i .",
|
||||
"codegraph:index": "codegraph index .",
|
||||
"codegraph:sync": "codegraph sync .",
|
||||
"codegraph:status": "codegraph status ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.1.14",
|
||||
@@ -73,6 +77,7 @@
|
||||
"vite": "^6.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@colbymchenry/codegraph": "^0.8.0",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@testing-library/user-event": "^14.6.1",
|
||||
"@types/node": "^22.14.0",
|
||||
|
||||
@@ -19,8 +19,17 @@ export type Match3DGeneratedItemSize = '大' | '中' | '小' | string;
|
||||
|
||||
export interface Match3DGeneratedBackgroundAsset {
|
||||
prompt: string;
|
||||
levelScenePrompt?: string | null;
|
||||
levelSceneImageSrc?: string | null;
|
||||
levelSceneImageObjectKey?: string | null;
|
||||
imageSrc?: string | null;
|
||||
imageObjectKey?: string | null;
|
||||
uiSpritesheetPrompt?: string | null;
|
||||
uiSpritesheetImageSrc?: string | null;
|
||||
uiSpritesheetImageObjectKey?: string | null;
|
||||
itemSpritesheetPrompt?: string | null;
|
||||
itemSpritesheetImageSrc?: string | null;
|
||||
itemSpritesheetImageObjectKey?: string | null;
|
||||
containerPrompt?: string | null;
|
||||
containerImageSrc?: string | null;
|
||||
containerImageObjectKey?: string | null;
|
||||
|
||||
@@ -52,6 +52,8 @@ export type PuzzleAgentActionRequest =
|
||||
pictureDescription?: string;
|
||||
referenceImageSrc?: string | null;
|
||||
referenceImageSrcs?: string[];
|
||||
referenceImageAssetObjectId?: string | null;
|
||||
referenceImageAssetObjectIds?: string[];
|
||||
imageModel?: string | null;
|
||||
aiRedraw?: boolean;
|
||||
}
|
||||
@@ -63,6 +65,8 @@ export type PuzzleAgentActionRequest =
|
||||
pictureDescription?: string;
|
||||
referenceImageSrc?: string | null;
|
||||
referenceImageSrcs?: string[];
|
||||
referenceImageAssetObjectId?: string | null;
|
||||
referenceImageAssetObjectIds?: string[];
|
||||
imageModel?: string | null;
|
||||
aiRedraw?: boolean;
|
||||
candidateCount?: number;
|
||||
@@ -73,6 +77,8 @@ export type PuzzleAgentActionRequest =
|
||||
promptText?: string | null;
|
||||
referenceImageSrc?: string | null;
|
||||
referenceImageSrcs?: string[];
|
||||
referenceImageAssetObjectId?: string | null;
|
||||
referenceImageAssetObjectIds?: string[];
|
||||
imageModel?: string | null;
|
||||
aiRedraw?: boolean;
|
||||
candidateCount?: number;
|
||||
|
||||
@@ -51,6 +51,12 @@ export interface PuzzleDraftLevel {
|
||||
uiBackgroundPrompt?: string | null;
|
||||
uiBackgroundImageSrc?: string | null;
|
||||
uiBackgroundImageObjectKey?: string | null;
|
||||
levelSceneImageSrc?: string | null;
|
||||
levelSceneImageObjectKey?: string | null;
|
||||
uiSpritesheetImageSrc?: string | null;
|
||||
uiSpritesheetImageObjectKey?: string | null;
|
||||
levelBackgroundImageSrc?: string | null;
|
||||
levelBackgroundImageObjectKey?: string | null;
|
||||
backgroundMusic?: CreationAudioAsset | null;
|
||||
candidates: PuzzleGeneratedImageCandidate[];
|
||||
selectedCandidateId: string | null;
|
||||
|
||||
@@ -51,6 +51,8 @@ export interface CreatePuzzleAgentSessionRequest {
|
||||
pictureDescription?: string;
|
||||
referenceImageSrc?: string | null;
|
||||
referenceImageSrcs?: string[];
|
||||
referenceImageAssetObjectId?: string | null;
|
||||
referenceImageAssetObjectIds?: string[];
|
||||
imageModel?: string | null;
|
||||
aiRedraw?: boolean;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ export interface PuzzleRuntimeLevelSnapshot {
|
||||
coverImageSrc: string | null;
|
||||
uiBackgroundImageSrc?: string | null;
|
||||
uiBackgroundImageObjectKey?: string | null;
|
||||
levelBackgroundImageSrc?: string | null;
|
||||
levelBackgroundImageObjectKey?: string | null;
|
||||
uiSpritesheetImageSrc?: string | null;
|
||||
uiSpritesheetImageObjectKey?: string | null;
|
||||
backgroundMusic?: CreationAudioAsset | null;
|
||||
board: PuzzleBoardSnapshot;
|
||||
status: PuzzleRuntimeLevelStatus;
|
||||
|
||||
@@ -120,6 +120,115 @@ PY
|
||||
fi
|
||||
}
|
||||
|
||||
read_env_value() {
|
||||
local file_path="$1"
|
||||
local key="$2"
|
||||
|
||||
if [[ ! -f "${file_path}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local python_script='
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
key = sys.argv[2]
|
||||
if not path.exists():
|
||||
raise SystemExit(0)
|
||||
for raw_line in path.read_text(encoding="utf-8").splitlines():
|
||||
line = raw_line.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
current_key, value = line.split("=", 1)
|
||||
if current_key == key:
|
||||
value = value.strip()
|
||||
if len(value) >= 2 and value[0] == value[-1] and value[0] in ("\"", "'\''"):
|
||||
value = value[1:-1]
|
||||
print(value)
|
||||
raise SystemExit(0)
|
||||
'
|
||||
|
||||
if [[ -r "${file_path}" ]]; then
|
||||
python3 -c "${python_script}" "${file_path}" "${key}"
|
||||
else
|
||||
if ! sudo -n true >/dev/null 2>&1; then
|
||||
echo "[production-api-deploy] 当前用户无权读取 ${file_path},且 sudo -n 不可用;无法检查运行态环境变量。" >&2
|
||||
exit 1
|
||||
fi
|
||||
sudo -n python3 -c "${python_script}" "${file_path}" "${key}"
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_env_value() {
|
||||
local file_path="$1"
|
||||
local key="$2"
|
||||
local default_value="$3"
|
||||
local current_value
|
||||
|
||||
current_value="$(read_env_value "${file_path}" "${key}")"
|
||||
if [[ -n "${current_value}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo "[production-api-deploy] 补齐 api-server 环境变量: ${key} -> ${file_path}"
|
||||
write_env_value "${file_path}" "${key}" "${default_value}"
|
||||
}
|
||||
|
||||
run_privileged() {
|
||||
if [[ "$(id -u)" -eq 0 ]]; then
|
||||
"$@"
|
||||
return
|
||||
fi
|
||||
if ! sudo -n true >/dev/null 2>&1; then
|
||||
echo "[production-api-deploy] 当前用户不是 root,且 sudo -n 不可用;无法执行: $*" >&2
|
||||
exit 1
|
||||
fi
|
||||
sudo -n "$@"
|
||||
}
|
||||
|
||||
ensure_runtime_dir() {
|
||||
local path="$1"
|
||||
local mode="$2"
|
||||
|
||||
if [[ -z "${path}" ]]; then
|
||||
return
|
||||
fi
|
||||
if [[ "${path}" != /* ]]; then
|
||||
echo "[production-api-deploy] 运行态目录必须使用绝对路径,避免写入只读发布目录: ${path}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[production-api-deploy] 确保运行态目录可写: ${path}"
|
||||
run_privileged install -d -o genarrative -g genarrative -m "${mode}" "${path}"
|
||||
}
|
||||
|
||||
ensure_runtime_env_and_dirs() {
|
||||
local api_env_file="$1"
|
||||
local tracking_enabled tracking_outbox_dir auth_store_path auth_store_dir
|
||||
|
||||
# 旧生产环境文件会被 server-provision 保留,不一定包含新增的运行态写入路径。
|
||||
# 发布前只补缺省值,不覆盖线上已经定制过的目录或开关。
|
||||
ensure_env_value "${api_env_file}" "GENARRATIVE_TRACKING_OUTBOX_ENABLED" "true"
|
||||
ensure_env_value "${api_env_file}" "GENARRATIVE_TRACKING_OUTBOX_DIR" "/var/lib/genarrative/tracking-outbox"
|
||||
ensure_env_value "${api_env_file}" "GENARRATIVE_TRACKING_OUTBOX_BATCH_SIZE" "500"
|
||||
ensure_env_value "${api_env_file}" "GENARRATIVE_TRACKING_OUTBOX_FLUSH_INTERVAL_MS" "1000"
|
||||
ensure_env_value "${api_env_file}" "GENARRATIVE_TRACKING_OUTBOX_MAX_BYTES" "268435456"
|
||||
ensure_env_value "${api_env_file}" "GENARRATIVE_AUTH_STORE_PATH" "/var/lib/genarrative/auth/auth-store.json"
|
||||
|
||||
tracking_enabled="$(read_env_value "${api_env_file}" "GENARRATIVE_TRACKING_OUTBOX_ENABLED")"
|
||||
tracking_outbox_dir="$(read_env_value "${api_env_file}" "GENARRATIVE_TRACKING_OUTBOX_DIR")"
|
||||
if [[ "$(printf "%s" "${tracking_enabled}" | tr '[:upper:]' '[:lower:]')" != "false" ]]; then
|
||||
ensure_runtime_dir "${tracking_outbox_dir}" "0750"
|
||||
fi
|
||||
|
||||
auth_store_path="$(read_env_value "${api_env_file}" "GENARRATIVE_AUTH_STORE_PATH")"
|
||||
if [[ -n "${auth_store_path}" ]]; then
|
||||
auth_store_dir="$(dirname "${auth_store_path}")"
|
||||
ensure_runtime_dir "${auth_store_dir}" "0750"
|
||||
fi
|
||||
}
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SOURCE_DIR=""
|
||||
VERSION=""
|
||||
@@ -243,6 +352,8 @@ if [[ -n "${SPACETIME_SERVER_URL}" ]]; then
|
||||
write_env_value "${API_ENV_FILE}" "GENARRATIVE_SPACETIME_SERVER_URL" "${SPACETIME_SERVER_URL}"
|
||||
fi
|
||||
|
||||
ensure_runtime_env_and_dirs "${API_ENV_FILE}"
|
||||
|
||||
mkdir -p "$(dirname "${CURRENT_LINK}")"
|
||||
ln -sfn "${RELEASE_DIR}" "${CURRENT_LINK}"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
@@ -101,7 +101,7 @@ const onlyIds = process.argv
|
||||
.filter(Boolean);
|
||||
const templates = rawTemplates.filter((template) => !onlyIds.length || onlyIds.includes(template.id));
|
||||
const dryRun = args.has('--dry-run') || !args.has('--live');
|
||||
const requests = templates.map((template) => ({ id: template.id, title: template.title, body: { model: 'gpt-image-2-all', prompt: template.prompt, n: 1, size: '1024x1024' } }));
|
||||
const requests = templates.map((template) => ({ id: template.id, title: template.title, body: { model: 'gpt-image-2', prompt: template.prompt, n: 1, size: '1024x1024' } }));
|
||||
if (dryRun) {
|
||||
console.log(JSON.stringify({ mode: 'dry-run', outDir, count: requests.length, requests }, null, 2));
|
||||
process.exit(0);
|
||||
|
||||
@@ -772,6 +772,12 @@ function buildVectorEngineImagesGenerationUrl(baseUrl) {
|
||||
: `${baseUrl}/v1/images/generations`;
|
||||
}
|
||||
|
||||
function buildVectorEngineImagesEditUrl(baseUrl) {
|
||||
return baseUrl.endsWith('/v1')
|
||||
? `${baseUrl}/images/edits`
|
||||
: `${baseUrl}/v1/images/edits`;
|
||||
}
|
||||
|
||||
function collectStringsByKey(value, targetKey, output) {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((entry) => collectStringsByKey(entry, targetKey, output));
|
||||
@@ -828,28 +834,41 @@ function inferExtensionFromBytes(bytes, preferredPath) {
|
||||
return path.extname(preferredPath).replace(/^\./u, '') || 'png';
|
||||
}
|
||||
|
||||
function toDataUrl(filePath) {
|
||||
function mimeFromExtension(extension) {
|
||||
if (extension === 'jpg' || extension === 'jpeg') {
|
||||
return 'image/jpeg';
|
||||
}
|
||||
if (extension === 'webp') {
|
||||
return 'image/webp';
|
||||
}
|
||||
return 'image/png';
|
||||
}
|
||||
|
||||
function readReferenceImage(filePath) {
|
||||
if (!existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
const bytes = readFileSync(filePath);
|
||||
const extension = inferExtensionFromBytes(bytes, filePath);
|
||||
const mime = extension === 'jpg' ? 'image/jpeg' : `image/${extension}`;
|
||||
return `data:${mime};base64,${bytes.toString('base64')}`;
|
||||
return {
|
||||
fileName: path.basename(filePath).replace(/"/gu, '_'),
|
||||
mimeType: mimeFromExtension(extension),
|
||||
bytes,
|
||||
};
|
||||
}
|
||||
|
||||
function pushReferenceImage(body, filePath) {
|
||||
const reference = toDataUrl(filePath);
|
||||
const reference = readReferenceImage(filePath);
|
||||
if (!reference) {
|
||||
return false;
|
||||
}
|
||||
body.image = [...(body.image || []), reference];
|
||||
body.referenceImages = [...(body.referenceImages || []), reference];
|
||||
return true;
|
||||
}
|
||||
|
||||
function buildRequestBody(asset, size) {
|
||||
const body = {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: asset.prompt,
|
||||
n: 1,
|
||||
size: size || asset.size,
|
||||
@@ -1624,18 +1643,49 @@ async function generateAsset(asset, env, size, force) {
|
||||
};
|
||||
}
|
||||
|
||||
const requestBody = buildRequestBody(asset, size);
|
||||
const { referenceImages = [], ...requestBody } = buildRequestBody(asset, size);
|
||||
const hasReferenceImages = referenceImages.length > 0;
|
||||
const requestOptions = hasReferenceImages
|
||||
? (() => {
|
||||
const formData = new FormData();
|
||||
formData.set('model', requestBody.model);
|
||||
formData.set('prompt', requestBody.prompt);
|
||||
formData.set('n', String(requestBody.n));
|
||||
formData.set('size', requestBody.size);
|
||||
for (const referenceImage of referenceImages) {
|
||||
formData.append(
|
||||
'image',
|
||||
new Blob([referenceImage.bytes], { type: referenceImage.mimeType }),
|
||||
referenceImage.fileName,
|
||||
);
|
||||
}
|
||||
return {
|
||||
url: buildVectorEngineImagesEditUrl(env.baseUrl),
|
||||
options: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${env.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: formData,
|
||||
},
|
||||
};
|
||||
})()
|
||||
: {
|
||||
url: buildVectorEngineImagesGenerationUrl(env.baseUrl),
|
||||
options: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${env.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
},
|
||||
};
|
||||
const payloadText = await fetchWithTimeout(
|
||||
buildVectorEngineImagesGenerationUrl(env.baseUrl),
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${env.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
},
|
||||
requestOptions.url,
|
||||
requestOptions.options,
|
||||
env.timeoutMs,
|
||||
);
|
||||
|
||||
@@ -1687,7 +1737,7 @@ async function generateAsset(asset, env, size, force) {
|
||||
size: requestBody.size,
|
||||
extension: actualExtension,
|
||||
source: urls[0] ? 'url' : 'b64_json',
|
||||
usedReferenceImage: Boolean(requestBody.image),
|
||||
usedReferenceImage: hasReferenceImages,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1715,19 +1765,27 @@ function dryRun(selectedAssets, size) {
|
||||
{
|
||||
mode: 'dry-run',
|
||||
assets: selectedAssets.map((asset) => {
|
||||
const body = buildRequestBody(asset, size);
|
||||
const { referenceImages = [], ...body } = buildRequestBody(asset, size);
|
||||
return {
|
||||
id: asset.id,
|
||||
endpoint: referenceImages.length
|
||||
? '/v1/images/edits'
|
||||
: '/v1/images/generations',
|
||||
outputPath: outputPathFor(asset),
|
||||
sourceOutputPath: asset.transparent
|
||||
? sourceOutputPathFor(asset)
|
||||
: undefined,
|
||||
transparent: asset.transparent,
|
||||
localPostprocess: asset.localPostprocess,
|
||||
body: {
|
||||
...body,
|
||||
image: body.image ? ['<local style reference image>'] : undefined,
|
||||
},
|
||||
body: referenceImages.length ? undefined : body,
|
||||
form: referenceImages.length
|
||||
? {
|
||||
...body,
|
||||
imageParts: referenceImages.map(
|
||||
(referenceImage) => referenceImage.fileName,
|
||||
),
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
@@ -215,7 +215,7 @@ async function downloadImage(url, timeoutMs) {
|
||||
|
||||
async function generateOne(env, template, outDir, size) {
|
||||
const requestBody = {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: buildPrompt(template),
|
||||
n: 1,
|
||||
size,
|
||||
@@ -278,7 +278,7 @@ if (dryRun) {
|
||||
id: template.id,
|
||||
title: template.title,
|
||||
body: {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: buildPrompt(template),
|
||||
n: 1,
|
||||
size,
|
||||
|
||||
@@ -817,12 +817,18 @@ function resolveEnv() {
|
||||
};
|
||||
}
|
||||
|
||||
function buildUrl(baseUrl) {
|
||||
function buildGenerationUrl(baseUrl) {
|
||||
return baseUrl.endsWith('/v1')
|
||||
? `${baseUrl}/images/generations`
|
||||
: `${baseUrl}/v1/images/generations`;
|
||||
}
|
||||
|
||||
function buildEditUrl(baseUrl) {
|
||||
return baseUrl.endsWith('/v1')
|
||||
? `${baseUrl}/images/edits`
|
||||
: `${baseUrl}/v1/images/edits`;
|
||||
}
|
||||
|
||||
function hasHeader(headers, targetName) {
|
||||
return Object.keys(headers).some(
|
||||
(name) => name.toLowerCase() === targetName.toLowerCase(),
|
||||
@@ -954,7 +960,7 @@ function inferExtensionFromBytes(bytes) {
|
||||
return 'png';
|
||||
}
|
||||
|
||||
function imagePathToDataUrl(imagePath) {
|
||||
function imagePathToReferenceImage(imagePath) {
|
||||
if (!existsSync(imagePath)) {
|
||||
throw new Error(`Reference image not found: ${imagePath}`);
|
||||
}
|
||||
@@ -967,7 +973,44 @@ function imagePathToDataUrl(imagePath) {
|
||||
: extension === '.webp'
|
||||
? 'image/webp'
|
||||
: 'image/png';
|
||||
return `data:${mimeType};base64,${bytes.toString('base64')}`;
|
||||
return {
|
||||
fieldName: 'image',
|
||||
fileName: path.basename(imagePath).replace(/"/gu, '_'),
|
||||
mimeType,
|
||||
bytes,
|
||||
};
|
||||
}
|
||||
|
||||
function buildMultipartBody(fields, files) {
|
||||
const boundary = `----genarrative-${Date.now().toString(16)}-${Math.random()
|
||||
.toString(16)
|
||||
.slice(2)}`;
|
||||
const chunks = [];
|
||||
const push = (value) => {
|
||||
chunks.push(Buffer.isBuffer(value) ? value : Buffer.from(value));
|
||||
};
|
||||
|
||||
for (const [name, value] of Object.entries(fields)) {
|
||||
push(`--${boundary}\r\n`);
|
||||
push(`Content-Disposition: form-data; name="${name}"\r\n\r\n`);
|
||||
push(`${value}\r\n`);
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
push(`--${boundary}\r\n`);
|
||||
push(
|
||||
`Content-Disposition: form-data; name="${file.fieldName}"; filename="${file.fileName}"\r\n`,
|
||||
);
|
||||
push(`Content-Type: ${file.mimeType}\r\n\r\n`);
|
||||
push(file.bytes);
|
||||
push('\r\n');
|
||||
}
|
||||
|
||||
push(`--${boundary}--\r\n`);
|
||||
return {
|
||||
body: Buffer.concat(chunks),
|
||||
contentType: `multipart/form-data; boundary=${boundary}`,
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchJson(url, options, timeoutMs) {
|
||||
@@ -1011,27 +1054,45 @@ async function downloadUrl(url, timeoutMs) {
|
||||
|
||||
async function generateConcept(env, concept) {
|
||||
const requestBody = {
|
||||
model: 'gpt-image-2-all',
|
||||
model: 'gpt-image-2',
|
||||
prompt: concept.prompt,
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
};
|
||||
if (concept.referenceImages?.length) {
|
||||
requestBody.image = concept.referenceImages.map(imagePathToDataUrl);
|
||||
}
|
||||
const payload = await fetchJson(
|
||||
buildUrl(env.baseUrl),
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${env.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
},
|
||||
env.timeoutMs,
|
||||
|
||||
const referenceImages = (concept.referenceImages || []).map(
|
||||
imagePathToReferenceImage,
|
||||
);
|
||||
const payload = referenceImages.length
|
||||
? await (async () => {
|
||||
const multipart = buildMultipartBody(requestBody, referenceImages);
|
||||
return fetchJson(
|
||||
buildEditUrl(env.baseUrl),
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${env.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
'Content-Type': multipart.contentType,
|
||||
},
|
||||
body: multipart.body,
|
||||
},
|
||||
env.timeoutMs,
|
||||
);
|
||||
})()
|
||||
: await fetchJson(
|
||||
buildGenerationUrl(env.baseUrl),
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${env.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
},
|
||||
env.timeoutMs,
|
||||
);
|
||||
|
||||
const urls = extractImageUrls(payload);
|
||||
const b64Images = extractBase64Images(payload);
|
||||
@@ -1072,19 +1133,28 @@ if (dryRun) {
|
||||
requests: selected.map((concept) => ({
|
||||
id: concept.id,
|
||||
title: concept.title,
|
||||
body: {
|
||||
model: 'gpt-image-2-all',
|
||||
prompt: concept.prompt,
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
...(concept.referenceImages?.length
|
||||
? {
|
||||
image: concept.referenceImages.map((imagePath) =>
|
||||
path.relative(repoRoot, imagePath),
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
endpoint: concept.referenceImages?.length
|
||||
? '/v1/images/edits'
|
||||
: '/v1/images/generations',
|
||||
body: concept.referenceImages?.length
|
||||
? undefined
|
||||
: {
|
||||
model: 'gpt-image-2',
|
||||
prompt: concept.prompt,
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
},
|
||||
form: concept.referenceImages?.length
|
||||
? {
|
||||
model: 'gpt-image-2',
|
||||
prompt: concept.prompt,
|
||||
n: 1,
|
||||
size: '1024x1024',
|
||||
imageParts: concept.referenceImages.map((imagePath) =>
|
||||
path.relative(repoRoot, imagePath),
|
||||
),
|
||||
}
|
||||
: undefined,
|
||||
})),
|
||||
},
|
||||
null,
|
||||
|
||||
@@ -292,6 +292,42 @@ write_env_value() {
|
||||
chown root:root "${file}"
|
||||
}
|
||||
|
||||
ensure_env_value() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
local default_value="$3"
|
||||
local current_value
|
||||
|
||||
current_value="$(read_env_value "${file}" "${key}")"
|
||||
if [[ -n "${current_value}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo "[server-provision] 补齐 api-server 环境变量: ${key} -> ${file}"
|
||||
if [[ "${DRY_RUN}" != "true" ]]; then
|
||||
write_env_value "${file}" "${key}" "${default_value}"
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_api_runtime_env_defaults() {
|
||||
if [[ "${DRY_RUN}" == "true" ]]; then
|
||||
echo "+ ensure api-server runtime env defaults in ${API_ENV_FILE}"
|
||||
return
|
||||
fi
|
||||
if [[ ! -f "${API_ENV_FILE}" ]]; then
|
||||
echo "[server-provision] 环境文件不存在,无法补齐 api-server 运行态目录变量: ${API_ENV_FILE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 已存在的生产 env 会被保留,不会整文件覆盖;这里仅补后续版本新增的运行态写入路径。
|
||||
ensure_env_value "${API_ENV_FILE}" "GENARRATIVE_TRACKING_OUTBOX_ENABLED" "true"
|
||||
ensure_env_value "${API_ENV_FILE}" "GENARRATIVE_TRACKING_OUTBOX_DIR" "/var/lib/genarrative/tracking-outbox"
|
||||
ensure_env_value "${API_ENV_FILE}" "GENARRATIVE_TRACKING_OUTBOX_BATCH_SIZE" "500"
|
||||
ensure_env_value "${API_ENV_FILE}" "GENARRATIVE_TRACKING_OUTBOX_FLUSH_INTERVAL_MS" "1000"
|
||||
ensure_env_value "${API_ENV_FILE}" "GENARRATIVE_TRACKING_OUTBOX_MAX_BYTES" "268435456"
|
||||
ensure_env_value "${API_ENV_FILE}" "GENARRATIVE_AUTH_STORE_PATH" "/var/lib/genarrative/auth/auth-store.json"
|
||||
}
|
||||
|
||||
parse_json_string_field() {
|
||||
local json="$1"
|
||||
local key="$2"
|
||||
@@ -437,11 +473,55 @@ validate_nginx_tls() {
|
||||
fi
|
||||
}
|
||||
|
||||
disable_nginx_default_sites_enabled() {
|
||||
local moves_file="$1"
|
||||
local sites_enabled="/etc/nginx/sites-enabled"
|
||||
local sites_disabled="/etc/nginx/sites-disabled"
|
||||
local stamp source target base
|
||||
local candidates=("${sites_enabled}/default" "${sites_enabled}/default."*)
|
||||
|
||||
stamp="$(date +%Y%m%d%H%M%S)"
|
||||
for source in "${candidates[@]}"; do
|
||||
if [[ ! -e "${source}" && ! -L "${source}" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
base="$(basename "${source}")"
|
||||
target="${sites_disabled}/${base}.disabled-${stamp}"
|
||||
echo "[server-provision] 禁用 Debian 默认 Nginx 站点,避免与 Genarrative server_name 冲突: ${source} -> ${target}"
|
||||
mkdir -p "${sites_disabled}"
|
||||
mv "${source}" "${target}"
|
||||
printf "%s\t%s\n" "${target}" "${source}" >>"${moves_file}"
|
||||
done
|
||||
}
|
||||
|
||||
restore_nginx_default_sites_enabled() {
|
||||
local moves_file="$1"
|
||||
local target source
|
||||
|
||||
if [[ ! -f "${moves_file}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
while IFS=$'\t' read -r target source || [[ -n "${target:-}" ]]; do
|
||||
if [[ -z "${target:-}" || -z "${source:-}" ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ -e "${target}" || -L "${target}" ]]; then
|
||||
mkdir -p "$(dirname "${source}")"
|
||||
if [[ ! -e "${source}" && ! -L "${source}" ]]; then
|
||||
echo "[server-provision] 恢复 Debian 默认 Nginx 站点: ${target} -> ${source}"
|
||||
mv "${target}" "${source}"
|
||||
fi
|
||||
fi
|
||||
done <"${moves_file}"
|
||||
}
|
||||
|
||||
install_nginx_config_with_rollback() {
|
||||
local config_target="/etc/nginx/conf.d/genarrative.conf"
|
||||
local snippet_target="/etc/nginx/snippets/genarrative-maintenance.conf"
|
||||
local config_source
|
||||
local rendered_config rendered_snippet config_backup snippet_backup
|
||||
local rendered_config rendered_snippet config_backup snippet_backup disabled_sites
|
||||
local had_config="false"
|
||||
local had_snippet="false"
|
||||
|
||||
@@ -459,6 +539,7 @@ install_nginx_config_with_rollback() {
|
||||
echo "+ install -m 0644 deploy/nginx/snippets/genarrative-maintenance.conf ${snippet_target}"
|
||||
|
||||
if [[ "${DRY_RUN}" == "true" ]]; then
|
||||
echo "+ disable /etc/nginx/sites-enabled/default* if present"
|
||||
echo "+ nginx -t"
|
||||
echo "+ nginx -s reload"
|
||||
return
|
||||
@@ -468,6 +549,7 @@ install_nginx_config_with_rollback() {
|
||||
rendered_snippet="$(mktemp)"
|
||||
config_backup="$(mktemp)"
|
||||
snippet_backup="$(mktemp)"
|
||||
disabled_sites="$(mktemp)"
|
||||
if [[ "${NGINX_CONFIG_MODE}" == "production-https" ]]; then
|
||||
validate_nginx_tls
|
||||
render_nginx_https_config >"${rendered_config}"
|
||||
@@ -487,6 +569,7 @@ install_nginx_config_with_rollback() {
|
||||
|
||||
install -m 0644 "${rendered_config}" "${config_target}"
|
||||
install -m 0644 "${rendered_snippet}" "${snippet_target}"
|
||||
disable_nginx_default_sites_enabled "${disabled_sites}"
|
||||
|
||||
if ! nginx -t; then
|
||||
echo "[server-provision] nginx -t 失败,恢复写入前的 Nginx 配置。" >&2
|
||||
@@ -500,13 +583,14 @@ install_nginx_config_with_rollback() {
|
||||
else
|
||||
rm -f "${snippet_target}"
|
||||
fi
|
||||
rm -f "${rendered_config}" "${rendered_snippet}" "${config_backup}" "${snippet_backup}"
|
||||
restore_nginx_default_sites_enabled "${disabled_sites}"
|
||||
rm -f "${rendered_config}" "${rendered_snippet}" "${config_backup}" "${snippet_backup}" "${disabled_sites}"
|
||||
exit 1
|
||||
fi
|
||||
echo "+ nginx -s reload"
|
||||
nginx -s reload
|
||||
|
||||
rm -f "${rendered_config}" "${rendered_snippet}" "${config_backup}" "${snippet_backup}"
|
||||
rm -f "${rendered_config}" "${rendered_snippet}" "${config_backup}" "${snippet_backup}" "${disabled_sites}"
|
||||
}
|
||||
|
||||
cleanup_placeholder_nginx_config() {
|
||||
@@ -625,6 +709,7 @@ if [[ ! -f "${API_ENV_FILE}" ]]; then
|
||||
else
|
||||
echo "[server-provision] 已存在环境文件,保留不覆盖: ${API_ENV_FILE}"
|
||||
fi
|
||||
ensure_api_runtime_env_defaults
|
||||
|
||||
if [[ "${ENABLE_OTELCOL:-true}" == "true" ]]; then
|
||||
sync_otelcol_install
|
||||
|
||||
@@ -394,9 +394,13 @@ pub async fn confirm_asset_object(
|
||||
let result = state
|
||||
.spacetime_client()
|
||||
.confirm_asset_object(
|
||||
build_confirm_asset_object_upsert_input(oss_client, payload)
|
||||
.await
|
||||
.map_err(map_confirm_asset_object_prepare_error)?,
|
||||
build_confirm_asset_object_upsert_input(
|
||||
oss_client,
|
||||
payload,
|
||||
authenticated.claims().user_id(),
|
||||
)
|
||||
.await
|
||||
.map_err(map_confirm_asset_object_prepare_error)?,
|
||||
)
|
||||
.await
|
||||
.map_err(map_confirm_asset_object_error)?;
|
||||
@@ -592,6 +596,7 @@ fn supported_asset_history_kind_message() -> String {
|
||||
async fn build_confirm_asset_object_upsert_input(
|
||||
oss_client: &platform_oss::OssClient,
|
||||
payload: ConfirmAssetObjectRequest,
|
||||
authenticated_owner_user_id: &str,
|
||||
) -> Result<module_assets::AssetObjectUpsertInput, ConfirmAssetObjectPrepareError> {
|
||||
let configured_bucket = oss_client.config_bucket().to_string();
|
||||
let resolved_bucket = payload
|
||||
@@ -629,6 +634,14 @@ async fn build_confirm_asset_object_upsert_input(
|
||||
{
|
||||
return Err(ConfirmAssetObjectPrepareError::ContentLengthMismatch);
|
||||
}
|
||||
let owner_user_id = normalize_optional_value(payload.owner_user_id).or_else(|| {
|
||||
let owner = authenticated_owner_user_id.trim();
|
||||
if owner.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(owner.to_string())
|
||||
}
|
||||
});
|
||||
|
||||
let now_micros = current_utc_micros();
|
||||
build_asset_object_upsert_input(
|
||||
@@ -645,7 +658,7 @@ async fn build_confirm_asset_object_upsert_input(
|
||||
normalize_optional_value(payload.content_hash),
|
||||
payload.asset_kind,
|
||||
payload.source_job_id,
|
||||
payload.owner_user_id,
|
||||
owner_user_id,
|
||||
payload.profile_id,
|
||||
payload.entity_id,
|
||||
now_micros,
|
||||
|
||||
@@ -1049,6 +1049,7 @@ mod tests {
|
||||
base_url: "https://vector.example".to_string(),
|
||||
api_key: "secret".to_string(),
|
||||
request_timeout_ms: 180_000,
|
||||
external_api_audit_state: None,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
|
||||
372
server-rs/crates/api-server/src/external_api_audit.rs
Normal file
372
server-rs/crates/api-server/src/external_api_audit.rs
Normal file
@@ -0,0 +1,372 @@
|
||||
use axum::http::StatusCode;
|
||||
use module_runtime::RuntimeTrackingScopeKind;
|
||||
use serde_json::{Value, json};
|
||||
use time::OffsetDateTime;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{state::AppState, tracking::TrackingEventDraft};
|
||||
|
||||
pub(crate) const EXTERNAL_API_FAILURE_EVENT_KEY: &str = "external_api_call_failure";
|
||||
pub(crate) const EXTERNAL_API_AUDIT_MODULE_KEY: &str = "external-api";
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ExternalApiFailureDraft {
|
||||
pub(crate) provider: &'static str,
|
||||
pub(crate) endpoint: String,
|
||||
pub(crate) operation: String,
|
||||
pub(crate) failure_stage: &'static str,
|
||||
pub(crate) status_code: Option<u16>,
|
||||
pub(crate) status_class: Option<&'static str>,
|
||||
pub(crate) timeout: bool,
|
||||
pub(crate) retryable: bool,
|
||||
pub(crate) error_message: String,
|
||||
pub(crate) error_source: Option<String>,
|
||||
pub(crate) raw_excerpt: Option<String>,
|
||||
pub(crate) latency_ms: Option<u64>,
|
||||
pub(crate) prompt_chars: Option<usize>,
|
||||
pub(crate) reference_image_count: Option<usize>,
|
||||
pub(crate) image_model: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl ExternalApiFailureDraft {
|
||||
pub(crate) fn new(
|
||||
provider: &'static str,
|
||||
endpoint: impl Into<String>,
|
||||
operation: impl Into<String>,
|
||||
failure_stage: &'static str,
|
||||
error_message: impl Into<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
provider,
|
||||
endpoint: endpoint.into(),
|
||||
operation: operation.into(),
|
||||
failure_stage,
|
||||
status_code: None,
|
||||
status_class: None,
|
||||
timeout: false,
|
||||
retryable: false,
|
||||
error_message: error_message.into(),
|
||||
error_source: None,
|
||||
raw_excerpt: None,
|
||||
latency_ms: None,
|
||||
prompt_chars: None,
|
||||
reference_image_count: None,
|
||||
image_model: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn with_status_code(mut self, status_code: Option<u16>) -> Self {
|
||||
self.status_code = status_code;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_optional_status_class(mut self, status_class: Option<&'static str>) -> Self {
|
||||
self.status_class = status_class;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_timeout(mut self, timeout: bool) -> Self {
|
||||
self.timeout = timeout;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_retryable(mut self, retryable: bool) -> Self {
|
||||
self.retryable = retryable;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_error_source(mut self, error_source: Option<String>) -> Self {
|
||||
self.error_source = error_source;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_raw_excerpt(mut self, raw_excerpt: Option<String>) -> Self {
|
||||
self.raw_excerpt = raw_excerpt;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_latency_ms(mut self, latency_ms: Option<u64>) -> Self {
|
||||
self.latency_ms = latency_ms;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_prompt_chars(mut self, prompt_chars: Option<usize>) -> Self {
|
||||
self.prompt_chars = prompt_chars;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_reference_image_count(
|
||||
mut self,
|
||||
reference_image_count: Option<usize>,
|
||||
) -> Self {
|
||||
self.reference_image_count = reference_image_count;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_image_model(mut self, image_model: Option<&'static str>) -> Self {
|
||||
self.image_model = image_model;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// 中文注释:下载图片、OSS 读写等非标准 HTTP 状态统一显式归类,避免 OTLP 低基数 label 误落到 `transport`。
|
||||
pub(crate) fn app_error_status_class(status_code: StatusCode) -> &'static str {
|
||||
status_class(Some(status_code.as_u16()))
|
||||
}
|
||||
|
||||
/// 中文注释:外部供应商失败同时进入 OTLP 和 tracking_event;失败审计不能反向阻断主业务错误返回。
|
||||
pub(crate) async fn record_external_api_failure(state: &AppState, draft: ExternalApiFailureDraft) {
|
||||
record_external_api_failure_otlp(&draft);
|
||||
|
||||
let tracking_event = build_external_api_failure_tracking_draft(&draft);
|
||||
if let Some(outbox) = state.tracking_outbox() {
|
||||
match outbox
|
||||
.enqueue(crate::tracking::build_tracking_event_input(
|
||||
tracking_event.clone(),
|
||||
))
|
||||
.await
|
||||
{
|
||||
Ok(crate::tracking_outbox::TrackingOutboxEnqueueOutcome::Enqueued) => {}
|
||||
Ok(crate::tracking_outbox::TrackingOutboxEnqueueOutcome::Dropped { reason }) => {
|
||||
tracing::warn!(
|
||||
provider = draft.provider,
|
||||
endpoint = %draft.endpoint,
|
||||
operation = %draft.operation,
|
||||
failure_stage = draft.failure_stage,
|
||||
reason,
|
||||
"外部 API 失败审计写入 outbox 被保护阈值拒绝,回退同步直写 SpacetimeDB"
|
||||
);
|
||||
crate::tracking::record_tracking_event_after_success(
|
||||
state,
|
||||
&audit_request_context(),
|
||||
tracking_event,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(
|
||||
provider = draft.provider,
|
||||
endpoint = %draft.endpoint,
|
||||
operation = %draft.operation,
|
||||
failure_stage = draft.failure_stage,
|
||||
error = %error,
|
||||
"外部 API 失败审计写入 outbox 失败,回退同步直写 SpacetimeDB"
|
||||
);
|
||||
crate::tracking::record_tracking_event_after_success(
|
||||
state,
|
||||
&audit_request_context(),
|
||||
tracking_event,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
crate::tracking::record_tracking_event_after_success(
|
||||
state,
|
||||
&audit_request_context(),
|
||||
tracking_event,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub(crate) fn build_external_api_failure_tracking_draft(
|
||||
failure: &ExternalApiFailureDraft,
|
||||
) -> TrackingEventDraft {
|
||||
let mut draft = TrackingEventDraft::new(
|
||||
EXTERNAL_API_FAILURE_EVENT_KEY,
|
||||
EXTERNAL_API_AUDIT_MODULE_KEY,
|
||||
);
|
||||
draft.scope_kind = RuntimeTrackingScopeKind::Module;
|
||||
draft.scope_id = failure.provider.to_string();
|
||||
draft.metadata = build_external_api_failure_metadata(failure);
|
||||
draft
|
||||
}
|
||||
|
||||
fn build_external_api_failure_metadata(failure: &ExternalApiFailureDraft) -> Value {
|
||||
let mut metadata = json!({
|
||||
"provider": failure.provider,
|
||||
"endpoint": failure.endpoint,
|
||||
"operation": failure.operation,
|
||||
"failureStage": failure.failure_stage,
|
||||
"statusCode": failure.status_code,
|
||||
"statusClass": failure.status_class.unwrap_or_else(|| status_class(failure.status_code)),
|
||||
"timeout": failure.timeout,
|
||||
"retryable": failure.retryable,
|
||||
"errorMessage": truncate_field(failure.error_message.as_str(), 1_000),
|
||||
"occurredAt": current_utc_iso_text(),
|
||||
});
|
||||
|
||||
if let Some(latency_ms) = failure.latency_ms {
|
||||
metadata["latencyMs"] = json!(latency_ms);
|
||||
}
|
||||
if let Some(prompt_chars) = failure.prompt_chars {
|
||||
metadata["promptChars"] = json!(prompt_chars);
|
||||
}
|
||||
if let Some(reference_image_count) = failure.reference_image_count {
|
||||
metadata["referenceImageCount"] = json!(reference_image_count);
|
||||
}
|
||||
if let Some(image_model) = failure.image_model {
|
||||
metadata["imageModel"] = json!(image_model);
|
||||
}
|
||||
if let Some(source) = failure
|
||||
.error_source
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
{
|
||||
metadata["errorSource"] = json!(truncate_field(source, 1_000));
|
||||
}
|
||||
if let Some(excerpt) = failure
|
||||
.raw_excerpt
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
{
|
||||
metadata["rawExcerpt"] = json!(truncate_field(excerpt, 800));
|
||||
}
|
||||
|
||||
metadata
|
||||
}
|
||||
|
||||
pub(crate) fn is_retryable_external_api_failure(
|
||||
status_code: Option<u16>,
|
||||
timeout: bool,
|
||||
connect: bool,
|
||||
) -> bool {
|
||||
timeout
|
||||
|| connect
|
||||
|| status_code.is_some_and(|status| {
|
||||
status == StatusCode::TOO_MANY_REQUESTS.as_u16()
|
||||
|| status == StatusCode::REQUEST_TIMEOUT.as_u16()
|
||||
|| status >= 500
|
||||
})
|
||||
}
|
||||
|
||||
fn record_external_api_failure_otlp(failure: &ExternalApiFailureDraft) {
|
||||
crate::telemetry::record_external_api_failure(
|
||||
failure.provider,
|
||||
failure.failure_stage,
|
||||
failure
|
||||
.status_class
|
||||
.unwrap_or_else(|| status_class(failure.status_code)),
|
||||
failure.retryable,
|
||||
);
|
||||
|
||||
tracing::error!(
|
||||
provider = failure.provider,
|
||||
endpoint = %failure.endpoint,
|
||||
operation = %failure.operation,
|
||||
failure_stage = failure.failure_stage,
|
||||
status_code = failure.status_code,
|
||||
status_class = failure.status_class.unwrap_or_else(|| status_class(failure.status_code)),
|
||||
timeout = failure.timeout,
|
||||
retryable = failure.retryable,
|
||||
latency_ms = failure.latency_ms,
|
||||
prompt_chars = failure.prompt_chars,
|
||||
reference_image_count = failure.reference_image_count,
|
||||
image_model = failure.image_model,
|
||||
error = %failure.error_message,
|
||||
"外部 API 调用失败"
|
||||
);
|
||||
}
|
||||
|
||||
fn status_class(status_code: Option<u16>) -> &'static str {
|
||||
match status_code {
|
||||
Some(100..=199) => "1xx",
|
||||
Some(200..=299) => "2xx",
|
||||
Some(300..=399) => "3xx",
|
||||
Some(400..=499) => "4xx",
|
||||
Some(500..=599) => "5xx",
|
||||
Some(_) => "unknown",
|
||||
None => "transport",
|
||||
}
|
||||
}
|
||||
|
||||
fn audit_request_context() -> crate::request_context::RequestContext {
|
||||
crate::request_context::RequestContext::new(
|
||||
format!("external-api-audit-{}", Uuid::new_v4()),
|
||||
"external-api audit".to_string(),
|
||||
std::time::Duration::ZERO,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn truncate_field(value: &str, max_chars: usize) -> String {
|
||||
value.chars().take(max_chars).collect()
|
||||
}
|
||||
|
||||
fn current_utc_iso_text() -> String {
|
||||
shared_kernel::format_rfc3339(OffsetDateTime::now_utc())
|
||||
.unwrap_or_else(|_| "1970-01-01T00:00:00Z".to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::Value;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn external_api_failure_tracking_draft_uses_module_scope_and_safe_metadata() {
|
||||
let draft = build_external_api_failure_tracking_draft(
|
||||
&ExternalApiFailureDraft::new(
|
||||
"vector-engine",
|
||||
"https://vector.example/v1/images/generations",
|
||||
"拼图 UI 背景图生成失败",
|
||||
"upstream_status",
|
||||
"上游 429",
|
||||
)
|
||||
.with_status_code(Some(429))
|
||||
.with_retryable(true)
|
||||
.with_latency_ms(Some(1234))
|
||||
.with_prompt_chars(Some(88))
|
||||
.with_reference_image_count(Some(2))
|
||||
.with_image_model(Some("gpt-image-2-all")),
|
||||
);
|
||||
|
||||
assert_eq!(draft.event_key, EXTERNAL_API_FAILURE_EVENT_KEY);
|
||||
assert_eq!(draft.scope_kind, RuntimeTrackingScopeKind::Module);
|
||||
assert_eq!(draft.scope_id, "vector-engine");
|
||||
assert_eq!(draft.module_key, Some(EXTERNAL_API_AUDIT_MODULE_KEY));
|
||||
|
||||
let metadata = draft.metadata;
|
||||
assert_eq!(metadata["provider"], "vector-engine");
|
||||
assert_eq!(metadata["statusCode"], 429);
|
||||
assert_eq!(metadata["statusClass"], "4xx");
|
||||
assert_eq!(metadata["retryable"], true);
|
||||
assert_eq!(metadata["latencyMs"], 1234);
|
||||
assert_eq!(metadata["promptChars"], 88);
|
||||
assert_eq!(metadata["referenceImageCount"], 2);
|
||||
assert_eq!(metadata["imageModel"], "gpt-image-2-all");
|
||||
assert!(matches!(metadata["occurredAt"], Value::String(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retryable_classification_keeps_transport_and_overload_failures_actionable() {
|
||||
assert!(is_retryable_external_api_failure(None, true, false));
|
||||
assert!(is_retryable_external_api_failure(None, false, true));
|
||||
assert!(is_retryable_external_api_failure(Some(429), false, false));
|
||||
assert!(is_retryable_external_api_failure(Some(502), false, false));
|
||||
assert!(!is_retryable_external_api_failure(Some(400), false, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_error_status_class_can_override_successful_upstream_status() {
|
||||
let draft = build_external_api_failure_tracking_draft(
|
||||
&ExternalApiFailureDraft::new(
|
||||
"vector-engine",
|
||||
"https://cdn.example/generated.png",
|
||||
"下载生成图片",
|
||||
"image_download",
|
||||
"下载生成图片失败",
|
||||
)
|
||||
.with_status_code(Some(200))
|
||||
.with_optional_status_class(Some(app_error_status_class(StatusCode::BAD_GATEWAY))),
|
||||
);
|
||||
|
||||
assert_eq!(draft.metadata["statusCode"], 200);
|
||||
assert_eq!(draft.metadata["statusClass"], "5xx");
|
||||
}
|
||||
}
|
||||
@@ -197,6 +197,86 @@ pub(crate) fn slice_generated_asset_sheet(
|
||||
Ok(slices)
|
||||
}
|
||||
|
||||
pub(crate) fn slice_generated_asset_sheet_two_items_per_row(
|
||||
image: &DownloadedOpenAiImage,
|
||||
item_names: &[String],
|
||||
grid_size: usize,
|
||||
views_per_item: usize,
|
||||
) -> Result<Vec<Vec<GeneratedAssetSheetSliceImage>>, AppError> {
|
||||
if grid_size == 0 || views_per_item == 0 {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": GENERATED_ASSET_SHEET_PROVIDER,
|
||||
"message": "系列素材图集的 n 和每物品视图数必须大于 0。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
if !grid_size.is_multiple_of(views_per_item) {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": GENERATED_ASSET_SHEET_PROVIDER,
|
||||
"message": "系列素材图集每行必须能均分为若干物品。",
|
||||
"gridSize": grid_size,
|
||||
"viewsPerItem": views_per_item,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
let grid_size_u32 = u32::try_from(grid_size).map_err(|_| {
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": GENERATED_ASSET_SHEET_PROVIDER,
|
||||
"message": "系列素材图集的 n 超出可支持范围。",
|
||||
}))
|
||||
})?;
|
||||
let source = image::load_from_memory(image.bytes.as_slice()).map_err(|error| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": GENERATED_ASSET_SHEET_PROVIDER,
|
||||
"message": format!("系列素材图集解码失败:{error}"),
|
||||
}))
|
||||
})?;
|
||||
let source = apply_generated_asset_sheet_green_screen_alpha(source);
|
||||
let (width, height) = source.dimensions();
|
||||
if width / grid_size_u32 == 0 || height / grid_size_u32 == 0 {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": GENERATED_ASSET_SHEET_PROVIDER,
|
||||
"message": "系列素材图集尺寸过小,无法切割。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
let items_per_row = grid_size / views_per_item;
|
||||
let max_item_count = grid_size.saturating_mul(items_per_row);
|
||||
let mut slices = Vec::with_capacity(item_names.len().min(max_item_count));
|
||||
for item_index in 0..item_names.len().min(max_item_count) {
|
||||
let row = (item_index / items_per_row) as u32;
|
||||
let start_col = ((item_index % items_per_row) * views_per_item) as u32;
|
||||
let mut views = Vec::with_capacity(views_per_item);
|
||||
for view_offset in 0..views_per_item {
|
||||
let col = start_col + view_offset as u32;
|
||||
let (crop_x, crop_y, crop_width, crop_height) =
|
||||
resolve_generated_asset_sheet_cell_crop(&source, grid_size_u32, row, col);
|
||||
let cropped = source.crop_imm(crop_x, crop_y, crop_width, crop_height);
|
||||
let cleaned = crop_generated_asset_sheet_view_edge_matte(cropped);
|
||||
let mut cursor = std::io::Cursor::new(Vec::new());
|
||||
cleaned
|
||||
.write_to(&mut cursor, ImageFormat::Png)
|
||||
.map_err(|error| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": GENERATED_ASSET_SHEET_PROVIDER,
|
||||
"message": format!("系列素材图集切割失败:{error}"),
|
||||
}))
|
||||
})?;
|
||||
views.push(GeneratedAssetSheetSliceImage {
|
||||
bytes: cursor.into_inner(),
|
||||
});
|
||||
}
|
||||
slices.push(views);
|
||||
}
|
||||
|
||||
Ok(slices)
|
||||
}
|
||||
|
||||
pub(crate) fn crop_generated_asset_sheet_view_edge_matte(
|
||||
image: image::DynamicImage,
|
||||
) -> image::DynamicImage {
|
||||
@@ -958,7 +1038,7 @@ fn collect_generated_asset_sheet_visible_neighbor_color(
|
||||
))
|
||||
}
|
||||
|
||||
fn apply_generated_asset_sheet_green_screen_alpha(
|
||||
pub(crate) fn apply_generated_asset_sheet_green_screen_alpha(
|
||||
source: image::DynamicImage,
|
||||
) -> image::DynamicImage {
|
||||
let mut image = source.to_rgba8();
|
||||
|
||||
@@ -39,6 +39,7 @@ mod custom_world_rpg_draft_prompts;
|
||||
mod edutainment_baby_drawing;
|
||||
mod edutainment_baby_object;
|
||||
mod error_middleware;
|
||||
mod external_api_audit;
|
||||
pub(crate) mod generated_asset_sheets;
|
||||
mod generated_image_assets;
|
||||
mod health;
|
||||
|
||||
@@ -71,10 +71,12 @@ use crate::{
|
||||
},
|
||||
auth::AuthenticatedAccessToken,
|
||||
config::AppConfig,
|
||||
generated_asset_sheets::apply_generated_asset_sheet_green_screen_alpha,
|
||||
http_error::AppError,
|
||||
openai_image_generation::{
|
||||
DownloadedOpenAiImage, OpenAiGeneratedImages, OpenAiReferenceImage,
|
||||
build_openai_image_http_client, create_openai_image_edit, create_openai_image_generation,
|
||||
build_openai_image_http_client, create_openai_image_edit,
|
||||
create_openai_image_edit_with_references, create_openai_image_generation,
|
||||
require_openai_image_settings,
|
||||
},
|
||||
platform_errors::map_oss_error,
|
||||
@@ -95,10 +97,10 @@ const MATCH3D_DEFAULT_DIFFICULTY: u32 = 4;
|
||||
const MATCH3D_DRAFT_GENERATION_POINTS_COST: u64 = 10;
|
||||
const MATCH3D_BACKGROUND_IMAGE_POINTS_COST: u64 = 2;
|
||||
const MATCH3D_ITEM_ASSETS_POINTS_PER_BATCH: u64 = 2;
|
||||
const MATCH3D_MATERIAL_ITEM_BATCH_SIZE: usize = 5;
|
||||
const MATCH3D_MATERIAL_ITEM_BATCH_SIZE: usize = 20;
|
||||
const MATCH3D_ITEM_VIEW_COUNT: usize = 5;
|
||||
const MATCH3D_MATERIAL_GRID_SIZE: u32 = 5;
|
||||
const MATCH3D_MAX_GENERATED_ITEM_COUNT: usize = 25;
|
||||
const MATCH3D_MATERIAL_GRID_SIZE: u32 = 10;
|
||||
const MATCH3D_MAX_GENERATED_ITEM_COUNT: usize = 20;
|
||||
const MATCH3D_MATERIAL_VECTOR_ENGINE_GEMINI_MODEL: &str = "gemini-3-pro-image-preview";
|
||||
const MATCH3D_MATERIAL_VECTOR_ENGINE_GEMINI_ASPECT_RATIO: &str = "1:1";
|
||||
const MATCH3D_LEGACY_MODEL_DOWNLOAD_TIMEOUT_MS: u64 = 3 * 60_000;
|
||||
@@ -118,7 +120,7 @@ const MATCH3D_QUESTION_DIFFICULTY: &str = "如果难度是从1-10,你要创作
|
||||
const MATCH3D_CLICK_SOUND_ASSET_KIND: &str = "match3d_click_sound";
|
||||
const MATCH3D_PIXEL_RETRO_STYLE_PROMPT: &str = "真正复古像素 2D 游戏道具 sprite 风格,先以约 64x64 低分辨率像素块绘制再按整数倍放大,硬边方块像素清晰可见,有限色板 12-24 色,禁止抗锯齿、柔焦、平滑渐变、真实 3D 渲染、PBR 材质和摄影光照。";
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Match3DConfigJson {
|
||||
theme_text: String,
|
||||
@@ -170,15 +172,33 @@ struct Match3DGeneratedItemImageView {
|
||||
image_object_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Match3DGeneratedBackgroundAsset {
|
||||
prompt: String,
|
||||
#[serde(default)]
|
||||
level_scene_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
level_scene_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
level_scene_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
ui_spritesheet_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
ui_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
ui_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
item_spritesheet_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
item_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
item_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
container_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
container_image_src: Option<String>,
|
||||
@@ -445,8 +465,17 @@ impl From<shared_contracts::match3d_works::Match3DGeneratedItemAssetResponse>
|
||||
.background_asset
|
||||
.map(|asset| Match3DGeneratedBackgroundAsset {
|
||||
prompt: asset.prompt,
|
||||
level_scene_prompt: asset.level_scene_prompt,
|
||||
level_scene_image_src: asset.level_scene_image_src,
|
||||
level_scene_image_object_key: asset.level_scene_image_object_key,
|
||||
image_src: asset.image_src,
|
||||
image_object_key: asset.image_object_key,
|
||||
ui_spritesheet_prompt: asset.ui_spritesheet_prompt,
|
||||
ui_spritesheet_image_src: asset.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: asset.ui_spritesheet_image_object_key,
|
||||
item_spritesheet_prompt: asset.item_spritesheet_prompt,
|
||||
item_spritesheet_image_src: asset.item_spritesheet_image_src,
|
||||
item_spritesheet_image_object_key: asset.item_spritesheet_image_object_key,
|
||||
container_prompt: asset.container_prompt,
|
||||
container_image_src: asset.container_image_src,
|
||||
container_image_object_key: asset.container_image_object_key,
|
||||
|
||||
@@ -229,12 +229,27 @@ pub(super) async fn compile_match3d_draft_for_session(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let existing_assets = get_match3d_existing_generated_item_assets(
|
||||
let mut existing_assets = get_match3d_existing_generated_item_assets(
|
||||
state,
|
||||
owner_user_id.as_str(),
|
||||
profile_id.as_str(),
|
||||
)
|
||||
.await;
|
||||
let generated_background_asset = resolve_or_generate_match3d_level_asset_bundle(
|
||||
state,
|
||||
request_context,
|
||||
owner_user_id.as_str(),
|
||||
session.session_id.as_str(),
|
||||
profile_id.as_str(),
|
||||
&config,
|
||||
generated_work_metadata.background_prompt.as_str(),
|
||||
&existing_assets,
|
||||
)
|
||||
.await?;
|
||||
attach_match3d_background_asset_to_assets(
|
||||
&mut existing_assets,
|
||||
generated_background_asset.clone(),
|
||||
);
|
||||
let generated_item_assets = generate_match3d_item_assets(
|
||||
state,
|
||||
request_context,
|
||||
@@ -245,18 +260,22 @@ pub(super) async fn compile_match3d_draft_for_session(
|
||||
&config,
|
||||
generated_work_metadata.items,
|
||||
existing_assets,
|
||||
Some(generated_background_asset.clone()),
|
||||
)
|
||||
.await?;
|
||||
let generated_item_assets = ensure_match3d_background_asset(
|
||||
let mut generated_item_assets = generated_item_assets;
|
||||
attach_match3d_background_asset_to_assets(
|
||||
&mut generated_item_assets,
|
||||
generated_background_asset,
|
||||
);
|
||||
persist_match3d_generated_item_assets_snapshot(
|
||||
state,
|
||||
request_context,
|
||||
authenticated,
|
||||
owner_user_id.as_str(),
|
||||
session.session_id.as_str(),
|
||||
owner_user_id.as_str(),
|
||||
profile_id.as_str(),
|
||||
&config,
|
||||
generated_work_metadata.background_prompt.as_str(),
|
||||
generated_item_assets,
|
||||
&generated_item_assets,
|
||||
)
|
||||
.await?;
|
||||
let existing_cover_image_src = get_match3d_existing_cover_image_src(
|
||||
|
||||
@@ -3,9 +3,8 @@ use super::*;
|
||||
use crate::generated_asset_sheets::crop_generated_asset_sheet_view_edge_matte;
|
||||
use crate::generated_asset_sheets::{
|
||||
GeneratedAssetSheetPersistInput, GeneratedAssetSheetPersistPrompt,
|
||||
GeneratedAssetSheetPromptInput, GeneratedAssetSheetSliceImage,
|
||||
build_generated_asset_sheet_prompt, persist_generated_asset_sheet_bytes,
|
||||
slice_generated_asset_sheet,
|
||||
GeneratedAssetSheetSliceImage, persist_generated_asset_sheet_bytes,
|
||||
slice_generated_asset_sheet_two_items_per_row,
|
||||
};
|
||||
|
||||
pub(super) async fn generate_match3d_item_assets(
|
||||
@@ -18,6 +17,7 @@ pub(super) async fn generate_match3d_item_assets(
|
||||
config: &Match3DConfigJson,
|
||||
item_plan: Vec<Match3DGeneratedItemPlan>,
|
||||
existing_assets: Vec<Match3DGeneratedItemAsset>,
|
||||
generated_background_asset: Option<Match3DGeneratedBackgroundAsset>,
|
||||
) -> Result<Vec<Match3DGeneratedItemAsset>, Response> {
|
||||
// 中文注释:抓大鹅音频生成当前关闭;自动草稿只补齐 2D 物品图片和可选点击音效。
|
||||
let target_item_count = resolve_match3d_generated_item_count(config);
|
||||
@@ -37,6 +37,7 @@ pub(super) async fn generate_match3d_item_assets(
|
||||
config,
|
||||
item_plan,
|
||||
assets,
|
||||
generated_background_asset,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@@ -76,6 +77,7 @@ async fn ensure_match3d_item_image_assets(
|
||||
config: &Match3DConfigJson,
|
||||
item_plan: Vec<Match3DGeneratedItemPlan>,
|
||||
existing_assets: Vec<Match3DGeneratedItemAsset>,
|
||||
generated_background_asset: Option<Match3DGeneratedBackgroundAsset>,
|
||||
) -> Result<Vec<Match3DGeneratedItemAsset>, Response> {
|
||||
let mut assets = normalize_match3d_generated_item_assets_for_resume(existing_assets);
|
||||
let target_item_count = resolve_match3d_generated_item_count(config);
|
||||
@@ -101,9 +103,11 @@ async fn ensure_match3d_item_image_assets(
|
||||
background_music_style: None,
|
||||
background_music_prompt: None,
|
||||
background_asset: if index == 0 {
|
||||
assets
|
||||
.first()
|
||||
.and_then(|asset| asset.background_asset.clone())
|
||||
generated_background_asset.clone().or_else(|| {
|
||||
assets
|
||||
.first()
|
||||
.and_then(|asset| asset.background_asset.clone())
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
@@ -160,6 +164,8 @@ struct Match3DItemImageGenerationSeed {
|
||||
struct Match3DMaterialBatchOutput {
|
||||
task_id: String,
|
||||
prompt: String,
|
||||
image_src: Option<String>,
|
||||
image_object_key: Option<String>,
|
||||
generated_at_micros: i64,
|
||||
items: Vec<(
|
||||
Match3DItemImageGenerationSeed,
|
||||
@@ -194,12 +200,17 @@ async fn generate_match3d_item_image_assets_in_batches(
|
||||
.map(|chunk| {
|
||||
let chunk_seeds = chunk.to_vec();
|
||||
async move {
|
||||
let item_names = chunk_seeds
|
||||
.iter()
|
||||
.map(|item| item.item_name.clone())
|
||||
.collect::<Vec<_>>();
|
||||
let material_sheet =
|
||||
generate_match3d_material_sheet(state, config, &item_names).await?;
|
||||
let material_sheet = generate_match3d_material_sheet_from_level_scene(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
profile_id,
|
||||
config,
|
||||
chunk_seeds
|
||||
.iter()
|
||||
.find_map(|seed| seed.background_asset.as_ref()),
|
||||
)
|
||||
.await?;
|
||||
let generated_at_micros = current_utc_micros();
|
||||
let persisted_seed_count = chunk_seeds
|
||||
.iter()
|
||||
@@ -218,14 +229,17 @@ async fn generate_match3d_item_image_assets_in_batches(
|
||||
.iter()
|
||||
.map(|item| item.item_name.clone())
|
||||
.collect::<Vec<_>>();
|
||||
let item_images = slice_generated_asset_sheet(
|
||||
let item_images = slice_generated_asset_sheet_two_items_per_row(
|
||||
&material_sheet.image,
|
||||
&persisted_item_names,
|
||||
MATCH3D_MATERIAL_GRID_SIZE as usize,
|
||||
MATCH3D_ITEM_VIEW_COUNT,
|
||||
)?;
|
||||
Ok::<_, AppError>(Match3DMaterialBatchOutput {
|
||||
task_id: material_sheet.task_id,
|
||||
prompt: material_sheet.prompt,
|
||||
image_src: material_sheet.image_src,
|
||||
image_object_key: material_sheet.image_object_key,
|
||||
generated_at_micros,
|
||||
items: persisted_seeds
|
||||
.into_iter()
|
||||
@@ -248,14 +262,22 @@ async fn generate_match3d_item_image_assets_in_batches(
|
||||
for batch in batches {
|
||||
let sheet_task_id = batch.task_id;
|
||||
let sheet_prompt = batch.prompt;
|
||||
let sheet_image_src = batch.image_src;
|
||||
let sheet_image_object_key = batch.image_object_key;
|
||||
let generated_at_micros = batch.generated_at_micros;
|
||||
for (item_index, (seed, item_images)) in batch.items.into_iter().enumerate() {
|
||||
let item_slug = build_match3d_item_slug(seed.item_id.as_str(), seed.item_name.as_str());
|
||||
let mut image_views = Vec::with_capacity(item_images.len());
|
||||
for (view_index, item_image) in item_images.into_iter().enumerate() {
|
||||
let view_number = view_index + 1;
|
||||
let item_name_prompt =
|
||||
format!("第{}行:{} 的 5 个不同视角", item_index + 1, seed.item_name);
|
||||
let (sheet_row_index, sheet_col_index) =
|
||||
resolve_match3d_material_sheet_cell_indices(item_index, view_index);
|
||||
let item_name_prompt = format!(
|
||||
"第{}行第{}种:{} 的 5 个不同形态",
|
||||
item_index / 2 + 1,
|
||||
item_index % 2 + 1,
|
||||
seed.item_name
|
||||
);
|
||||
let view_upload = persist_generated_asset_sheet_bytes(
|
||||
state,
|
||||
GeneratedAssetSheetPersistInput {
|
||||
@@ -277,8 +299,8 @@ async fn generate_match3d_item_image_assets_in_batches(
|
||||
(item_index * MATCH3D_ITEM_VIEW_COUNT + view_index) as i64 + 1,
|
||||
),
|
||||
grid_size: MATCH3D_MATERIAL_GRID_SIZE as usize,
|
||||
row_index: item_index + 1,
|
||||
view_index: view_number,
|
||||
row_index: sheet_row_index,
|
||||
view_index: sheet_col_index,
|
||||
prompt: GeneratedAssetSheetPersistPrompt {
|
||||
sheet_prompt: Some(sheet_prompt.clone()),
|
||||
item_name_prompt: Some(item_name_prompt),
|
||||
@@ -322,7 +344,12 @@ async fn generate_match3d_item_image_assets_in_batches(
|
||||
background_music_prompt: seed.background_music_prompt,
|
||||
background_music: None,
|
||||
click_sound: None,
|
||||
background_asset: seed.background_asset,
|
||||
background_asset: merge_match3d_item_spritesheet_asset_metadata(
|
||||
seed.background_asset,
|
||||
sheet_prompt.clone(),
|
||||
sheet_image_src.clone(),
|
||||
sheet_image_object_key.clone(),
|
||||
),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
},
|
||||
@@ -512,6 +539,7 @@ async fn append_match3d_new_item_assets(
|
||||
return Ok(assets);
|
||||
}
|
||||
let mut next_item_index = next_match3d_generated_item_index(&assets);
|
||||
let background_asset = find_match3d_generated_background_asset(&assets);
|
||||
let item_seeds = append_plan
|
||||
.padded_item_names
|
||||
.into_iter()
|
||||
@@ -527,7 +555,11 @@ async fn append_match3d_new_item_assets(
|
||||
background_music_title: None,
|
||||
background_music_style: None,
|
||||
background_music_prompt: None,
|
||||
background_asset: None,
|
||||
background_asset: if index == 0 {
|
||||
background_asset.clone()
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -697,6 +729,8 @@ async fn replace_match3d_item_assets(
|
||||
pub(super) struct Match3DMaterialSheet {
|
||||
pub(super) task_id: String,
|
||||
pub(super) prompt: String,
|
||||
pub(super) image_src: Option<String>,
|
||||
pub(super) image_object_key: Option<String>,
|
||||
pub(super) image: DownloadedOpenAiImage,
|
||||
}
|
||||
|
||||
@@ -710,6 +744,118 @@ pub(super) struct Match3DVectorEngineGeminiImageSettings {
|
||||
pub(super) struct Match3DSlicedItemImage {
|
||||
pub(super) bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
async fn generate_match3d_material_sheet_from_level_scene(
|
||||
state: &AppState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
profile_id: &str,
|
||||
config: &Match3DConfigJson,
|
||||
background_asset: Option<&Match3DGeneratedBackgroundAsset>,
|
||||
) -> Result<Match3DMaterialSheet, AppError> {
|
||||
let settings = require_openai_image_settings(state)?;
|
||||
let http_client = build_openai_image_http_client(&settings)?;
|
||||
let prompt = build_match3d_item_spritesheet_prompt();
|
||||
let reference = load_match3d_level_scene_reference_image(state, background_asset).await?;
|
||||
let generated = create_openai_image_edit(
|
||||
&http_client,
|
||||
&settings,
|
||||
prompt.as_str(),
|
||||
Some(build_match3d_material_sheet_negative_prompt(config).as_str()),
|
||||
"2k",
|
||||
&reference,
|
||||
"抓大鹅物品 spritesheet 生成失败",
|
||||
)
|
||||
.await?;
|
||||
let image = generated.images.into_iter().next().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": "vector-engine",
|
||||
"message": "抓大鹅物品 spritesheet 生成失败:未返回图片",
|
||||
}))
|
||||
})?;
|
||||
let image = make_match3d_spritesheet_image_transparent(image)?;
|
||||
let upload = persist_match3d_generated_bytes(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
profile_id,
|
||||
&["item-spritesheet", generated.task_id.as_str()],
|
||||
"item-spritesheet.png",
|
||||
image.mime_type.as_str(),
|
||||
image.bytes.clone(),
|
||||
"match3d_item_spritesheet_image",
|
||||
Some(generated.task_id.as_str()),
|
||||
current_utc_micros(),
|
||||
)
|
||||
.await?;
|
||||
Ok(Match3DMaterialSheet {
|
||||
task_id: generated.task_id,
|
||||
prompt,
|
||||
image_src: Some(upload.src),
|
||||
image_object_key: Some(upload.object_key),
|
||||
image,
|
||||
})
|
||||
}
|
||||
|
||||
fn merge_match3d_item_spritesheet_asset_metadata(
|
||||
background_asset: Option<Match3DGeneratedBackgroundAsset>,
|
||||
prompt: String,
|
||||
image_src: Option<String>,
|
||||
image_object_key: Option<String>,
|
||||
) -> Option<Match3DGeneratedBackgroundAsset> {
|
||||
background_asset.map(|mut asset| {
|
||||
asset.item_spritesheet_prompt = Some(prompt);
|
||||
asset.item_spritesheet_image_src = image_src;
|
||||
asset.item_spritesheet_image_object_key = image_object_key;
|
||||
asset
|
||||
})
|
||||
}
|
||||
|
||||
async fn load_match3d_level_scene_reference_image(
|
||||
state: &AppState,
|
||||
background_asset: Option<&Match3DGeneratedBackgroundAsset>,
|
||||
) -> Result<OpenAiReferenceImage, AppError> {
|
||||
let Some(source) = background_asset
|
||||
.and_then(|asset| {
|
||||
asset
|
||||
.level_scene_image_object_key
|
||||
.as_deref()
|
||||
.or(asset.level_scene_image_src.as_deref())
|
||||
})
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
else {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": MATCH3D_AGENT_PROVIDER,
|
||||
"message": "抓大鹅物品 spritesheet 生成缺少关卡画面参考图",
|
||||
})),
|
||||
);
|
||||
};
|
||||
let bytes = if source.starts_with("data:image/") {
|
||||
decode_match3d_data_url_bytes(source)?
|
||||
} else if source.trim_start_matches('/').starts_with("generated-") {
|
||||
read_match3d_generated_object_bytes(
|
||||
state,
|
||||
source,
|
||||
"读取抓大鹅关卡画面参考图失败",
|
||||
MATCH3D_ITEM_IMAGE_MAX_BYTES,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": MATCH3D_AGENT_PROVIDER,
|
||||
"message": "抓大鹅关卡画面参考图必须是图片 Data URL 或 /generated-* 路径",
|
||||
})),
|
||||
);
|
||||
};
|
||||
Ok(OpenAiReferenceImage {
|
||||
bytes,
|
||||
mime_type: "image/png".to_string(),
|
||||
file_name: "match3d-level-scene.png".to_string(),
|
||||
})
|
||||
}
|
||||
pub(super) fn normalize_match3d_item_name(raw: &str) -> String {
|
||||
raw.trim()
|
||||
.trim_matches(['"', '\'', '“', '”', '。', ',', ',', '、'])
|
||||
@@ -1115,20 +1261,20 @@ pub(super) fn resolve_match3d_gameplay_item_count(config: &Match3DConfigJson) ->
|
||||
8 => 3,
|
||||
12 => 9,
|
||||
16 => 15,
|
||||
20 | 21 => 21,
|
||||
20 | 21 => 20,
|
||||
_ => match config.difficulty {
|
||||
0..=2 => 3,
|
||||
3..=4 => 9,
|
||||
5..=6 => 15,
|
||||
_ => 21,
|
||||
_ => 20,
|
||||
},
|
||||
}
|
||||
.min(MATCH3D_MAX_GENERATED_ITEM_COUNT)
|
||||
}
|
||||
|
||||
pub(super) fn resolve_match3d_generated_item_count(config: &Match3DConfigJson) -> usize {
|
||||
round_match3d_item_count_to_full_sheet(resolve_match3d_gameplay_item_count(config))
|
||||
.min(MATCH3D_MAX_GENERATED_ITEM_COUNT)
|
||||
let _ = config;
|
||||
MATCH3D_MAX_GENERATED_ITEM_COUNT
|
||||
}
|
||||
|
||||
fn round_match3d_item_count_to_full_sheet(item_count: usize) -> usize {
|
||||
@@ -1138,6 +1284,16 @@ fn round_match3d_item_count_to_full_sheet(item_count: usize) -> usize {
|
||||
item_count.div_ceil(MATCH3D_MATERIAL_ITEM_BATCH_SIZE) * MATCH3D_MATERIAL_ITEM_BATCH_SIZE
|
||||
}
|
||||
|
||||
pub(super) fn resolve_match3d_material_sheet_cell_indices(
|
||||
item_index: usize,
|
||||
view_index: usize,
|
||||
) -> (usize, usize) {
|
||||
let items_per_row = (MATCH3D_MATERIAL_GRID_SIZE as usize / MATCH3D_ITEM_VIEW_COUNT).max(1);
|
||||
let row_index = item_index / items_per_row + 1;
|
||||
let col_index = (item_index % items_per_row) * MATCH3D_ITEM_VIEW_COUNT + view_index + 1;
|
||||
(row_index, col_index)
|
||||
}
|
||||
|
||||
pub(super) fn sort_match3d_generated_assets(
|
||||
mut assets: Vec<Match3DGeneratedItemAsset>,
|
||||
) -> Vec<Match3DGeneratedItemAsset> {
|
||||
@@ -1295,11 +1451,23 @@ pub(super) fn is_match3d_background_asset_ready(asset: &Match3DGeneratedBackgrou
|
||||
.filter(|value| !value.is_empty())
|
||||
.is_some())
|
||||
&& (asset
|
||||
.container_image_object_key
|
||||
.ui_spritesheet_image_object_key
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.is_some()
|
||||
|| asset
|
||||
.ui_spritesheet_image_src
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.is_some()
|
||||
|| asset
|
||||
.container_image_object_key
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.is_some()
|
||||
|| asset
|
||||
.container_image_src
|
||||
.as_deref()
|
||||
@@ -1312,34 +1480,16 @@ pub(super) fn build_match3d_material_sheet_prompt(
|
||||
config: &Match3DConfigJson,
|
||||
item_names: &[String],
|
||||
) -> String {
|
||||
let asset_style_prompt = resolve_match3d_asset_style_prompt(config);
|
||||
let style_clause = asset_style_prompt
|
||||
.as_ref()
|
||||
.map(|prompt| format!("整体画风遵循:{prompt}。"))
|
||||
.unwrap_or_default();
|
||||
let subject_text = format!(
|
||||
"{}题材的抓大鹅游戏2D物品素材。{style_clause}",
|
||||
config.theme_text
|
||||
);
|
||||
let special_prompt = match3d_material_sheet_special_prompt();
|
||||
build_generated_asset_sheet_prompt(&GeneratedAssetSheetPromptInput {
|
||||
subject_text: subject_text.as_str(),
|
||||
item_names,
|
||||
grid_size: MATCH3D_MATERIAL_GRID_SIZE as usize,
|
||||
item_name_prompt_template: Some("第{row_index}行:{item_name} 的 {view_count} 个不同视角"),
|
||||
special_prompt: Some(special_prompt.as_str()),
|
||||
})
|
||||
.unwrap_or_else(|_| {
|
||||
format!(
|
||||
"生成一张1:1图片。固定生成5行*5列网格素材图,画面是{}题材的抓大鹅游戏2D物品素材。{}",
|
||||
config.theme_text,
|
||||
match3d_material_sheet_special_prompt(),
|
||||
)
|
||||
})
|
||||
let _ = (config, item_names);
|
||||
build_match3d_item_spritesheet_prompt()
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_item_spritesheet_prompt() -> String {
|
||||
"固定生成10行*10列spritesheet图,统一纯绿色绿幕背景(高饱和亮绿色,接近 #00FF00),背景平整无纹理、无渐变、无阴影、无场景内容,后端会在生图后将绿幕扣成透明并把透明背景 PNG 存到 OSS。素材间距严格均匀分布,任意两个素材间距相同,物品来自参考图中画面中心容器中的2D素材。每一行包含两种物品,每种物品的五个不同形态。物品素材自身不得使用接近 #00FF00 的高饱和纯绿;绿色物品只能使用深绿、橄榄绿、金绿或蓝绿,并用清晰描边与绿幕区分。严禁出现两种高相似度的物品".to_string()
|
||||
}
|
||||
|
||||
fn match3d_material_sheet_special_prompt() -> String {
|
||||
"同一行五格必须是同一物品的五个不同视角,依次为正面、左前、右前、俯视、背面;".to_string()
|
||||
"每一行包含两种物品,每种物品的五个不同形态。".to_string()
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_material_sheet_negative_prompt(config: &Match3DConfigJson) -> String {
|
||||
@@ -1389,18 +1539,22 @@ pub(super) fn slice_match3d_material_sheet(
|
||||
image: &DownloadedOpenAiImage,
|
||||
item_names: &[String],
|
||||
) -> Result<Vec<Vec<Match3DSlicedItemImage>>, AppError> {
|
||||
slice_generated_asset_sheet(image, item_names, MATCH3D_MATERIAL_GRID_SIZE as usize).map(
|
||||
|rows| {
|
||||
rows.into_iter()
|
||||
.map(|views| {
|
||||
views
|
||||
.into_iter()
|
||||
.map(|view| Match3DSlicedItemImage { bytes: view.bytes })
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
},
|
||||
slice_generated_asset_sheet_two_items_per_row(
|
||||
image,
|
||||
item_names,
|
||||
MATCH3D_MATERIAL_GRID_SIZE as usize,
|
||||
MATCH3D_ITEM_VIEW_COUNT,
|
||||
)
|
||||
.map(|rows| {
|
||||
rows.into_iter()
|
||||
.map(|views| {
|
||||
views
|
||||
.into_iter()
|
||||
.map(|view| Match3DSlicedItemImage { bytes: view.bytes })
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -282,13 +282,25 @@ pub(super) fn map_match3d_image_view_from_work(
|
||||
pub(super) fn map_match3d_background_asset_for_agent(
|
||||
asset: Match3DGeneratedBackgroundAsset,
|
||||
) -> shared_contracts::match3d_agent::Match3DGeneratedBackgroundAssetResponse {
|
||||
let ui_spritesheet_image_src = asset.ui_spritesheet_image_src.clone();
|
||||
let ui_spritesheet_image_object_key = asset.ui_spritesheet_image_object_key.clone();
|
||||
shared_contracts::match3d_agent::Match3DGeneratedBackgroundAssetResponse {
|
||||
prompt: asset.prompt,
|
||||
level_scene_prompt: asset.level_scene_prompt,
|
||||
level_scene_image_src: asset.level_scene_image_src,
|
||||
level_scene_image_object_key: asset.level_scene_image_object_key,
|
||||
image_src: asset.image_src,
|
||||
image_object_key: asset.image_object_key,
|
||||
ui_spritesheet_prompt: asset.ui_spritesheet_prompt,
|
||||
ui_spritesheet_image_src: ui_spritesheet_image_src.clone(),
|
||||
ui_spritesheet_image_object_key: ui_spritesheet_image_object_key.clone(),
|
||||
item_spritesheet_prompt: asset.item_spritesheet_prompt,
|
||||
item_spritesheet_image_src: asset.item_spritesheet_image_src,
|
||||
item_spritesheet_image_object_key: asset.item_spritesheet_image_object_key,
|
||||
container_prompt: asset.container_prompt,
|
||||
container_image_src: asset.container_image_src,
|
||||
container_image_object_key: asset.container_image_object_key,
|
||||
container_image_src: ui_spritesheet_image_src.or(asset.container_image_src),
|
||||
container_image_object_key: ui_spritesheet_image_object_key
|
||||
.or(asset.container_image_object_key),
|
||||
status: asset.status,
|
||||
error: asset.error,
|
||||
}
|
||||
@@ -299,8 +311,17 @@ pub(super) fn map_match3d_background_asset_for_work(
|
||||
) -> shared_contracts::match3d_works::Match3DGeneratedBackgroundAssetResponse {
|
||||
shared_contracts::match3d_works::Match3DGeneratedBackgroundAssetResponse {
|
||||
prompt: asset.prompt,
|
||||
level_scene_prompt: asset.level_scene_prompt,
|
||||
level_scene_image_src: asset.level_scene_image_src,
|
||||
level_scene_image_object_key: asset.level_scene_image_object_key,
|
||||
image_src: asset.image_src,
|
||||
image_object_key: asset.image_object_key,
|
||||
ui_spritesheet_prompt: asset.ui_spritesheet_prompt,
|
||||
ui_spritesheet_image_src: asset.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: asset.ui_spritesheet_image_object_key,
|
||||
item_spritesheet_prompt: asset.item_spritesheet_prompt,
|
||||
item_spritesheet_image_src: asset.item_spritesheet_image_src,
|
||||
item_spritesheet_image_object_key: asset.item_spritesheet_image_object_key,
|
||||
container_prompt: asset.container_prompt,
|
||||
container_image_src: asset.container_image_src,
|
||||
container_image_object_key: asset.container_image_object_key,
|
||||
@@ -327,6 +348,14 @@ pub(super) fn resolve_match3d_default_cover_image_src(
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(str::to_string)
|
||||
.or_else(|| {
|
||||
asset
|
||||
.ui_spritesheet_image_src
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(str::to_string)
|
||||
})
|
||||
.or_else(|| {
|
||||
asset
|
||||
.container_image_object_key
|
||||
@@ -335,6 +364,14 @@ pub(super) fn resolve_match3d_default_cover_image_src(
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(str::to_string)
|
||||
})
|
||||
.or_else(|| {
|
||||
asset
|
||||
.ui_spritesheet_image_object_key
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(str::to_string)
|
||||
})
|
||||
.or_else(|| {
|
||||
asset
|
||||
.image_src
|
||||
@@ -408,6 +445,10 @@ fn match3d_item_asset_has_image(asset: &Match3DGeneratedItemAssetJson) -> bool {
|
||||
fn match3d_background_asset_has_image(asset: &Match3DGeneratedBackgroundAsset) -> bool {
|
||||
match3d_text_present(asset.image_src.as_ref())
|
||||
|| match3d_text_present(asset.image_object_key.as_ref())
|
||||
|| match3d_text_present(asset.ui_spritesheet_image_src.as_ref())
|
||||
|| match3d_text_present(asset.ui_spritesheet_image_object_key.as_ref())
|
||||
|| match3d_text_present(asset.item_spritesheet_image_src.as_ref())
|
||||
|| match3d_text_present(asset.item_spritesheet_image_object_key.as_ref())
|
||||
|| match3d_text_present(asset.container_image_src.as_ref())
|
||||
|| match3d_text_present(asset.container_image_object_key.as_ref())
|
||||
}
|
||||
|
||||
@@ -147,17 +147,17 @@ fn match3d_item_image_path_segments_stay_unique_for_chinese_names() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_material_sheet_slicing_uses_fixed_five_by_five_rows() {
|
||||
let width = 500;
|
||||
let height = 500;
|
||||
fn match3d_material_sheet_slicing_uses_fixed_ten_by_ten_two_items_per_row() {
|
||||
let width = 1000;
|
||||
let height = 1000;
|
||||
let item_names = vec!["樱桃".to_string(), "苹果".to_string(), "香蕉".to_string()];
|
||||
let mut sheet = image::RgbaImage::new(width, height);
|
||||
for row in 0..5 {
|
||||
for col in 0..5 {
|
||||
for row in 0..10 {
|
||||
for col in 0..10 {
|
||||
let color = image::Rgba([
|
||||
32 + row as u8 * 40,
|
||||
24 + col as u8 * 36,
|
||||
210 - row as u8 * 30,
|
||||
32 + row as u8 * 16,
|
||||
24 + col as u8 * 18,
|
||||
210 - row as u8 * 12,
|
||||
255,
|
||||
]);
|
||||
for y in row * 100..(row + 1) * 100 {
|
||||
@@ -180,9 +180,12 @@ fn match3d_material_sheet_slicing_uses_fixed_five_by_five_rows() {
|
||||
let slices = slice_match3d_material_sheet(&image, &item_names).expect("sheet should slice");
|
||||
|
||||
assert_eq!(slices.len(), 3);
|
||||
for (row, views) in slices.iter().enumerate() {
|
||||
for (item_index, views) in slices.iter().enumerate() {
|
||||
let row = item_index / 2;
|
||||
let start_col = (item_index % 2) * MATCH3D_ITEM_VIEW_COUNT;
|
||||
assert_eq!(views.len(), MATCH3D_ITEM_VIEW_COUNT);
|
||||
for (col, view) in views.iter().enumerate() {
|
||||
for (view_index, view) in views.iter().enumerate() {
|
||||
let col = start_col + view_index;
|
||||
let decoded = image::load_from_memory(view.bytes.as_slice())
|
||||
.expect("view should decode")
|
||||
.to_rgba8();
|
||||
@@ -190,12 +193,12 @@ fn match3d_material_sheet_slicing_uses_fixed_five_by_five_rows() {
|
||||
assert_eq!(
|
||||
pixel.0,
|
||||
[
|
||||
32 + row as u8 * 40,
|
||||
24 + col as u8 * 36,
|
||||
210 - row as u8 * 30,
|
||||
32 + row as u8 * 16,
|
||||
24 + col as u8 * 18,
|
||||
210 - row as u8 * 12,
|
||||
255,
|
||||
],
|
||||
"row {row} col {col} should be cut from the fixed 5*5 grid row"
|
||||
"item {item_index} view {view_index} should be cut from the fixed 10*10 grid"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -203,8 +206,8 @@ fn match3d_material_sheet_slicing_uses_fixed_five_by_five_rows() {
|
||||
|
||||
#[test]
|
||||
fn match3d_material_sheet_slicing_keeps_near_edge_foreground_pixels() {
|
||||
let width = 500;
|
||||
let height = 500;
|
||||
let width = 1000;
|
||||
let height = 1000;
|
||||
let item_names = vec!["樱桃".to_string(), "苹果".to_string(), "香蕉".to_string()];
|
||||
let mut sheet = image::RgbaImage::from_pixel(width, height, image::Rgba([255, 255, 255, 255]));
|
||||
for y in 1..5 {
|
||||
@@ -616,6 +619,52 @@ fn match3d_background_image_postprocess_removes_transparent_pixels() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_level_scene_prompt_uses_requested_theme_and_full_ui_layout() {
|
||||
let prompt = build_match3d_level_scene_generation_prompt(&config("重庆火锅", 12, 4));
|
||||
|
||||
assert!(prompt.contains("重庆火锅"));
|
||||
assert!(prompt.contains("第1关 重庆火锅"));
|
||||
assert!(prompt.contains("返回按钮位于顶部左上角"));
|
||||
assert!(prompt.contains("设置按钮"));
|
||||
assert!(prompt.contains("和主题匹配的容器"));
|
||||
assert!(prompt.contains("移出"));
|
||||
assert!(prompt.contains("凑齐"));
|
||||
assert!(prompt.contains("打乱"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_derived_asset_prompts_match_three_sheet_pipeline() {
|
||||
let config = config("水果", 12, 4);
|
||||
let ui_prompt = build_match3d_ui_spritesheet_prompt();
|
||||
let background_prompt = build_match3d_background_from_scene_prompt();
|
||||
let item_prompt = build_match3d_material_sheet_prompt(
|
||||
&config,
|
||||
&["草莓".to_string(), "苹果".to_string(), "香蕉".to_string()],
|
||||
);
|
||||
|
||||
assert!(ui_prompt.contains("返回按钮"));
|
||||
assert!(ui_prompt.contains("设置按钮"));
|
||||
assert!(ui_prompt.contains("方格素材"));
|
||||
assert!(ui_prompt.contains("纯绿色绿幕背景spritesheet"));
|
||||
assert!(ui_prompt.contains("绿幕扣成透明"));
|
||||
assert!(background_prompt.contains("移除画面中的所有UI组件"));
|
||||
assert!(background_prompt.contains("完整保留容器和背景"));
|
||||
assert!(item_prompt.contains("10行*10列"));
|
||||
assert!(item_prompt.contains("纯绿色绿幕背景"));
|
||||
assert!(item_prompt.contains("扣成透明"));
|
||||
assert!(item_prompt.contains("每一行包含两种物品"));
|
||||
assert!(item_prompt.contains("五个不同形态"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_hardcore_generated_item_count_is_capped_by_ten_by_ten_sheet() {
|
||||
assert_eq!(
|
||||
resolve_match3d_generated_item_count(&config("水果", 21, 8)),
|
||||
20
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_work_metadata_parses_gpt4o_json() {
|
||||
let metadata = parse_match3d_work_metadata(
|
||||
@@ -687,38 +736,69 @@ fn match3d_legacy_item_asset_without_size_defaults_to_large() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_draft_item_plan_rounds_up_to_full_five_item_sheets() {
|
||||
fn match3d_draft_item_plan_rounds_up_to_full_ten_by_ten_sheet() {
|
||||
let plan = parse_match3d_draft_plan(
|
||||
r#"{"gameName":"果园大鹅宴","tags":["水果","抓大鹅"],"backgroundMusic":{"title":"果园轻舞","style":"轻快, 休闲","prompt":""},"backgroundPrompt":"果园主题竖屏纯背景","items":[{"name":"草莓","soundPrompt":"草莓点击音效"},{"name":"苹果","soundPrompt":"苹果点击音效"},{"name":"香蕉","soundPrompt":"香蕉点击音效"},{"name":"葡萄","soundPrompt":"葡萄点击音效"},{"name":"西瓜","soundPrompt":"西瓜点击音效"},{"name":"梨子","soundPrompt":"梨子点击音效"},{"name":"桃子","soundPrompt":"桃子点击音效"},{"name":"橙子","soundPrompt":"橙子点击音效"},{"name":"蓝莓","soundPrompt":"蓝莓点击音效"}]}"#,
|
||||
&config("水果", 12, 4),
|
||||
)
|
||||
.expect("draft plan should parse");
|
||||
|
||||
assert_eq!(plan.items.len(), 10);
|
||||
assert_eq!(plan.items.len(), 20);
|
||||
assert_eq!(plan.items[8].name, "蓝莓");
|
||||
assert_ne!(plan.items[9].name, "蓝莓");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_generated_item_count_rounds_up_to_five_multiples() {
|
||||
fn match3d_generated_item_count_uses_full_ten_by_ten_sheet_capacity() {
|
||||
assert_eq!(
|
||||
resolve_match3d_generated_item_count(&config("水果", 8, 2)),
|
||||
5
|
||||
20
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_match3d_generated_item_count(&config("水果", 12, 4)),
|
||||
10
|
||||
20
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_match3d_generated_item_count(&config("水果", 16, 6)),
|
||||
15
|
||||
20
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_match3d_generated_item_count(&config("水果", 21, 8)),
|
||||
25
|
||||
20
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_gameplay_item_count_uses_difficulty_loading_limit() {
|
||||
assert_eq!(
|
||||
resolve_match3d_gameplay_item_count(&config("水果", 8, 2)),
|
||||
3
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_match3d_gameplay_item_count(&config("水果", 12, 4)),
|
||||
9
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_match3d_gameplay_item_count(&config("水果", 16, 6)),
|
||||
15
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_match3d_gameplay_item_count(&config("水果", 21, 8)),
|
||||
20
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_material_sheet_cell_indices_stay_inside_ten_by_ten_grid() {
|
||||
let first = resolve_match3d_material_sheet_cell_indices(0, 0);
|
||||
let second = resolve_match3d_material_sheet_cell_indices(1, 0);
|
||||
let twentieth_last_view = resolve_match3d_material_sheet_cell_indices(19, 4);
|
||||
|
||||
assert_eq!(first, (1, 1));
|
||||
assert_eq!(second, (1, 6));
|
||||
assert_eq!(twentieth_last_view, (10, 10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_generated_assets_require_only_images_when_click_sound_is_closed() {
|
||||
let assets = vec![test_match3d_generated_item_asset(1, "草莓")];
|
||||
@@ -731,12 +811,11 @@ fn match3d_generated_assets_require_only_images_when_click_sound_is_closed() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_item_asset_points_cost_counts_five_item_batches() {
|
||||
fn match3d_item_asset_points_cost_counts_ten_by_ten_sheet_batches() {
|
||||
assert_eq!(calculate_match3d_item_assets_points_cost(0), 0);
|
||||
assert_eq!(calculate_match3d_item_assets_points_cost(1), 2);
|
||||
assert_eq!(calculate_match3d_item_assets_points_cost(5), 2);
|
||||
assert_eq!(calculate_match3d_item_assets_points_cost(6), 4);
|
||||
assert_eq!(calculate_match3d_item_assets_points_cost(10), 4);
|
||||
assert_eq!(calculate_match3d_item_assets_points_cost(20), 2);
|
||||
assert_eq!(calculate_match3d_item_assets_points_cost(21), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -775,7 +854,7 @@ fn match3d_item_asset_append_plan_pads_generation_without_persisting_padding() {
|
||||
);
|
||||
|
||||
assert_eq!(plan.requested_item_names, vec!["苹果", "香蕉", "梨子"]);
|
||||
assert_eq!(plan.padded_item_names.len(), 5);
|
||||
assert_eq!(plan.padded_item_names.len(), 20);
|
||||
assert_eq!(&plan.padded_item_names[..3], ["苹果", "香蕉", "梨子"]);
|
||||
assert_eq!(
|
||||
calculate_match3d_item_assets_points_cost(plan.requested_item_names.len()),
|
||||
@@ -872,6 +951,7 @@ fn match3d_regenerated_asset_keeps_stable_identity_and_side_assets() {
|
||||
container_image_object_key: None,
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
});
|
||||
let mut generated_asset = test_match3d_generated_item_asset(99, "新草莓");
|
||||
generated_asset.image_src =
|
||||
@@ -897,20 +977,19 @@ fn match3d_regenerated_asset_keeps_stable_identity_and_side_assets() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_material_sheet_prompt_requires_uniform_five_by_five_layout() {
|
||||
fn match3d_material_sheet_prompt_requires_uniform_ten_by_ten_transparent_layout() {
|
||||
let prompt = build_match3d_material_sheet_prompt(
|
||||
&config("水果", 12, 4),
|
||||
&["草莓".to_string(), "苹果".to_string(), "香蕉".to_string()],
|
||||
);
|
||||
|
||||
assert!(prompt.contains("5行*5列"));
|
||||
assert!(prompt.contains("严格5*5均匀排布"));
|
||||
assert!(prompt.contains("绿幕背景"));
|
||||
assert!(prompt.contains("10行*10列spritesheet图"));
|
||||
assert!(prompt.contains("纯绿色绿幕背景"));
|
||||
assert!(prompt.contains("#00FF00"));
|
||||
assert!(prompt.contains("单个素材格宽度的1/4空白间距"));
|
||||
assert!(prompt.contains("约25%单格宽度"));
|
||||
assert!(prompt.contains("禁止主体跨格"));
|
||||
assert!(prompt.contains("贴边或越界"));
|
||||
assert!(prompt.contains("素材间距严格均匀分布"));
|
||||
assert!(prompt.contains("每一行包含两种物品"));
|
||||
assert!(prompt.contains("每种物品的五个不同形态"));
|
||||
assert!(prompt.contains("严禁出现两种高相似度的物品"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -921,16 +1000,53 @@ fn match3d_material_sheet_prompt_hardens_pixel_retro_style() {
|
||||
let prompt = build_match3d_material_sheet_prompt(&config, &["草莓".to_string()]);
|
||||
let negative_prompt = build_match3d_material_sheet_negative_prompt(&config);
|
||||
|
||||
assert!(prompt.contains("64x64"));
|
||||
assert!(prompt.contains("整数倍放大"));
|
||||
assert!(prompt.contains("禁止抗锯齿"));
|
||||
assert!(prompt.contains("真实 3D 渲染"));
|
||||
assert!(prompt.contains("PBR 材质"));
|
||||
assert!(prompt.contains("10行*10列spritesheet图"));
|
||||
assert!(prompt.contains("纯绿色绿幕背景"));
|
||||
assert!(negative_prompt.contains("抗锯齿"));
|
||||
assert!(negative_prompt.contains("平滑插画"));
|
||||
assert!(negative_prompt.contains("真实 3D 渲染"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_spritesheet_green_screen_postprocess_turns_background_transparent() {
|
||||
let width = 100;
|
||||
let height = 100;
|
||||
let mut image = image::RgbaImage::from_pixel(width, height, image::Rgba([0, 255, 0, 255]));
|
||||
for y in 32..68 {
|
||||
for x in 32..68 {
|
||||
image.put_pixel(x, y, image::Rgba([220, 32, 48, 255]));
|
||||
}
|
||||
}
|
||||
|
||||
let mut encoded = std::io::Cursor::new(Vec::new());
|
||||
image::DynamicImage::ImageRgba8(image)
|
||||
.write_to(&mut encoded, ImageFormat::Png)
|
||||
.expect("spritesheet should encode");
|
||||
|
||||
let processed = make_match3d_spritesheet_image_transparent(DownloadedOpenAiImage {
|
||||
bytes: encoded.into_inner(),
|
||||
mime_type: "image/png".to_string(),
|
||||
extension: "png".to_string(),
|
||||
})
|
||||
.expect("spritesheet should postprocess");
|
||||
let decoded = image::load_from_memory(processed.bytes.as_slice())
|
||||
.expect("processed spritesheet should decode")
|
||||
.to_rgba8();
|
||||
|
||||
assert_eq!(processed.mime_type, "image/png");
|
||||
assert_eq!(processed.extension, "png");
|
||||
assert_eq!(
|
||||
decoded.get_pixel(0, 0).0[3],
|
||||
0,
|
||||
"绿幕背景必须在上传 OSS 前扣成透明 alpha"
|
||||
);
|
||||
assert_eq!(
|
||||
decoded.get_pixel(width / 2, height / 2).0,
|
||||
[220, 32, 48, 255],
|
||||
"物品主体不能被绿幕去背误删"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_material_sheet_request_uses_vector_engine_gemini_contract() {
|
||||
let body = build_match3d_vector_engine_gemini_image_request_body(
|
||||
@@ -1060,6 +1176,7 @@ fn match3d_background_asset_requires_background_and_container_images() {
|
||||
container_image_object_key: None,
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
};
|
||||
let with_container = Match3DGeneratedBackgroundAsset {
|
||||
container_prompt: Some("果园容器".to_string()),
|
||||
@@ -1106,6 +1223,7 @@ fn match3d_default_cover_prefers_generated_container_ui_image() {
|
||||
container_image_object_key: None,
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
}),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
@@ -1181,8 +1299,8 @@ fn match3d_cover_reference_prompt_marks_reference_images() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match3d_cover_edit_prompt_preserves_uploaded_image() {
|
||||
let prompt = build_match3d_cover_edit_prompt("水果封面");
|
||||
fn match3d_cover_reference_generation_prompt_preserves_uploaded_image() {
|
||||
let prompt = build_match3d_cover_uploaded_reference_prompt("水果封面");
|
||||
|
||||
assert!(prompt.contains("上传的封面图作为第一优先级"));
|
||||
assert!(prompt.contains("保留主图的主体、构图、视角和主要配色"));
|
||||
@@ -1225,6 +1343,7 @@ fn match3d_fallback_work_profile_keeps_generated_background_asset() {
|
||||
),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
}),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
@@ -1362,6 +1481,7 @@ fn match3d_agent_session_response_hydrates_persisted_ui_assets() {
|
||||
),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
}),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
@@ -1437,6 +1557,7 @@ fn match3d_agent_session_response_keeps_draft_ui_assets_without_work_detail_hydr
|
||||
),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
}),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
@@ -1820,6 +1941,7 @@ fn match3d_work_summary_marks_complete_generated_assets_ready() {
|
||||
),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
}),
|
||||
..test_match3d_generated_item_asset(1, "草莓")
|
||||
}];
|
||||
|
||||
@@ -27,6 +27,8 @@ pub(super) async fn generate_match3d_material_sheet(
|
||||
Ok(Match3DMaterialSheet {
|
||||
task_id: generated.task_id,
|
||||
prompt,
|
||||
image_src: None,
|
||||
image_object_key: None,
|
||||
image,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ pub(super) async fn ensure_match3d_background_asset(
|
||||
}
|
||||
}
|
||||
|
||||
let generated_background = generate_match3d_background_image(
|
||||
let generated_background = generate_match3d_level_asset_bundle(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
@@ -236,6 +236,40 @@ pub(super) async fn ensure_match3d_background_asset(
|
||||
Ok(assets)
|
||||
}
|
||||
|
||||
pub(super) async fn resolve_or_generate_match3d_level_asset_bundle(
|
||||
state: &AppState,
|
||||
request_context: &RequestContext,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
profile_id: &str,
|
||||
config: &Match3DConfigJson,
|
||||
background_prompt: &str,
|
||||
assets: &[Match3DGeneratedItemAsset],
|
||||
) -> Result<Match3DGeneratedBackgroundAsset, Response> {
|
||||
if let Some(existing_background) = find_match3d_generated_background_asset(assets) {
|
||||
if is_match3d_background_asset_ready(&existing_background) {
|
||||
return Ok(existing_background);
|
||||
}
|
||||
}
|
||||
|
||||
let normalized_prompt = normalize_match3d_background_prompt(background_prompt);
|
||||
let resolved_prompt = if normalized_prompt.is_empty() {
|
||||
build_fallback_match3d_background_prompt(config)
|
||||
} else {
|
||||
normalized_prompt
|
||||
};
|
||||
generate_match3d_level_asset_bundle(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
profile_id,
|
||||
config,
|
||||
resolved_prompt.as_str(),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| match3d_error_response(request_context, MATCH3D_AGENT_PROVIDER, error))
|
||||
}
|
||||
|
||||
pub(super) fn attach_match3d_background_asset_to_assets(
|
||||
assets: &mut Vec<Match3DGeneratedItemAsset>,
|
||||
background_asset: Match3DGeneratedBackgroundAsset,
|
||||
@@ -281,7 +315,7 @@ pub(super) async fn generate_match3d_cover_image_asset(
|
||||
create_openai_image_edit(
|
||||
&http_client,
|
||||
&settings,
|
||||
build_match3d_cover_edit_prompt(cover_prompt.as_str()).as_str(),
|
||||
build_match3d_cover_uploaded_reference_prompt(cover_prompt.as_str()).as_str(),
|
||||
Some("文字、水印、UI、按钮、倒计时、分数、教程浮层、菜单、边框"),
|
||||
"1:1",
|
||||
&uploaded_image,
|
||||
@@ -289,27 +323,38 @@ pub(super) async fn generate_match3d_cover_image_asset(
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
let reference_images = resolve_match3d_cover_reference_image_data_urls(
|
||||
let reference_images = resolve_match3d_cover_reference_images_for_edit(
|
||||
state,
|
||||
reference_image_srcs,
|
||||
MATCH3D_ITEM_IMAGE_MAX_BYTES,
|
||||
)
|
||||
.await?;
|
||||
create_openai_image_generation(
|
||||
&http_client,
|
||||
&settings,
|
||||
build_match3d_cover_reference_generation_prompt(
|
||||
if reference_images.is_empty() {
|
||||
create_openai_image_generation(
|
||||
&http_client,
|
||||
&settings,
|
||||
cover_prompt.as_str(),
|
||||
!reference_images.is_empty(),
|
||||
Some("文字、水印、UI、按钮、倒计时、分数、教程浮层、菜单、边框"),
|
||||
"1:1",
|
||||
1,
|
||||
&[],
|
||||
"抓大鹅封面图生成失败",
|
||||
)
|
||||
.as_str(),
|
||||
Some("文字、水印、UI、按钮、倒计时、分数、教程浮层、菜单、边框"),
|
||||
"1:1",
|
||||
1,
|
||||
reference_images.as_slice(),
|
||||
"抓大鹅封面图生成失败",
|
||||
)
|
||||
.await?
|
||||
.await?
|
||||
} else {
|
||||
create_openai_image_edit_with_references(
|
||||
&http_client,
|
||||
&settings,
|
||||
build_match3d_cover_reference_generation_prompt(cover_prompt.as_str(), true)
|
||||
.as_str(),
|
||||
Some("文字、水印、UI、按钮、倒计时、分数、教程浮层、菜单、边框"),
|
||||
"1:1",
|
||||
1,
|
||||
reference_images.as_slice(),
|
||||
"抓大鹅封面图生成失败",
|
||||
)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
let image = generated.images.into_iter().next().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
@@ -347,7 +392,7 @@ fn build_match3d_cover_generation_prompt(config: &Match3DConfigJson, prompt: &st
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_cover_edit_prompt(prompt: &str) -> String {
|
||||
pub(super) fn build_match3d_cover_uploaded_reference_prompt(prompt: &str) -> String {
|
||||
format!(
|
||||
concat!(
|
||||
"请以随请求上传的封面图作为第一优先级重绘依据,保留主图的主体、构图、视角和主要配色;",
|
||||
@@ -382,24 +427,113 @@ pub(super) async fn generate_match3d_background_image(
|
||||
profile_id: &str,
|
||||
config: &Match3DConfigJson,
|
||||
prompt: &str,
|
||||
) -> Result<Match3DGeneratedBackgroundAsset, AppError> {
|
||||
generate_match3d_level_asset_bundle(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
profile_id,
|
||||
config,
|
||||
prompt,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(super) async fn generate_match3d_level_asset_bundle(
|
||||
state: &AppState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
profile_id: &str,
|
||||
config: &Match3DConfigJson,
|
||||
prompt: &str,
|
||||
) -> Result<Match3DGeneratedBackgroundAsset, AppError> {
|
||||
require_match3d_oss_client(state)?;
|
||||
let settings = require_openai_image_settings(state)?;
|
||||
let http_client = build_openai_image_http_client(&settings)?;
|
||||
let reference_image = load_match3d_container_reference_image()?;
|
||||
let generated_background = create_openai_image_generation(
|
||||
|
||||
let level_scene_prompt = build_match3d_level_scene_generation_prompt(config);
|
||||
let generated_scene = create_openai_image_generation(
|
||||
&http_client,
|
||||
&settings,
|
||||
build_match3d_background_generation_prompt(config, prompt).as_str(),
|
||||
Some(
|
||||
"文字、水印、UI、按钮、倒计时、分数、物品、角色、手、边框、教程浮层、菜单、透明区域、透明 alpha、镂空、棋盘格透明底",
|
||||
),
|
||||
level_scene_prompt.as_str(),
|
||||
Some("水印、教程浮层、菜单、广告、真实手机外框、浏览器 UI"),
|
||||
"9:16",
|
||||
1,
|
||||
&[],
|
||||
"抓大鹅背景图生成失败",
|
||||
"抓大鹅关卡画面生成失败",
|
||||
)
|
||||
.await?;
|
||||
let level_scene_image = generated_scene.images.into_iter().next().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": "vector-engine",
|
||||
"message": "抓大鹅关卡画面生成失败:未返回图片",
|
||||
}))
|
||||
})?;
|
||||
let level_scene_reference = OpenAiReferenceImage {
|
||||
bytes: level_scene_image.bytes.clone(),
|
||||
mime_type: level_scene_image.mime_type.clone(),
|
||||
file_name: "match3d-level-scene.png".to_string(),
|
||||
};
|
||||
let level_scene_upload = persist_match3d_generated_bytes(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
profile_id,
|
||||
&["level-scene", generated_scene.task_id.as_str()],
|
||||
"scene.png",
|
||||
level_scene_image.mime_type.as_str(),
|
||||
level_scene_image.bytes,
|
||||
"match3d_level_scene_image",
|
||||
Some(generated_scene.task_id.as_str()),
|
||||
current_utc_micros(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let ui_prompt = build_match3d_ui_spritesheet_prompt();
|
||||
let background_extract_prompt = build_match3d_background_from_scene_prompt();
|
||||
let generated_ui_future = create_openai_image_edit(
|
||||
&http_client,
|
||||
&settings,
|
||||
ui_prompt.as_str(),
|
||||
Some("整页背景、中心物品、容器内物品、重复按钮、文字说明、白底、纯色底、网格线"),
|
||||
"1:1",
|
||||
&level_scene_reference,
|
||||
"抓大鹅 UI spritesheet 生成失败",
|
||||
);
|
||||
let generated_background_future = create_openai_image_edit(
|
||||
&http_client,
|
||||
&settings,
|
||||
background_extract_prompt.as_str(),
|
||||
Some("返回按钮、设置按钮、倒计时、标题文字、道具按钮、物品、容器内含物、菜单、教程浮层"),
|
||||
"9:16",
|
||||
&level_scene_reference,
|
||||
"抓大鹅背景图生成失败",
|
||||
);
|
||||
let (generated_ui, generated_background) =
|
||||
tokio::try_join!(generated_ui_future, generated_background_future)?;
|
||||
|
||||
let ui_image = generated_ui.images.into_iter().next().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": "vector-engine",
|
||||
"message": "抓大鹅 UI spritesheet 生成失败:未返回图片",
|
||||
}))
|
||||
})?;
|
||||
let ui_image = make_match3d_spritesheet_image_transparent(ui_image)?;
|
||||
let ui_upload = persist_match3d_generated_bytes(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
profile_id,
|
||||
&["ui-spritesheet", generated_ui.task_id.as_str()],
|
||||
"ui-spritesheet.png",
|
||||
ui_image.mime_type.as_str(),
|
||||
ui_image.bytes,
|
||||
"match3d_ui_spritesheet_image",
|
||||
Some(generated_ui.task_id.as_str()),
|
||||
current_utc_micros(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let background_image = generated_background
|
||||
.images
|
||||
.into_iter()
|
||||
@@ -426,50 +560,22 @@ pub(super) async fn generate_match3d_background_image(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let container_prompt = build_match3d_container_generation_prompt(config, prompt);
|
||||
let generated_container = create_openai_image_edit(
|
||||
&http_client,
|
||||
&settings,
|
||||
container_prompt.as_str(),
|
||||
Some("文字、水印、按钮、倒计时、分数、物品、角色、手、教程浮层、菜单、整页背景、小容器、正俯视圆盘、侧视碗、餐盘、托盘、画布大留白"),
|
||||
"1:1",
|
||||
&reference_image,
|
||||
"抓大鹅容器 UI 图生成失败",
|
||||
)
|
||||
.await?;
|
||||
let container_image = generated_container
|
||||
.images
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": "vector-engine",
|
||||
"message": "抓大鹅容器 UI 图生成失败:未返回图片",
|
||||
}))
|
||||
})?;
|
||||
let container_image = make_match3d_container_image_transparent(container_image)?;
|
||||
let container_upload = persist_match3d_generated_bytes(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
profile_id,
|
||||
&["ui-container", generated_container.task_id.as_str()],
|
||||
"container.png",
|
||||
container_image.mime_type.as_str(),
|
||||
container_image.bytes,
|
||||
"match3d_ui_container_image",
|
||||
Some(generated_container.task_id.as_str()),
|
||||
current_utc_micros(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Match3DGeneratedBackgroundAsset {
|
||||
prompt: prompt.to_string(),
|
||||
level_scene_prompt: Some(level_scene_prompt),
|
||||
level_scene_image_src: Some(level_scene_upload.src),
|
||||
level_scene_image_object_key: Some(level_scene_upload.object_key),
|
||||
image_src: Some(background_upload.src),
|
||||
image_object_key: Some(background_upload.object_key),
|
||||
container_prompt: Some(container_prompt),
|
||||
container_image_src: Some(container_upload.src),
|
||||
container_image_object_key: Some(container_upload.object_key),
|
||||
ui_spritesheet_prompt: Some(ui_prompt.clone()),
|
||||
ui_spritesheet_image_src: Some(ui_upload.src.clone()),
|
||||
ui_spritesheet_image_object_key: Some(ui_upload.object_key.clone()),
|
||||
item_spritesheet_prompt: None,
|
||||
item_spritesheet_image_src: None,
|
||||
item_spritesheet_image_object_key: None,
|
||||
container_prompt: Some(ui_prompt),
|
||||
container_image_src: Some(ui_upload.src),
|
||||
container_image_object_key: Some(ui_upload.object_key),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
})
|
||||
@@ -533,6 +639,7 @@ pub(super) async fn generate_match3d_container_image(
|
||||
container_image_object_key: Some(container_upload.object_key),
|
||||
status: "image_ready".to_string(),
|
||||
error: None,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -549,12 +656,39 @@ pub(super) fn merge_match3d_container_image_into_background_asset(
|
||||
.unwrap_or_else(|| container_asset.prompt.clone());
|
||||
Match3DGeneratedBackgroundAsset {
|
||||
prompt,
|
||||
level_scene_prompt: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.level_scene_prompt.clone()),
|
||||
level_scene_image_src: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.level_scene_image_src.clone()),
|
||||
level_scene_image_object_key: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.level_scene_image_object_key.clone()),
|
||||
image_src: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.image_src.clone()),
|
||||
image_object_key: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.image_object_key.clone()),
|
||||
ui_spritesheet_prompt: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.ui_spritesheet_prompt.clone()),
|
||||
ui_spritesheet_image_src: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.ui_spritesheet_image_src.clone()),
|
||||
ui_spritesheet_image_object_key: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.ui_spritesheet_image_object_key.clone()),
|
||||
item_spritesheet_prompt: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.item_spritesheet_prompt.clone()),
|
||||
item_spritesheet_image_src: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.item_spritesheet_image_src.clone()),
|
||||
item_spritesheet_image_object_key: existing_background
|
||||
.as_ref()
|
||||
.and_then(|asset| asset.item_spritesheet_image_object_key.clone()),
|
||||
container_prompt: container_asset.container_prompt,
|
||||
container_image_src: container_asset.container_image_src,
|
||||
container_image_object_key: container_asset.container_image_object_key,
|
||||
@@ -582,6 +716,44 @@ pub(super) fn load_match3d_container_reference_image() -> Result<OpenAiReference
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_level_scene_generation_prompt(config: &Match3DConfigJson) -> String {
|
||||
let theme = config.theme_text.trim();
|
||||
let theme = if theme.is_empty() {
|
||||
MATCH3D_DEFAULT_THEME
|
||||
} else {
|
||||
theme
|
||||
};
|
||||
let style_clause = resolve_match3d_asset_style_prompt(config)
|
||||
.map(|style| format!("\n整体美术风格要求:{style}"))
|
||||
.unwrap_or_default();
|
||||
|
||||
format!(
|
||||
concat!(
|
||||
"生成抓大鹅游戏关卡画面,要求画面中所有元素精致且风格高度一致,画面中所有UI细节饱满精致、完成度高、顶级游戏品质\n\n",
|
||||
"抓大鹅主题描述:\n",
|
||||
"{theme}{style_clause}\n\n",
|
||||
"画面元素:\n",
|
||||
"返回按钮位于顶部左上角,顶部中间显示关卡标题“第1关 重庆火锅”和倒计时时间,右上角显示设置按钮\n",
|
||||
"画面中间是一个和主题匹配的容器,宽度与画面宽度同宽,紧贴画面横向边缘\n",
|
||||
"底部还有三个道具按钮分别为“移出”、“凑齐”、“打乱”"
|
||||
),
|
||||
theme = theme,
|
||||
style_clause = style_clause,
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_ui_spritesheet_prompt() -> String {
|
||||
"提取画面中的UI元素,将返回按钮、设置按钮、方格素材(不含边框,仅保留一个)、移出按钮、凑齐按钮、打乱按钮的顺序从上到下从左到右整理成纯绿色绿幕背景spritesheet。背景必须是统一纯绿色绿幕(高饱和亮绿色,接近 #00FF00),背景平整无纹理、无渐变、无阴影、无场景内容,后端会在生图后将绿幕扣成透明并把透明背景 PNG 存到 OSS。UI 素材自身不得使用接近 #00FF00 的高饱和纯绿;绿色题材只能使用深绿、橄榄绿、金绿或蓝绿,并用清晰描边与绿幕区分。".to_string()
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_background_from_scene_prompt() -> String {
|
||||
"移除画面中的所有UI组件和容器中的内含物,完整保留容器和背景,补全被UI覆盖的背景内容".to_string()
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_item_spritesheet_prompt() -> String {
|
||||
"固定生成10行*10列spritesheet图,统一纯绿色绿幕背景(高饱和亮绿色,接近 #00FF00),背景平整无纹理、无渐变、无阴影、无场景内容,后端会在生图后将绿幕扣成透明并把透明背景 PNG 存到 OSS。素材间距严格均匀分布,任意两个素材间距相同,物品来自参考图中画面中心容器中的2D素材。每一行包含两种物品,每种物品的五个不同形态。物品素材自身不得使用接近 #00FF00 的高饱和纯绿;绿色物品只能使用深绿、橄榄绿、金绿或蓝绿,并用清晰描边与绿幕区分。严禁出现两种高相似度的物品".to_string()
|
||||
}
|
||||
|
||||
pub(super) fn build_match3d_background_generation_prompt(
|
||||
config: &Match3DConfigJson,
|
||||
prompt: &str,
|
||||
@@ -761,6 +933,32 @@ pub(super) fn make_match3d_container_image_transparent(
|
||||
extension: "png".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn make_match3d_spritesheet_image_transparent(
|
||||
image: DownloadedOpenAiImage,
|
||||
) -> Result<DownloadedOpenAiImage, AppError> {
|
||||
let source = image::load_from_memory(image.bytes.as_slice()).map_err(|error| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": "match3d-assets",
|
||||
"message": format!("抓大鹅 spritesheet 图解码失败:{error}"),
|
||||
}))
|
||||
})?;
|
||||
let mut encoded = std::io::Cursor::new(Vec::new());
|
||||
apply_generated_asset_sheet_green_screen_alpha(source)
|
||||
.write_to(&mut encoded, ImageFormat::Png)
|
||||
.map_err(|error| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": "match3d-assets",
|
||||
"message": format!("抓大鹅 spritesheet 图透明化失败:{error}"),
|
||||
}))
|
||||
})?;
|
||||
|
||||
Ok(DownloadedOpenAiImage {
|
||||
bytes: encoded.into_inner(),
|
||||
mime_type: "image/png".to_string(),
|
||||
extension: "png".to_string(),
|
||||
})
|
||||
}
|
||||
pub(super) async fn download_match3d_legacy_model(
|
||||
file: &hyper3d_contract::Hyper3dDownloadFilePayload,
|
||||
) -> Result<Match3DDownloadedModel, AppError> {
|
||||
@@ -864,7 +1062,7 @@ pub(super) fn is_match3d_glb_binary_payload(bytes: &[u8]) -> bool {
|
||||
magic == 0x4654_6c67 && version == 2 && declared_length == bytes.len()
|
||||
}
|
||||
|
||||
async fn read_match3d_generated_object_bytes(
|
||||
pub(super) async fn read_match3d_generated_object_bytes(
|
||||
state: &AppState,
|
||||
object_key: &str,
|
||||
message_prefix: &str,
|
||||
@@ -915,57 +1113,6 @@ async fn read_match3d_generated_object_bytes(
|
||||
Ok(bytes.to_vec())
|
||||
}
|
||||
|
||||
async fn resolve_match3d_reference_image_data_url(
|
||||
state: &AppState,
|
||||
source: Option<&str>,
|
||||
max_size_bytes: usize,
|
||||
) -> Result<Option<String>, AppError> {
|
||||
let Some(source) = source.map(str::trim).filter(|value| !value.is_empty()) else {
|
||||
return Ok(None);
|
||||
};
|
||||
if source.starts_with("data:image/") {
|
||||
return Ok(Some(source.to_string()));
|
||||
}
|
||||
if let Some(public_path) = normalize_match3d_public_reference_image_path(source) {
|
||||
let bytes = tokio::fs::read(public_path.as_str())
|
||||
.await
|
||||
.map_err(|error| {
|
||||
AppError::from_status(StatusCode::INTERNAL_SERVER_ERROR).with_details(json!({
|
||||
"provider": MATCH3D_WORKS_PROVIDER,
|
||||
"message": format!("读取抓大鹅本地参考图失败:{error}"),
|
||||
"path": public_path,
|
||||
}))
|
||||
})?;
|
||||
if bytes.is_empty() || bytes.len() > max_size_bytes {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": MATCH3D_WORKS_PROVIDER,
|
||||
"field": "referenceImageSrcs",
|
||||
"message": "封面参考图过大,请压缩后重试。",
|
||||
"maxBytes": max_size_bytes,
|
||||
"actualBytes": bytes.len(),
|
||||
})),
|
||||
);
|
||||
}
|
||||
return Ok(Some(format!(
|
||||
"data:{};base64,{}",
|
||||
infer_match3d_image_mime_type(bytes.as_slice()),
|
||||
BASE64_STANDARD.encode(bytes)
|
||||
)));
|
||||
}
|
||||
if !source.trim_start_matches('/').starts_with("generated-") {
|
||||
return Ok(Some(source.to_string()));
|
||||
}
|
||||
let bytes =
|
||||
read_match3d_generated_object_bytes(state, source, "读取抓大鹅参考图失败", max_size_bytes)
|
||||
.await?;
|
||||
Ok(Some(format!(
|
||||
"data:{};base64,{}",
|
||||
infer_match3d_image_mime_type(bytes.as_slice()),
|
||||
BASE64_STANDARD.encode(bytes)
|
||||
)))
|
||||
}
|
||||
|
||||
pub(super) fn normalize_match3d_public_reference_image_path(source: &str) -> Option<String> {
|
||||
let source = source
|
||||
.trim()
|
||||
@@ -1018,18 +1165,22 @@ pub(super) fn collect_match3d_cover_reference_image_sources(
|
||||
sources
|
||||
}
|
||||
|
||||
async fn resolve_match3d_cover_reference_image_data_urls(
|
||||
async fn resolve_match3d_cover_reference_images_for_edit(
|
||||
state: &AppState,
|
||||
sources: Vec<String>,
|
||||
max_size_bytes: usize,
|
||||
) -> Result<Vec<String>, AppError> {
|
||||
) -> Result<Vec<OpenAiReferenceImage>, AppError> {
|
||||
let mut resolved = Vec::new();
|
||||
for source in sources {
|
||||
if let Some(data_url) =
|
||||
resolve_match3d_reference_image_data_url(state, Some(source.as_str()), max_size_bytes)
|
||||
.await?
|
||||
for (index, source) in sources.into_iter().enumerate() {
|
||||
if let Some(image) = resolve_match3d_reference_image_for_edit(
|
||||
state,
|
||||
Some(source.as_str()),
|
||||
max_size_bytes,
|
||||
format!("match3d-cover-reference-{index}").as_str(),
|
||||
)
|
||||
.await?
|
||||
{
|
||||
resolved.push(data_url);
|
||||
resolved.push(image);
|
||||
}
|
||||
}
|
||||
Ok(resolved)
|
||||
@@ -1046,6 +1197,16 @@ async fn resolve_match3d_reference_image_for_edit(
|
||||
};
|
||||
let bytes = if source.starts_with("data:image/") {
|
||||
decode_match3d_data_url_bytes(source)?
|
||||
} else if let Some(public_path) = normalize_match3d_public_reference_image_path(source) {
|
||||
tokio::fs::read(public_path.as_str())
|
||||
.await
|
||||
.map_err(|error| {
|
||||
AppError::from_status(StatusCode::INTERNAL_SERVER_ERROR).with_details(json!({
|
||||
"provider": MATCH3D_WORKS_PROVIDER,
|
||||
"message": format!("读取抓大鹅本地参考图失败:{error}"),
|
||||
"path": public_path,
|
||||
}))
|
||||
})?
|
||||
} else if source.trim_start_matches('/').starts_with("generated-") {
|
||||
read_match3d_generated_object_bytes(
|
||||
state,
|
||||
@@ -1059,7 +1220,7 @@ async fn resolve_match3d_reference_image_for_edit(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": MATCH3D_WORKS_PROVIDER,
|
||||
"field": "uploadedImageSrc",
|
||||
"message": "封面上传图必须是图片 Data URL 或 /generated-* 路径。",
|
||||
"message": "封面参考图必须是图片 Data URL、本地 public 参考图或 /generated-* 路径。",
|
||||
})),
|
||||
);
|
||||
};
|
||||
@@ -1086,7 +1247,7 @@ async fn resolve_match3d_reference_image_for_edit(
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_match3d_data_url_bytes(source: &str) -> Result<Vec<u8>, AppError> {
|
||||
pub(super) fn decode_match3d_data_url_bytes(source: &str) -> Result<Vec<u8>, AppError> {
|
||||
let Some((header, data)) = source.split_once(',') else {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use axum::{
|
||||
Router,
|
||||
extract::DefaultBodyLimit,
|
||||
extract::{DefaultBodyLimit, FromRef},
|
||||
middleware,
|
||||
routing::{get, post},
|
||||
};
|
||||
@@ -17,12 +17,13 @@ use crate::{
|
||||
submit_puzzle_agent_message, submit_puzzle_leaderboard, swap_puzzle_pieces,
|
||||
update_puzzle_run_pause, use_puzzle_runtime_prop,
|
||||
},
|
||||
state::AppState,
|
||||
state::{AppState, PuzzleApiState},
|
||||
};
|
||||
|
||||
const PUZZLE_REFERENCE_IMAGE_BODY_LIMIT_BYTES: usize = 12 * 1024 * 1024;
|
||||
|
||||
pub fn router(state: AppState) -> Router<AppState> {
|
||||
// 中文注释:拼图 handler 只接收 PuzzleApiState,鉴权层仍使用全局 AppState。
|
||||
Router::new()
|
||||
.route(
|
||||
"/api/runtime/puzzle/agent/sessions",
|
||||
@@ -181,4 +182,6 @@ pub fn router(state: AppState) -> Router<AppState> {
|
||||
require_bearer_auth,
|
||||
)),
|
||||
)
|
||||
.with_state(PuzzleApiState::from_ref(&state))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,9 +40,11 @@ pub(crate) fn resolve_puzzle_draft_cover_prompt(
|
||||
pub(crate) fn resolve_puzzle_level_image_prompt(
|
||||
explicit_prompt: Option<&str>,
|
||||
level_picture_description: &str,
|
||||
draft_summary: &str,
|
||||
) -> String {
|
||||
normalize_prompt_part(explicit_prompt)
|
||||
.or_else(|| normalize_prompt_part(Some(level_picture_description)))
|
||||
.or_else(|| normalize_prompt_part(Some(draft_summary)))
|
||||
.unwrap_or_default()
|
||||
.to_string()
|
||||
}
|
||||
@@ -76,8 +78,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn level_image_prompt_falls_back_to_level_description() {
|
||||
let prompt = resolve_puzzle_level_image_prompt(Some(" "), "关卡画面描述");
|
||||
let prompt = resolve_puzzle_level_image_prompt(Some(" "), "关卡画面描述", "作品简介");
|
||||
|
||||
assert_eq!(prompt, "关卡画面描述");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn level_image_prompt_falls_back_to_draft_summary_like_initial_cover() {
|
||||
let prompt = resolve_puzzle_level_image_prompt(Some(" "), " ", "作品简介");
|
||||
|
||||
assert_eq!(prompt, "作品简介");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ fn build_puzzle_image_prompt_text(_level_name: &str, prompt: &str) -> String {
|
||||
concat!(
|
||||
"请生成一张高清插画。",
|
||||
"画面主体:{prompt}。",
|
||||
"画面要求:1:1",
|
||||
"画面要求:输出画面比例为1:1,",
|
||||
"主体要清晰集中,前中后景层次明确,局部细节丰富但不要杂乱,",
|
||||
"避免文字、水印、边框和 UI 元素。"
|
||||
),
|
||||
@@ -77,7 +77,7 @@ mod tests {
|
||||
let prompt = build_puzzle_image_prompt("雨夜神庙", "猫咪在发光遗迹前寻找线索");
|
||||
|
||||
assert!(prompt.contains("猫咪在发光遗迹前寻找线索"));
|
||||
assert!(prompt.contains("1:1"));
|
||||
assert!(prompt.contains("输出画面比例为1:1"));
|
||||
assert!(prompt.contains("主体要清晰集中"));
|
||||
assert!(prompt.contains("避免文字、水印、边框和 UI 元素"));
|
||||
}
|
||||
@@ -90,7 +90,7 @@ mod tests {
|
||||
let prompt = build_puzzle_image_prompt(long_level_name.as_str(), long_description.as_str());
|
||||
|
||||
assert!(prompt.chars().count() <= PUZZLE_TEXT_TO_IMAGE_PROMPT_MAX_CHARS);
|
||||
assert!(prompt.contains("1:1"));
|
||||
assert!(prompt.contains("输出画面比例为1:1"));
|
||||
assert!(prompt.contains("主体要清晰集中"));
|
||||
assert!(prompt.contains("避免文字、水印、边框和 UI 元素"));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
error::Error as StdError,
|
||||
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@@ -21,10 +20,8 @@ use module_assets::{
|
||||
};
|
||||
use module_puzzle::{PuzzleGeneratedImageCandidate, PuzzleRuntimeLevelStatus};
|
||||
use platform_llm::{LlmMessage, LlmMessageContentPart, LlmTextRequest};
|
||||
use platform_oss::{
|
||||
LegacyAssetPrefix, OssHeadObjectRequest, OssObjectAccess, OssPutObjectRequest,
|
||||
OssSignedGetObjectUrlRequest,
|
||||
};
|
||||
use platform_oss::{LegacyAssetPrefix, OssSignedGetObjectUrlRequest};
|
||||
use platform_oss::{OssHeadObjectRequest, OssObjectAccess, OssPutObjectRequest};
|
||||
use serde_json::{Map, Value, json};
|
||||
use shared_contracts::{
|
||||
creation_audio::CreationAudioAsset,
|
||||
@@ -80,10 +77,11 @@ use crate::{
|
||||
should_skip_asset_operation_billing_for_connectivity,
|
||||
},
|
||||
auth::AuthenticatedAccessToken,
|
||||
generated_asset_sheets::apply_generated_asset_sheet_green_screen_alpha,
|
||||
http_error::AppError,
|
||||
llm_model_routing::{CREATION_TEMPLATE_LLM_MODEL, PUZZLE_LEVEL_NAME_VISION_LLM_MODEL},
|
||||
openai_image_generation::{
|
||||
DownloadedOpenAiImage, VECTOR_ENGINE_GPT_IMAGE_2_MODEL, build_openai_image_http_client,
|
||||
DownloadedOpenAiImage, GPT_IMAGE_2_MODEL, build_openai_image_http_client,
|
||||
create_openai_image_generation, require_openai_image_settings,
|
||||
},
|
||||
platform_errors::map_oss_error,
|
||||
@@ -105,12 +103,9 @@ use crate::{
|
||||
},
|
||||
puzzle_gallery_cache::{build_puzzle_gallery_window_response, puzzle_gallery_cached_json},
|
||||
request_context::RequestContext,
|
||||
state::AppState,
|
||||
vector_engine_audio_generation::{
|
||||
GeneratedCreationAudioTarget, generate_background_music_asset_for_creation,
|
||||
},
|
||||
work_author::resolve_work_author_by_user_id,
|
||||
work_play_tracking::{WorkPlayTrackingDraft, record_work_play_start_after_success},
|
||||
state::PuzzleApiState,
|
||||
work_author::resolve_puzzle_work_author_by_user_id,
|
||||
work_play_tracking::{WorkPlayTrackingDraft, record_puzzle_work_play_start_after_success},
|
||||
};
|
||||
|
||||
const PUZZLE_AGENT_API_BASE_PROVIDER: &str = "puzzle-agent";
|
||||
@@ -121,8 +116,6 @@ const PUZZLE_IMAGE_MODEL_GPT_IMAGE_2: &str = "gpt-image-2";
|
||||
const PUZZLE_IMAGE_MODEL_GEMINI_31_FLASH_PREVIEW: &str = "gemini-3.1-flash-image-preview";
|
||||
const PUZZLE_IMAGE_GENERATION_POINTS_COST: u64 = 2;
|
||||
const PUZZLE_ENTITY_KIND: &str = "puzzle_work";
|
||||
const PUZZLE_BACKGROUND_MUSIC_ASSET_KIND: &str = "puzzle_background_music";
|
||||
const PUZZLE_BACKGROUND_MUSIC_SLOT: &str = "background_music";
|
||||
#[cfg(test)]
|
||||
const PUZZLE_GENERATED_IMAGE_SIZE: &str = "1024*1024";
|
||||
const PUZZLE_VECTOR_ENGINE_GENERATED_IMAGE_SIZE: &str = "1024x1024";
|
||||
@@ -131,9 +124,13 @@ const PUZZLE_LEVEL_NAME_VISION_IMAGE_MAX_SIDE: u32 = 768;
|
||||
const PUZZLE_LEVEL_NAME_VISION_MAX_TOKENS: u32 = 512;
|
||||
const PUZZLE_REFERENCE_IMAGE_MAX_BYTES: usize = 8 * 1024 * 1024;
|
||||
const PUZZLE_REFERENCE_IMAGE_SOURCE_LIMIT: usize = 5;
|
||||
const PUZZLE_VECTOR_ENGINE_IMAGE_EDIT_MODEL: &str = "gpt-image-2";
|
||||
const PUZZLE_UI_BACKGROUND_PROMPT_FALLBACK_MARKER: &str =
|
||||
"移动端拼图游戏纯背景,题材氛围清晰,不包含拼图槽或 UI 元素";
|
||||
const PUZZLE_VECTOR_ENGINE_SQUARE_IMAGE_SIZE: &str = "1024x1024";
|
||||
const PUZZLE_VECTOR_ENGINE_PORTRAIT_IMAGE_SIZE: &str = "1024x1536";
|
||||
const PUZZLE_LEVEL_SCENE_IMAGE_PROMPT: &str = "参考图作为拼图画面,生成对应的拼图游戏关卡画面,要求画面中所有元素精致且风格高度一致,画面中所有UI细节饱满精致、完成度高、顶级游戏品质\n\n画面元素:\n返回按钮位于顶部左上角,顶部中间显示关卡标题“第1关 影”和倒计时时间,右上角显示设置按钮\n画面中间是一个正方形的3*3拼图,拼图区域宽度与画面宽度同宽,紧贴画面横向边缘,拼图区域边界带有边框装饰\n拼图区域下方包含一个下一关按钮,仅在关卡完成时显示\n底部是三个贴合画面主题的道具按钮分别为“提示”、“原图”、“冻结”\n道具按钮上不要显示次数标注,返回按钮和设置按钮旁禁止标注文字";
|
||||
const PUZZLE_UI_SPRITESHEET_IMAGE_PROMPT: &str = "提取画面中的UI元素,将返回按钮、设置按钮、下一关按钮、提示按钮、原图按钮、冻结按钮整理成纯绿色绿幕背景的spritesheet。背景必须是统一纯绿色绿幕(高饱和亮绿色,接近 #00FF00),背景平整无纹理、无渐变、无阴影、无场景内容,后端会在生图后将绿幕扣成透明并把透明背景 PNG 存到 OSS。按钮顺序必须按原图位置从左到右、从上到下排列:返回、设置、下一关、提示、原图、冻结。按钮素材内必须保留对应中文文字,每个按钮必须是独立完整图形,按钮之间保留足够纯绿色绿幕空白,不能相互接触、重叠或连成一片,方便运行态按自动边界检测识别矩形素材。返回按钮和设置按钮不要额外画白色外圈、白底圆环或浮雕外框,直接画扁平图标本体。按钮自身不得使用接近 #00FF00 的高饱和纯绿;绿色题材只能使用深绿、橄榄绿、金绿或蓝绿,并用清晰描边与绿幕区分。禁止水印、数字、次数标注、透明背景、背景图、拼图块、棋盘、网格线、按钮外标签和额外按钮。";
|
||||
const PUZZLE_LEVEL_BACKGROUND_IMAGE_PROMPT: &str = "移除参考图中所有UI元素、移除拼图画面,仅保留背景图,补全被覆盖的背景图内容。禁止在背景中出现人像或和拼图画面中主体一致的内容";
|
||||
mod handlers;
|
||||
pub(crate) use self::handlers::*;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ pub(crate) fn build_puzzle_form_seed_text_from_parts(
|
||||
}
|
||||
|
||||
pub(crate) async fn save_puzzle_form_payload_before_compile(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
request_context: &RequestContext,
|
||||
session_id: &str,
|
||||
owner_user_id: &str,
|
||||
@@ -76,7 +76,7 @@ pub(crate) async fn save_puzzle_form_payload_before_compile(
|
||||
}
|
||||
|
||||
pub(crate) async fn create_seeded_puzzle_session_when_form_save_missing(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
request_context: &RequestContext,
|
||||
session_id: &str,
|
||||
owner_user_id: &str,
|
||||
@@ -184,6 +184,12 @@ pub(crate) fn parse_puzzle_level_records_from_module_json(
|
||||
ui_background_prompt: level.ui_background_prompt,
|
||||
ui_background_image_src: level.ui_background_image_src,
|
||||
ui_background_image_object_key: level.ui_background_image_object_key,
|
||||
level_scene_image_src: level.level_scene_image_src,
|
||||
level_scene_image_object_key: level.level_scene_image_object_key,
|
||||
ui_spritesheet_image_src: level.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: level.ui_spritesheet_image_object_key,
|
||||
level_background_image_src: level.level_background_image_src,
|
||||
level_background_image_object_key: level.level_background_image_object_key,
|
||||
background_music: level
|
||||
.background_music
|
||||
.map(map_puzzle_audio_asset_domain_record),
|
||||
@@ -209,7 +215,7 @@ pub(crate) fn parse_puzzle_level_records_from_module_json(
|
||||
}
|
||||
|
||||
pub(crate) async fn get_puzzle_session_for_image_generation(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
session_id: String,
|
||||
owner_user_id: String,
|
||||
payload: &ExecutePuzzleAgentActionRequest,
|
||||
@@ -357,6 +363,12 @@ pub(crate) fn serialize_puzzle_levels_response(
|
||||
"ui_background_prompt": level.ui_background_prompt,
|
||||
"ui_background_image_src": level.ui_background_image_src,
|
||||
"ui_background_image_object_key": level.ui_background_image_object_key,
|
||||
"level_scene_image_src": level.level_scene_image_src,
|
||||
"level_scene_image_object_key": level.level_scene_image_object_key,
|
||||
"ui_spritesheet_image_src": level.ui_spritesheet_image_src,
|
||||
"ui_spritesheet_image_object_key": level.ui_spritesheet_image_object_key,
|
||||
"level_background_image_src": level.level_background_image_src,
|
||||
"level_background_image_object_key": level.level_background_image_object_key,
|
||||
"background_music": puzzle_audio_asset_response_module_json(&level.background_music),
|
||||
"candidates": level
|
||||
.candidates
|
||||
@@ -411,6 +423,12 @@ pub(crate) fn normalize_puzzle_levels_json_for_module(
|
||||
"ui_background_prompt": level.ui_background_prompt,
|
||||
"ui_background_image_src": level.ui_background_image_src,
|
||||
"ui_background_image_object_key": level.ui_background_image_object_key,
|
||||
"level_scene_image_src": level.level_scene_image_src,
|
||||
"level_scene_image_object_key": level.level_scene_image_object_key,
|
||||
"ui_spritesheet_image_src": level.ui_spritesheet_image_src,
|
||||
"ui_spritesheet_image_object_key": level.ui_spritesheet_image_object_key,
|
||||
"level_background_image_src": level.level_background_image_src,
|
||||
"level_background_image_object_key": level.level_background_image_object_key,
|
||||
"background_music": puzzle_audio_asset_response_module_json(&level.background_music),
|
||||
"candidates": level
|
||||
.candidates
|
||||
@@ -469,7 +487,7 @@ impl PuzzleLevelNaming {
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_first_level_name(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
picture_description: &str,
|
||||
) -> PuzzleLevelNaming {
|
||||
if let Some(llm_client) = state.llm_client() {
|
||||
@@ -511,7 +529,7 @@ pub(crate) async fn generate_puzzle_first_level_name(
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_first_level_name_from_image(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
picture_description: &str,
|
||||
image: &PuzzleDownloadedImage,
|
||||
) -> Option<PuzzleLevelNaming> {
|
||||
@@ -918,6 +936,15 @@ pub(crate) fn build_puzzle_levels_with_primary_update(
|
||||
levels[index].ui_background_image_src = target_level.ui_background_image_src.clone();
|
||||
levels[index].ui_background_image_object_key =
|
||||
target_level.ui_background_image_object_key.clone();
|
||||
levels[index].level_scene_image_src = target_level.level_scene_image_src.clone();
|
||||
levels[index].level_scene_image_object_key =
|
||||
target_level.level_scene_image_object_key.clone();
|
||||
levels[index].ui_spritesheet_image_src = target_level.ui_spritesheet_image_src.clone();
|
||||
levels[index].ui_spritesheet_image_object_key =
|
||||
target_level.ui_spritesheet_image_object_key.clone();
|
||||
levels[index].level_background_image_src = target_level.level_background_image_src.clone();
|
||||
levels[index].level_background_image_object_key =
|
||||
target_level.level_background_image_object_key.clone();
|
||||
if let Some(picture_reference) = picture_reference
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
@@ -1033,42 +1060,31 @@ pub(crate) fn attach_puzzle_level_ui_background(
|
||||
levels[index].ui_background_image_object_key = Some(generated.object_key);
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_background_music_required(
|
||||
state: &AppState,
|
||||
owner_user_id: &str,
|
||||
profile_id: &str,
|
||||
title: &str,
|
||||
) -> Result<CreationAudioAsset, AppError> {
|
||||
let normalized_title = title.trim();
|
||||
if normalized_title.is_empty() {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": PUZZLE_AGENT_API_BASE_PROVIDER,
|
||||
"message": "拼图草稿背景音乐名称为空,无法完成背景音乐生成",
|
||||
})),
|
||||
);
|
||||
}
|
||||
generate_background_music_asset_for_creation(
|
||||
state,
|
||||
owner_user_id,
|
||||
String::new(),
|
||||
normalized_title.to_string(),
|
||||
Some("轻快, 拼图, 循环, instrumental".to_string()),
|
||||
None,
|
||||
GeneratedCreationAudioTarget {
|
||||
entity_kind: PUZZLE_ENTITY_KIND.to_string(),
|
||||
entity_id: profile_id.to_string(),
|
||||
slot: PUZZLE_BACKGROUND_MUSIC_SLOT.to_string(),
|
||||
asset_kind: PUZZLE_BACKGROUND_MUSIC_ASSET_KIND.to_string(),
|
||||
profile_id: Some(profile_id.to_string()),
|
||||
storage_prefix: LegacyAssetPrefix::PuzzleAssets,
|
||||
},
|
||||
)
|
||||
.await
|
||||
pub(crate) fn attach_puzzle_level_asset_bundle(
|
||||
levels: &mut [PuzzleDraftLevelRecord],
|
||||
level_id: &str,
|
||||
generated: GeneratedPuzzleLevelAssetBundle,
|
||||
) {
|
||||
let Some(index) = levels
|
||||
.iter()
|
||||
.position(|level| level.level_id == level_id)
|
||||
.or_else(|| (!levels.is_empty()).then_some(0))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let level = &mut levels[index];
|
||||
level.level_scene_image_src = Some(generated.level_scene.image_src);
|
||||
level.level_scene_image_object_key = Some(generated.level_scene.object_key);
|
||||
level.ui_spritesheet_image_src = Some(generated.ui_spritesheet.image_src);
|
||||
level.ui_spritesheet_image_object_key = Some(generated.ui_spritesheet.object_key);
|
||||
level.level_background_image_src = Some(generated.level_background.image_src.clone());
|
||||
level.level_background_image_object_key = Some(generated.level_background.object_key.clone());
|
||||
level.ui_background_image_src = Some(generated.level_background.image_src);
|
||||
level.ui_background_image_object_key = Some(generated.level_background.object_key);
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_initial_ui_background_required(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
draft: &PuzzleResultDraftRecord,
|
||||
@@ -1086,26 +1102,56 @@ pub(crate) async fn generate_puzzle_initial_ui_background_required(
|
||||
Ok((prompt, generated))
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_level_asset_bundle_required(
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
target_level: &PuzzleDraftLevelRecord,
|
||||
puzzle_image: &PuzzleDownloadedImage,
|
||||
) -> Result<GeneratedPuzzleLevelAssetBundle, AppError> {
|
||||
generate_puzzle_level_asset_bundle(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
target_level.level_name.as_str(),
|
||||
puzzle_image,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_puzzle_initial_level_assets_ready(
|
||||
level: &PuzzleDraftLevelRecord,
|
||||
) -> Result<(), AppError> {
|
||||
let has_ui_background = level
|
||||
.ui_background_image_src
|
||||
let has_level_background = level
|
||||
.level_background_image_src
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.is_some_and(|value| !value.is_empty())
|
||||
|| level
|
||||
.ui_background_image_object_key
|
||||
.level_background_image_object_key
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.is_some_and(|value| !value.is_empty());
|
||||
if has_ui_background {
|
||||
let has_ui_spritesheet = level
|
||||
.ui_spritesheet_image_src
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.is_some_and(|value| !value.is_empty())
|
||||
|| level
|
||||
.ui_spritesheet_image_object_key
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.is_some_and(|value| !value.is_empty());
|
||||
if has_level_background && has_ui_spritesheet {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut missing = Vec::new();
|
||||
if !has_ui_background {
|
||||
missing.push("UI背景图");
|
||||
if !has_level_background {
|
||||
missing.push("关卡背景图");
|
||||
}
|
||||
if !has_ui_spritesheet {
|
||||
missing.push("UI spritesheet");
|
||||
}
|
||||
|
||||
Err(
|
||||
@@ -1128,7 +1174,7 @@ pub(crate) fn find_puzzle_level_for_initial_asset_check<'a>(
|
||||
}
|
||||
|
||||
pub(crate) async fn compile_puzzle_draft_with_initial_cover(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
session_id: String,
|
||||
owner_user_id: String,
|
||||
prompt_text: Option<&str>,
|
||||
@@ -1159,8 +1205,8 @@ pub(crate) async fn compile_puzzle_draft_with_initial_cover(
|
||||
target_level.level_name = generated_naming.level_name.clone();
|
||||
target_level.ui_background_prompt = generated_naming.ui_background_prompt.clone();
|
||||
let mut generated_metadata = generated_naming;
|
||||
// 点击生成草稿时一次性完成首图生成、UI 背景生成与正式图选定,前端只展示进度,不再承担业务编排。
|
||||
let candidates_future = generate_puzzle_image_candidates(
|
||||
// 点击生成草稿时一次性完成拼图主图和运行态资产包,前端只展示进度,不再承担业务编排。
|
||||
let mut candidates = generate_puzzle_image_candidates(
|
||||
state,
|
||||
owner_user_id.as_str(),
|
||||
&compiled_session.session_id,
|
||||
@@ -1171,18 +1217,8 @@ pub(crate) async fn compile_puzzle_draft_with_initial_cover(
|
||||
image_model,
|
||||
1,
|
||||
target_level.candidates.len(),
|
||||
);
|
||||
let ui_background_future = generate_puzzle_initial_ui_background_required(
|
||||
state,
|
||||
owner_user_id.as_str(),
|
||||
compiled_session.session_id.as_str(),
|
||||
&draft,
|
||||
&target_level,
|
||||
);
|
||||
// 中文注释:命名稳定后并行发起首关图与 UI 背景,避免两次外部生图串行等待。
|
||||
let (candidates_result, ui_background_result) =
|
||||
tokio::join!(candidates_future, ui_background_future);
|
||||
let mut candidates = candidates_result?;
|
||||
)
|
||||
.await?;
|
||||
if let Some(first_candidate) = candidates.first()
|
||||
&& let Some(refined_naming) = generate_puzzle_first_level_name_from_image(
|
||||
state,
|
||||
@@ -1218,19 +1254,25 @@ pub(crate) async fn compile_puzzle_draft_with_initial_cover(
|
||||
"message": "拼图候选图生成结果为空",
|
||||
}))
|
||||
})?;
|
||||
// 中文注释:拼图草稿音频生成临时关闭,首版生成只补首图与 UI 背景。
|
||||
let (ui_prompt, ui_background) = ui_background_result?;
|
||||
attach_puzzle_level_ui_background(
|
||||
&mut updated_levels,
|
||||
target_level.level_id.as_str(),
|
||||
ui_prompt,
|
||||
ui_background,
|
||||
);
|
||||
// 中文注释:拼图草稿音频生成临时关闭,首版生成只补首图、关卡背景和 UI spritesheet。
|
||||
if let Some(selected_candidate) = candidates
|
||||
.iter()
|
||||
.find(|candidate| candidate.record.selected)
|
||||
.or_else(|| candidates.first())
|
||||
{
|
||||
let asset_bundle = generate_puzzle_level_asset_bundle_required(
|
||||
state,
|
||||
owner_user_id.as_str(),
|
||||
compiled_session.session_id.as_str(),
|
||||
&target_level,
|
||||
&selected_candidate.downloaded_image,
|
||||
)
|
||||
.await?;
|
||||
attach_puzzle_level_asset_bundle(
|
||||
&mut updated_levels,
|
||||
target_level.level_id.as_str(),
|
||||
asset_bundle,
|
||||
);
|
||||
attach_selected_puzzle_candidate_to_levels(
|
||||
&mut updated_levels,
|
||||
target_level.level_id.as_str(),
|
||||
@@ -1398,7 +1440,7 @@ pub(crate) async fn compile_puzzle_draft_with_initial_cover(
|
||||
}
|
||||
|
||||
pub(crate) async fn compile_puzzle_draft_with_uploaded_cover(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
session_id: String,
|
||||
owner_user_id: String,
|
||||
prompt_text: Option<&str>,
|
||||
@@ -1417,7 +1459,12 @@ pub(crate) async fn compile_puzzle_draft_with_uploaded_cover(
|
||||
})?;
|
||||
let http_client = reqwest::Client::new();
|
||||
let uploaded_downloaded_image =
|
||||
resolve_puzzle_reference_image_as_data_url(state, &http_client, uploaded_image_src)
|
||||
resolve_puzzle_reference_image(
|
||||
state,
|
||||
&http_client,
|
||||
uploaded_image_src,
|
||||
Some(owner_user_id.as_str()),
|
||||
)
|
||||
.await
|
||||
.map(PuzzleDownloadedImage::from_resolved_reference_image)
|
||||
.map_err(|error| {
|
||||
@@ -1425,7 +1472,7 @@ pub(crate) async fn compile_puzzle_draft_with_uploaded_cover(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": PUZZLE_AGENT_API_BASE_PROVIDER,
|
||||
"field": "referenceImageSrc",
|
||||
"message": "关闭 AI 重绘时上传图必须是图片 Data URL 或历史生成图片路径。",
|
||||
"message": "关闭 AI 重绘时上传图必须是拼图图片 assetObjectId、图片 Data URL 或历史生成图片路径。",
|
||||
}))
|
||||
} else {
|
||||
error
|
||||
@@ -1484,7 +1531,7 @@ pub(crate) async fn compile_puzzle_draft_with_uploaded_cover(
|
||||
let generated_level_name = target_level.level_name.clone();
|
||||
let mut updated_levels =
|
||||
build_puzzle_levels_with_primary_update(&draft, &target_level, reference_image_src);
|
||||
let persist_upload_future = persist_puzzle_generated_asset(
|
||||
let persisted_upload = persist_puzzle_generated_asset(
|
||||
state,
|
||||
owner_user_id.as_str(),
|
||||
&compiled_session.session_id,
|
||||
@@ -1493,24 +1540,20 @@ pub(crate) async fn compile_puzzle_draft_with_uploaded_cover(
|
||||
"uploaded-direct",
|
||||
uploaded_downloaded_image.clone(),
|
||||
current_utc_micros(),
|
||||
);
|
||||
let ui_background_future = generate_puzzle_initial_ui_background_required(
|
||||
)
|
||||
.await?;
|
||||
let asset_bundle = generate_puzzle_level_asset_bundle_required(
|
||||
state,
|
||||
owner_user_id.as_str(),
|
||||
compiled_session.session_id.as_str(),
|
||||
&draft,
|
||||
&target_level,
|
||||
);
|
||||
// 中文注释:直用上传图时并行完成上传图持久化与 UI 背景生成;音频生成入口临时关闭。
|
||||
let (persisted_upload_result, ui_background_result) =
|
||||
tokio::join!(persist_upload_future, ui_background_future);
|
||||
let persisted_upload = persisted_upload_result?;
|
||||
let (ui_prompt, ui_background) = ui_background_result?;
|
||||
attach_puzzle_level_ui_background(
|
||||
&uploaded_downloaded_image,
|
||||
)
|
||||
.await?;
|
||||
attach_puzzle_level_asset_bundle(
|
||||
&mut updated_levels,
|
||||
target_level.level_id.as_str(),
|
||||
ui_prompt,
|
||||
ui_background,
|
||||
asset_bundle,
|
||||
);
|
||||
attach_selected_puzzle_candidate_to_levels(
|
||||
&mut updated_levels,
|
||||
|
||||
@@ -12,19 +12,77 @@ pub(crate) fn map_puzzle_generation_endpoint_error(error: AppError) -> AppError
|
||||
error
|
||||
}
|
||||
|
||||
pub(crate) fn should_fallback_puzzle_reference_edit_to_generation(error: &AppError) -> bool {
|
||||
error.status_code() == StatusCode::GATEWAY_TIMEOUT
|
||||
|| is_puzzle_request_timeout_message(error.body_text().as_str())
|
||||
pub(crate) fn should_use_uploaded_puzzle_image_directly(
|
||||
reference_image_src: Option<&str>,
|
||||
ai_redraw: bool,
|
||||
) -> bool {
|
||||
!ai_redraw
|
||||
&& reference_image_src
|
||||
.map(str::trim)
|
||||
.is_some_and(|value| !value.is_empty())
|
||||
}
|
||||
|
||||
pub(crate) async fn create_uploaded_puzzle_image_candidate(
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
prompt: &str,
|
||||
reference_image_src: &str,
|
||||
candidate_start_index: usize,
|
||||
) -> Result<GeneratedPuzzleImageCandidate, AppError> {
|
||||
let http_client = reqwest::Client::new();
|
||||
let downloaded_image =
|
||||
resolve_puzzle_reference_image_as_data_url(state, &http_client, reference_image_src)
|
||||
.await
|
||||
.map(PuzzleDownloadedImage::from_resolved_reference_image)
|
||||
.map_err(|error| {
|
||||
if error.status_code() == StatusCode::BAD_REQUEST {
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": PUZZLE_AGENT_API_BASE_PROVIDER,
|
||||
"field": "referenceImageSrc",
|
||||
"message": "关闭 AI 重绘时上传图必须是图片 Data URL 或历史生成图片路径。",
|
||||
}))
|
||||
} else {
|
||||
error
|
||||
}
|
||||
})?;
|
||||
let candidate_id = format!("{session_id}-candidate-{}", candidate_start_index + 1);
|
||||
let asset = persist_puzzle_generated_asset(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
level_name,
|
||||
candidate_id.as_str(),
|
||||
"uploaded-direct",
|
||||
downloaded_image.clone(),
|
||||
current_utc_micros(),
|
||||
)
|
||||
.await
|
||||
.map_err(map_puzzle_generation_endpoint_error)?;
|
||||
|
||||
Ok(GeneratedPuzzleImageCandidate {
|
||||
record: PuzzleGeneratedImageCandidateRecord {
|
||||
candidate_id,
|
||||
image_src: asset.image_src,
|
||||
asset_id: asset.asset_id,
|
||||
prompt: prompt.to_string(),
|
||||
actual_prompt: None,
|
||||
source_type: "uploaded".to_string(),
|
||||
selected: true,
|
||||
},
|
||||
downloaded_image,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_image_candidates(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
prompt: &str,
|
||||
reference_image_src: Option<&str>,
|
||||
use_reference_image_edit: bool,
|
||||
use_reference_image_generation: bool,
|
||||
image_model: Option<&str>,
|
||||
candidate_count: u32,
|
||||
candidate_start_index: usize,
|
||||
@@ -34,11 +92,13 @@ pub(crate) async fn generate_puzzle_image_candidates(
|
||||
let resolved_model = resolve_puzzle_image_model(image_model);
|
||||
let http_client = build_puzzle_image_http_client(state, resolved_model)?;
|
||||
let has_reference_image = has_puzzle_reference_image(reference_image_src);
|
||||
let should_use_reference_image_edit =
|
||||
should_use_puzzle_reference_image_edit(reference_image_src, use_reference_image_edit);
|
||||
let should_use_reference_image_generation = should_use_puzzle_reference_image_generation(
|
||||
reference_image_src,
|
||||
use_reference_image_generation,
|
||||
);
|
||||
let actual_prompt = build_puzzle_vector_engine_generation_prompt(
|
||||
build_puzzle_image_prompt(level_name, prompt).as_str(),
|
||||
should_use_reference_image_edit,
|
||||
should_use_reference_image_generation,
|
||||
);
|
||||
tracing::info!(
|
||||
provider = resolved_model.provider_name(),
|
||||
@@ -48,18 +108,19 @@ pub(crate) async fn generate_puzzle_image_candidates(
|
||||
prompt_chars = prompt.chars().count(),
|
||||
actual_prompt_chars = actual_prompt.chars().count(),
|
||||
has_reference_image,
|
||||
use_reference_image_edit = should_use_reference_image_edit,
|
||||
use_reference_image_generation = should_use_reference_image_generation,
|
||||
"拼图图片生成请求已准备"
|
||||
);
|
||||
let reference_image_started_at = Instant::now();
|
||||
let reference_image = match reference_image_src
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.filter(|_| should_use_reference_image_edit)
|
||||
.filter(|_| should_use_reference_image_generation)
|
||||
{
|
||||
Some(source) => {
|
||||
let resolved =
|
||||
resolve_puzzle_reference_image_as_data_url(state, &http_client, source).await?;
|
||||
resolve_puzzle_reference_image(state, &http_client, source, Some(owner_user_id))
|
||||
.await?;
|
||||
tracing::info!(
|
||||
provider = resolved_model.provider_name(),
|
||||
image_model = resolved_model.request_model_name(),
|
||||
@@ -74,14 +135,14 @@ pub(crate) async fn generate_puzzle_image_candidates(
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
if !should_use_reference_image_edit {
|
||||
if !should_use_reference_image_generation {
|
||||
tracing::info!(
|
||||
provider = resolved_model.provider_name(),
|
||||
image_model = resolved_model.request_model_name(),
|
||||
session_id,
|
||||
level_name,
|
||||
has_reference_image,
|
||||
use_reference_image_edit = should_use_reference_image_edit,
|
||||
use_reference_image_generation = should_use_reference_image_generation,
|
||||
elapsed_ms = reference_image_started_at.elapsed().as_millis() as u64,
|
||||
"拼图参考图解析跳过"
|
||||
);
|
||||
@@ -90,7 +151,7 @@ pub(crate) async fn generate_puzzle_image_candidates(
|
||||
// 中文注释:拼图作品资产统一按 1:1 正方形生成,前端运行时也按正方形棋盘切块承载。
|
||||
let settings = require_puzzle_vector_engine_settings(state)?;
|
||||
let vector_engine_started_at = Instant::now();
|
||||
let generated = if should_use_reference_image_edit {
|
||||
let generated = if should_use_reference_image_generation {
|
||||
let reference_image = reference_image.as_ref().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "puzzle",
|
||||
@@ -98,43 +159,17 @@ pub(crate) async fn generate_puzzle_image_candidates(
|
||||
"message": "AI 重绘需要提供参考图。",
|
||||
}))
|
||||
})?;
|
||||
let edit_result = create_puzzle_vector_engine_image_edit(
|
||||
create_puzzle_vector_engine_image_generation(
|
||||
&http_client,
|
||||
&settings,
|
||||
resolved_model,
|
||||
actual_prompt.as_str(),
|
||||
PUZZLE_DEFAULT_NEGATIVE_PROMPT,
|
||||
PUZZLE_VECTOR_ENGINE_GENERATED_IMAGE_SIZE,
|
||||
count,
|
||||
reference_image,
|
||||
Some(reference_image),
|
||||
)
|
||||
.await;
|
||||
match edit_result {
|
||||
Ok(generated) => Ok(generated),
|
||||
Err(error) if should_fallback_puzzle_reference_edit_to_generation(&error) => {
|
||||
tracing::warn!(
|
||||
provider = resolved_model.provider_name(),
|
||||
image_model = resolved_model.request_model_name(),
|
||||
session_id,
|
||||
level_name,
|
||||
reference_mime = %reference_image.mime_type,
|
||||
reference_bytes = reference_image.bytes_len,
|
||||
error = %error,
|
||||
"拼图参考图编辑接口超时,降级为带参考图的生成接口"
|
||||
);
|
||||
create_puzzle_vector_engine_image_generation(
|
||||
&http_client,
|
||||
&settings,
|
||||
resolved_model,
|
||||
actual_prompt.as_str(),
|
||||
PUZZLE_DEFAULT_NEGATIVE_PROMPT,
|
||||
PUZZLE_VECTOR_ENGINE_GENERATED_IMAGE_SIZE,
|
||||
count,
|
||||
Some(reference_image),
|
||||
)
|
||||
.await
|
||||
}
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
.await
|
||||
} else {
|
||||
create_puzzle_vector_engine_image_generation(
|
||||
&http_client,
|
||||
@@ -219,13 +254,13 @@ pub(crate) async fn generate_puzzle_image_candidates(
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_ui_background_image(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
prompt: &str,
|
||||
) -> Result<GeneratedPuzzleUiBackgroundResponse, AppError> {
|
||||
let settings = require_openai_image_settings(state)?;
|
||||
let settings = require_openai_image_settings(state.root_state())?;
|
||||
let http_client = build_openai_image_http_client(&settings)?;
|
||||
let generated = create_openai_image_generation(
|
||||
&http_client,
|
||||
@@ -255,6 +290,175 @@ pub(crate) async fn generate_puzzle_ui_background_image(
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn generate_puzzle_level_asset_bundle(
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
puzzle_image: &PuzzleDownloadedImage,
|
||||
) -> Result<GeneratedPuzzleLevelAssetBundle, AppError> {
|
||||
let settings = require_puzzle_vector_engine_settings(state)?;
|
||||
let http_client = build_puzzle_image_http_client(state, PuzzleImageModel::GptImage2)?;
|
||||
let puzzle_reference = build_puzzle_downloaded_image_reference(puzzle_image);
|
||||
let scene_generated = create_puzzle_vector_engine_image_generation(
|
||||
&http_client,
|
||||
&settings,
|
||||
PuzzleImageModel::GptImage2,
|
||||
PUZZLE_LEVEL_SCENE_IMAGE_PROMPT,
|
||||
"",
|
||||
PUZZLE_VECTOR_ENGINE_PORTRAIT_IMAGE_SIZE,
|
||||
1,
|
||||
Some(&puzzle_reference),
|
||||
)
|
||||
.await
|
||||
.map_err(map_puzzle_generation_endpoint_error)?;
|
||||
let scene_image = scene_generated.images.into_iter().next().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": VECTOR_ENGINE_PROVIDER,
|
||||
"message": "拼图关卡画面图生成失败:未返回图片",
|
||||
}))
|
||||
})?;
|
||||
let scene_reference = build_puzzle_downloaded_image_reference(&scene_image);
|
||||
let scene_persist_future = persist_puzzle_level_asset_image(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
level_name,
|
||||
scene_generated.task_id.as_str(),
|
||||
"level-scene",
|
||||
"puzzle_level_scene_image",
|
||||
"level_scene",
|
||||
"scene",
|
||||
scene_image,
|
||||
);
|
||||
let spritesheet_future = generate_and_persist_puzzle_level_asset(
|
||||
state,
|
||||
&http_client,
|
||||
&settings,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
level_name,
|
||||
PUZZLE_UI_SPRITESHEET_IMAGE_PROMPT,
|
||||
PUZZLE_VECTOR_ENGINE_SQUARE_IMAGE_SIZE,
|
||||
&scene_reference,
|
||||
"ui-spritesheet",
|
||||
"puzzle_ui_spritesheet_image",
|
||||
"ui_spritesheet",
|
||||
"spritesheet",
|
||||
);
|
||||
let background_future = generate_and_persist_puzzle_level_asset(
|
||||
state,
|
||||
&http_client,
|
||||
&settings,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
level_name,
|
||||
PUZZLE_LEVEL_BACKGROUND_IMAGE_PROMPT,
|
||||
PUZZLE_VECTOR_ENGINE_PORTRAIT_IMAGE_SIZE,
|
||||
&scene_reference,
|
||||
"level-background",
|
||||
"puzzle_level_background_image",
|
||||
"level_background",
|
||||
"background",
|
||||
);
|
||||
let (level_scene, ui_spritesheet, level_background) =
|
||||
tokio::join!(scene_persist_future, spritesheet_future, background_future);
|
||||
|
||||
Ok(GeneratedPuzzleLevelAssetBundle {
|
||||
level_scene: level_scene?,
|
||||
ui_spritesheet: ui_spritesheet?,
|
||||
level_background: level_background?,
|
||||
})
|
||||
}
|
||||
|
||||
async fn generate_and_persist_puzzle_level_asset(
|
||||
state: &PuzzleApiState,
|
||||
http_client: &reqwest::Client,
|
||||
settings: &PuzzleVectorEngineSettings,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
prompt: &str,
|
||||
size: &str,
|
||||
reference_image: &PuzzleResolvedReferenceImage,
|
||||
path_segment: &str,
|
||||
asset_kind: &str,
|
||||
slot: &str,
|
||||
file_stem: &str,
|
||||
) -> Result<GeneratedPuzzleLevelAssetResponse, AppError> {
|
||||
let generated = create_puzzle_vector_engine_image_generation(
|
||||
http_client,
|
||||
settings,
|
||||
PuzzleImageModel::GptImage2,
|
||||
prompt,
|
||||
"",
|
||||
size,
|
||||
1,
|
||||
Some(reference_image),
|
||||
)
|
||||
.await
|
||||
.map_err(map_puzzle_generation_endpoint_error)?;
|
||||
let image = generated.images.into_iter().next().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": VECTOR_ENGINE_PROVIDER,
|
||||
"message": format!("拼图关卡资产生成失败:{asset_kind} 未返回图片"),
|
||||
}))
|
||||
})?;
|
||||
let image = if slot == "ui_spritesheet" {
|
||||
make_puzzle_ui_spritesheet_image_transparent(image)?
|
||||
} else {
|
||||
image
|
||||
};
|
||||
|
||||
persist_puzzle_level_asset_image(
|
||||
state,
|
||||
owner_user_id,
|
||||
session_id,
|
||||
level_name,
|
||||
generated.task_id.as_str(),
|
||||
path_segment,
|
||||
asset_kind,
|
||||
slot,
|
||||
file_stem,
|
||||
image,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) fn make_puzzle_ui_spritesheet_image_transparent(
|
||||
image: PuzzleDownloadedImage,
|
||||
) -> Result<PuzzleDownloadedImage, AppError> {
|
||||
let source = image::load_from_memory(image.bytes.as_slice()).map_err(|error| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": VECTOR_ENGINE_PROVIDER,
|
||||
"message": format!("拼图 UI spritesheet 图解码失败:{error}"),
|
||||
}))
|
||||
})?;
|
||||
|
||||
let mut encoded = std::io::Cursor::new(Vec::new());
|
||||
apply_generated_asset_sheet_green_screen_alpha(source)
|
||||
.write_to(&mut encoded, ImageFormat::Png)
|
||||
.map_err(|error| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": VECTOR_ENGINE_PROVIDER,
|
||||
"message": format!("拼图 UI spritesheet 图透明化失败:{error}"),
|
||||
}))
|
||||
})?;
|
||||
|
||||
Ok(PuzzleDownloadedImage {
|
||||
extension: "png".to_string(),
|
||||
mime_type: "image/png".to_string(),
|
||||
bytes: encoded.into_inner(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn make_puzzle_ui_spritesheet_image_transparent_for_test(
|
||||
image: PuzzleDownloadedImage,
|
||||
) -> Result<PuzzleDownloadedImage, AppError> {
|
||||
make_puzzle_ui_spritesheet_image_transparent(image)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn build_puzzle_ui_background_request_prompt_for_test(
|
||||
level_name: &str,
|
||||
@@ -262,3 +466,45 @@ pub(crate) fn build_puzzle_ui_background_request_prompt_for_test(
|
||||
) -> String {
|
||||
build_puzzle_ui_background_generation_prompt(level_name, prompt)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn build_puzzle_level_scene_image_request_body_for_test(
|
||||
reference_image: &PuzzleDownloadedImage,
|
||||
) -> Result<Value, AppError> {
|
||||
Ok(build_puzzle_vector_engine_image_request_body(
|
||||
PuzzleImageModel::GptImage2,
|
||||
PUZZLE_LEVEL_SCENE_IMAGE_PROMPT,
|
||||
"",
|
||||
PUZZLE_VECTOR_ENGINE_PORTRAIT_IMAGE_SIZE,
|
||||
1,
|
||||
Some(&build_puzzle_downloaded_image_reference(reference_image)),
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn build_puzzle_ui_spritesheet_request_body_for_test(
|
||||
reference_image: &PuzzleDownloadedImage,
|
||||
) -> Result<Value, AppError> {
|
||||
Ok(build_puzzle_vector_engine_image_request_body(
|
||||
PuzzleImageModel::GptImage2,
|
||||
PUZZLE_UI_SPRITESHEET_IMAGE_PROMPT,
|
||||
"",
|
||||
PUZZLE_VECTOR_ENGINE_SQUARE_IMAGE_SIZE,
|
||||
1,
|
||||
Some(&build_puzzle_downloaded_image_reference(reference_image)),
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn build_puzzle_level_background_request_body_for_test(
|
||||
reference_image: &PuzzleDownloadedImage,
|
||||
) -> Result<Value, AppError> {
|
||||
Ok(build_puzzle_vector_engine_image_request_body(
|
||||
PuzzleImageModel::GptImage2,
|
||||
PUZZLE_LEVEL_BACKGROUND_IMAGE_PROMPT,
|
||||
"",
|
||||
PUZZLE_VECTOR_ENGINE_PORTRAIT_IMAGE_SIZE,
|
||||
1,
|
||||
Some(&build_puzzle_downloaded_image_reference(reference_image)),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
pub async fn create_puzzle_agent_session(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
payload: Result<Json<CreatePuzzleAgentSessionRequest>, JsonRejection>,
|
||||
@@ -46,7 +46,7 @@ pub async fn create_puzzle_agent_session(
|
||||
}
|
||||
|
||||
pub async fn generate_puzzle_onboarding_work(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
payload: Result<Json<PuzzleOnboardingGenerateRequest>, JsonRejection>,
|
||||
) -> Result<Json<Value>, Response> {
|
||||
@@ -113,6 +113,12 @@ pub async fn generate_puzzle_onboarding_work(
|
||||
ui_background_prompt: naming.ui_background_prompt.clone(),
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates,
|
||||
selected_candidate_id: Some(selected.candidate_id.clone()),
|
||||
@@ -161,7 +167,7 @@ pub async fn generate_puzzle_onboarding_work(
|
||||
}
|
||||
|
||||
pub async fn save_puzzle_onboarding_work(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
payload: Result<Json<PuzzleOnboardingSaveRequest>, JsonRejection>,
|
||||
@@ -270,7 +276,7 @@ pub async fn save_puzzle_onboarding_work(
|
||||
}
|
||||
|
||||
pub async fn get_puzzle_agent_session(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(session_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -303,7 +309,7 @@ pub async fn get_puzzle_agent_session(
|
||||
}
|
||||
|
||||
pub async fn submit_puzzle_agent_message(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(session_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -359,7 +365,7 @@ pub async fn submit_puzzle_agent_message(
|
||||
llm_client: state.llm_client(),
|
||||
session: &submitted_session,
|
||||
quick_fill_requested: payload.quick_fill_requested.unwrap_or(false),
|
||||
enable_web_search: state.config.creation_agent_llm_web_search_enabled,
|
||||
enable_web_search: state.creation_agent_llm_web_search_enabled(),
|
||||
},
|
||||
|_| {},
|
||||
)
|
||||
@@ -401,7 +407,7 @@ pub async fn submit_puzzle_agent_message(
|
||||
}
|
||||
|
||||
pub async fn stream_puzzle_agent_message(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(session_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -464,7 +470,7 @@ pub async fn stream_puzzle_agent_message(
|
||||
llm_client: state.llm_client(),
|
||||
session: &session,
|
||||
quick_fill_requested,
|
||||
enable_web_search: state.config.creation_agent_llm_web_search_enabled,
|
||||
enable_web_search: state.creation_agent_llm_web_search_enabled(),
|
||||
},
|
||||
move |text| {
|
||||
let _ = reply_tx.send(text.to_string());
|
||||
@@ -554,7 +560,7 @@ pub async fn stream_puzzle_agent_message(
|
||||
}
|
||||
|
||||
pub async fn execute_puzzle_agent_action(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(session_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -595,6 +601,8 @@ pub async fn execute_puzzle_agent_action(
|
||||
has_reference_image = has_puzzle_reference_images(
|
||||
payload.reference_image_src.as_deref(),
|
||||
payload.reference_image_srcs.as_slice(),
|
||||
payload.reference_image_asset_object_id.as_deref(),
|
||||
payload.reference_image_asset_object_ids.as_slice(),
|
||||
),
|
||||
"拼图 Agent action 开始执行"
|
||||
);
|
||||
@@ -604,6 +612,8 @@ pub async fn execute_puzzle_agent_action(
|
||||
let reference_image_sources = collect_puzzle_reference_image_sources(
|
||||
payload.reference_image_src.as_deref(),
|
||||
payload.reference_image_srcs.as_slice(),
|
||||
payload.reference_image_asset_object_id.as_deref(),
|
||||
payload.reference_image_asset_object_ids.as_slice(),
|
||||
);
|
||||
let primary_reference_image_src = reference_image_sources.first().map(String::as_str);
|
||||
let prompt_text = payload
|
||||
@@ -627,7 +637,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
};
|
||||
let session = if ai_redraw {
|
||||
execute_billable_asset_operation_with_cost(
|
||||
&state,
|
||||
state.root_state(),
|
||||
&owner_user_id,
|
||||
"puzzle_initial_image",
|
||||
&billing_asset_id,
|
||||
@@ -652,7 +662,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
compile_session_id.clone(),
|
||||
owner_user_id.clone(),
|
||||
prompt_text,
|
||||
payload.reference_image_src.as_deref(),
|
||||
primary_reference_image_src,
|
||||
now,
|
||||
)
|
||||
.await
|
||||
@@ -737,7 +747,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
}))
|
||||
});
|
||||
let session = execute_billable_asset_operation_with_cost(
|
||||
&state,
|
||||
state.root_state(),
|
||||
&owner_user_id,
|
||||
"puzzle_generated_image",
|
||||
&billing_asset_id,
|
||||
@@ -768,6 +778,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
let prompt = resolve_puzzle_level_image_prompt(
|
||||
payload.prompt_text.as_deref(),
|
||||
&target_level.picture_description,
|
||||
&draft.summary,
|
||||
);
|
||||
let should_auto_name_level = payload
|
||||
.should_auto_name_level
|
||||
@@ -787,26 +798,46 @@ pub async fn execute_puzzle_agent_action(
|
||||
let reference_image_sources = collect_puzzle_reference_image_sources(
|
||||
payload.reference_image_src.as_deref(),
|
||||
payload.reference_image_srcs.as_slice(),
|
||||
payload.reference_image_asset_object_id.as_deref(),
|
||||
payload.reference_image_asset_object_ids.as_slice(),
|
||||
);
|
||||
let primary_reference_image_src =
|
||||
reference_image_sources.first().map(String::as_str);
|
||||
// 拼图结果页从多候选抽卡收口为单图替换,前端传入的旧 candidateCount 只做兼容忽略。
|
||||
let candidate_count = 1;
|
||||
let candidate_start_index = target_level.candidates.len();
|
||||
let candidates = generate_puzzle_image_candidates(
|
||||
&state,
|
||||
owner_user_id.as_str(),
|
||||
&session.session_id,
|
||||
&target_level.level_name,
|
||||
&prompt,
|
||||
let ai_redraw = payload.ai_redraw.unwrap_or(true);
|
||||
let mut candidates = if should_use_uploaded_puzzle_image_directly(
|
||||
primary_reference_image_src,
|
||||
payload.ai_redraw.unwrap_or(true),
|
||||
payload.image_model.as_deref(),
|
||||
candidate_count,
|
||||
candidate_start_index,
|
||||
)
|
||||
.await
|
||||
.map_err(map_puzzle_generation_endpoint_error)?;
|
||||
ai_redraw,
|
||||
) {
|
||||
vec![
|
||||
create_uploaded_puzzle_image_candidate(
|
||||
&state,
|
||||
owner_user_id.as_str(),
|
||||
&session.session_id,
|
||||
&target_level.level_name,
|
||||
&prompt,
|
||||
primary_reference_image_src.expect("checked reference image"),
|
||||
candidate_start_index,
|
||||
)
|
||||
.await?,
|
||||
]
|
||||
} else {
|
||||
generate_puzzle_image_candidates(
|
||||
&state,
|
||||
owner_user_id.as_str(),
|
||||
&session.session_id,
|
||||
&target_level.level_name,
|
||||
&prompt,
|
||||
primary_reference_image_src,
|
||||
ai_redraw,
|
||||
payload.image_model.as_deref(),
|
||||
1,
|
||||
candidate_start_index,
|
||||
)
|
||||
.await
|
||||
.map_err(map_puzzle_generation_endpoint_error)?
|
||||
};
|
||||
if candidates.is_empty() {
|
||||
return Err(AppError::from_status(StatusCode::BAD_GATEWAY).with_details(
|
||||
json!({
|
||||
@@ -831,14 +862,44 @@ pub async fn execute_puzzle_agent_action(
|
||||
generated_naming = Some(refined_naming);
|
||||
}
|
||||
let generated_level_name = target_level.level_name.clone();
|
||||
let mut updated_levels = build_puzzle_levels_with_primary_update(
|
||||
&draft,
|
||||
&target_level,
|
||||
primary_reference_image_src,
|
||||
);
|
||||
for candidate in &mut candidates {
|
||||
candidate.record.prompt = prompt.clone();
|
||||
}
|
||||
let selected_candidate = candidates
|
||||
.iter()
|
||||
.find(|candidate| candidate.record.selected)
|
||||
.or_else(|| candidates.first())
|
||||
.ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": PUZZLE_AGENT_API_BASE_PROVIDER,
|
||||
"message": "拼图候选图生成结果为空",
|
||||
}))
|
||||
})?;
|
||||
let asset_bundle = generate_puzzle_level_asset_bundle_required(
|
||||
&state,
|
||||
owner_user_id.as_str(),
|
||||
&session.session_id,
|
||||
&target_level,
|
||||
&selected_candidate.downloaded_image,
|
||||
)
|
||||
.await?;
|
||||
attach_puzzle_level_asset_bundle(
|
||||
&mut updated_levels,
|
||||
target_level.level_id.as_str(),
|
||||
asset_bundle,
|
||||
);
|
||||
attach_selected_puzzle_candidate_to_levels(
|
||||
&mut updated_levels,
|
||||
target_level.level_id.as_str(),
|
||||
&selected_candidate.record,
|
||||
);
|
||||
let levels_json_with_generated_name =
|
||||
Some(serialize_puzzle_level_records_for_module(
|
||||
&build_puzzle_levels_with_primary_update(
|
||||
&draft,
|
||||
&target_level,
|
||||
primary_reference_image_src,
|
||||
),
|
||||
)?);
|
||||
Some(serialize_puzzle_level_records_for_module(&updated_levels)?);
|
||||
let candidates_json = serde_json::to_string(
|
||||
&candidates
|
||||
.iter()
|
||||
@@ -890,7 +951,11 @@ pub async fn execute_puzzle_agent_action(
|
||||
};
|
||||
let mut fallback_session =
|
||||
apply_generated_puzzle_candidates_to_session_snapshot(
|
||||
fallback_session,
|
||||
apply_generated_puzzle_levels_to_session_snapshot(
|
||||
fallback_session,
|
||||
updated_levels,
|
||||
now,
|
||||
),
|
||||
target_level.level_id.as_str(),
|
||||
candidates.into_records(),
|
||||
primary_reference_image_src,
|
||||
@@ -942,7 +1007,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
}))
|
||||
});
|
||||
let session = execute_billable_asset_operation_with_cost(
|
||||
&state,
|
||||
state.root_state(),
|
||||
&owner_user_id,
|
||||
"puzzle_ui_background_image",
|
||||
&billing_asset_id,
|
||||
@@ -1147,7 +1212,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
let (work_id, profile_id) = build_stable_puzzle_work_ids(&session_id);
|
||||
let author_display_name = resolve_author_display_name(&state, &authenticated);
|
||||
let profile = execute_billable_asset_operation(
|
||||
&state,
|
||||
state.root_state(),
|
||||
&owner_user_id,
|
||||
"puzzle_publish_work",
|
||||
&work_id,
|
||||
@@ -1235,7 +1300,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
}
|
||||
|
||||
pub async fn get_puzzle_works(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
) -> Result<Json<Value>, Response> {
|
||||
@@ -1263,7 +1328,7 @@ pub async fn get_puzzle_works(
|
||||
}
|
||||
|
||||
pub async fn get_puzzle_work_detail(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(profile_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(_authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1296,7 +1361,7 @@ pub async fn get_puzzle_work_detail(
|
||||
}
|
||||
|
||||
pub async fn put_puzzle_work(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(profile_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1355,7 +1420,7 @@ pub async fn put_puzzle_work(
|
||||
}
|
||||
|
||||
pub async fn delete_puzzle_work(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(profile_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1391,7 +1456,7 @@ pub async fn delete_puzzle_work(
|
||||
}
|
||||
|
||||
pub async fn claim_puzzle_work_point_incentive(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(profile_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1428,7 +1493,7 @@ pub async fn claim_puzzle_work_point_incentive(
|
||||
}
|
||||
|
||||
pub async fn list_puzzle_gallery(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
) -> Result<Response, Response> {
|
||||
if let Some(response) = state.puzzle_gallery_cache().read_fresh_response().await {
|
||||
@@ -1487,7 +1552,7 @@ pub async fn list_puzzle_gallery(
|
||||
}
|
||||
|
||||
pub async fn get_puzzle_gallery_detail(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(profile_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
) -> Result<Json<Value>, Response> {
|
||||
@@ -1519,7 +1584,7 @@ pub async fn get_puzzle_gallery_detail(
|
||||
}
|
||||
|
||||
pub async fn record_puzzle_gallery_like(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(profile_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1556,7 +1621,7 @@ pub async fn record_puzzle_gallery_like(
|
||||
}
|
||||
|
||||
pub async fn remix_puzzle_gallery_work(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(profile_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1599,7 +1664,7 @@ pub async fn remix_puzzle_gallery_work(
|
||||
}
|
||||
|
||||
pub async fn start_puzzle_run(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
payload: Result<Json<StartPuzzleRunRequest>, JsonRejection>,
|
||||
@@ -1639,7 +1704,7 @@ pub async fn start_puzzle_run(
|
||||
)
|
||||
})?;
|
||||
|
||||
record_work_play_start_after_success(
|
||||
record_puzzle_work_play_start_after_success(
|
||||
&state,
|
||||
&request_context,
|
||||
WorkPlayTrackingDraft::new(
|
||||
@@ -1665,7 +1730,7 @@ pub async fn start_puzzle_run(
|
||||
}
|
||||
|
||||
pub async fn get_puzzle_run(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(run_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1693,7 +1758,7 @@ pub async fn get_puzzle_run(
|
||||
}
|
||||
|
||||
pub async fn swap_puzzle_pieces(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(run_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1750,7 +1815,7 @@ pub async fn swap_puzzle_pieces(
|
||||
}
|
||||
|
||||
pub async fn drag_puzzle_piece_or_group(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(run_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1802,7 +1867,7 @@ pub async fn drag_puzzle_piece_or_group(
|
||||
}
|
||||
|
||||
pub async fn advance_puzzle_next_level(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(run_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1854,7 +1919,7 @@ pub async fn advance_puzzle_next_level(
|
||||
}
|
||||
|
||||
pub async fn update_puzzle_run_pause(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(run_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1898,7 +1963,7 @@ pub async fn update_puzzle_run_pause(
|
||||
}
|
||||
|
||||
pub async fn use_puzzle_runtime_prop(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(run_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
@@ -1944,7 +2009,7 @@ pub async fn use_puzzle_runtime_prop(
|
||||
let fallback_run_id = run_id.clone();
|
||||
let fallback_owner_user_id = owner_user_id.clone();
|
||||
let run_result = execute_billable_asset_operation(
|
||||
&state,
|
||||
state.root_state(),
|
||||
&owner_user_id,
|
||||
billing_asset_kind,
|
||||
billing_asset_id.as_str(),
|
||||
@@ -1996,7 +2061,7 @@ pub async fn use_puzzle_runtime_prop(
|
||||
}
|
||||
|
||||
pub async fn submit_puzzle_leaderboard(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<PuzzleApiState>,
|
||||
AxumPath(run_id): AxumPath<String>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Extension(authenticated): Extension<AuthenticatedAccessToken>,
|
||||
|
||||
@@ -105,6 +105,12 @@ pub(super) fn map_puzzle_draft_level_response(
|
||||
ui_background_prompt: level.ui_background_prompt,
|
||||
ui_background_image_src: level.ui_background_image_src,
|
||||
ui_background_image_object_key: level.ui_background_image_object_key,
|
||||
level_scene_image_src: level.level_scene_image_src,
|
||||
level_scene_image_object_key: level.level_scene_image_object_key,
|
||||
ui_spritesheet_image_src: level.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: level.ui_spritesheet_image_object_key,
|
||||
level_background_image_src: level.level_background_image_src,
|
||||
level_background_image_object_key: level.level_background_image_object_key,
|
||||
background_music: level
|
||||
.background_music
|
||||
.map(map_puzzle_audio_asset_record_response),
|
||||
@@ -343,11 +349,11 @@ fn has_puzzle_level_image(level: &PuzzleDraftLevelRecord) -> bool {
|
||||
}
|
||||
|
||||
pub(super) fn map_puzzle_work_summary_response(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
item: PuzzleWorkProfileRecord,
|
||||
) -> PuzzleWorkSummaryResponse {
|
||||
let generation_status = resolve_puzzle_work_generation_status(&item);
|
||||
let author = resolve_work_author_by_user_id(
|
||||
let author = resolve_puzzle_work_author_by_user_id(
|
||||
state,
|
||||
&item.owner_user_id,
|
||||
Some(&item.author_display_name),
|
||||
@@ -391,10 +397,10 @@ pub(super) fn map_puzzle_work_summary_response(
|
||||
}
|
||||
|
||||
pub(super) fn map_puzzle_gallery_card_response(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
item: PuzzleGalleryCardRecord,
|
||||
) -> PuzzleWorkSummaryResponse {
|
||||
let author = resolve_work_author_by_user_id(
|
||||
let author = resolve_puzzle_work_author_by_user_id(
|
||||
state,
|
||||
&item.owner_user_id,
|
||||
Some(&item.author_display_name),
|
||||
@@ -434,7 +440,7 @@ pub(super) fn map_puzzle_gallery_card_response(
|
||||
}
|
||||
|
||||
pub(super) fn map_puzzle_work_profile_response(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
item: PuzzleWorkProfileRecord,
|
||||
) -> PuzzleWorkProfileResponse {
|
||||
let mut summary = map_puzzle_work_summary_response(state, item.clone());
|
||||
@@ -491,7 +497,7 @@ pub(super) fn map_puzzle_recommended_next_work_response(
|
||||
}
|
||||
|
||||
pub(super) async fn enrich_puzzle_run_author_name(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
mut run: PuzzleRunRecord,
|
||||
) -> PuzzleRunRecord {
|
||||
if let Some(level) = run.current_level.as_mut() {
|
||||
@@ -500,7 +506,7 @@ pub(super) async fn enrich_puzzle_run_author_name(
|
||||
.get_puzzle_gallery_detail(level.profile_id.clone())
|
||||
.await
|
||||
{
|
||||
level.author_display_name = resolve_work_author_by_user_id(
|
||||
level.author_display_name = resolve_puzzle_work_author_by_user_id(
|
||||
state,
|
||||
&profile.owner_user_id,
|
||||
Some(&profile.author_display_name),
|
||||
@@ -541,6 +547,10 @@ pub(super) fn map_puzzle_runtime_level_response(
|
||||
cover_image_src: level.cover_image_src,
|
||||
ui_background_image_src: level.ui_background_image_src,
|
||||
ui_background_image_object_key: level.ui_background_image_object_key,
|
||||
level_background_image_src: level.level_background_image_src,
|
||||
level_background_image_object_key: level.level_background_image_object_key,
|
||||
ui_spritesheet_image_src: level.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: level.ui_spritesheet_image_object_key,
|
||||
background_music: level
|
||||
.background_music
|
||||
.map(map_puzzle_audio_asset_record_response),
|
||||
@@ -632,7 +642,7 @@ pub(super) fn map_puzzle_board_response(
|
||||
}
|
||||
|
||||
pub(super) fn resolve_author_display_name(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
authenticated: &AuthenticatedAccessToken,
|
||||
) -> String {
|
||||
state
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
pub(super) async fn generate_puzzle_work_tags(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
work_title: &str,
|
||||
work_description: &str,
|
||||
) -> Vec<String> {
|
||||
@@ -143,7 +143,7 @@ pub(super) fn build_fallback_puzzle_tags(
|
||||
}
|
||||
|
||||
pub(super) async fn save_generated_puzzle_tags_to_session(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
session_id: &str,
|
||||
owner_user_id: &str,
|
||||
payload: &ExecutePuzzleAgentActionRequest,
|
||||
@@ -278,6 +278,12 @@ pub(super) fn serialize_puzzle_level_records_for_module(
|
||||
"ui_background_prompt": level.ui_background_prompt,
|
||||
"ui_background_image_src": level.ui_background_image_src,
|
||||
"ui_background_image_object_key": level.ui_background_image_object_key,
|
||||
"level_scene_image_src": level.level_scene_image_src,
|
||||
"level_scene_image_object_key": level.level_scene_image_object_key,
|
||||
"ui_spritesheet_image_src": level.ui_spritesheet_image_src,
|
||||
"ui_spritesheet_image_object_key": level.ui_spritesheet_image_object_key,
|
||||
"level_background_image_src": level.level_background_image_src,
|
||||
"level_background_image_object_key": level.level_background_image_object_key,
|
||||
"background_music": puzzle_audio_asset_record_module_json(&level.background_music),
|
||||
"candidates": level
|
||||
.candidates
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use crate::openai_image_generation::GPT_IMAGE_2_MODEL;
|
||||
|
||||
#[test]
|
||||
fn puzzle_generated_image_size_is_square_1_1() {
|
||||
@@ -7,7 +8,7 @@ fn puzzle_generated_image_size_is_square_1_1() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_request_uses_gpt_image_2_all_and_reference_images() {
|
||||
fn puzzle_vector_engine_create_request_uses_gpt_image_2_without_reference_images() {
|
||||
let body = build_puzzle_vector_engine_image_request_body(
|
||||
PuzzleImageModel::Gemini31FlashPreview,
|
||||
"一只猫在雨夜灯牌下回头。",
|
||||
@@ -17,7 +18,7 @@ fn puzzle_vector_engine_request_uses_gpt_image_2_all_and_reference_images() {
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(body["model"], VECTOR_ENGINE_GPT_IMAGE_2_MODEL);
|
||||
assert_eq!(body["model"], GPT_IMAGE_2_MODEL);
|
||||
assert_eq!(body["size"], PUZZLE_VECTOR_ENGINE_GENERATED_IMAGE_SIZE);
|
||||
assert_eq!(body["n"], 1);
|
||||
assert!(body.get("official_fallback").is_none());
|
||||
@@ -31,7 +32,7 @@ fn puzzle_vector_engine_request_uses_gpt_image_2_all_and_reference_images() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_generation_fallback_includes_reference_image() {
|
||||
fn puzzle_vector_engine_create_request_never_embeds_reference_image() {
|
||||
let image = image::DynamicImage::ImageRgb8(image::RgbImage::new(4, 4));
|
||||
let mut cursor = std::io::Cursor::new(Vec::new());
|
||||
image
|
||||
@@ -41,6 +42,7 @@ fn puzzle_vector_engine_generation_fallback_includes_reference_image() {
|
||||
mime_type: "image/png".to_string(),
|
||||
bytes_len: cursor.get_ref().len(),
|
||||
bytes: cursor.into_inner(),
|
||||
signed_read_url: None,
|
||||
};
|
||||
|
||||
let body = build_puzzle_vector_engine_image_request_body(
|
||||
@@ -52,20 +54,185 @@ fn puzzle_vector_engine_generation_fallback_includes_reference_image() {
|
||||
Some(&reference_image),
|
||||
);
|
||||
|
||||
let images = body["image"]
|
||||
.as_array()
|
||||
.expect("fallback generation should include reference image array");
|
||||
assert_eq!(images.len(), 1);
|
||||
assert!(body.get("image").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_level_scene_spritesheet_and_background_requests_use_references() {
|
||||
let image = image::DynamicImage::ImageRgb8(image::RgbImage::new(4, 4));
|
||||
let mut cursor = std::io::Cursor::new(Vec::new());
|
||||
image
|
||||
.write_to(&mut cursor, ImageFormat::Png)
|
||||
.expect("test image should encode");
|
||||
let reference_image = PuzzleDownloadedImage {
|
||||
extension: "png".to_string(),
|
||||
mime_type: "image/png".to_string(),
|
||||
bytes: cursor.into_inner(),
|
||||
};
|
||||
|
||||
let scene_body = build_puzzle_level_scene_image_request_body_for_test(&reference_image)
|
||||
.expect("scene request should build");
|
||||
assert_eq!(scene_body["model"], GPT_IMAGE_2_MODEL);
|
||||
assert_eq!(scene_body["size"], "1024x1536");
|
||||
assert!(scene_body.get("image").is_none());
|
||||
assert!(
|
||||
images[0]
|
||||
scene_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.starts_with("data:image/png;base64,")
|
||||
.contains("参考图作为拼图画面")
|
||||
);
|
||||
assert!(
|
||||
scene_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("道具按钮上不要显示次数标注")
|
||||
);
|
||||
assert!(
|
||||
scene_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("返回按钮和设置按钮旁禁止标注文字")
|
||||
);
|
||||
|
||||
let spritesheet_body = build_puzzle_ui_spritesheet_request_body_for_test(&reference_image)
|
||||
.expect("spritesheet request should build");
|
||||
assert_eq!(spritesheet_body["model"], GPT_IMAGE_2_MODEL);
|
||||
assert_eq!(spritesheet_body["size"], "1024x1024");
|
||||
assert!(
|
||||
spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("返回按钮、设置按钮、下一关按钮、提示按钮、原图按钮、冻结按钮")
|
||||
);
|
||||
assert!(
|
||||
spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("纯绿色绿幕背景")
|
||||
);
|
||||
assert!(
|
||||
spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("绿幕扣成透明")
|
||||
);
|
||||
assert!(
|
||||
spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("自动边界检测")
|
||||
);
|
||||
assert!(
|
||||
spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("按钮素材内必须保留对应中文文字")
|
||||
);
|
||||
assert!(
|
||||
spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("不要额外画白色外圈")
|
||||
);
|
||||
assert!(
|
||||
spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("白底圆环")
|
||||
);
|
||||
assert!(
|
||||
!spritesheet_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("禁止文字")
|
||||
);
|
||||
|
||||
let background_body = build_puzzle_level_background_request_body_for_test(&reference_image)
|
||||
.expect("background request should build");
|
||||
assert_eq!(background_body["model"], GPT_IMAGE_2_MODEL);
|
||||
assert_eq!(background_body["size"], "1024x1536");
|
||||
assert!(
|
||||
background_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("移除参考图中所有UI元素")
|
||||
);
|
||||
assert!(
|
||||
background_body["prompt"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.contains("禁止在背景中出现人像或和拼图画面中主体一致的内容")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_edit_url_uses_images_edits_endpoint() {
|
||||
fn puzzle_ui_spritesheet_postprocess_turns_green_screen_transparent() {
|
||||
let mut source = image::RgbaImage::from_pixel(8, 8, image::Rgba([0, 255, 0, 255]));
|
||||
for y in 2..6 {
|
||||
for x in 2..6 {
|
||||
source.put_pixel(x, y, image::Rgba([190, 78, 42, 255]));
|
||||
}
|
||||
}
|
||||
let mut cursor = std::io::Cursor::new(Vec::new());
|
||||
image::DynamicImage::ImageRgba8(source)
|
||||
.write_to(&mut cursor, ImageFormat::Png)
|
||||
.expect("test image should encode");
|
||||
|
||||
let processed = make_puzzle_ui_spritesheet_image_transparent_for_test(PuzzleDownloadedImage {
|
||||
extension: "png".to_string(),
|
||||
mime_type: "image/png".to_string(),
|
||||
bytes: cursor.into_inner(),
|
||||
})
|
||||
.expect("green screen postprocess should succeed");
|
||||
|
||||
assert_eq!(processed.extension, "png");
|
||||
assert_eq!(processed.mime_type, "image/png");
|
||||
let decoded = image::load_from_memory(processed.bytes.as_slice())
|
||||
.expect("processed image should decode")
|
||||
.to_rgba8();
|
||||
assert_eq!(decoded.get_pixel(0, 0).0[3], 0);
|
||||
assert_eq!(decoded.get_pixel(3, 3).0[3], 255);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_create_request_never_embeds_signed_reference_url() {
|
||||
let reference_image = PuzzleResolvedReferenceImage {
|
||||
mime_type: "image/png".to_string(),
|
||||
bytes_len: 4,
|
||||
bytes: b"test".to_vec(),
|
||||
signed_read_url: Some(
|
||||
"https://oss.example/generated-puzzle-assets/reference.png?x-oss-signature=abc"
|
||||
.to_string(),
|
||||
),
|
||||
};
|
||||
|
||||
let body = build_puzzle_vector_engine_image_request_body(
|
||||
PuzzleImageModel::GptImage2,
|
||||
"参考图里的小猫做成拼图主图。",
|
||||
PUZZLE_DEFAULT_NEGATIVE_PROMPT,
|
||||
PUZZLE_VECTOR_ENGINE_GENERATED_IMAGE_SIZE,
|
||||
1,
|
||||
Some(&reference_image),
|
||||
);
|
||||
|
||||
assert!(body.get("image").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_generation_url_normalizes_base_url() {
|
||||
let settings = PuzzleVectorEngineSettings {
|
||||
base_url: "https://vector.example/v1".to_string(),
|
||||
api_key: "test-key".to_string(),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
puzzle_vector_engine_images_generation_url(&settings),
|
||||
"https://vector.example/v1/images/generations"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_edit_url_normalizes_base_url() {
|
||||
let settings = PuzzleVectorEngineSettings {
|
||||
base_url: "https://vector.example/v1".to_string(),
|
||||
api_key: "test-key".to_string(),
|
||||
@@ -107,18 +274,31 @@ fn puzzle_vector_engine_prompt_keeps_text_only_prompt_unchanged() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_reference_image_edit_requires_ai_redraw() {
|
||||
assert!(!should_use_puzzle_reference_image_edit(None, true));
|
||||
assert!(!should_use_puzzle_reference_image_edit(
|
||||
fn puzzle_reference_image_generation_requires_ai_redraw() {
|
||||
assert!(!should_use_puzzle_reference_image_generation(None, true));
|
||||
assert!(!should_use_puzzle_reference_image_generation(
|
||||
Some("data:image/png;base64,abcd"),
|
||||
false
|
||||
));
|
||||
assert!(should_use_puzzle_reference_image_edit(
|
||||
assert!(should_use_puzzle_reference_image_generation(
|
||||
Some("data:image/png;base64,abcd"),
|
||||
true
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_result_level_direct_upload_skips_cover_image_generation() {
|
||||
assert!(should_use_uploaded_puzzle_image_directly(
|
||||
Some("data:image/png;base64,abcd"),
|
||||
false
|
||||
));
|
||||
assert!(!should_use_uploaded_puzzle_image_directly(
|
||||
Some("data:image/png;base64,abcd"),
|
||||
true
|
||||
));
|
||||
assert!(!should_use_uploaded_puzzle_image_directly(None, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_reference_image_sources_are_deduped_and_limited() {
|
||||
let sources = collect_puzzle_reference_image_sources(
|
||||
@@ -131,6 +311,8 @@ fn puzzle_reference_image_sources_are_deduped_and_limited() {
|
||||
"data:image/png;base64,e".to_string(),
|
||||
"data:image/png;base64,f".to_string(),
|
||||
],
|
||||
None,
|
||||
&[],
|
||||
);
|
||||
|
||||
assert_eq!(sources.len(), 5);
|
||||
@@ -139,6 +321,62 @@ fn puzzle_reference_image_sources_are_deduped_and_limited() {
|
||||
assert!(!sources.contains(&"data:image/png;base64,f".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_reference_image_sources_prefer_asset_object_ids() {
|
||||
let sources = collect_puzzle_reference_image_sources(
|
||||
Some("data:image/png;base64,legacy"),
|
||||
&["/generated-puzzle-assets/legacy.png".to_string()],
|
||||
Some("asset-main-1"),
|
||||
&[
|
||||
"asset-main-1".to_string(),
|
||||
"asset-prompt-1".to_string(),
|
||||
"asset-prompt-2".to_string(),
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
sources,
|
||||
vec![
|
||||
"asset-object:asset-main-1".to_string(),
|
||||
"asset-object:asset-prompt-1".to_string(),
|
||||
"asset-object:asset-prompt-2".to_string(),
|
||||
"data:image/png;base64,legacy".to_string(),
|
||||
"/generated-puzzle-assets/legacy.png".to_string(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_asset_object_reference_requires_matching_owner() {
|
||||
let asset_object = module_assets::AssetObjectRecord {
|
||||
asset_object_id: "assetobj_reference_1".to_string(),
|
||||
bucket: "genarrative-assets".to_string(),
|
||||
object_key: "generated-puzzle-assets/reference/image.png".to_string(),
|
||||
access_policy: module_assets::AssetObjectAccessPolicy::Private,
|
||||
content_type: Some("image/png".to_string()),
|
||||
content_length: 1024,
|
||||
content_hash: None,
|
||||
version: 1,
|
||||
source_job_id: None,
|
||||
owner_user_id: Some("user-other".to_string()),
|
||||
profile_id: None,
|
||||
entity_id: None,
|
||||
asset_kind: "puzzle_cover_image".to_string(),
|
||||
created_at: "2026-05-21T00:00:00Z".to_string(),
|
||||
updated_at: "2026-05-21T00:00:00Z".to_string(),
|
||||
};
|
||||
|
||||
let error = validate_puzzle_reference_asset_object(
|
||||
&asset_object,
|
||||
Some("user-current"),
|
||||
"genarrative-assets",
|
||||
)
|
||||
.expect_err("其他账号的参考图资产应被拒绝");
|
||||
|
||||
assert_eq!(error.status_code(), StatusCode::FORBIDDEN);
|
||||
assert!(error.body_text().contains("不属于当前账号"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_timeout_maps_to_gateway_timeout() {
|
||||
let error = map_puzzle_vector_engine_request_error(
|
||||
@@ -153,51 +391,14 @@ fn puzzle_vector_engine_timeout_maps_to_gateway_timeout() {
|
||||
fn puzzle_vector_engine_upstream_timeout_maps_to_gateway_timeout() {
|
||||
let error = map_puzzle_vector_engine_upstream_error(
|
||||
reqwest::StatusCode::GATEWAY_TIMEOUT,
|
||||
r#"{"error":{"message":"VectorEngine edit endpoint timeout"}}"#,
|
||||
"创建拼图 VectorEngine 图片编辑任务失败",
|
||||
r#"{"error":{"message":"VectorEngine generation endpoint timeout"}}"#,
|
||||
"创建拼图 VectorEngine 图片生成任务失败",
|
||||
);
|
||||
|
||||
let response = error.into_response();
|
||||
assert_eq!(response.status(), StatusCode::GATEWAY_TIMEOUT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_reference_edit_fallback_only_accepts_timeout_errors() {
|
||||
let timeout_error = map_puzzle_vector_engine_upstream_error(
|
||||
reqwest::StatusCode::GATEWAY_TIMEOUT,
|
||||
r#"{"error":{"message":"VectorEngine edit endpoint timeout"}}"#,
|
||||
"创建拼图 VectorEngine 图片编辑任务失败",
|
||||
);
|
||||
assert!(should_fallback_puzzle_reference_edit_to_generation(
|
||||
&timeout_error
|
||||
));
|
||||
|
||||
let auth_error = map_puzzle_vector_engine_upstream_error(
|
||||
reqwest::StatusCode::UNAUTHORIZED,
|
||||
r#"{"error":{"message":"invalid api key"}}"#,
|
||||
"创建拼图 VectorEngine 图片编辑任务失败",
|
||||
);
|
||||
assert!(!should_fallback_puzzle_reference_edit_to_generation(
|
||||
&auth_error
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_vector_engine_reqwest_error_maps_to_bad_gateway() {
|
||||
let error = match reqwest::Client::new().get("http://[::1").build() {
|
||||
Ok(_) => panic!("invalid url should fail request build"),
|
||||
Err(error) => error,
|
||||
};
|
||||
let app_error = map_puzzle_vector_engine_reqwest_error(
|
||||
"创建拼图 VectorEngine 图片编辑任务失败",
|
||||
"https://api.vectorengine.ai/v1/images/edits",
|
||||
error,
|
||||
);
|
||||
|
||||
let response = app_error.into_response();
|
||||
assert_eq!(response.status(), StatusCode::BAD_GATEWAY);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_compile_error_preserves_vector_engine_unavailable_status() {
|
||||
let error = map_puzzle_compile_error(SpacetimeClientError::Runtime(
|
||||
@@ -250,6 +451,8 @@ fn puzzle_image_generation_builds_fallback_session_from_levels_snapshot() {
|
||||
prompt_text: None,
|
||||
reference_image_src: None,
|
||||
reference_image_srcs: Vec::new(),
|
||||
reference_image_asset_object_id: None,
|
||||
reference_image_asset_object_ids: Vec::new(),
|
||||
image_model: Some(PUZZLE_IMAGE_MODEL_GPT_IMAGE_2.to_string()),
|
||||
ai_redraw: None,
|
||||
candidate_count: Some(1),
|
||||
@@ -383,6 +586,7 @@ fn puzzle_uploaded_cover_can_reuse_resolved_history_image() {
|
||||
mime_type: "image/png".to_string(),
|
||||
bytes_len: 8,
|
||||
bytes: b"pngbytes".to_vec(),
|
||||
signed_read_url: None,
|
||||
};
|
||||
|
||||
let downloaded = PuzzleDownloadedImage::from_resolved_reference_image(resolved);
|
||||
@@ -410,6 +614,8 @@ fn puzzle_first_level_name_snapshot_defaults_work_title() {
|
||||
prompt_text: None,
|
||||
reference_image_src: None,
|
||||
reference_image_srcs: Vec::new(),
|
||||
reference_image_asset_object_id: None,
|
||||
reference_image_asset_object_ids: Vec::new(),
|
||||
image_model: Some(PUZZLE_IMAGE_MODEL_GPT_IMAGE_2.to_string()),
|
||||
ai_redraw: None,
|
||||
candidate_count: Some(1),
|
||||
@@ -510,6 +716,12 @@ fn puzzle_level_audio_asset_roundtrips_between_response_and_module_json() {
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: Some(CreationAudioAsset {
|
||||
task_id: "suno-task-1".to_string(),
|
||||
provider: "vector-engine-suno".to_string(),
|
||||
@@ -575,6 +787,12 @@ fn puzzle_ui_background_fields_roundtrip_between_response_and_module_json() {
|
||||
ui_background_image_object_key: Some(
|
||||
"generated-puzzle-assets/session/ui/background.png".to_string(),
|
||||
),
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: vec![],
|
||||
selected_candidate_id: None,
|
||||
@@ -612,9 +830,86 @@ fn puzzle_ui_background_fields_roundtrip_between_response_and_module_json() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_level_asset_bundle_fields_roundtrip_between_response_and_module_json() {
|
||||
let level = PuzzleDraftLevelResponse {
|
||||
level_id: "puzzle-level-1".to_string(),
|
||||
level_name: "雨夜猫街".to_string(),
|
||||
picture_description: "一只猫在雨夜灯牌下回头。".to_string(),
|
||||
picture_reference: None,
|
||||
ui_background_prompt: Some("雨夜猫街竖屏拼图UI背景".to_string()),
|
||||
ui_background_image_src: Some(
|
||||
"/generated-puzzle-assets/session/legacy-ui/background.png".to_string(),
|
||||
),
|
||||
ui_background_image_object_key: Some(
|
||||
"generated-puzzle-assets/session/legacy-ui/background.png".to_string(),
|
||||
),
|
||||
level_scene_image_src: Some(
|
||||
"/generated-puzzle-assets/session/level-scene/scene.png".to_string(),
|
||||
),
|
||||
level_scene_image_object_key: Some(
|
||||
"generated-puzzle-assets/session/level-scene/scene.png".to_string(),
|
||||
),
|
||||
ui_spritesheet_image_src: Some(
|
||||
"/generated-puzzle-assets/session/ui-spritesheet/sheet.png".to_string(),
|
||||
),
|
||||
ui_spritesheet_image_object_key: Some(
|
||||
"generated-puzzle-assets/session/ui-spritesheet/sheet.png".to_string(),
|
||||
),
|
||||
level_background_image_src: Some(
|
||||
"/generated-puzzle-assets/session/level-background/background.png".to_string(),
|
||||
),
|
||||
level_background_image_object_key: Some(
|
||||
"generated-puzzle-assets/session/level-background/background.png".to_string(),
|
||||
),
|
||||
background_music: None,
|
||||
candidates: vec![],
|
||||
selected_candidate_id: None,
|
||||
cover_image_src: Some("/generated-puzzle-assets/session/cover.png".to_string()),
|
||||
cover_asset_id: Some("asset-1".to_string()),
|
||||
generation_status: "ready".to_string(),
|
||||
};
|
||||
let request_context = RequestContext::new(
|
||||
"test-request".to_string(),
|
||||
"PUT /api/runtime/puzzle/works/test".to_string(),
|
||||
Duration::ZERO,
|
||||
false,
|
||||
);
|
||||
|
||||
let levels_json = serialize_puzzle_levels_response(&request_context, &[level])
|
||||
.expect("levels should serialize");
|
||||
let payload: Value = serde_json::from_str(&levels_json).expect("levels json should parse");
|
||||
assert_eq!(
|
||||
payload[0]["level_background_image_object_key"],
|
||||
Value::String(
|
||||
"generated-puzzle-assets/session/level-background/background.png".to_string()
|
||||
)
|
||||
);
|
||||
assert!(payload[0].get("levelBackgroundImageObjectKey").is_none());
|
||||
|
||||
let records = parse_puzzle_level_records_from_module_json(&levels_json)
|
||||
.expect("levels should map back into records");
|
||||
assert_eq!(
|
||||
records[0].level_scene_image_src.as_deref(),
|
||||
Some("/generated-puzzle-assets/session/level-scene/scene.png")
|
||||
);
|
||||
assert_eq!(
|
||||
records[0].ui_spritesheet_image_object_key.as_deref(),
|
||||
Some("generated-puzzle-assets/session/ui-spritesheet/sheet.png")
|
||||
);
|
||||
|
||||
let response = map_puzzle_draft_level_response(records[0].clone());
|
||||
assert_eq!(
|
||||
response.level_background_image_src.as_deref(),
|
||||
Some("/generated-puzzle-assets/session/level-background/background.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_work_summary_response_keeps_levels_for_shelf_cover() {
|
||||
let state = AppState::new(crate::config::AppConfig::default()).expect("state should build");
|
||||
let app_state = crate::state::AppState::new(crate::config::AppConfig::default())
|
||||
.expect("state should build");
|
||||
let state: PuzzleApiState = axum::extract::FromRef::from_ref(&app_state);
|
||||
let level = PuzzleDraftLevelRecord {
|
||||
level_id: "puzzle-level-1".to_string(),
|
||||
level_name: "雨夜猫街".to_string(),
|
||||
@@ -623,6 +918,12 @@ fn puzzle_work_summary_response_keeps_levels_for_shelf_cover() {
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: vec![PuzzleGeneratedImageCandidateRecord {
|
||||
candidate_id: "candidate-1".to_string(),
|
||||
@@ -756,12 +1057,15 @@ fn puzzle_initial_draft_assets_must_include_ui_background() {
|
||||
let missing_all = ensure_puzzle_initial_level_assets_ready(&draft.levels[0])
|
||||
.expect_err("缺少自动生成资产时不能把草稿标记为完成");
|
||||
assert_eq!(missing_all.status_code(), StatusCode::BAD_GATEWAY);
|
||||
assert!(missing_all.body_text().contains("UI背景图"));
|
||||
assert!(missing_all.body_text().contains("关卡背景图"));
|
||||
assert!(missing_all.body_text().contains("UI spritesheet"));
|
||||
|
||||
draft.levels[0].ui_background_image_src =
|
||||
Some("/generated-puzzle-assets/session/ui/background.png".to_string());
|
||||
draft.levels[0].level_background_image_src =
|
||||
Some("/generated-puzzle-assets/session/background/background.png".to_string());
|
||||
draft.levels[0].ui_spritesheet_image_src =
|
||||
Some("/generated-puzzle-assets/session/spritesheet/sheet.png".to_string());
|
||||
ensure_puzzle_initial_level_assets_ready(&draft.levels[0])
|
||||
.expect("UI 背景存在时即可完成自动草稿资源检查");
|
||||
.expect("关卡背景和 UI spritesheet 存在时即可完成自动草稿资源检查");
|
||||
}
|
||||
|
||||
fn test_puzzle_anchor_pack_record() -> PuzzleAnchorPackRecord {
|
||||
@@ -805,6 +1109,12 @@ fn test_puzzle_draft_record() -> PuzzleResultDraftRecord {
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: vec![],
|
||||
selected_candidate_id: None,
|
||||
|
||||
@@ -12,7 +12,7 @@ impl PuzzleImageModel {
|
||||
}
|
||||
|
||||
pub(crate) fn request_model_name(self) -> &'static str {
|
||||
VECTOR_ENGINE_GPT_IMAGE_2_MODEL
|
||||
GPT_IMAGE_2_MODEL
|
||||
}
|
||||
|
||||
pub(crate) fn candidate_source_type(self) -> &'static str {
|
||||
@@ -37,6 +37,7 @@ pub(crate) struct PuzzleResolvedReferenceImage {
|
||||
pub(crate) mime_type: String,
|
||||
pub(crate) bytes_len: usize,
|
||||
pub(crate) bytes: Vec<u8>,
|
||||
pub(crate) signed_read_url: Option<String>,
|
||||
}
|
||||
|
||||
pub(crate) struct GeneratedPuzzleImageCandidate {
|
||||
@@ -94,13 +95,26 @@ pub(crate) struct GeneratedPuzzleUiBackgroundResponse {
|
||||
pub(crate) object_key: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct GeneratedPuzzleLevelAssetResponse {
|
||||
pub(crate) image_src: String,
|
||||
pub(crate) object_key: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct GeneratedPuzzleLevelAssetBundle {
|
||||
pub(crate) level_scene: GeneratedPuzzleLevelAssetResponse,
|
||||
pub(crate) ui_spritesheet: GeneratedPuzzleLevelAssetResponse,
|
||||
pub(crate) level_background: GeneratedPuzzleLevelAssetResponse,
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_puzzle_image_model(value: Option<&str>) -> PuzzleImageModel {
|
||||
match value.map(str::trim).filter(|value| !value.is_empty()) {
|
||||
Some(PUZZLE_IMAGE_MODEL_GEMINI_31_FLASH_PREVIEW) => {
|
||||
tracing::warn!(
|
||||
requested_model = PUZZLE_IMAGE_MODEL_GEMINI_31_FLASH_PREVIEW,
|
||||
effective_model = VECTOR_ENGINE_GPT_IMAGE_2_MODEL,
|
||||
"拼图 nanobanana2 历史选项已回落到 VectorEngine GPT-image-2-all"
|
||||
effective_model = GPT_IMAGE_2_MODEL,
|
||||
"拼图 nanobanana2 历史选项已回落到 VectorEngine GPT-image-2"
|
||||
);
|
||||
PuzzleImageModel::Gemini31FlashPreview
|
||||
}
|
||||
@@ -109,13 +123,9 @@ pub(crate) fn resolve_puzzle_image_model(value: Option<&str>) -> PuzzleImageMode
|
||||
}
|
||||
|
||||
pub(crate) fn require_puzzle_vector_engine_settings(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
) -> Result<PuzzleVectorEngineSettings, AppError> {
|
||||
let base_url = state
|
||||
.config
|
||||
.vector_engine_base_url
|
||||
.trim()
|
||||
.trim_end_matches('/');
|
||||
let base_url = state.vector_engine_base_url().trim().trim_end_matches('/');
|
||||
if base_url.is_empty() {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::SERVICE_UNAVAILABLE).with_details(json!({
|
||||
@@ -127,9 +137,7 @@ pub(crate) fn require_puzzle_vector_engine_settings(
|
||||
}
|
||||
|
||||
let api_key = state
|
||||
.config
|
||||
.vector_engine_api_key
|
||||
.as_deref()
|
||||
.vector_engine_api_key()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.ok_or_else(|| {
|
||||
@@ -147,15 +155,15 @@ pub(crate) fn require_puzzle_vector_engine_settings(
|
||||
}
|
||||
|
||||
pub(crate) fn build_puzzle_image_http_client(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
image_model: PuzzleImageModel,
|
||||
) -> Result<reqwest::Client, AppError> {
|
||||
let provider = image_model.provider_name();
|
||||
let request_timeout_ms = state.config.vector_engine_image_request_timeout_ms;
|
||||
let request_timeout_ms = state.vector_engine_image_request_timeout_ms();
|
||||
|
||||
reqwest::Client::builder()
|
||||
.timeout(Duration::from_millis(request_timeout_ms.max(1)))
|
||||
// 中文注释:VectorEngine 的图片编辑接口是 multipart 请求;强制 HTTP/1.1 可避开部分网关对 HTTP/2 multipart 流的中断兼容问题。
|
||||
// 中文注释:参考图走 multipart edits;强制 HTTP/1.1 可降低部分网关对长耗时上传流的兼容风险。
|
||||
.http1_only()
|
||||
.build()
|
||||
.map_err(|error| {
|
||||
@@ -191,6 +199,20 @@ pub(crate) async fn create_puzzle_vector_engine_image_generation(
|
||||
candidate_count: u32,
|
||||
reference_image: Option<&PuzzleResolvedReferenceImage>,
|
||||
) -> Result<PuzzleGeneratedImages, AppError> {
|
||||
if let Some(reference_image) = reference_image {
|
||||
return create_puzzle_vector_engine_image_edit(
|
||||
http_client,
|
||||
settings,
|
||||
image_model,
|
||||
prompt,
|
||||
negative_prompt,
|
||||
size,
|
||||
candidate_count,
|
||||
reference_image,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
let request_body = build_puzzle_vector_engine_image_request_body(
|
||||
image_model,
|
||||
prompt,
|
||||
@@ -267,6 +289,15 @@ pub(crate) async fn create_puzzle_vector_engine_image_generation(
|
||||
return Ok(images);
|
||||
}
|
||||
|
||||
let b64_images = extract_puzzle_b64_images(&payload);
|
||||
if !b64_images.is_empty() {
|
||||
return Ok(puzzle_images_from_base64(
|
||||
format!("vector-engine-{}", current_utc_micros()),
|
||||
b64_images,
|
||||
candidate_count,
|
||||
));
|
||||
}
|
||||
|
||||
Err(
|
||||
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
|
||||
"provider": VECTOR_ENGINE_PROVIDER,
|
||||
@@ -278,6 +309,7 @@ pub(crate) async fn create_puzzle_vector_engine_image_generation(
|
||||
pub(crate) async fn create_puzzle_vector_engine_image_edit(
|
||||
http_client: &reqwest::Client,
|
||||
settings: &PuzzleVectorEngineSettings,
|
||||
image_model: PuzzleImageModel,
|
||||
prompt: &str,
|
||||
negative_prompt: &str,
|
||||
size: &str,
|
||||
@@ -300,7 +332,7 @@ pub(crate) async fn create_puzzle_vector_engine_image_edit(
|
||||
})?;
|
||||
let form = reqwest::multipart::Form::new()
|
||||
.part("image", image_part)
|
||||
.text("model", PUZZLE_VECTOR_ENGINE_IMAGE_EDIT_MODEL.to_string())
|
||||
.text("model", image_model.request_model_name().to_string())
|
||||
.text(
|
||||
"prompt",
|
||||
build_puzzle_vector_engine_prompt(prompt, negative_prompt),
|
||||
@@ -319,16 +351,14 @@ pub(crate) async fn create_puzzle_vector_engine_image_edit(
|
||||
.send()
|
||||
.await
|
||||
.map_err(|error| {
|
||||
map_puzzle_vector_engine_reqwest_error(
|
||||
"创建拼图 VectorEngine 图片编辑任务失败",
|
||||
&request_url,
|
||||
error,
|
||||
)
|
||||
map_puzzle_vector_engine_request_error(format!(
|
||||
"创建拼图 VectorEngine 图片编辑任务失败:{error}"
|
||||
))
|
||||
})?;
|
||||
let status = response.status();
|
||||
tracing::info!(
|
||||
provider = VECTOR_ENGINE_PROVIDER,
|
||||
image_model = PUZZLE_VECTOR_ENGINE_IMAGE_EDIT_MODEL,
|
||||
image_model = image_model.request_model_name(),
|
||||
endpoint = %request_url,
|
||||
status = status.as_u16(),
|
||||
prompt_chars = prompt.chars().count(),
|
||||
@@ -377,6 +407,17 @@ pub(crate) async fn create_puzzle_vector_engine_image_edit(
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn build_puzzle_downloaded_image_reference(
|
||||
image: &PuzzleDownloadedImage,
|
||||
) -> PuzzleResolvedReferenceImage {
|
||||
PuzzleResolvedReferenceImage {
|
||||
mime_type: image.mime_type.clone(),
|
||||
bytes_len: image.bytes.len(),
|
||||
bytes: image.bytes.clone(),
|
||||
signed_read_url: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn build_puzzle_vector_engine_image_request_body(
|
||||
image_model: PuzzleImageModel,
|
||||
prompt: &str,
|
||||
@@ -385,7 +426,7 @@ pub(crate) fn build_puzzle_vector_engine_image_request_body(
|
||||
candidate_count: u32,
|
||||
reference_image: Option<&PuzzleResolvedReferenceImage>,
|
||||
) -> Value {
|
||||
let mut body = Map::from_iter([
|
||||
let body = Map::from_iter([
|
||||
(
|
||||
"model".to_string(),
|
||||
Value::String(image_model.request_model_name().to_string()),
|
||||
@@ -397,12 +438,7 @@ pub(crate) fn build_puzzle_vector_engine_image_request_body(
|
||||
("n".to_string(), json!(candidate_count.clamp(1, 1))),
|
||||
("size".to_string(), Value::String(size.to_string())),
|
||||
]);
|
||||
if let Some(reference_image) = reference_image
|
||||
&& let Some(reference_data_url) =
|
||||
build_puzzle_generation_reference_image_data_url(reference_image)
|
||||
{
|
||||
body.insert("image".to_string(), json!([reference_data_url]));
|
||||
}
|
||||
let _ = reference_image;
|
||||
|
||||
Value::Object(body)
|
||||
}
|
||||
@@ -426,32 +462,6 @@ pub(crate) fn build_puzzle_vector_engine_generation_prompt(
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn build_puzzle_generation_reference_image_data_url(
|
||||
image: &PuzzleResolvedReferenceImage,
|
||||
) -> Option<String> {
|
||||
let bytes = resize_puzzle_generation_reference_image_bytes(image.bytes.as_slice())
|
||||
.unwrap_or_else(|| image.bytes.clone());
|
||||
let mime_type = if bytes.starts_with(b"\x89PNG\r\n\x1A\n") {
|
||||
"image/png"
|
||||
} else {
|
||||
image.mime_type.as_str()
|
||||
};
|
||||
|
||||
Some(format!(
|
||||
"data:{};base64,{}",
|
||||
normalize_puzzle_downloaded_image_mime_type(mime_type),
|
||||
BASE64_STANDARD.encode(bytes)
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) fn resize_puzzle_generation_reference_image_bytes(bytes: &[u8]) -> Option<Vec<u8>> {
|
||||
let image = image::load_from_memory(bytes).ok()?;
|
||||
let resized = image.resize(1024, 1024, image::imageops::FilterType::Triangle);
|
||||
let mut cursor = std::io::Cursor::new(Vec::new());
|
||||
resized.write_to(&mut cursor, ImageFormat::Png).ok()?;
|
||||
Some(cursor.into_inner())
|
||||
}
|
||||
|
||||
pub(crate) fn has_puzzle_reference_image(reference_image_src: Option<&str>) -> bool {
|
||||
reference_image_src
|
||||
.map(str::trim)
|
||||
@@ -462,6 +472,48 @@ pub(crate) fn has_puzzle_reference_image(reference_image_src: Option<&str>) -> b
|
||||
pub(crate) fn collect_puzzle_reference_image_sources(
|
||||
legacy_reference_image_src: Option<&str>,
|
||||
reference_image_srcs: &[String],
|
||||
reference_image_asset_object_id: Option<&str>,
|
||||
reference_image_asset_object_ids: &[String],
|
||||
) -> Vec<String> {
|
||||
let mut sources = Vec::new();
|
||||
for source in reference_image_asset_object_id
|
||||
.into_iter()
|
||||
.chain(reference_image_asset_object_ids.iter().map(String::as_str))
|
||||
.map(|asset_object_id| {
|
||||
asset_object_id
|
||||
.trim()
|
||||
.strip_prefix("asset-object:")
|
||||
.unwrap_or_else(|| asset_object_id.trim())
|
||||
})
|
||||
.filter(|asset_object_id| !asset_object_id.is_empty())
|
||||
.map(|asset_object_id| format!("asset-object:{asset_object_id}"))
|
||||
.chain(
|
||||
legacy_reference_image_src
|
||||
.into_iter()
|
||||
.chain(reference_image_srcs.iter().map(String::as_str))
|
||||
.map(str::to_string),
|
||||
)
|
||||
{
|
||||
let normalized = source.trim();
|
||||
if normalized.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if !sources
|
||||
.iter()
|
||||
.any(|existing: &String| existing == normalized)
|
||||
{
|
||||
sources.push(normalized.to_string());
|
||||
}
|
||||
if sources.len() >= PUZZLE_REFERENCE_IMAGE_SOURCE_LIMIT {
|
||||
break;
|
||||
}
|
||||
}
|
||||
sources
|
||||
}
|
||||
|
||||
pub(crate) fn collect_legacy_puzzle_reference_image_sources(
|
||||
legacy_reference_image_src: Option<&str>,
|
||||
reference_image_srcs: &[String],
|
||||
) -> Vec<String> {
|
||||
let mut sources = Vec::new();
|
||||
for source in legacy_reference_image_src
|
||||
@@ -488,16 +540,23 @@ pub(crate) fn collect_puzzle_reference_image_sources(
|
||||
pub(crate) fn has_puzzle_reference_images(
|
||||
legacy_reference_image_src: Option<&str>,
|
||||
reference_image_srcs: &[String],
|
||||
reference_image_asset_object_id: Option<&str>,
|
||||
reference_image_asset_object_ids: &[String],
|
||||
) -> bool {
|
||||
!collect_puzzle_reference_image_sources(legacy_reference_image_src, reference_image_srcs)
|
||||
.is_empty()
|
||||
!collect_puzzle_reference_image_sources(
|
||||
legacy_reference_image_src,
|
||||
reference_image_srcs,
|
||||
reference_image_asset_object_id,
|
||||
reference_image_asset_object_ids,
|
||||
)
|
||||
.is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn should_use_puzzle_reference_image_edit(
|
||||
pub(crate) fn should_use_puzzle_reference_image_generation(
|
||||
reference_image_src: Option<&str>,
|
||||
use_reference_image_edit: bool,
|
||||
use_reference_image_generation: bool,
|
||||
) -> bool {
|
||||
use_reference_image_edit && has_puzzle_reference_image(reference_image_src)
|
||||
use_reference_image_generation && has_puzzle_reference_image(reference_image_src)
|
||||
}
|
||||
|
||||
pub(crate) fn build_puzzle_vector_engine_prompt(prompt: &str, negative_prompt: &str) -> String {
|
||||
@@ -546,10 +605,19 @@ pub(crate) async fn download_puzzle_images_from_urls(
|
||||
Ok(PuzzleGeneratedImages { task_id, images })
|
||||
}
|
||||
|
||||
pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
state: &AppState,
|
||||
pub(crate) fn parse_puzzle_asset_object_reference(source: &str) -> Option<&str> {
|
||||
source
|
||||
.trim()
|
||||
.strip_prefix("asset-object:")
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
}
|
||||
|
||||
pub(crate) async fn resolve_puzzle_reference_image(
|
||||
state: &PuzzleApiState,
|
||||
http_client: &reqwest::Client,
|
||||
source: &str,
|
||||
owner_user_id: Option<&str>,
|
||||
) -> Result<PuzzleResolvedReferenceImage, AppError> {
|
||||
let trimmed = source.trim();
|
||||
if trimmed.is_empty() {
|
||||
@@ -562,6 +630,16 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(asset_object_id) = parse_puzzle_asset_object_reference(trimmed) {
|
||||
return resolve_puzzle_reference_asset_object(
|
||||
state,
|
||||
http_client,
|
||||
asset_object_id,
|
||||
owner_user_id,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
if let Some(parsed) = parse_puzzle_image_data_url(trimmed) {
|
||||
let bytes_len = parsed.bytes.len();
|
||||
if bytes_len > PUZZLE_REFERENCE_IMAGE_MAX_BYTES {
|
||||
@@ -579,6 +657,7 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
mime_type: parsed.mime_type,
|
||||
bytes_len,
|
||||
bytes: parsed.bytes,
|
||||
signed_read_url: None,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -587,7 +666,7 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "puzzle",
|
||||
"field": "referenceImageSrc",
|
||||
"message": "参考图必须是 Data URL 或 /generated-* 旧路径。",
|
||||
"message": "参考图必须是 assetObjectId、Data URL 或 /generated-* 旧路径。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
@@ -598,7 +677,7 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "puzzle",
|
||||
"field": "referenceImageSrc",
|
||||
"message": "参考图当前只支持 /generated-* 旧路径。",
|
||||
"message": "参考图当前只支持 assetObjectId 或 /generated-* 旧路径。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
@@ -615,8 +694,159 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
expire_seconds: Some(60),
|
||||
})
|
||||
.map_err(map_puzzle_asset_oss_error)?;
|
||||
let signed_read_url = signed.signed_url;
|
||||
download_signed_puzzle_reference_image(
|
||||
http_client,
|
||||
signed_read_url,
|
||||
object_key,
|
||||
None,
|
||||
"referenceImageSrc",
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
state: &PuzzleApiState,
|
||||
http_client: &reqwest::Client,
|
||||
source: &str,
|
||||
) -> Result<PuzzleResolvedReferenceImage, AppError> {
|
||||
resolve_puzzle_reference_image(state, http_client, source, None).await
|
||||
}
|
||||
|
||||
async fn resolve_puzzle_reference_asset_object(
|
||||
state: &PuzzleApiState,
|
||||
http_client: &reqwest::Client,
|
||||
asset_object_id: &str,
|
||||
owner_user_id: Option<&str>,
|
||||
) -> Result<PuzzleResolvedReferenceImage, AppError> {
|
||||
let asset_object = state
|
||||
.spacetime_client()
|
||||
.get_asset_object(asset_object_id.to_string())
|
||||
.await
|
||||
.map_err(map_puzzle_client_error)?
|
||||
.ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "asset-object",
|
||||
"field": "referenceImageAssetObjectId",
|
||||
"assetObjectId": asset_object_id,
|
||||
"message": "参考图资产不存在或当前账号不可见。",
|
||||
}))
|
||||
})?;
|
||||
let oss_client = state.oss_client().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::SERVICE_UNAVAILABLE).with_details(json!({
|
||||
"provider": "aliyun-oss",
|
||||
"reason": "OSS 未完成环境变量配置",
|
||||
}))
|
||||
})?;
|
||||
validate_puzzle_reference_asset_object(
|
||||
&asset_object,
|
||||
owner_user_id,
|
||||
oss_client.config_bucket(),
|
||||
)?;
|
||||
let signed = oss_client
|
||||
.sign_get_object_url(OssSignedGetObjectUrlRequest {
|
||||
object_key: asset_object.object_key.clone(),
|
||||
expire_seconds: Some(60),
|
||||
})
|
||||
.map_err(map_puzzle_asset_oss_error)?;
|
||||
let content_type = asset_object.content_type.clone();
|
||||
download_signed_puzzle_reference_image(
|
||||
http_client,
|
||||
signed.signed_url,
|
||||
asset_object.object_key.as_str(),
|
||||
content_type.as_deref(),
|
||||
"referenceImageAssetObjectId",
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) fn validate_puzzle_reference_asset_object(
|
||||
asset_object: &module_assets::AssetObjectRecord,
|
||||
owner_user_id: Option<&str>,
|
||||
oss_bucket: &str,
|
||||
) -> Result<(), AppError> {
|
||||
if asset_object.bucket.trim() != oss_bucket.trim() {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "asset-object",
|
||||
"field": "referenceImageAssetObjectId",
|
||||
"assetObjectId": asset_object.asset_object_id,
|
||||
"message": "参考图资产 bucket 与当前服务 OSS 配置不一致。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
if asset_object.asset_kind.trim() != "puzzle_cover_image" {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "asset-object",
|
||||
"field": "referenceImageAssetObjectId",
|
||||
"assetObjectId": asset_object.asset_object_id,
|
||||
"message": "参考图资产类型不属于拼图图片。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
let content_type = asset_object
|
||||
.content_type
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.unwrap_or_default();
|
||||
if !content_type.starts_with("image/") {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "asset-object",
|
||||
"field": "referenceImageAssetObjectId",
|
||||
"assetObjectId": asset_object.asset_object_id,
|
||||
"message": "参考图资产不是图片类型。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
if asset_object.content_length == 0
|
||||
|| asset_object.content_length > PUZZLE_REFERENCE_IMAGE_MAX_BYTES as u64
|
||||
{
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
|
||||
"provider": "asset-object",
|
||||
"field": "referenceImageAssetObjectId",
|
||||
"assetObjectId": asset_object.asset_object_id,
|
||||
"message": "参考图资产大小不符合拼图生成要求。",
|
||||
"maxBytes": PUZZLE_REFERENCE_IMAGE_MAX_BYTES,
|
||||
"actualBytes": asset_object.content_length,
|
||||
})),
|
||||
);
|
||||
}
|
||||
if let Some(expected_owner_user_id) = owner_user_id
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
{
|
||||
let actual_owner_user_id = asset_object
|
||||
.owner_user_id
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty());
|
||||
if actual_owner_user_id != Some(expected_owner_user_id) {
|
||||
return Err(
|
||||
AppError::from_status(StatusCode::FORBIDDEN).with_details(json!({
|
||||
"provider": "asset-object",
|
||||
"field": "referenceImageAssetObjectId",
|
||||
"assetObjectId": asset_object.asset_object_id,
|
||||
"message": "参考图资产不属于当前账号。",
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn download_signed_puzzle_reference_image(
|
||||
http_client: &reqwest::Client,
|
||||
signed_read_url: String,
|
||||
object_key: &str,
|
||||
fallback_content_type: Option<&str>,
|
||||
field: &str,
|
||||
) -> Result<PuzzleResolvedReferenceImage, AppError> {
|
||||
let response = http_client
|
||||
.get(signed.signed_url)
|
||||
.get(signed_read_url.as_str())
|
||||
.send()
|
||||
.await
|
||||
.map_err(|error| map_puzzle_image_request_error(format!("读取拼图参考图失败:{error}")))?;
|
||||
@@ -625,6 +855,7 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
.headers()
|
||||
.get(reqwest::header::CONTENT_TYPE)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.or(fallback_content_type)
|
||||
.unwrap_or("image/png")
|
||||
.to_string();
|
||||
let body = response.bytes().await.map_err(|error| {
|
||||
@@ -636,6 +867,7 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
"provider": "aliyun-oss",
|
||||
"message": format!("读取参考图失败,状态码:{status}"),
|
||||
"objectKey": object_key,
|
||||
"field": field,
|
||||
})),
|
||||
);
|
||||
}
|
||||
@@ -645,6 +877,7 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
"provider": "aliyun-oss",
|
||||
"message": "读取参考图失败:对象内容为空",
|
||||
"objectKey": object_key,
|
||||
"field": field,
|
||||
})),
|
||||
);
|
||||
}
|
||||
@@ -655,6 +888,7 @@ pub(crate) async fn resolve_puzzle_reference_image_as_data_url(
|
||||
mime_type,
|
||||
bytes_len,
|
||||
bytes: body.to_vec(),
|
||||
signed_read_url: Some(signed_read_url),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -693,7 +927,7 @@ pub(crate) async fn download_puzzle_remote_image(
|
||||
}
|
||||
|
||||
pub(crate) async fn persist_puzzle_generated_asset(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
@@ -805,7 +1039,7 @@ pub(crate) async fn persist_puzzle_generated_asset(
|
||||
}
|
||||
|
||||
pub(crate) async fn persist_puzzle_ui_background_image(
|
||||
state: &AppState,
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
@@ -845,6 +1079,57 @@ pub(crate) async fn persist_puzzle_ui_background_image(
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn persist_puzzle_level_asset_image(
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
level_name: &str,
|
||||
task_id: &str,
|
||||
path_segment: &str,
|
||||
asset_kind: &str,
|
||||
slot: &str,
|
||||
file_stem: &str,
|
||||
image: PuzzleDownloadedImage,
|
||||
) -> Result<GeneratedPuzzleLevelAssetResponse, AppError> {
|
||||
let oss_client = state.oss_client().ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::SERVICE_UNAVAILABLE).with_details(json!({
|
||||
"provider": "aliyun-oss",
|
||||
"reason": "OSS 未完成环境变量配置",
|
||||
}))
|
||||
})?;
|
||||
let http_client = reqwest::Client::new();
|
||||
let put_result = oss_client
|
||||
.put_object(
|
||||
&http_client,
|
||||
OssPutObjectRequest {
|
||||
prefix: LegacyAssetPrefix::PuzzleAssets,
|
||||
path_segments: vec![
|
||||
sanitize_path_segment(session_id, "session"),
|
||||
sanitize_path_segment(level_name, "puzzle"),
|
||||
sanitize_path_segment(path_segment, "level-asset"),
|
||||
sanitize_path_segment(task_id, "task"),
|
||||
],
|
||||
file_name: format!("{file_stem}.{}", image.extension),
|
||||
content_type: Some(image.mime_type.clone()),
|
||||
access: OssObjectAccess::Private,
|
||||
metadata: build_puzzle_level_asset_metadata(
|
||||
owner_user_id,
|
||||
session_id,
|
||||
asset_kind,
|
||||
slot,
|
||||
),
|
||||
body: image.bytes,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(map_puzzle_asset_oss_error)?;
|
||||
|
||||
Ok(GeneratedPuzzleLevelAssetResponse {
|
||||
image_src: put_result.legacy_public_path,
|
||||
object_key: put_result.object_key,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn handle_puzzle_asset_spacetime_index_error(
|
||||
error: SpacetimeClientError,
|
||||
owner_user_id: &str,
|
||||
@@ -899,6 +1184,21 @@ pub(crate) fn build_puzzle_ui_background_asset_metadata(
|
||||
])
|
||||
}
|
||||
|
||||
pub(crate) fn build_puzzle_level_asset_metadata(
|
||||
owner_user_id: &str,
|
||||
session_id: &str,
|
||||
asset_kind: &str,
|
||||
slot: &str,
|
||||
) -> BTreeMap<String, String> {
|
||||
BTreeMap::from([
|
||||
("asset_kind".to_string(), asset_kind.to_string()),
|
||||
("owner_user_id".to_string(), owner_user_id.to_string()),
|
||||
("entity_kind".to_string(), PUZZLE_ENTITY_KIND.to_string()),
|
||||
("entity_id".to_string(), session_id.to_string()),
|
||||
("slot".to_string(), slot.to_string()),
|
||||
])
|
||||
}
|
||||
|
||||
pub(crate) fn parse_puzzle_json_payload(
|
||||
raw_text: &str,
|
||||
fallback_message: &str,
|
||||
@@ -1104,72 +1404,6 @@ pub(crate) fn map_puzzle_vector_engine_request_error(message: String) -> AppErro
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn map_puzzle_vector_engine_reqwest_error(
|
||||
context: &str,
|
||||
request_url: &str,
|
||||
error: reqwest::Error,
|
||||
) -> AppError {
|
||||
let message = format!(
|
||||
"{context}:{}",
|
||||
normalize_puzzle_reqwest_error_message(&error)
|
||||
);
|
||||
let is_timeout = error.is_timeout() || is_puzzle_request_timeout_message(message.as_str());
|
||||
let is_connect = error.is_connect();
|
||||
let status = if is_timeout {
|
||||
StatusCode::GATEWAY_TIMEOUT
|
||||
} else {
|
||||
StatusCode::BAD_GATEWAY
|
||||
};
|
||||
let source = error.source().map(ToString::to_string).unwrap_or_default();
|
||||
|
||||
tracing::warn!(
|
||||
provider = VECTOR_ENGINE_PROVIDER,
|
||||
endpoint = %request_url,
|
||||
timeout = is_timeout,
|
||||
connect = is_connect,
|
||||
request = error.is_request(),
|
||||
body = error.is_body(),
|
||||
source = %source,
|
||||
message = %message,
|
||||
"拼图 VectorEngine 请求发送失败"
|
||||
);
|
||||
|
||||
AppError::from_status(status).with_details(json!({
|
||||
"provider": VECTOR_ENGINE_PROVIDER,
|
||||
"message": message,
|
||||
"reason": resolve_puzzle_vector_engine_request_failure_reason(&error),
|
||||
"endpoint": request_url,
|
||||
"timeout": is_timeout,
|
||||
"connect": is_connect,
|
||||
"request": error.is_request(),
|
||||
"body": error.is_body(),
|
||||
"source": source,
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn normalize_puzzle_reqwest_error_message(error: &reqwest::Error) -> String {
|
||||
error
|
||||
.to_string()
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_puzzle_vector_engine_request_failure_reason(
|
||||
error: &reqwest::Error,
|
||||
) -> &'static str {
|
||||
if error.is_timeout() {
|
||||
return "VectorEngine 图片编辑请求超时,请稍后重试或调大 VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS";
|
||||
}
|
||||
if error.is_connect() {
|
||||
return "无法连接 VectorEngine 图片编辑接口,请检查服务器网络、DNS、防火墙或代理配置";
|
||||
}
|
||||
if error.is_body() {
|
||||
return "发送 VectorEngine 图片编辑 multipart 请求体失败,请重试并检查参考图大小";
|
||||
}
|
||||
"VectorEngine 图片编辑请求发送失败,请查看 source 字段中的底层网络错误"
|
||||
}
|
||||
|
||||
pub(crate) fn is_puzzle_request_timeout_message(message: &str) -> bool {
|
||||
let lower = message.to_ascii_lowercase();
|
||||
lower.contains("timed out")
|
||||
|
||||
@@ -141,6 +141,86 @@ impl FromRef<AppState> for BackpressureState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PuzzleApiState {
|
||||
root_state: AppState,
|
||||
spacetime_client: SpacetimeClient,
|
||||
puzzle_gallery_cache: PuzzleGalleryCache,
|
||||
oss_client: Option<OssClient>,
|
||||
auth_user_service: AuthUserService,
|
||||
llm_client: Option<LlmClient>,
|
||||
creative_agent_gpt5_client: Option<LlmClient>,
|
||||
creation_agent_llm_web_search_enabled: bool,
|
||||
vector_engine_image_request_timeout_ms: u64,
|
||||
}
|
||||
|
||||
impl PuzzleApiState {
|
||||
pub fn root_state(&self) -> &AppState {
|
||||
&self.root_state
|
||||
}
|
||||
|
||||
pub fn spacetime_client(&self) -> &SpacetimeClient {
|
||||
&self.spacetime_client
|
||||
}
|
||||
|
||||
pub fn puzzle_gallery_cache(&self) -> &PuzzleGalleryCache {
|
||||
&self.puzzle_gallery_cache
|
||||
}
|
||||
|
||||
pub fn oss_client(&self) -> Option<&OssClient> {
|
||||
self.oss_client.as_ref()
|
||||
}
|
||||
|
||||
pub fn auth_user_service(&self) -> &AuthUserService {
|
||||
&self.auth_user_service
|
||||
}
|
||||
|
||||
pub fn llm_client(&self) -> Option<&LlmClient> {
|
||||
self.llm_client.as_ref()
|
||||
}
|
||||
|
||||
pub fn creative_agent_gpt5_client(&self) -> Option<&LlmClient> {
|
||||
self.creative_agent_gpt5_client.as_ref()
|
||||
}
|
||||
|
||||
pub fn creation_agent_llm_web_search_enabled(&self) -> bool {
|
||||
self.creation_agent_llm_web_search_enabled
|
||||
}
|
||||
|
||||
pub fn vector_engine_image_request_timeout_ms(&self) -> u64 {
|
||||
self.vector_engine_image_request_timeout_ms
|
||||
}
|
||||
|
||||
pub fn vector_engine_base_url(&self) -> &str {
|
||||
self.root_state.config.vector_engine_base_url.as_str()
|
||||
}
|
||||
|
||||
pub fn vector_engine_api_key(&self) -> Option<&str> {
|
||||
self.root_state.config.vector_engine_api_key.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for PuzzleApiState {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
// 中文注释:拼图路由只暴露本能力需要的依赖快照,避免 handler 直接看见完整 AppState。
|
||||
Self {
|
||||
root_state: state.clone(),
|
||||
spacetime_client: state.spacetime_client.clone(),
|
||||
puzzle_gallery_cache: state.puzzle_gallery_cache.clone(),
|
||||
oss_client: state.oss_client.clone(),
|
||||
auth_user_service: state.auth_user_service.clone(),
|
||||
llm_client: state.llm_client.clone(),
|
||||
creative_agent_gpt5_client: state.creative_agent_gpt5_client.clone(),
|
||||
creation_agent_llm_web_search_enabled: state
|
||||
.config
|
||||
.creation_agent_llm_web_search_enabled,
|
||||
vector_engine_image_request_timeout_ms: state
|
||||
.config
|
||||
.vector_engine_image_request_timeout_ms,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Axum/Hyper 会在路由树和连接 service 上频繁 clone state;AppState 外层必须保持浅拷贝。
|
||||
#[derive(Debug)]
|
||||
pub struct AppStateInner {
|
||||
@@ -1319,4 +1399,23 @@ mod tests {
|
||||
);
|
||||
assert!(client.config().official_fallback());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puzzle_api_state_exposes_puzzle_dependency_snapshot() {
|
||||
let mut config = AppConfig::default();
|
||||
config.creation_agent_llm_web_search_enabled = false;
|
||||
config.vector_engine_image_request_timeout_ms = 987_654;
|
||||
|
||||
let state = AppState::new(config).expect("state should build");
|
||||
let puzzle_state: PuzzleApiState = FromRef::from_ref(&state);
|
||||
|
||||
assert!(!puzzle_state.creation_agent_llm_web_search_enabled());
|
||||
assert_eq!(
|
||||
puzzle_state.vector_engine_image_request_timeout_ms(),
|
||||
987_654
|
||||
);
|
||||
assert!(puzzle_state.llm_client().is_none());
|
||||
assert!(puzzle_state.creative_agent_gpt5_client().is_none());
|
||||
assert!(puzzle_state.oss_client().is_none());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,23 @@ pub(crate) fn update_tracking_outbox_pending_files(files: usize) {
|
||||
TRACKING_OUTBOX_PENDING_FILES.store(files.min(i64::MAX as usize) as i64, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn record_external_api_failure(
|
||||
provider: &'static str,
|
||||
failure_stage: &'static str,
|
||||
status_class: &'static str,
|
||||
retryable: bool,
|
||||
) {
|
||||
external_api_metrics().failures.add(
|
||||
1,
|
||||
&[
|
||||
KeyValue::new("provider", provider),
|
||||
KeyValue::new("failure_stage", failure_stage),
|
||||
KeyValue::new("status_class", status_class),
|
||||
KeyValue::new("retryable", retryable),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn track_response_body_in_flight(response: Response<Body>) -> Response<Body> {
|
||||
response.map(|body| {
|
||||
HTTP_RESPONSE_BODY_IN_FLIGHT.fetch_add(1, Ordering::Relaxed);
|
||||
@@ -211,6 +228,10 @@ struct TrackingOutboxMetrics {
|
||||
flushed_bytes: Counter<u64>,
|
||||
}
|
||||
|
||||
struct ExternalApiMetrics {
|
||||
failures: Counter<u64>,
|
||||
}
|
||||
|
||||
struct HttpRequestPermitsAvailableGauges {
|
||||
default: Arc<AtomicI64>,
|
||||
gallery: Arc<AtomicI64>,
|
||||
@@ -359,6 +380,21 @@ fn tracking_outbox_metrics() -> &'static TrackingOutboxMetrics {
|
||||
})
|
||||
}
|
||||
|
||||
fn external_api_metrics() -> &'static ExternalApiMetrics {
|
||||
static METRICS: std::sync::OnceLock<ExternalApiMetrics> = std::sync::OnceLock::new();
|
||||
METRICS.get_or_init(|| {
|
||||
let meter = global::meter("genarrative-api");
|
||||
ExternalApiMetrics {
|
||||
failures: meter
|
||||
.u64_counter("genarrative.external_api.failures")
|
||||
.with_description(
|
||||
"External API call failures grouped by provider and failure stage",
|
||||
)
|
||||
.build(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn register_http_request_permits_available_metric() -> HttpRequestPermitsAvailableGauges {
|
||||
let gauges = HttpRequestPermitsAvailableGauges::new();
|
||||
let meter = global::meter("genarrative-api");
|
||||
|
||||
@@ -584,6 +584,26 @@ async fn record_route_tracking_event_via_outbox_after_success(
|
||||
record_tracking_event_input_after_success(state, request_context, event).await;
|
||||
}
|
||||
|
||||
pub(crate) fn build_tracking_event_input(
|
||||
draft: TrackingEventDraft,
|
||||
) -> module_runtime::RuntimeTrackingEventInput {
|
||||
let occurred_at_micros = OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000;
|
||||
let event_id = build_tracking_event_id(&draft, occurred_at_micros);
|
||||
|
||||
module_runtime::RuntimeTrackingEventInput {
|
||||
event_id,
|
||||
event_key: draft.event_key.to_string(),
|
||||
scope_kind: draft.scope_kind,
|
||||
scope_id: draft.scope_id,
|
||||
user_id: draft.user_id,
|
||||
owner_user_id: draft.owner_user_id,
|
||||
profile_id: draft.profile_id,
|
||||
module_key: draft.module_key.map(str::to_string),
|
||||
metadata_json: draft.metadata.to_string(),
|
||||
occurred_at_micros: occurred_at_micros as i64,
|
||||
}
|
||||
}
|
||||
|
||||
async fn record_tracking_event_input_after_success(
|
||||
state: &AppState,
|
||||
request_context: &RequestContext,
|
||||
@@ -642,26 +662,6 @@ async fn record_tracking_event_input_after_success(
|
||||
}
|
||||
}
|
||||
|
||||
fn build_tracking_event_input(
|
||||
draft: TrackingEventDraft,
|
||||
) -> module_runtime::RuntimeTrackingEventInput {
|
||||
let occurred_at_micros = OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000;
|
||||
let event_id = build_tracking_event_id(&draft, occurred_at_micros);
|
||||
|
||||
module_runtime::RuntimeTrackingEventInput {
|
||||
event_id,
|
||||
event_key: draft.event_key.to_string(),
|
||||
scope_kind: draft.scope_kind,
|
||||
scope_id: draft.scope_id,
|
||||
user_id: draft.user_id,
|
||||
owner_user_id: draft.owner_user_id,
|
||||
profile_id: draft.profile_id,
|
||||
module_key: draft.module_key.map(str::to_string),
|
||||
metadata_json: draft.metadata.to_string(),
|
||||
occurred_at_micros: occurred_at_micros as i64,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_tracking_event_id(draft: &TrackingEventDraft, occurred_at_micros: i128) -> String {
|
||||
if draft.event_key == "daily_login"
|
||||
&& draft.scope_kind == RuntimeTrackingScopeKind::User
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use module_auth::AuthUser;
|
||||
|
||||
use crate::state::AppState;
|
||||
use crate::state::{AppState, PuzzleApiState};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct WorkAuthorSummary {
|
||||
@@ -14,6 +14,34 @@ pub fn resolve_work_author_by_user_id(
|
||||
owner_user_id: &str,
|
||||
fallback_display_name: Option<&str>,
|
||||
fallback_public_user_code: Option<&str>,
|
||||
) -> WorkAuthorSummary {
|
||||
resolve_work_author_by_user_id_with_service(
|
||||
state.auth_user_service(),
|
||||
owner_user_id,
|
||||
fallback_display_name,
|
||||
fallback_public_user_code,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn resolve_puzzle_work_author_by_user_id(
|
||||
state: &PuzzleApiState,
|
||||
owner_user_id: &str,
|
||||
fallback_display_name: Option<&str>,
|
||||
fallback_public_user_code: Option<&str>,
|
||||
) -> WorkAuthorSummary {
|
||||
resolve_work_author_by_user_id_with_service(
|
||||
state.auth_user_service(),
|
||||
owner_user_id,
|
||||
fallback_display_name,
|
||||
fallback_public_user_code,
|
||||
)
|
||||
}
|
||||
|
||||
fn resolve_work_author_by_user_id_with_service(
|
||||
auth_user_service: &module_auth::AuthUserService,
|
||||
owner_user_id: &str,
|
||||
fallback_display_name: Option<&str>,
|
||||
fallback_public_user_code: Option<&str>,
|
||||
) -> WorkAuthorSummary {
|
||||
let fallback_display_name =
|
||||
normalize_optional_text(fallback_display_name).unwrap_or_else(|| "玩家".to_string());
|
||||
@@ -26,7 +54,7 @@ pub fn resolve_work_author_by_user_id(
|
||||
};
|
||||
};
|
||||
|
||||
match state.auth_user_service().get_user_by_id(&owner_user_id) {
|
||||
match auth_user_service.get_user_by_id(&owner_user_id) {
|
||||
Ok(Some(user)) => map_auth_user_to_work_author_summary(user, fallback_display_name),
|
||||
Ok(None) | Err(_) => WorkAuthorSummary {
|
||||
display_name: fallback_display_name,
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde_json::{Value, json};
|
||||
use crate::{
|
||||
auth::AuthenticatedAccessToken,
|
||||
request_context::RequestContext,
|
||||
state::AppState,
|
||||
state::{AppState, PuzzleApiState},
|
||||
tracking::{TrackingEventDraft, record_tracking_event_after_success},
|
||||
};
|
||||
|
||||
@@ -68,6 +68,22 @@ pub(crate) async fn record_work_play_start_after_success(
|
||||
state: &AppState,
|
||||
request_context: &RequestContext,
|
||||
draft: WorkPlayTrackingDraft,
|
||||
) {
|
||||
record_work_play_start_input_after_success(state, request_context, draft).await;
|
||||
}
|
||||
|
||||
pub(crate) async fn record_puzzle_work_play_start_after_success(
|
||||
state: &PuzzleApiState,
|
||||
request_context: &RequestContext,
|
||||
draft: WorkPlayTrackingDraft,
|
||||
) {
|
||||
record_work_play_start_input_after_success(state.root_state(), request_context, draft).await;
|
||||
}
|
||||
|
||||
async fn record_work_play_start_input_after_success(
|
||||
state: &AppState,
|
||||
request_context: &RequestContext,
|
||||
draft: WorkPlayTrackingDraft,
|
||||
) {
|
||||
let mut metadata = json!({
|
||||
"operation": WORK_PLAY_START_EVENT_KEY,
|
||||
|
||||
@@ -348,15 +348,15 @@ mod tests {
|
||||
assert_eq!(perfect.status, JumpHopRunStatus::Playing);
|
||||
assert_eq!(perfect.current_platform_index, 1);
|
||||
|
||||
let hit = apply_jump(&run, perfect_charge.saturating_add(80), 200)
|
||||
.expect("jump should resolve");
|
||||
let hit =
|
||||
apply_jump(&run, perfect_charge.saturating_add(80), 200).expect("jump should resolve");
|
||||
assert_eq!(
|
||||
hit.last_jump.as_ref().unwrap().result,
|
||||
JumpHopJumpResultKind::Hit
|
||||
);
|
||||
|
||||
let miss = apply_jump(&run, perfect_charge.saturating_add(900), 200)
|
||||
.expect("jump should resolve");
|
||||
let miss =
|
||||
apply_jump(&run, perfect_charge.saturating_add(900), 200).expect("jump should resolve");
|
||||
assert_eq!(miss.status, JumpHopRunStatus::Failed);
|
||||
assert_eq!(
|
||||
miss.last_jump.as_ref().unwrap().result,
|
||||
|
||||
@@ -419,12 +419,12 @@ pub fn resolve_match3d_item_type_count_for_difficulty(clear_count: u32, difficul
|
||||
8 => 3,
|
||||
12 => 9,
|
||||
16 => 15,
|
||||
20 | 21 => 21,
|
||||
20 | 21 => 20,
|
||||
_ => match difficulty {
|
||||
0..=2 => 3,
|
||||
3..=4 => 9,
|
||||
5..=6 => 15,
|
||||
_ => 21,
|
||||
_ => 20,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -432,8 +432,8 @@ pub fn resolve_match3d_item_type_count_for_difficulty(clear_count: u32, difficul
|
||||
}
|
||||
|
||||
pub fn normalize_match3d_runtime_clear_count(clear_count: u32, difficulty: u32) -> u32 {
|
||||
// 中文注释:旧硬核草稿曾保存 clear_count=20;新硬核固定 21 种物品,
|
||||
// 运行态也升到 21 组三消,避免出现 20 组却要求 21 种素材的不可达状态。
|
||||
// 中文注释:旧硬核草稿曾保存 clear_count=20;运行态保留硬核 21 组三消节奏,
|
||||
// 但本局物品类型池仍由难度映射到最多 20 种,避免超过 10*10 Sprite 解析素材上限。
|
||||
if clear_count == 20 && difficulty >= 7 {
|
||||
21
|
||||
} else {
|
||||
@@ -885,7 +885,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_hardcore_clear_count_runs_as_twenty_one_groups() {
|
||||
fn legacy_hardcore_clear_count_runs_with_twenty_item_types() {
|
||||
let run = start_run_with_seed_at(
|
||||
"run-types-legacy-hardcore".to_string(),
|
||||
"user-1".to_string(),
|
||||
@@ -903,8 +903,8 @@ mod tests {
|
||||
|
||||
assert_eq!(run.clear_count, 21);
|
||||
assert_eq!(run.total_item_count, 63);
|
||||
assert_eq!(counts.len(), 21);
|
||||
assert!(counts.values().all(|count| *count == 3));
|
||||
assert_eq!(counts.len(), 20);
|
||||
assert_eq!(counts.values().sum::<u32>(), 63);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -931,8 +931,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn size_tier_plan_follows_ratio_for_twenty_five_types() {
|
||||
let plan = resolve_size_tier_plan(25);
|
||||
fn size_tier_plan_follows_ratio_for_twenty_types() {
|
||||
let plan = resolve_size_tier_plan(20);
|
||||
let mut counts = BTreeMap::<&str, usize>::new();
|
||||
for rule in plan {
|
||||
*counts.entry(rule.tier).or_default() += 1;
|
||||
@@ -946,10 +946,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(counts.get("XL"), Some(&5));
|
||||
assert_eq!(counts.get("L"), Some(&8));
|
||||
assert_eq!(counts.get("M"), Some(&7));
|
||||
assert_eq!(counts.get("XS"), Some(&4));
|
||||
assert_eq!(counts.get("XL"), Some(&4));
|
||||
assert_eq!(counts.get("L"), Some(&6));
|
||||
assert_eq!(counts.get("M"), Some(&6));
|
||||
assert_eq!(counts.get("XS"), Some(&3));
|
||||
assert_eq!(counts.get("S"), Some(&1));
|
||||
}
|
||||
|
||||
@@ -962,7 +962,7 @@ mod tests {
|
||||
&test_config(30),
|
||||
42,
|
||||
1_000,
|
||||
Some(25),
|
||||
Some(20),
|
||||
)
|
||||
.expect("run should start");
|
||||
|
||||
@@ -974,7 +974,7 @@ mod tests {
|
||||
.push((item.radius * 10_000.0).round() as u32);
|
||||
}
|
||||
|
||||
assert_eq!(radii_by_visual_key.len(), 25);
|
||||
assert_eq!(radii_by_visual_key.len(), 20);
|
||||
assert!(
|
||||
radii_by_visual_key
|
||||
.values()
|
||||
@@ -1052,7 +1052,7 @@ mod tests {
|
||||
.filter(|item| {
|
||||
let dx = item.x - MATCH3D_BOARD_CENTER;
|
||||
let dy = item.y - MATCH3D_BOARD_CENTER;
|
||||
(dx * dx + dy * dy).sqrt() > 0.32
|
||||
(dx * dx + dy * dy).sqrt() > 0.26
|
||||
})
|
||||
.count();
|
||||
let mut quadrants = BTreeMap::<String, u32>::new();
|
||||
@@ -1081,15 +1081,15 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn twenty_five_or_less_does_not_repeat_visual_keys() {
|
||||
fn twenty_or_less_does_not_repeat_visual_keys() {
|
||||
let run = start_run_with_seed_at_and_item_type_count(
|
||||
"run-block-unique".to_string(),
|
||||
"user-1".to_string(),
|
||||
"profile-1".to_string(),
|
||||
&test_config(25),
|
||||
&test_config(20),
|
||||
27,
|
||||
1_000,
|
||||
Some(25),
|
||||
Some(20),
|
||||
)
|
||||
.expect("run should start");
|
||||
|
||||
@@ -1098,7 +1098,7 @@ mod tests {
|
||||
*counts.entry(item.visual_key.clone()).or_default() += 1;
|
||||
}
|
||||
|
||||
assert_eq!(counts.len(), 25);
|
||||
assert_eq!(counts.len(), 20);
|
||||
assert!(counts.values().all(|count| *count == 3));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ pub const MATCH3D_WORK_ID_PREFIX: &str = "match3d-work-";
|
||||
pub const MATCH3D_RUN_ID_PREFIX: &str = "match3d-run-";
|
||||
pub const MATCH3D_TRAY_SLOT_COUNT: u32 = 7;
|
||||
pub const MATCH3D_ITEMS_PER_CLEAR: u32 = 3;
|
||||
pub const MATCH3D_MAX_ITEM_TYPE_COUNT: u32 = 25;
|
||||
pub(crate) const MATCH3D_MAX_ITEM_TYPE_COUNT_USIZE: usize = 25;
|
||||
pub const MATCH3D_MAX_ITEM_TYPE_COUNT: u32 = 20;
|
||||
pub(crate) const MATCH3D_MAX_ITEM_TYPE_COUNT_USIZE: usize = 20;
|
||||
pub const MATCH3D_MIN_DIFFICULTY: u32 = 1;
|
||||
pub const MATCH3D_MAX_DIFFICULTY: u32 = 10;
|
||||
pub const MATCH3D_DEFAULT_DURATION_LIMIT_MS: u64 = 10 * 60 * 1000;
|
||||
@@ -18,8 +18,7 @@ pub const MATCH3D_BOARD_CENTER: f32 = 0.5;
|
||||
pub const MATCH3D_BOARD_RADIUS: f32 = 0.5;
|
||||
pub const MATCH3D_BOARD_SAFE_MARGIN: f32 = 0.035;
|
||||
|
||||
// 中文注释:首版 demo 不接真实图片生成,当前先用程序化积木件作为稳定可辨认的默认素材。
|
||||
// 中文注释:当前 demo 使用 25 个积木件作为默认可消除物资源池,前端据 visual_key 程序化生成 3D 模型。
|
||||
// 中文注释:默认资源池对齐抓大鹅 10*10 物品 Sprite 的 20 种物品上限。
|
||||
pub(crate) const MATCH3D_BLOCK_VISUAL_KEYS: [&str; MATCH3D_MAX_ITEM_TYPE_COUNT_USIZE] = [
|
||||
"block-red-2x4",
|
||||
"block-blue-1x2",
|
||||
@@ -29,19 +28,14 @@ pub(crate) const MATCH3D_BLOCK_VISUAL_KEYS: [&str; MATCH3D_MAX_ITEM_TYPE_COUNT_U
|
||||
"block-white-1x1",
|
||||
"block-black-1x8",
|
||||
"block-tan-2x3",
|
||||
"block-lime-1x2",
|
||||
"block-darkred-2x2",
|
||||
"block-blue-1x4",
|
||||
"block-pink-2x4",
|
||||
"block-gray-1x6",
|
||||
"block-lavender-tile-2x2",
|
||||
"block-teal-tile-1x3",
|
||||
"block-mint-tile-1x4",
|
||||
"block-magenta-tile-2x2",
|
||||
"block-orange-tile-2x2-stud",
|
||||
"block-purple-slope-1x2",
|
||||
"block-brown-slope-1x2",
|
||||
"block-sky-slope-2x2",
|
||||
"block-green-cylinder",
|
||||
"block-clear-ring",
|
||||
"block-mint-arch",
|
||||
|
||||
@@ -189,6 +189,12 @@ pub fn compile_result_draft_from_seed(
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
@@ -249,6 +255,12 @@ pub fn build_form_draft_from_parts(
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
@@ -358,6 +370,12 @@ pub fn normalize_puzzle_draft(mut draft: PuzzleResultDraft) -> PuzzleResultDraft
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: draft.candidates.clone(),
|
||||
selected_candidate_id: draft.selected_candidate_id.clone(),
|
||||
@@ -448,6 +466,12 @@ pub fn append_blank_puzzle_level(draft: &PuzzleResultDraft) -> PuzzleResultDraft
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
@@ -804,17 +828,89 @@ fn first_profile_ui_background_level(profile: &PuzzleWorkProfile) -> Option<Puzz
|
||||
})
|
||||
}
|
||||
|
||||
fn first_profile_level_background_level(profile: &PuzzleWorkProfile) -> Option<PuzzleDraftLevel> {
|
||||
normalize_puzzle_levels(profile.levels.clone(), &profile.theme_tags)
|
||||
.unwrap_or_else(|_| profile.levels.clone())
|
||||
.into_iter()
|
||||
.find(|level| {
|
||||
level
|
||||
.level_background_image_src
|
||||
.as_deref()
|
||||
.and_then(normalize_required_string)
|
||||
.is_some()
|
||||
|| level
|
||||
.level_background_image_object_key
|
||||
.as_deref()
|
||||
.and_then(normalize_required_string)
|
||||
.is_some()
|
||||
})
|
||||
}
|
||||
|
||||
fn resolve_puzzle_runtime_ui_background_fields(
|
||||
level: Option<&PuzzleDraftLevel>,
|
||||
fallback_level: Option<&PuzzleDraftLevel>,
|
||||
) -> (Option<String>, Option<String>) {
|
||||
for candidate in [level, fallback_level].into_iter().flatten() {
|
||||
let image_src = candidate
|
||||
.ui_background_image_src
|
||||
.level_background_image_src
|
||||
.as_deref()
|
||||
.and_then(normalize_required_string)
|
||||
.or_else(|| {
|
||||
candidate
|
||||
.ui_background_image_src
|
||||
.as_deref()
|
||||
.and_then(normalize_required_string)
|
||||
});
|
||||
let object_key = candidate
|
||||
.level_background_image_object_key
|
||||
.as_deref()
|
||||
.and_then(|value| normalize_required_string(value.trim_start_matches('/')))
|
||||
.or_else(|| {
|
||||
candidate
|
||||
.ui_background_image_object_key
|
||||
.as_deref()
|
||||
.and_then(|value| normalize_required_string(value.trim_start_matches('/')))
|
||||
});
|
||||
if image_src.is_some() || object_key.is_some() {
|
||||
return (image_src, object_key);
|
||||
}
|
||||
}
|
||||
|
||||
(None, None)
|
||||
}
|
||||
|
||||
fn resolve_puzzle_runtime_level_background_fields(
|
||||
level: Option<&PuzzleDraftLevel>,
|
||||
fallback_level: Option<&PuzzleDraftLevel>,
|
||||
) -> (Option<String>, Option<String>) {
|
||||
for candidate in [level, fallback_level].into_iter().flatten() {
|
||||
let image_src = candidate
|
||||
.level_background_image_src
|
||||
.as_deref()
|
||||
.and_then(normalize_required_string);
|
||||
let object_key = candidate
|
||||
.ui_background_image_object_key
|
||||
.level_background_image_object_key
|
||||
.as_deref()
|
||||
.and_then(|value| normalize_required_string(value.trim_start_matches('/')));
|
||||
if image_src.is_some() || object_key.is_some() {
|
||||
return (image_src, object_key);
|
||||
}
|
||||
}
|
||||
|
||||
(None, None)
|
||||
}
|
||||
|
||||
fn resolve_puzzle_runtime_ui_spritesheet_fields(
|
||||
level: Option<&PuzzleDraftLevel>,
|
||||
fallback_level: Option<&PuzzleDraftLevel>,
|
||||
) -> (Option<String>, Option<String>) {
|
||||
for candidate in [level, fallback_level].into_iter().flatten() {
|
||||
let image_src = candidate
|
||||
.ui_spritesheet_image_src
|
||||
.as_deref()
|
||||
.and_then(normalize_required_string);
|
||||
let object_key = candidate
|
||||
.ui_spritesheet_image_object_key
|
||||
.as_deref()
|
||||
.and_then(|value| normalize_required_string(value.trim_start_matches('/')));
|
||||
if image_src.is_some() || object_key.is_some() {
|
||||
@@ -1092,6 +1188,17 @@ pub fn start_run_with_shuffle_seed_at(
|
||||
current_profile_level.as_ref(),
|
||||
ui_background_level.as_ref(),
|
||||
);
|
||||
let level_background_level = first_profile_level_background_level(entry_profile);
|
||||
let (level_background_image_src, level_background_image_object_key) =
|
||||
resolve_puzzle_runtime_level_background_fields(
|
||||
current_profile_level.as_ref(),
|
||||
level_background_level.as_ref(),
|
||||
);
|
||||
let (ui_spritesheet_image_src, ui_spritesheet_image_object_key) =
|
||||
resolve_puzzle_runtime_ui_spritesheet_fields(
|
||||
current_profile_level.as_ref(),
|
||||
entry_profile.levels.first(),
|
||||
);
|
||||
Ok(PuzzleRunSnapshot {
|
||||
run_id: run_id.clone(),
|
||||
entry_profile_id: entry_profile.profile_id.clone(),
|
||||
@@ -1114,6 +1221,10 @@ pub fn start_run_with_shuffle_seed_at(
|
||||
cover_image_src: entry_profile.cover_image_src.clone(),
|
||||
ui_background_image_src,
|
||||
ui_background_image_object_key,
|
||||
level_background_image_src,
|
||||
level_background_image_object_key,
|
||||
ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key,
|
||||
background_music: current_profile_level
|
||||
.as_ref()
|
||||
.and_then(|level| level.background_music.clone()),
|
||||
@@ -1373,10 +1484,29 @@ pub fn advance_next_level_at(
|
||||
current_profile_level.as_ref(),
|
||||
ui_background_level.as_ref(),
|
||||
);
|
||||
let level_background_level = first_profile_level_background_level(next_profile);
|
||||
let (mut level_background_image_src, mut level_background_image_object_key) =
|
||||
resolve_puzzle_runtime_level_background_fields(
|
||||
current_profile_level.as_ref(),
|
||||
level_background_level.as_ref(),
|
||||
);
|
||||
let (mut ui_spritesheet_image_src, mut ui_spritesheet_image_object_key) =
|
||||
resolve_puzzle_runtime_ui_spritesheet_fields(
|
||||
current_profile_level.as_ref(),
|
||||
next_profile.levels.first(),
|
||||
);
|
||||
if ui_background_image_src.is_none() && ui_background_image_object_key.is_none() {
|
||||
ui_background_image_src = current_level.ui_background_image_src.clone();
|
||||
ui_background_image_object_key = current_level.ui_background_image_object_key.clone();
|
||||
}
|
||||
if level_background_image_src.is_none() && level_background_image_object_key.is_none() {
|
||||
level_background_image_src = current_level.level_background_image_src.clone();
|
||||
level_background_image_object_key = current_level.level_background_image_object_key.clone();
|
||||
}
|
||||
if ui_spritesheet_image_src.is_none() && ui_spritesheet_image_object_key.is_none() {
|
||||
ui_spritesheet_image_src = current_level.ui_spritesheet_image_src.clone();
|
||||
ui_spritesheet_image_object_key = current_level.ui_spritesheet_image_object_key.clone();
|
||||
}
|
||||
|
||||
Ok(PuzzleRunSnapshot {
|
||||
run_id: run.run_id.clone(),
|
||||
@@ -1400,6 +1530,10 @@ pub fn advance_next_level_at(
|
||||
cover_image_src: next_profile.cover_image_src.clone(),
|
||||
ui_background_image_src,
|
||||
ui_background_image_object_key,
|
||||
level_background_image_src,
|
||||
level_background_image_object_key,
|
||||
ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key,
|
||||
background_music: current_profile_level
|
||||
.as_ref()
|
||||
.and_then(|level| level.background_music.clone()),
|
||||
@@ -1461,6 +1595,17 @@ pub fn advance_to_new_work_first_level_at(
|
||||
current_profile_level.as_ref(),
|
||||
ui_background_level.as_ref(),
|
||||
);
|
||||
let level_background_level = first_profile_level_background_level(next_profile);
|
||||
let (level_background_image_src, level_background_image_object_key) =
|
||||
resolve_puzzle_runtime_level_background_fields(
|
||||
current_profile_level.as_ref(),
|
||||
level_background_level.as_ref(),
|
||||
);
|
||||
let (ui_spritesheet_image_src, ui_spritesheet_image_object_key) =
|
||||
resolve_puzzle_runtime_ui_spritesheet_fields(
|
||||
current_profile_level.as_ref(),
|
||||
next_profile.levels.first(),
|
||||
);
|
||||
|
||||
Ok(PuzzleRunSnapshot {
|
||||
run_id: run.run_id.clone(),
|
||||
@@ -1484,6 +1629,10 @@ pub fn advance_to_new_work_first_level_at(
|
||||
cover_image_src: next_profile.cover_image_src.clone(),
|
||||
ui_background_image_src,
|
||||
ui_background_image_object_key,
|
||||
level_background_image_src,
|
||||
level_background_image_object_key,
|
||||
ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key,
|
||||
background_music: current_profile_level
|
||||
.as_ref()
|
||||
.and_then(|level| level.background_music.clone()),
|
||||
@@ -2900,6 +3049,12 @@ mod tests {
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
@@ -3118,6 +3273,12 @@ mod tests {
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
@@ -3133,6 +3294,12 @@ mod tests {
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
@@ -3248,6 +3415,12 @@ mod tests {
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
|
||||
@@ -172,6 +172,12 @@ pub fn build_puzzle_draft_from_creative_fields(
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
|
||||
@@ -138,6 +138,18 @@ pub struct PuzzleDraftLevel {
|
||||
#[serde(default)]
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub background_music: Option<PuzzleAudioAsset>,
|
||||
pub candidates: Vec<PuzzleGeneratedImageCandidate>,
|
||||
pub selected_candidate_id: Option<String>,
|
||||
@@ -367,6 +379,14 @@ pub struct PuzzleRuntimeLevelSnapshot {
|
||||
#[serde(default)]
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub background_music: Option<PuzzleAudioAsset>,
|
||||
pub board: PuzzleBoardSnapshot,
|
||||
pub status: PuzzleRuntimeLevelStatus,
|
||||
|
||||
@@ -110,10 +110,28 @@ pub struct Match3DResultDraftResponse {
|
||||
pub struct Match3DGeneratedBackgroundAssetResponse {
|
||||
pub prompt: String,
|
||||
#[serde(default)]
|
||||
pub level_scene_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub item_spritesheet_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub item_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub item_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub container_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub container_image_src: Option<String>,
|
||||
|
||||
@@ -170,10 +170,28 @@ pub struct Match3DWorkSummaryResponse {
|
||||
pub struct Match3DGeneratedBackgroundAssetResponse {
|
||||
pub prompt: String,
|
||||
#[serde(default)]
|
||||
pub level_scene_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub item_spritesheet_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub item_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub item_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub container_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub container_image_src: Option<String>,
|
||||
|
||||
@@ -18,6 +18,10 @@ pub struct CreatePuzzleAgentSessionRequest {
|
||||
#[serde(default)]
|
||||
pub reference_image_srcs: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub reference_image_asset_object_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub reference_image_asset_object_ids: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub image_model: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ai_redraw: Option<bool>,
|
||||
@@ -43,6 +47,10 @@ pub struct ExecutePuzzleAgentActionRequest {
|
||||
#[serde(default)]
|
||||
pub reference_image_srcs: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub reference_image_asset_object_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub reference_image_asset_object_ids: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub image_model: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ai_redraw: Option<bool>,
|
||||
@@ -166,6 +174,18 @@ pub struct PuzzleDraftLevelResponse {
|
||||
#[serde(default)]
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_scene_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub background_music: Option<CreationAudioAsset>,
|
||||
pub candidates: Vec<PuzzleGeneratedImageCandidateResponse>,
|
||||
#[serde(default)]
|
||||
|
||||
@@ -122,6 +122,14 @@ pub struct PuzzleRuntimeLevelSnapshotResponse {
|
||||
#[serde(default)]
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub background_music: Option<CreationAudioAsset>,
|
||||
pub board: PuzzleBoardSnapshotResponse,
|
||||
pub status: String,
|
||||
|
||||
@@ -4,10 +4,7 @@ use opentelemetry::{KeyValue, global, trace::TracerProvider};
|
||||
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
|
||||
use opentelemetry_otlp::WithExportConfig;
|
||||
use opentelemetry_sdk::{
|
||||
Resource,
|
||||
logs::SdkLoggerProvider,
|
||||
metrics::SdkMeterProvider,
|
||||
trace::SdkTracerProvider,
|
||||
Resource, logs::SdkLoggerProvider, metrics::SdkMeterProvider, trace::SdkTracerProvider,
|
||||
};
|
||||
use tracing::warn;
|
||||
use tracing_subscriber::{
|
||||
@@ -54,9 +51,7 @@ pub fn init_tracing(default_filter: &str, otel_config: OtelConfig) -> Result<(),
|
||||
tracing_opentelemetry::layer()
|
||||
.with_tracer(otel.tracer_provider.tracer("genarrative-api")),
|
||||
)
|
||||
.with(
|
||||
OpenTelemetryTracingBridge::new(&otel.logger_provider).with_filter(LevelFilter::INFO),
|
||||
)
|
||||
.with(OpenTelemetryTracingBridge::new(&otel.logger_provider).with_filter(LevelFilter::INFO))
|
||||
.try_init()
|
||||
.map_err(|error| io::Error::other(format!("初始化 tracing subscriber 失败:{error}")))
|
||||
}
|
||||
@@ -127,10 +122,12 @@ fn build_otel_pipeline() -> Option<OtelPipeline> {
|
||||
.with_periodic_exporter(metric_exporter)
|
||||
.build();
|
||||
let logger_provider = SdkLoggerProvider::builder()
|
||||
.with_resource(Resource::builder()
|
||||
.with_service_name(read_env_or_default("OTEL_SERVICE_NAME", "genarrative-api"))
|
||||
.with_attribute(KeyValue::new("service.namespace", "genarrative"))
|
||||
.build())
|
||||
.with_resource(
|
||||
Resource::builder()
|
||||
.with_service_name(read_env_or_default("OTEL_SERVICE_NAME", "genarrative-api"))
|
||||
.with_attribute(KeyValue::new("service.namespace", "genarrative"))
|
||||
.build(),
|
||||
)
|
||||
.with_batch_exporter(log_exporter)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -46,6 +46,21 @@ impl SpacetimeClient {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_asset_object(
|
||||
&self,
|
||||
asset_object_id: String,
|
||||
) -> Result<Option<AssetObjectRecord>, SpacetimeClientError> {
|
||||
self.read_after_connect("get_asset_object", move |connection| {
|
||||
Ok(connection
|
||||
.db()
|
||||
.asset_object()
|
||||
.asset_object_id()
|
||||
.find(&asset_object_id)
|
||||
.map(map_asset_object_row))
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn bind_asset_object_to_entity(
|
||||
&self,
|
||||
input: module_assets::AssetEntityBindingInput,
|
||||
|
||||
@@ -5,11 +5,11 @@ use crate::mapper::{
|
||||
map_jump_hop_works_procedure_result,
|
||||
};
|
||||
use shared_contracts::jump_hop::{
|
||||
JumpHopActionRequest, JumpHopActionResponse, JumpHopActionType, JumpHopCharacterAsset, JumpHopDifficulty,
|
||||
JumpHopDraftResponse, JumpHopGalleryResponse, JumpHopGenerationStatus, JumpHopJumpRequest,
|
||||
JumpHopRestartRunRequest, JumpHopRuntimeRunSnapshotResponse, JumpHopSessionSnapshotResponse,
|
||||
JumpHopStartRunRequest, JumpHopStylePreset, JumpHopTileAsset, JumpHopTileType,
|
||||
JumpHopWorkProfileResponse,
|
||||
JumpHopActionRequest, JumpHopActionResponse, JumpHopActionType, JumpHopCharacterAsset,
|
||||
JumpHopDifficulty, JumpHopDraftResponse, JumpHopGalleryResponse, JumpHopGenerationStatus,
|
||||
JumpHopJumpRequest, JumpHopRestartRunRequest, JumpHopRuntimeRunSnapshotResponse,
|
||||
JumpHopSessionSnapshotResponse, JumpHopStartRunRequest, JumpHopStylePreset, JumpHopTileAsset,
|
||||
JumpHopTileType, JumpHopWorkProfileResponse,
|
||||
};
|
||||
use shared_kernel::build_prefixed_uuid_id;
|
||||
|
||||
@@ -21,10 +21,9 @@ impl SpacetimeClient {
|
||||
&self,
|
||||
session: JumpHopSessionSnapshotResponse,
|
||||
) -> Result<JumpHopSessionSnapshotResponse, SpacetimeClientError> {
|
||||
let draft = session
|
||||
.draft
|
||||
.clone()
|
||||
.ok_or_else(|| SpacetimeClientError::validation_failed("jump-hop session 缺少 draft"))?;
|
||||
let draft = session.draft.clone().ok_or_else(|| {
|
||||
SpacetimeClientError::validation_failed("jump-hop session 缺少 draft")
|
||||
})?;
|
||||
let theme_tags_json = Some(json_string(&draft.theme_tags)?);
|
||||
let config_json = Some(build_config_json(&draft)?);
|
||||
let work_title = draft.work_title.clone();
|
||||
@@ -164,15 +163,14 @@ impl SpacetimeClient {
|
||||
procedure_input: JumpHopWorkUpdateInput,
|
||||
) -> Result<JumpHopWorkProfileResponse, SpacetimeClientError> {
|
||||
self.call_after_connect("update_jump_hop_work", move |connection, sender| {
|
||||
connection.procedures().update_jump_hop_work_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
connection
|
||||
.procedures()
|
||||
.update_jump_hop_work_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_jump_hop_work_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -212,15 +210,14 @@ impl SpacetimeClient {
|
||||
};
|
||||
|
||||
self.call_after_connect("list_jump_hop_works", move |connection, sender| {
|
||||
connection.procedures().list_jump_hop_works_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
connection
|
||||
.procedures()
|
||||
.list_jump_hop_works_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_jump_hop_works_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -229,7 +226,8 @@ impl SpacetimeClient {
|
||||
&self,
|
||||
profile_id: String,
|
||||
) -> Result<JumpHopWorkProfileResponse, SpacetimeClientError> {
|
||||
self.get_jump_hop_work_profile(profile_id, String::new()).await
|
||||
self.get_jump_hop_work_profile(profile_id, String::new())
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn start_jump_hop_run(
|
||||
@@ -253,15 +251,14 @@ impl SpacetimeClient {
|
||||
procedure_input: JumpHopRunStartInput,
|
||||
) -> Result<JumpHopRuntimeRunSnapshotResponse, SpacetimeClientError> {
|
||||
self.call_after_connect("start_jump_hop_run", move |connection, sender| {
|
||||
connection.procedures().start_jump_hop_run_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
connection
|
||||
.procedures()
|
||||
.start_jump_hop_run_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_jump_hop_run_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -277,15 +274,14 @@ impl SpacetimeClient {
|
||||
};
|
||||
|
||||
self.call_after_connect("get_jump_hop_run", move |connection, sender| {
|
||||
connection.procedures().get_jump_hop_run_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
connection
|
||||
.procedures()
|
||||
.get_jump_hop_run_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_jump_hop_run_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -305,15 +301,14 @@ impl SpacetimeClient {
|
||||
};
|
||||
|
||||
self.call_after_connect("jump_hop_jump", move |connection, sender| {
|
||||
connection.procedures().jump_hop_jump_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
connection
|
||||
.procedures()
|
||||
.jump_hop_jump_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_jump_hop_run_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -333,15 +328,14 @@ impl SpacetimeClient {
|
||||
};
|
||||
|
||||
self.call_after_connect("restart_jump_hop_run", move |connection, sender| {
|
||||
connection.procedures().restart_jump_hop_run_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
connection
|
||||
.procedures()
|
||||
.restart_jump_hop_run_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(SpacetimeClientError::from_sdk_error)
|
||||
.and_then(map_jump_hop_run_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -430,16 +424,16 @@ fn build_jump_hop_action_plan(
|
||||
JumpHopAssetRefresh::Preserve,
|
||||
now_micros,
|
||||
)?),
|
||||
JumpHopActionType::RegenerateCharacter => JumpHopActionProcedure::Compile(
|
||||
build_compile_input(
|
||||
JumpHopActionType::RegenerateCharacter => {
|
||||
JumpHopActionProcedure::Compile(build_compile_input(
|
||||
current,
|
||||
owner_user_id,
|
||||
&profile_id,
|
||||
&mut draft,
|
||||
JumpHopAssetRefresh::Character,
|
||||
now_micros,
|
||||
)?,
|
||||
),
|
||||
)?)
|
||||
}
|
||||
JumpHopActionType::RegenerateTiles => JumpHopActionProcedure::Compile(build_compile_input(
|
||||
current,
|
||||
owner_user_id,
|
||||
@@ -472,7 +466,11 @@ fn merge_action_into_draft(
|
||||
scope,
|
||||
JumpHopDraftMergeScope::CompileDraft | JumpHopDraftMergeScope::UpdateWorkMeta
|
||||
) {
|
||||
if let Some(value) = payload.work_title.as_ref().filter(|value| !value.trim().is_empty()) {
|
||||
if let Some(value) = payload
|
||||
.work_title
|
||||
.as_ref()
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
{
|
||||
draft.work_title = value.trim().to_string();
|
||||
}
|
||||
if let Some(value) = payload.work_description.as_ref() {
|
||||
@@ -523,7 +521,9 @@ fn merge_action_into_draft(
|
||||
draft.tile_prompt = value.trim().to_string();
|
||||
}
|
||||
if draft.work_title.trim().is_empty() {
|
||||
return Err(SpacetimeClientError::validation_failed("jump-hop work_title 不能为空"));
|
||||
return Err(SpacetimeClientError::validation_failed(
|
||||
"jump-hop work_title 不能为空",
|
||||
));
|
||||
}
|
||||
Ok(draft)
|
||||
}
|
||||
@@ -762,7 +762,9 @@ fn ensure_tile_assets(
|
||||
.map(|(index, tile_type)| JumpHopTileAsset {
|
||||
tile_type,
|
||||
image_src: format!("/generated-jump-hop-assets/{profile_id}/tiles/{index}{suffix}.png"),
|
||||
image_object_key: format!("generated-jump-hop-assets/{profile_id}/tiles/{index}{suffix}.png"),
|
||||
image_object_key: format!(
|
||||
"generated-jump-hop-assets/{profile_id}/tiles/{index}{suffix}.png"
|
||||
),
|
||||
asset_object_id: format!("{profile_id}-tile-{index}{suffix}-object"),
|
||||
source_atlas_cell: format!("cell-{index}{suffix}"),
|
||||
visual_width: 256,
|
||||
@@ -788,7 +790,9 @@ fn resolve_cover_composite(
|
||||
{
|
||||
return Some(value.to_string());
|
||||
}
|
||||
let suffix = asset_revision_suffix((!matches!(refresh, JumpHopAssetRefresh::Preserve)).then_some(now_micros));
|
||||
let suffix = asset_revision_suffix(
|
||||
(!matches!(refresh, JumpHopAssetRefresh::Preserve)).then_some(now_micros),
|
||||
);
|
||||
Some(format!(
|
||||
"/generated-jump-hop-assets/{profile_id}/cover-composite{suffix}.png"
|
||||
))
|
||||
@@ -850,9 +854,27 @@ mod tests {
|
||||
assert_eq!(input.session_id, SESSION_ID);
|
||||
assert_eq!(input.owner_user_id, OWNER_USER_ID);
|
||||
assert_eq!(input.generation_status.as_deref(), Some("ready"));
|
||||
assert!(input.character_asset_json.as_deref().unwrap_or("").contains("-character"));
|
||||
assert!(input.tile_atlas_asset_json.as_deref().unwrap_or("").contains("-tile-atlas"));
|
||||
assert!(input.tile_assets_json.as_deref().unwrap_or("").contains("tile-0-object"));
|
||||
assert!(
|
||||
input
|
||||
.character_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("-character")
|
||||
);
|
||||
assert!(
|
||||
input
|
||||
.tile_atlas_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("-tile-atlas")
|
||||
);
|
||||
assert!(
|
||||
input
|
||||
.tile_assets_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("tile-0-object")
|
||||
);
|
||||
assert_eq!(draft.generation_status, JumpHopGenerationStatus::Ready);
|
||||
}
|
||||
|
||||
@@ -869,10 +891,34 @@ mod tests {
|
||||
let JumpHopActionProcedure::Compile(input) = plan else {
|
||||
panic!("regenerate-character should call compile_jump_hop_draft");
|
||||
};
|
||||
assert!(!input.character_asset_json.as_deref().unwrap_or("").contains("old-character"));
|
||||
assert!(input.character_asset_json.as_deref().unwrap_or("").contains(&NOW_MICROS.to_string()));
|
||||
assert!(input.tile_atlas_asset_json.as_deref().unwrap_or("").contains("old-tile-atlas"));
|
||||
assert!(input.tile_assets_json.as_deref().unwrap_or("").contains("old-normal-tile"));
|
||||
assert!(
|
||||
!input
|
||||
.character_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("old-character")
|
||||
);
|
||||
assert!(
|
||||
input
|
||||
.character_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains(&NOW_MICROS.to_string())
|
||||
);
|
||||
assert!(
|
||||
input
|
||||
.tile_atlas_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("old-tile-atlas")
|
||||
);
|
||||
assert!(
|
||||
input
|
||||
.tile_assets_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("old-normal-tile")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -888,11 +934,41 @@ mod tests {
|
||||
let JumpHopActionProcedure::Compile(input) = plan else {
|
||||
panic!("regenerate-tiles should call compile_jump_hop_draft");
|
||||
};
|
||||
assert!(input.character_asset_json.as_deref().unwrap_or("").contains("old-character"));
|
||||
assert!(!input.tile_atlas_asset_json.as_deref().unwrap_or("").contains("old-tile-atlas"));
|
||||
assert!(!input.tile_assets_json.as_deref().unwrap_or("").contains("old-normal-tile"));
|
||||
assert!(input.tile_atlas_asset_json.as_deref().unwrap_or("").contains(&NOW_MICROS.to_string()));
|
||||
assert!(input.tile_assets_json.as_deref().unwrap_or("").contains(&NOW_MICROS.to_string()));
|
||||
assert!(
|
||||
input
|
||||
.character_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("old-character")
|
||||
);
|
||||
assert!(
|
||||
!input
|
||||
.tile_atlas_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("old-tile-atlas")
|
||||
);
|
||||
assert!(
|
||||
!input
|
||||
.tile_assets_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("old-normal-tile")
|
||||
);
|
||||
assert!(
|
||||
input
|
||||
.tile_atlas_asset_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains(&NOW_MICROS.to_string())
|
||||
);
|
||||
assert!(
|
||||
input
|
||||
.tile_assets_json
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains(&NOW_MICROS.to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -934,8 +1010,20 @@ mod tests {
|
||||
};
|
||||
assert_eq!(input.difficulty.as_deref(), Some("challenge"));
|
||||
assert!(input.style_preset.is_none());
|
||||
assert_eq!(draft.character_asset.as_ref().map(|asset| asset.asset_id.as_str()), Some("old-character"));
|
||||
assert_eq!(draft.tile_assets.first().map(|asset| asset.asset_object_id.as_str()), Some("old-normal-tile-object"));
|
||||
assert_eq!(
|
||||
draft
|
||||
.character_asset
|
||||
.as_ref()
|
||||
.map(|asset| asset.asset_id.as_str()),
|
||||
Some("old-character")
|
||||
);
|
||||
assert_eq!(
|
||||
draft
|
||||
.tile_assets
|
||||
.first()
|
||||
.map(|asset| asset.asset_object_id.as_str()),
|
||||
Some("old-normal-tile-object")
|
||||
);
|
||||
}
|
||||
|
||||
fn action(action_type: JumpHopActionType) -> JumpHopActionRequest {
|
||||
|
||||
@@ -30,16 +30,8 @@ pub use mapper::{
|
||||
CustomWorldPublishGateRecord, CustomWorldPublishWorldRecord,
|
||||
CustomWorldPublishWorldRecordInput, CustomWorldPublishedProfileCompileRecord,
|
||||
CustomWorldResultPreviewBlockerRecord, CustomWorldSupportedActionRecord,
|
||||
CustomWorldWorkSummaryRecord, Match3DAgentMessageFinalizeRecordInput,
|
||||
Match3DAgentMessageRecord, Match3DAgentMessageSubmitRecordInput,
|
||||
Match3DAgentSessionCreateRecordInput, Match3DAgentSessionRecord, Match3DAnchorItemRecord,
|
||||
Match3DAnchorPackRecord, Match3DClickConfirmationRecord, Match3DCompileDraftRecordInput,
|
||||
Match3DCreatorConfigRecord, Match3DItemSnapshotRecord, Match3DResultDraftRecord,
|
||||
Match3DRunClickRecordInput, Match3DRunRecord, Match3DRunRestartRecordInput,
|
||||
Match3DRunStartRecordInput, Match3DRunStopRecordInput, Match3DRunTimeUpRecordInput,
|
||||
Match3DTraySlotRecord, Match3DWorkProfileRecord, Match3DWorkUpdateRecordInput,
|
||||
JumpHopActionRequest, JumpHopActionResponse, JumpHopActionType, JumpHopCharacterAsset,
|
||||
JumpHopDifficulty, JumpHopDraftResponse, JumpHopGalleryCardResponse,
|
||||
CustomWorldWorkSummaryRecord, JumpHopActionRequest, JumpHopActionResponse, JumpHopActionType,
|
||||
JumpHopCharacterAsset, JumpHopDifficulty, JumpHopDraftResponse, JumpHopGalleryCardResponse,
|
||||
JumpHopGalleryDetailResponse, JumpHopGalleryResponse, JumpHopGenerationStatus,
|
||||
JumpHopJumpRequest, JumpHopJumpResponse, JumpHopJumpResult, JumpHopLastJump, JumpHopPath,
|
||||
JumpHopPlatform, JumpHopRestartRunRequest, JumpHopRunResponse, JumpHopRunStatus,
|
||||
@@ -47,7 +39,14 @@ pub use mapper::{
|
||||
JumpHopSessionSnapshotResponse, JumpHopStartRunRequest, JumpHopStylePreset, JumpHopTileAsset,
|
||||
JumpHopTileType, JumpHopWorkDetailResponse, JumpHopWorkMutationResponse,
|
||||
JumpHopWorkProfileResponse, JumpHopWorkSummaryResponse, JumpHopWorksResponse,
|
||||
JumpHopWorkspaceCreateRequest,
|
||||
JumpHopWorkspaceCreateRequest, Match3DAgentMessageFinalizeRecordInput,
|
||||
Match3DAgentMessageRecord, Match3DAgentMessageSubmitRecordInput,
|
||||
Match3DAgentSessionCreateRecordInput, Match3DAgentSessionRecord, Match3DAnchorItemRecord,
|
||||
Match3DAnchorPackRecord, Match3DClickConfirmationRecord, Match3DCompileDraftRecordInput,
|
||||
Match3DCreatorConfigRecord, Match3DItemSnapshotRecord, Match3DResultDraftRecord,
|
||||
Match3DRunClickRecordInput, Match3DRunRecord, Match3DRunRestartRecordInput,
|
||||
Match3DRunStartRecordInput, Match3DRunStopRecordInput, Match3DRunTimeUpRecordInput,
|
||||
Match3DTraySlotRecord, Match3DWorkProfileRecord, Match3DWorkUpdateRecordInput,
|
||||
NpcBattleInteractionRecord, NpcInteractionRecord, NpcStateRecord,
|
||||
PuzzleAgentMessageFinalizeRecordInput, PuzzleAgentMessageRecord,
|
||||
PuzzleAgentMessageSubmitRecordInput, PuzzleAgentSessionCreateRecordInput,
|
||||
@@ -585,6 +584,7 @@ impl SpacetimeClient {
|
||||
"SELECT * FROM public_work_play_daily_stat WHERE source_type = 'big-fish'",
|
||||
"SELECT * FROM creation_entry_config",
|
||||
"SELECT * FROM creation_entry_type_config",
|
||||
"SELECT * FROM asset_object",
|
||||
] {
|
||||
if let Ok(subscription) = self
|
||||
.subscribe_cached_read_model_query(connection, broken.clone(), query, false)
|
||||
|
||||
@@ -36,18 +36,6 @@ pub use self::combat::{
|
||||
BarkBattleDraftConfigRecord, BarkBattleRunRecord, BarkBattleRuntimeConfigRecord,
|
||||
ResolveCombatActionRecord,
|
||||
};
|
||||
pub use self::jump_hop::{
|
||||
JumpHopActionRequest, JumpHopActionResponse, JumpHopActionType, JumpHopCharacterAsset,
|
||||
JumpHopDifficulty, JumpHopDraftResponse, JumpHopGalleryCardResponse,
|
||||
JumpHopGalleryDetailResponse, JumpHopGalleryResponse, JumpHopGenerationStatus,
|
||||
JumpHopJumpRequest, JumpHopJumpResponse, JumpHopJumpResult, JumpHopLastJump, JumpHopPath,
|
||||
JumpHopPlatform, JumpHopRestartRunRequest, JumpHopRunResponse, JumpHopRunStatus,
|
||||
JumpHopRuntimeRunSnapshotResponse, JumpHopScoring, JumpHopSessionResponse,
|
||||
JumpHopSessionSnapshotResponse, JumpHopStartRunRequest, JumpHopStylePreset, JumpHopTileAsset,
|
||||
JumpHopTileType, JumpHopWorkDetailResponse, JumpHopWorkMutationResponse,
|
||||
JumpHopWorkProfileResponse, JumpHopWorkSummaryResponse, JumpHopWorksResponse,
|
||||
JumpHopWorkspaceCreateRequest,
|
||||
};
|
||||
pub use self::common::{
|
||||
BigFishAgentMessageRecord, BigFishAnchorItemRecord, BigFishAnchorPackRecord,
|
||||
BigFishBackgroundBlueprintRecord, BigFishDraftCompileRecordInput,
|
||||
@@ -77,6 +65,18 @@ pub use self::common::{
|
||||
VisualNovelRunSnapshotRecordInput, VisualNovelRunStartRecordInput,
|
||||
VisualNovelWorkCompileRecordInput,
|
||||
};
|
||||
pub use self::jump_hop::{
|
||||
JumpHopActionRequest, JumpHopActionResponse, JumpHopActionType, JumpHopCharacterAsset,
|
||||
JumpHopDifficulty, JumpHopDraftResponse, JumpHopGalleryCardResponse,
|
||||
JumpHopGalleryDetailResponse, JumpHopGalleryResponse, JumpHopGenerationStatus,
|
||||
JumpHopJumpRequest, JumpHopJumpResponse, JumpHopJumpResult, JumpHopLastJump, JumpHopPath,
|
||||
JumpHopPlatform, JumpHopRestartRunRequest, JumpHopRunResponse, JumpHopRunStatus,
|
||||
JumpHopRuntimeRunSnapshotResponse, JumpHopScoring, JumpHopSessionResponse,
|
||||
JumpHopSessionSnapshotResponse, JumpHopStartRunRequest, JumpHopStylePreset, JumpHopTileAsset,
|
||||
JumpHopTileType, JumpHopWorkDetailResponse, JumpHopWorkMutationResponse,
|
||||
JumpHopWorkProfileResponse, JumpHopWorkSummaryResponse, JumpHopWorksResponse,
|
||||
JumpHopWorkspaceCreateRequest,
|
||||
};
|
||||
pub use self::match3d::{
|
||||
Match3DAgentMessageFinalizeRecordInput, Match3DAgentMessageRecord,
|
||||
Match3DAgentMessageSubmitRecordInput, Match3DAgentSessionCreateRecordInput,
|
||||
@@ -120,7 +120,9 @@ pub use self::runtime_profile::{
|
||||
pub use self::story::{VisualNovelRuntimeEventRecord, VisualNovelRuntimeEventRecordInput};
|
||||
|
||||
pub(crate) use self::ai::map_ai_task_procedure_result;
|
||||
pub(crate) use self::assets::{map_entity_binding_procedure_result, map_procedure_result};
|
||||
pub(crate) use self::assets::{
|
||||
map_asset_object_row, map_entity_binding_procedure_result, map_procedure_result,
|
||||
};
|
||||
pub(crate) use self::auth::{
|
||||
map_auth_store_snapshot_import_procedure_result, map_auth_store_snapshot_procedure_result,
|
||||
};
|
||||
|
||||
@@ -115,6 +115,26 @@ pub(crate) fn map_snapshot(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn map_asset_object_row(row: AssetObject) -> AssetObjectRecord {
|
||||
build_asset_object_record(module_assets::AssetObjectUpsertSnapshot {
|
||||
asset_object_id: row.asset_object_id,
|
||||
bucket: row.bucket,
|
||||
object_key: row.object_key,
|
||||
access_policy: map_access_policy_back(row.access_policy),
|
||||
content_type: row.content_type,
|
||||
content_length: row.content_length,
|
||||
content_hash: row.content_hash,
|
||||
version: row.version,
|
||||
source_job_id: row.source_job_id,
|
||||
owner_user_id: row.owner_user_id,
|
||||
profile_id: row.profile_id,
|
||||
entity_id: row.entity_id,
|
||||
asset_kind: row.asset_kind,
|
||||
created_at_micros: row.created_at.to_micros_since_unix_epoch(),
|
||||
updated_at_micros: row.updated_at.to_micros_since_unix_epoch(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn map_access_policy(
|
||||
value: AssetObjectAccessPolicy,
|
||||
) -> crate::module_bindings::AssetObjectAccessPolicy {
|
||||
|
||||
@@ -161,7 +161,11 @@ fn map_jump_hop_work_snapshot(
|
||||
path: map_jump_hop_path(snapshot.path),
|
||||
character_asset,
|
||||
tile_atlas_asset,
|
||||
tile_assets: snapshot.tile_assets.into_iter().map(map_tile_asset).collect(),
|
||||
tile_assets: snapshot
|
||||
.tile_assets
|
||||
.into_iter()
|
||||
.map(map_tile_asset)
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -180,7 +184,11 @@ fn map_jump_hop_draft_snapshot(snapshot: JumpHopDraftSnapshot) -> JumpHopDraftRe
|
||||
end_mood_prompt: snapshot.end_mood_prompt,
|
||||
character_asset: snapshot.character_asset.map(map_character_asset),
|
||||
tile_atlas_asset: snapshot.tile_atlas_asset.map(map_character_asset),
|
||||
tile_assets: snapshot.tile_assets.into_iter().map(map_tile_asset).collect(),
|
||||
tile_assets: snapshot
|
||||
.tile_assets
|
||||
.into_iter()
|
||||
.map(map_tile_asset)
|
||||
.collect(),
|
||||
path: snapshot.path.map(map_jump_hop_path),
|
||||
cover_composite: snapshot.cover_composite,
|
||||
generation_status: parse_generation_status(&snapshot.generation_status),
|
||||
@@ -268,7 +276,9 @@ fn map_jump_hop_run_snapshot(snapshot: JumpHopRunSnapshot) -> JumpHopRuntimeRunS
|
||||
crate::module_bindings::JumpHopJumpResultKind::Miss => JumpHopJumpResult::Miss,
|
||||
crate::module_bindings::JumpHopJumpResultKind::Hit => JumpHopJumpResult::Hit,
|
||||
crate::module_bindings::JumpHopJumpResultKind::Finish => JumpHopJumpResult::Finish,
|
||||
crate::module_bindings::JumpHopJumpResultKind::Perfect => JumpHopJumpResult::Perfect,
|
||||
crate::module_bindings::JumpHopJumpResultKind::Perfect => {
|
||||
JumpHopJumpResult::Perfect
|
||||
}
|
||||
},
|
||||
}),
|
||||
started_at_ms: snapshot.started_at_ms,
|
||||
|
||||
@@ -145,6 +145,12 @@ pub(crate) fn map_puzzle_draft_level(snapshot: PuzzleDraftLevel) -> PuzzleDraftL
|
||||
ui_background_prompt: snapshot.ui_background_prompt,
|
||||
ui_background_image_src: snapshot.ui_background_image_src,
|
||||
ui_background_image_object_key: snapshot.ui_background_image_object_key,
|
||||
level_scene_image_src: snapshot.level_scene_image_src,
|
||||
level_scene_image_object_key: snapshot.level_scene_image_object_key,
|
||||
ui_spritesheet_image_src: snapshot.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: snapshot.ui_spritesheet_image_object_key,
|
||||
level_background_image_src: snapshot.level_background_image_src,
|
||||
level_background_image_object_key: snapshot.level_background_image_object_key,
|
||||
background_music: snapshot.background_music.map(map_puzzle_audio_asset),
|
||||
candidates: snapshot
|
||||
.candidates
|
||||
@@ -392,6 +398,10 @@ pub(crate) fn map_puzzle_runtime_level_snapshot(
|
||||
cover_image_src: snapshot.cover_image_src,
|
||||
ui_background_image_src: snapshot.ui_background_image_src,
|
||||
ui_background_image_object_key: snapshot.ui_background_image_object_key,
|
||||
level_background_image_src: snapshot.level_background_image_src,
|
||||
level_background_image_object_key: snapshot.level_background_image_object_key,
|
||||
ui_spritesheet_image_src: snapshot.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: snapshot.ui_spritesheet_image_object_key,
|
||||
background_music: snapshot.background_music.map(map_puzzle_audio_asset),
|
||||
board: map_puzzle_board_snapshot(snapshot.board),
|
||||
status: format_puzzle_runtime_level_status(snapshot.status).to_string(),
|
||||
@@ -835,6 +845,12 @@ pub struct PuzzleDraftLevelRecord {
|
||||
pub ui_background_prompt: Option<String>,
|
||||
pub ui_background_image_src: Option<String>,
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
pub level_scene_image_src: Option<String>,
|
||||
pub level_scene_image_object_key: Option<String>,
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
pub level_background_image_src: Option<String>,
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
pub background_music: Option<PuzzleAudioAssetRecord>,
|
||||
pub candidates: Vec<PuzzleGeneratedImageCandidateRecord>,
|
||||
pub selected_candidate_id: Option<String>,
|
||||
@@ -1038,6 +1054,10 @@ pub struct PuzzleRuntimeLevelRecord {
|
||||
pub cover_image_src: Option<String>,
|
||||
pub ui_background_image_src: Option<String>,
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
pub level_background_image_src: Option<String>,
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
pub background_music: Option<PuzzleAudioAssetRecord>,
|
||||
pub board: PuzzleBoardRecord,
|
||||
pub status: String,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||
|
||||
|
||||
@@ -17,6 +17,12 @@ pub struct PuzzleDraftLevel {
|
||||
pub ui_background_prompt: Option<String>,
|
||||
pub ui_background_image_src: Option<String>,
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
pub level_scene_image_src: Option<String>,
|
||||
pub level_scene_image_object_key: Option<String>,
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
pub level_background_image_src: Option<String>,
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
pub background_music: Option<PuzzleAudioAsset>,
|
||||
pub candidates: Vec<PuzzleGeneratedImageCandidate>,
|
||||
pub selected_candidate_id: Option<String>,
|
||||
|
||||
@@ -23,6 +23,10 @@ pub struct PuzzleRuntimeLevelSnapshot {
|
||||
pub cover_image_src: Option<String>,
|
||||
pub ui_background_image_src: Option<String>,
|
||||
pub ui_background_image_object_key: Option<String>,
|
||||
pub level_background_image_src: Option<String>,
|
||||
pub level_background_image_object_key: Option<String>,
|
||||
pub ui_spritesheet_image_src: Option<String>,
|
||||
pub ui_spritesheet_image_object_key: Option<String>,
|
||||
pub background_music: Option<PuzzleAudioAsset>,
|
||||
pub board: PuzzleBoardSnapshot,
|
||||
pub status: PuzzleRuntimeLevelStatus,
|
||||
|
||||
@@ -81,7 +81,9 @@ fn spacetime_metrics() -> &'static SpacetimeMetrics {
|
||||
read_duration_ms: meter
|
||||
.f64_histogram("genarrative.spacetime.read.duration_ms")
|
||||
.with_unit("ms")
|
||||
.with_description("SpacetimeDB local subscription cache read duration in milliseconds")
|
||||
.with_description(
|
||||
"SpacetimeDB local subscription cache read duration in milliseconds",
|
||||
)
|
||||
.build(),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1293,6 +1293,12 @@ fn select_puzzle_cover_image_tx(
|
||||
ui_background_prompt: target_level.ui_background_prompt,
|
||||
ui_background_image_src: target_level.ui_background_image_src,
|
||||
ui_background_image_object_key: target_level.ui_background_image_object_key,
|
||||
level_scene_image_src: target_level.level_scene_image_src,
|
||||
level_scene_image_object_key: target_level.level_scene_image_object_key,
|
||||
ui_spritesheet_image_src: target_level.ui_spritesheet_image_src,
|
||||
ui_spritesheet_image_object_key: target_level.ui_spritesheet_image_object_key,
|
||||
level_background_image_src: target_level.level_background_image_src,
|
||||
level_background_image_object_key: target_level.level_background_image_object_key,
|
||||
background_music: target_level.background_music,
|
||||
candidates: selected_level_draft.candidates,
|
||||
selected_candidate_id: selected_level_draft.selected_candidate_id,
|
||||
@@ -2636,6 +2642,12 @@ fn build_profile_levels_from_row(
|
||||
ui_background_prompt: None,
|
||||
ui_background_image_src: None,
|
||||
ui_background_image_object_key: None,
|
||||
level_scene_image_src: None,
|
||||
level_scene_image_object_key: None,
|
||||
ui_spritesheet_image_src: None,
|
||||
ui_spritesheet_image_object_key: None,
|
||||
level_background_image_src: None,
|
||||
level_background_image_object_key: None,
|
||||
background_music: None,
|
||||
candidates: Vec::new(),
|
||||
selected_candidate_id: None,
|
||||
|
||||
@@ -22,7 +22,7 @@ const PLACEHOLDER_PUZZLE_IMAGE =
|
||||
<defs>
|
||||
<linearGradient id="sky" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#fef3c7" />
|
||||
<stop offset="0.45" stop-color="#fb7185" />
|
||||
<stop offset="0.45" stop-color="#c7653d" />
|
||||
<stop offset="1" stop-color="#312e81" />
|
||||
</linearGradient>
|
||||
<radialGradient id="glow" cx="42%" cy="34%" r="46%">
|
||||
|
||||
@@ -173,7 +173,7 @@ function ImageFrame({
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`overflow-hidden rounded-2xl border border-[var(--platform-subpanel-border)] bg-[radial-gradient(circle_at_top,rgba(255,255,255,0.22),transparent_42%),linear-gradient(180deg,rgba(255,96,147,0.92),rgba(255,146,109,0.84))] ${tone === 'landscape' ? 'aspect-[16/9]' : 'aspect-square'}`}
|
||||
className={`overflow-hidden rounded-2xl border border-[var(--platform-subpanel-border)] bg-[radial-gradient(circle_at_top,rgba(255,255,255,0.22),transparent_42%),linear-gradient(180deg,rgba(204,117,76,0.9),rgba(223,127,64,0.82))] ${tone === 'landscape' ? 'aspect-[16/9]' : 'aspect-square'}`}
|
||||
>
|
||||
{src ? (
|
||||
<ResolvedAssetImage
|
||||
@@ -238,7 +238,7 @@ function PendingEntityCard({
|
||||
</div>
|
||||
<div className="platform-progress-track mt-3 h-2.5 overflow-hidden rounded-full">
|
||||
<div
|
||||
className="h-full bg-[linear-gradient(90deg,#ff4f8b_0%,#ff8a73_100%)] transition-[width] duration-300"
|
||||
className="h-full bg-[var(--platform-button-primary-solid)] transition-[width] duration-300"
|
||||
style={{ width: `${Math.max(6, Math.min(100, progress))}%` }}
|
||||
/>
|
||||
</div>
|
||||
@@ -313,7 +313,7 @@ function OpeningCgPreview({
|
||||
</div>
|
||||
{isGenerating ? (
|
||||
<div className="platform-progress-track h-2 overflow-hidden rounded-full">
|
||||
<div className="h-full w-2/3 animate-pulse bg-[linear-gradient(90deg,#ff4f8b_0%,#ff8a73_52%,#ffd2a6_100%)]" />
|
||||
<div className="h-full w-2/3 animate-pulse bg-[linear-gradient(90deg,#df7f40_0%,#cc754c_52%,#eaccb3_100%)]" />
|
||||
</div>
|
||||
) : null}
|
||||
{openingCg?.status === 'failed' && openingCg.errorMessage ? (
|
||||
@@ -437,7 +437,7 @@ function CatalogCard({
|
||||
<div
|
||||
className={`shrink-0 rounded-full border px-2.5 py-1 text-[10px] ${
|
||||
isSelected
|
||||
? 'border-rose-300/25 bg-rose-500/14 text-rose-50'
|
||||
? 'border-[var(--platform-button-danger-border)] bg-[var(--platform-button-danger-fill)] text-[var(--platform-button-danger-text)]'
|
||||
: 'platform-subpanel text-[var(--platform-text-soft)]'
|
||||
}`}
|
||||
>
|
||||
@@ -453,7 +453,7 @@ function CatalogCard({
|
||||
onClick={disabled ? undefined : onClick}
|
||||
aria-disabled={disabled}
|
||||
className={`w-full rounded-[1.3rem] border p-2.5 text-left transition-colors xl:p-3 ${
|
||||
isSelected ? 'border-rose-300/35 bg-rose-500/10' : 'platform-subpanel'
|
||||
isSelected ? 'border-[var(--platform-button-danger-border)] bg-[var(--platform-button-danger-fill)]' : 'platform-subpanel'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-start gap-3 xl:gap-3.5">
|
||||
@@ -491,7 +491,7 @@ function CatalogCard({
|
||||
onClick={disabled ? undefined : onClick}
|
||||
aria-disabled={disabled}
|
||||
className={`w-full rounded-[1.4rem] border p-3 text-left transition-colors ${
|
||||
isSelected ? 'border-rose-300/35 bg-rose-500/10' : 'platform-subpanel'
|
||||
isSelected ? 'border-[var(--platform-button-danger-border)] bg-[var(--platform-button-danger-fill)]' : 'platform-subpanel'
|
||||
}`}
|
||||
>
|
||||
<div className="space-y-3">
|
||||
@@ -899,7 +899,7 @@ export function CustomWorldEntityCatalog({
|
||||
ref={scrollContainerRef}
|
||||
className="h-full min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-1 scrollbar-hide xl:space-y-4 xl:pr-2 2xl:space-y-5 2xl:pr-3"
|
||||
>
|
||||
<div className="px-1 pb-1 text-center xl:flex xl:items-end xl:justify-between xl:gap-6 xl:rounded-[2rem] xl:border xl:border-[var(--platform-subpanel-border)] xl:bg-white/55 xl:px-6 xl:py-3 xl:text-left xl:shadow-[0_18px_70px_rgba(255,79,139,0.08)] xl:backdrop-blur-sm 2xl:px-7">
|
||||
<div className="px-1 pb-1 text-center xl:flex xl:items-end xl:justify-between xl:gap-6 xl:rounded-[2rem] xl:border xl:border-[var(--platform-subpanel-border)] xl:bg-white/55 xl:px-6 xl:py-3 xl:text-left xl:shadow-[0_18px_70px_rgba(112,57,30,0.08)] xl:backdrop-blur-sm 2xl:px-7">
|
||||
<div className="text-[11px] font-bold tracking-[0.28em] text-zinc-500">
|
||||
世界档案
|
||||
</div>
|
||||
@@ -913,7 +913,7 @@ export function CustomWorldEntityCatalog({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="platform-sticky-fade sticky top-0 z-10 -mx-1 space-y-3 px-1 pb-3 pt-1 backdrop-blur-sm xl:rounded-[1.75rem] xl:border xl:border-[var(--platform-subpanel-border)] xl:bg-white/70 xl:px-4 xl:py-3 xl:shadow-[0_16px_48px_rgba(255,79,139,0.08)]">
|
||||
<div className="platform-sticky-fade sticky top-0 z-10 -mx-1 space-y-3 px-1 pb-3 pt-1 backdrop-blur-sm xl:rounded-[1.75rem] xl:border xl:border-[var(--platform-subpanel-border)] xl:bg-white/70 xl:px-4 xl:py-3 xl:shadow-[0_16px_48px_rgba(112,57,30,0.08)]">
|
||||
<div className="flex gap-2 overflow-x-auto pb-1 scrollbar-hide xl:pb-0">
|
||||
{RESULT_TABS.map((tab) => (
|
||||
<div key={tab.id}>
|
||||
|
||||
@@ -225,7 +225,7 @@ export function CustomWorldGenerationView({
|
||||
|
||||
<div className="platform-progress-track mt-4 h-4 overflow-hidden rounded-full xl:mt-5 xl:h-5">
|
||||
<motion.div
|
||||
className="h-full bg-[linear-gradient(90deg,#ff4f8b_0%,#ff8a73_52%,#ffd2a6_100%)]"
|
||||
className="h-full bg-[linear-gradient(90deg,#df7f40_0%,#cc754c_52%,#eaccb3_100%)]"
|
||||
animate={{ width: `${progressValue}%` }}
|
||||
transition={{ duration: 0.35, ease: 'easeOut' }}
|
||||
/>
|
||||
@@ -283,9 +283,9 @@ export function CustomWorldGenerationView({
|
||||
)}
|
||||
className={`rounded-2xl border px-4 py-3 transition-colors ${
|
||||
step.status === 'completed'
|
||||
? 'border-emerald-400/16 bg-emerald-500/8'
|
||||
? 'border-[var(--platform-success-border)] bg-[var(--platform-success-bg)]'
|
||||
: step.status === 'active'
|
||||
? 'border-sky-300/22 bg-sky-500/10'
|
||||
? 'border-[var(--platform-cool-border)] bg-[var(--platform-cool-bg)]'
|
||||
: 'platform-subpanel'
|
||||
} custom-world-generation-step`}
|
||||
initial={
|
||||
@@ -317,9 +317,9 @@ export function CustomWorldGenerationView({
|
||||
<motion.div
|
||||
className={`h-full rounded-full ${
|
||||
step.status === 'completed'
|
||||
? 'bg-emerald-300'
|
||||
? 'bg-[var(--platform-success-text)]'
|
||||
: step.status === 'active'
|
||||
? 'bg-[linear-gradient(90deg,#7dd3fc_0%,#fcd34d_100%)]'
|
||||
? 'bg-[linear-gradient(90deg,#df7f40_0%,#cc754c_56%,#eaccb3_100%)]'
|
||||
: 'bg-white/18'
|
||||
}`}
|
||||
animate={{ width: `${stepProgress}%` }}
|
||||
@@ -335,7 +335,7 @@ export function CustomWorldGenerationView({
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="mt-4 rounded-2xl border border-rose-400/18 bg-rose-500/10 px-4 py-3 text-sm leading-6 text-rose-100">
|
||||
<div className="mt-4 rounded-2xl border border-[var(--platform-button-danger-border)] bg-[var(--platform-button-danger-fill)] px-4 py-3 text-sm leading-6 text-[var(--platform-button-danger-text)]">
|
||||
{error}
|
||||
</div>
|
||||
) : null}
|
||||
@@ -364,7 +364,7 @@ export function CustomWorldGenerationView({
|
||||
<button
|
||||
type="button"
|
||||
onClick={onInterrupt}
|
||||
className="rounded-full border border-rose-300/18 bg-rose-500/10 px-4 py-2 text-sm text-rose-100 transition-colors hover:text-white"
|
||||
className="rounded-full border border-[var(--platform-button-danger-border)] bg-[var(--platform-button-danger-fill)] px-4 py-2 text-sm text-[var(--platform-button-danger-text)] transition-colors hover:text-[var(--platform-text-strong)]"
|
||||
>
|
||||
{interruptLabel}
|
||||
</button>
|
||||
|
||||
@@ -260,7 +260,7 @@ function ThemeOptionCard({
|
||||
onClick={onClick}
|
||||
className={`platform-subpanel w-full rounded-[1.5rem] p-4 text-left transition ${
|
||||
active
|
||||
? 'border-[var(--platform-surface-hover-border)] shadow-[0_18px_44px_rgba(255,91,132,0.14)]'
|
||||
? 'border-[var(--platform-surface-hover-border)] shadow-[0_18px_44px_rgba(112,57,30,0.14)]'
|
||||
: 'hover:border-[var(--platform-surface-hover-border)]'
|
||||
}`}
|
||||
>
|
||||
@@ -534,8 +534,8 @@ export function AccountModal({
|
||||
<ThemeOptionCard
|
||||
active={platformTheme === 'light'}
|
||||
title="亮色主题"
|
||||
detail="暖白底面板,粉橘强调。"
|
||||
previewClassName="bg-[radial-gradient(circle_at_top,rgba(255,255,255,0.28),transparent_30%),linear-gradient(135deg,#fff8fb_0%,#ffe9ee_52%,#ffd8cb_100%)] border border-white/70"
|
||||
detail="暖白底面板,陶土橙强调。"
|
||||
previewClassName="bg-[radial-gradient(circle_at_top,rgba(255,255,255,0.32),transparent_30%),linear-gradient(135deg,#fffdf9_0%,#f4e5d7_52%,#eaccb3_100%)] border border-white/70"
|
||||
onClick={() => onPlatformThemeChange('light')}
|
||||
/>
|
||||
<ThemeOptionCard
|
||||
|
||||
@@ -60,7 +60,7 @@ export function BindPhoneScreen({
|
||||
<div className={`platform-theme platform-theme--${platformTheme} min-h-screen bg-[var(--platform-body-fill)] px-4 py-6 text-[var(--platform-text-strong)] sm:py-8`}>
|
||||
<div className="mx-auto flex min-h-[calc(100vh-3rem)] w-full max-w-5xl items-center justify-center sm:min-h-[calc(100vh-4rem)]">
|
||||
<div className="platform-auth-card grid w-full max-w-4xl overflow-hidden rounded-[28px] md:grid-cols-[1.05fr_0.95fr]">
|
||||
<div className="border-b border-[var(--platform-subpanel-border)] bg-[linear-gradient(135deg,rgba(255,79,139,0.18),rgba(255,155,120,0.14))] px-6 py-8 md:border-b-0 md:border-r md:px-10 md:py-12">
|
||||
<div className="border-b border-[var(--platform-subpanel-border)] bg-[linear-gradient(135deg,rgba(204,117,76,0.18),rgba(240,203,169,0.16))] px-6 py-8 md:border-b-0 md:border-r md:px-10 md:py-12">
|
||||
<div className="selection-hero-brand selection-hero-brand--left">
|
||||
<div className="selection-hero-brand__title">陶泥儿</div>
|
||||
<div className="selection-hero-brand__subtitle">视觉叙事 RPG</div>
|
||||
|
||||
@@ -127,7 +127,7 @@ export function BarkBattleConfigEditor({
|
||||
value={title}
|
||||
disabled={isBusy}
|
||||
onChange={(event) => setTitle(event.target.value)}
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-base font-semibold text-[var(--platform-text-strong)] outline-none transition focus:border-rose-200 focus:bg-white focus:ring-2 focus:ring-rose-100"
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-base font-semibold text-[var(--platform-text-strong)] outline-none transition focus:border-[var(--platform-surface-hover-border)] focus:bg-white focus:ring-2 focus:ring-[var(--platform-warm-border)]"
|
||||
maxLength={40}
|
||||
aria-label="作品标题"
|
||||
/>
|
||||
@@ -141,7 +141,7 @@ export function BarkBattleConfigEditor({
|
||||
value={description}
|
||||
disabled={isBusy}
|
||||
onChange={(event) => setDescription(event.target.value)}
|
||||
className="h-[5.5rem] min-h-[5.5rem] w-full resize-none rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 py-3 text-base leading-6 text-[var(--platform-text-strong)] outline-none transition focus:border-rose-200 focus:bg-white focus:ring-2 focus:ring-rose-100"
|
||||
className="h-[5.5rem] min-h-[5.5rem] w-full resize-none rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 py-3 text-base leading-6 text-[var(--platform-text-strong)] outline-none transition focus:border-[var(--platform-surface-hover-border)] focus:bg-white focus:ring-2 focus:ring-[var(--platform-warm-border)]"
|
||||
maxLength={160}
|
||||
placeholder=""
|
||||
aria-label="简介"
|
||||
@@ -157,7 +157,7 @@ export function BarkBattleConfigEditor({
|
||||
value={themePreset}
|
||||
disabled={isBusy}
|
||||
onChange={(event) => setThemePreset(event.target.value)}
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-rose-200 focus:bg-white focus:ring-2 focus:ring-rose-100"
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-[var(--platform-surface-hover-border)] focus:bg-white focus:ring-2 focus:ring-[var(--platform-warm-border)]"
|
||||
aria-label="主题背景"
|
||||
>
|
||||
{THEME_OPTIONS.map((option) => (
|
||||
@@ -180,7 +180,7 @@ export function BarkBattleConfigEditor({
|
||||
event.target.value as BarkBattleDifficultyPreset,
|
||||
)
|
||||
}
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-rose-200 focus:bg-white focus:ring-2 focus:ring-rose-100"
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-[var(--platform-surface-hover-border)] focus:bg-white focus:ring-2 focus:ring-[var(--platform-warm-border)]"
|
||||
aria-label="难度预设"
|
||||
>
|
||||
{DIFFICULTY_OPTIONS.map((option) => (
|
||||
@@ -201,7 +201,7 @@ export function BarkBattleConfigEditor({
|
||||
onChange={(event) =>
|
||||
setPlayerDogSkinPreset(event.target.value)
|
||||
}
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-rose-200 focus:bg-white focus:ring-2 focus:ring-rose-100"
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-[var(--platform-surface-hover-border)] focus:bg-white focus:ring-2 focus:ring-[var(--platform-warm-border)]"
|
||||
aria-label="玩家狗狗"
|
||||
>
|
||||
{DOG_SKIN_OPTIONS.map((option) => (
|
||||
@@ -222,7 +222,7 @@ export function BarkBattleConfigEditor({
|
||||
onChange={(event) =>
|
||||
setOpponentDogSkinPreset(event.target.value)
|
||||
}
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-rose-200 focus:bg-white focus:ring-2 focus:ring-rose-100"
|
||||
className="h-11 w-full rounded-[1.05rem] border border-[var(--platform-subpanel-border)] bg-white/90 px-4 text-sm font-black text-[var(--platform-text-strong)] outline-none transition focus:border-[var(--platform-surface-hover-border)] focus:bg-white focus:ring-2 focus:ring-[var(--platform-warm-border)]"
|
||||
aria-label="对手狗狗"
|
||||
>
|
||||
{DOG_SKIN_OPTIONS.map((option) => (
|
||||
|
||||
@@ -275,3 +275,64 @@ test('creative image input panel can show an image without exposing AI redraw co
|
||||
expect(screen.queryByRole('switch', { name: 'AI重绘' })).toBeNull();
|
||||
expect(screen.getByLabelText('画面描述')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('creative image input panel can upload prompt references while showing a main image', () => {
|
||||
const onPromptReferenceFilesSelect = vi.fn();
|
||||
|
||||
render(
|
||||
<CreativeImageInputPanel
|
||||
uploadedImageSrc="/generated-puzzle-assets/session/level/image.png"
|
||||
uploadedImageAlt="拼图关卡图"
|
||||
canUploadPromptReferences
|
||||
mainImageInputId="level-image-upload-input"
|
||||
promptTextareaId="level-prompt-input"
|
||||
prompt="旧街灯牌下的猫。"
|
||||
promptLabel="画面描述"
|
||||
aiRedraw
|
||||
promptReferenceImages={[
|
||||
{
|
||||
id: 'prompt-ref-1',
|
||||
label: '描述参考图 1',
|
||||
imageSrc: 'data:image/png;base64,prompt-ref-1',
|
||||
},
|
||||
]}
|
||||
imageModelPicker={null}
|
||||
submitLabel="重新生成画面"
|
||||
submitDisabled={false}
|
||||
labels={{
|
||||
imageField: '画面图',
|
||||
uploadImage: '上传主图',
|
||||
replaceImage: '更换主图',
|
||||
emptyImageHint: '上传图片/填写画面描述',
|
||||
removeImage: '移除主图',
|
||||
removeImageConfirmTitle: '移除主图?',
|
||||
removeImageConfirmBody: '移除后可重新上传或选择历史图片。',
|
||||
promptReferenceUpload: '上传参考图',
|
||||
promptReferencePreviewAlt: '参考图预览',
|
||||
closePromptReferencePreview: '关闭参考图预览',
|
||||
}}
|
||||
onMainImageFileSelect={() => {}}
|
||||
onMainImageRemove={() => {}}
|
||||
onAiRedrawChange={() => {}}
|
||||
onPromptChange={() => {}}
|
||||
onPromptReferenceFilesSelect={onPromptReferenceFilesSelect}
|
||||
onSubmit={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const promptReferenceInput = screen.getByLabelText('上传参考图', {
|
||||
selector: 'input',
|
||||
});
|
||||
fireEvent.change(promptReferenceInput, {
|
||||
target: {
|
||||
files: [new File(['a'], 'prompt-reference.png', { type: 'image/png' })],
|
||||
},
|
||||
});
|
||||
|
||||
expect(onPromptReferenceFilesSelect).toHaveBeenCalledWith([
|
||||
expect.any(File),
|
||||
]);
|
||||
expect(
|
||||
screen.getByRole('button', { name: '预览参考图 描述参考图 1' }),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ export type CreativeImageInputReferenceImage = {
|
||||
id: string;
|
||||
label: string;
|
||||
imageSrc: string;
|
||||
assetObjectId?: string | null;
|
||||
};
|
||||
|
||||
export type CreativeImageInputPanelLabels = {
|
||||
@@ -37,6 +38,7 @@ export type CreativeImageInputPanelProps = {
|
||||
mainImageMode?: 'edit' | 'preview';
|
||||
canRemoveMainImage?: boolean;
|
||||
canToggleAiRedraw?: boolean;
|
||||
canUploadPromptReferences?: boolean;
|
||||
uploadedImageSrc: string;
|
||||
uploadedImageAlt: string;
|
||||
uploadedImageRefreshKey?: string | number | null;
|
||||
@@ -78,6 +80,7 @@ export function CreativeImageInputPanel({
|
||||
mainImageMode = 'edit',
|
||||
canRemoveMainImage = true,
|
||||
canToggleAiRedraw = true,
|
||||
canUploadPromptReferences,
|
||||
uploadedImageSrc,
|
||||
uploadedImageAlt,
|
||||
uploadedImageRefreshKey = null,
|
||||
@@ -113,6 +116,8 @@ export function CreativeImageInputPanel({
|
||||
const [isRemoveImageConfirmOpen, setIsRemoveImageConfirmOpen] =
|
||||
useState(false);
|
||||
const showPrompt = mainImageMode === 'preview' || !uploadedImageSrc || aiRedraw;
|
||||
const shouldShowPromptReferences =
|
||||
canUploadPromptReferences ?? !uploadedImageSrc;
|
||||
const promptReferenceUploadDisabled =
|
||||
disabled || promptReferenceImages.length >= promptReferenceLimit;
|
||||
const canEditMainImage = mainImageMode === 'edit';
|
||||
@@ -156,7 +161,7 @@ export function CreativeImageInputPanel({
|
||||
{labels.imageField}
|
||||
</div>
|
||||
<div className="creative-image-input-panel__image-frame puzzle-image-card-frame flex min-h-0 flex-1 items-center justify-center">
|
||||
<div className="creative-image-input-panel__image-card puzzle-image-upload-card relative aspect-square h-full max-h-full max-w-full overflow-hidden rounded-[1.25rem] border border-[var(--platform-subpanel-border)] bg-white/90 shadow-[0_12px_28px_rgba(15,23,42,0.08)] transition lg:h-auto lg:w-full">
|
||||
<div className="creative-image-input-panel__image-card puzzle-image-upload-card relative aspect-square h-full min-h-[14rem] max-h-full max-w-full overflow-hidden rounded-[1.25rem] border border-[var(--platform-subpanel-border)] bg-white/90 shadow-[0_12px_28px_rgba(15,23,42,0.08)] transition sm:min-h-[18rem] lg:h-auto lg:w-full">
|
||||
{canEditMainImage ? (
|
||||
<>
|
||||
<input
|
||||
@@ -207,7 +212,7 @@ export function CreativeImageInputPanel({
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={onHistoryClick}
|
||||
className={`absolute right-3 top-3 z-10 inline-flex items-center gap-1.5 rounded-full border border-white/80 bg-white/94 px-3 py-2 text-[11px] font-black text-[var(--platform-text-strong)] shadow-sm backdrop-blur transition hover:text-[#ff4056] ${
|
||||
className={`absolute right-3 top-3 z-10 inline-flex items-center gap-1.5 rounded-full border border-white/80 bg-white/94 px-3 py-2 text-[11px] font-black text-[var(--platform-text-strong)] shadow-sm backdrop-blur transition hover:text-[var(--platform-accent)] ${
|
||||
disabled ? 'cursor-not-allowed opacity-55' : ''
|
||||
}`}
|
||||
aria-label={labels.history ?? '选择历史图片'}
|
||||
@@ -232,7 +237,7 @@ export function CreativeImageInputPanel({
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`relative h-5 w-9 rounded-full transition ${
|
||||
aiRedraw ? 'bg-[#ff4056]' : 'bg-zinc-300'
|
||||
aiRedraw ? 'bg-[var(--platform-accent)]' : 'bg-zinc-300'
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
@@ -248,7 +253,7 @@ export function CreativeImageInputPanel({
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => setIsRemoveImageConfirmOpen(true)}
|
||||
className="absolute left-3 top-3 z-10 inline-flex h-10 w-10 items-center justify-center rounded-full border border-white/80 bg-white/94 text-[var(--platform-text-strong)] shadow-sm backdrop-blur transition hover:text-[#ff4056] disabled:cursor-not-allowed disabled:opacity-55"
|
||||
className="absolute left-3 top-3 z-10 inline-flex h-10 w-10 items-center justify-center rounded-full border border-white/80 bg-white/94 text-[var(--platform-text-strong)] shadow-sm backdrop-blur transition hover:text-[var(--platform-accent)] disabled:cursor-not-allowed disabled:opacity-55"
|
||||
aria-label={labels.removeImage}
|
||||
title={labels.removeImage}
|
||||
>
|
||||
@@ -257,7 +262,7 @@ export function CreativeImageInputPanel({
|
||||
) : canEditMainImage && !uploadedImageSrc ? (
|
||||
<label
|
||||
htmlFor={mainImageInputId}
|
||||
className={`absolute bottom-9 left-1/2 z-10 -translate-x-1/2 whitespace-nowrap text-center text-sm font-black text-[var(--platform-text-strong)] drop-shadow-[0_1px_0_rgba(255,255,255,0.82)] transition hover:text-[#ff4056] sm:bottom-10 ${
|
||||
className={`absolute bottom-9 left-1/2 z-10 -translate-x-1/2 whitespace-nowrap text-center text-sm font-black text-[var(--platform-text-strong)] drop-shadow-[0_1px_0_rgba(255,255,255,0.82)] transition hover:text-[var(--platform-accent)] sm:bottom-10 ${
|
||||
disabled
|
||||
? 'cursor-not-allowed opacity-55'
|
||||
: 'cursor-pointer'
|
||||
@@ -291,9 +296,9 @@ export function CreativeImageInputPanel({
|
||||
aria-label={promptAriaLabel ?? promptLabel}
|
||||
/>
|
||||
{imageModelPicker}
|
||||
{!uploadedImageSrc && onPromptReferenceFilesSelect ? (
|
||||
{shouldShowPromptReferences && onPromptReferenceFilesSelect ? (
|
||||
<label
|
||||
className={`absolute bottom-3 right-3 z-10 inline-flex h-8 w-8 items-center justify-center rounded-full border border-[var(--platform-subpanel-border)] bg-white/96 text-[var(--platform-text-strong)] shadow-sm transition hover:bg-[var(--platform-subpanel-fill)] hover:text-[#ff4056] ${
|
||||
className={`absolute bottom-3 right-3 z-10 inline-flex h-8 w-8 items-center justify-center rounded-full border border-[var(--platform-subpanel-border)] bg-white/96 text-[var(--platform-text-strong)] shadow-sm transition hover:bg-[var(--platform-subpanel-fill)] hover:text-[var(--platform-accent)] ${
|
||||
promptReferenceUploadDisabled
|
||||
? 'cursor-not-allowed opacity-55'
|
||||
: 'cursor-pointer'
|
||||
@@ -320,7 +325,7 @@ export function CreativeImageInputPanel({
|
||||
</label>
|
||||
) : null}
|
||||
</div>
|
||||
{!uploadedImageSrc && promptReferenceImages.length > 0 ? (
|
||||
{shouldShowPromptReferences && promptReferenceImages.length > 0 ? (
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{promptReferenceImages.map((reference) => (
|
||||
<div
|
||||
@@ -347,7 +352,7 @@ export function CreativeImageInputPanel({
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => onPromptReferenceRemove(reference.id)}
|
||||
className="absolute right-0.5 top-0.5 inline-flex h-5 w-5 items-center justify-center rounded-full bg-white/94 text-[var(--platform-text-strong)] shadow-sm transition hover:text-[#ff4056] disabled:opacity-55"
|
||||
className="absolute right-0.5 top-0.5 inline-flex h-5 w-5 items-center justify-center rounded-full bg-white/94 text-[var(--platform-text-strong)] shadow-sm transition hover:text-[var(--platform-accent)] disabled:opacity-55"
|
||||
aria-label={`移除参考图 ${reference.label}`}
|
||||
title="移除参考图"
|
||||
>
|
||||
|
||||
@@ -377,7 +377,7 @@ export function SquareImageCropModal({
|
||||
className="h-full w-full object-fill"
|
||||
/>
|
||||
<div
|
||||
className={`absolute border-2 border-sky-200/95 shadow-[0_0_0_9999px_rgba(0,0,0,0.38)] outline outline-1 outline-black/35 ${
|
||||
className={`absolute border-2 border-[var(--platform-accent)] shadow-[0_0_0_9999px_rgba(61,31,16,0.34)] outline outline-1 outline-[rgba(74,34,15,0.35)] ${
|
||||
activeDragHandle === 'move' ? 'cursor-grabbing' : 'cursor-grab'
|
||||
}`}
|
||||
style={previewStyle}
|
||||
@@ -410,13 +410,13 @@ export function SquareImageCropModal({
|
||||
onPointerUp={stopCropDrag}
|
||||
onPointerCancel={stopCropDrag}
|
||||
>
|
||||
<span className="absolute left-1/2 top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full border border-white bg-sky-300 shadow-[0_0_0_3px_rgba(2,132,199,0.32)]" />
|
||||
<span className="absolute left-1/2 top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full border border-white bg-[var(--platform-accent)] shadow-[0_0_0_3px_rgba(204,117,76,0.32)]" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{error ? (
|
||||
<div className="mt-4 rounded-2xl border border-rose-400/25 bg-rose-500/10 px-3 py-2 text-sm text-rose-600">
|
||||
<div className="mt-4 rounded-2xl border border-[var(--platform-button-danger-border)] bg-[var(--platform-button-danger-fill)] px-3 py-2 text-sm text-[var(--platform-button-danger-text)]">
|
||||
{error}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -136,7 +136,7 @@ function CreationAgentOperationBanner({
|
||||
: 'platform-banner--success';
|
||||
const progress = normalizeCreationAgentProgress(visibleOperation.progress);
|
||||
const progressFillStyle = isFailed
|
||||
? { background: 'linear-gradient(90deg, #fb7185 0%, #f43f5e 100%)' }
|
||||
? { background: 'linear-gradient(90deg, #c7653d 0%, #a6402f 100%)' }
|
||||
: isRunning
|
||||
? { background: 'var(--platform-button-primary-fill)' }
|
||||
: { background: 'linear-gradient(90deg, #86efac 0%, #34d399 100%)' };
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user