Compare commits
100 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1fa973d25 | |||
| 9fa05eccaf | |||
| 709ef6256c | |||
| 37d45d2de8 | |||
| 6b13d1d613 | |||
| d5eca8cce6 | |||
| 2e78cbf152 | |||
| 840baf208f | |||
| d8af0fa882 | |||
| faed0ec251 | |||
| 6e63a118e0 | |||
| 4ae5ab14fa | |||
| b73a329b2c | |||
| 06004bfeea | |||
| ecea7b4ad3 | |||
| b1e82d64cb | |||
| b7622f4a24 | |||
| cb840c6e8c | |||
| 0a9cdf6395 | |||
| e382d23892 | |||
| 37ae7508b8 | |||
| 1ae6c6cd06 | |||
| 459f8a60e5 | |||
| 63c495dab0 | |||
| b37d91882c | |||
| dd339638cc | |||
| 0caf998227 | |||
| 6eed6bd13f | |||
| b543a060b7 | |||
| 9993b2feb5 | |||
| d348cf9064 | |||
| e640219243 | |||
| da2ad83c3b | |||
| ad19c9475e | |||
| 975a2e577c | |||
| 1b40f030e7 | |||
| 098693636a | |||
| e17af3008e | |||
| 64bd006981 | |||
| 6a4cb2bc18 | |||
| 1b3a3b003f | |||
| ff8e517c8e | |||
| d874a13a92 | |||
| 5eba53a5cc | |||
| 33ddb5de27 | |||
| bf8f96c115 | |||
| e469831543 | |||
| 869abad879 | |||
| 280a2dc5d1 | |||
| 3c6e084a41 | |||
| ed3369a494 | |||
| fdc48fe725 | |||
| 2748468d12 | |||
| 09ad0073fe | |||
| 42b702d362 | |||
| edfd1f9143 | |||
| 423f2d7184 | |||
| 656c89e4b2 | |||
| aa9076c95c | |||
| 0ec1179bf1 | |||
| 2938a49cac | |||
| ae0f9376c9 | |||
| 29d0cbb4df | |||
| 41366dd71d | |||
| 721e45f01b | |||
| f4b496caca | |||
| fc0fd846f9 | |||
| fa99d9ad62 | |||
| 64a52005f8 | |||
| 645d806fed | |||
| 0b9d16e8f1 | |||
| d5c4e0e780 | |||
| 30e27abc60 | |||
| b607501916 | |||
| 46e3cd9744 | |||
| 5fb3db662b | |||
| 87b798322e | |||
| ec286b3480 | |||
| 35733f0e33 | |||
| 3c7b02b9f8 | |||
| f2030a616f | |||
| b3b5d77990 | |||
| 1da106af7d | |||
| cd2edd6966 | |||
| 22e830ff93 | |||
| c266ae7b50 | |||
| a543b75cf7 | |||
| f213987f9a | |||
| 2c623bb577 | |||
| 3353906e6f | |||
| 17716347e2 | |||
| 9ad66a67a3 | |||
| ba3aa3ccdb | |||
| 2b38eaafba | |||
| 7d5b9071e7 | |||
| 9e83f1d88c | |||
| 7e35d7c344 | |||
| 5ec40c8b83 | |||
| 948a80fc49 | |||
| dfd6fadedf |
-3
@@ -14,9 +14,6 @@ Implement the user's actual game request in the current project as an npm-manage
|
|||||||
3. Build with the project's npm script before previewing. The playable entry is the package directory's `dist/index.html`; never report an unbuilt bare-module page as playable. Import assets or configure public assets so all runtime media is included in dist; preview and exports cannot read outside it.
|
3. Build with the project's npm script before previewing. The playable entry is the package directory's `dist/index.html`; never report an unbuilt bare-module page as playable. Import assets or configure public assets so all runtime media is included in dist; preview and exports cannot read outside it.
|
||||||
4. Build a complete playable loop: visible objective, responsive input, meaningful state changes, success or failure feedback, and a reliable restart path where the game needs one.
|
4. Build a complete playable loop: visible objective, responsive input, meaningful state changes, success or failure feedback, and a reliable restart path where the game needs one.
|
||||||
5. Fit the active game scene to desktop and mobile viewports without accidental page scrollbars. Reserve deliberate safe space for HUD elements instead of covering interactive content.
|
5. Fit the active game scene to desktop and mobile viewports without accidental page scrollbars. Reserve deliberate safe space for HUD elements instead of covering interactive content.
|
||||||
- **画布居中只能由一处负责。** 使用 `Phaser.Scale.FIT` 与 `autoCenter: Phaser.Scale.CENTER_BOTH` 时,canvas 的直接父容器应使用尺寸明确的普通块布局,不再对同一 canvas 叠加 Grid/Flex 居中、`place-items: center`、自动外边距或居中 transform。Phaser 自动计算的 margin 与 CSS 居中叠加会使竖屏画面向右偏移。
|
|
||||||
- 若决定由 CSS 居中,则显式使用 `autoCenter: Phaser.Scale.NO_CENTER`,由 CSS 独立完成定位;外围页面可以继续使用 Grid/Flex,限制只针对同一 canvas 的重复定位。
|
|
||||||
- 出现偏移先检查游戏自身的 CSS 与 Phaser scale 配置,不添加 AGC 预览容器固定偏移补偿。修改布局后重新构建 dist,在桌面、移动及窗口 resize 后检查 canvas 相对游戏父容器居中(误差不超过 1 CSS px)、画面完整且无意外滚动条;不能仅凭 build 成功宣称布局通过。
|
|
||||||
6. Invoke `taonier-art-assets` for every new game brief that needs visual assets. First reuse suitable registered Taonier art; when the brief's required visual elements are missing or unsuitable, call the reviewed `agc_tools` generation/edit workflow in the same task. After the tool returns, wire its relative paths into the game and verify the rendered result. A game with unused generated assets or placeholder emoji/CSS where requested art should appear is not complete. Load media defensively only for genuinely optional effects, and never relabel a local placeholder as platform art.
|
6. Invoke `taonier-art-assets` for every new game brief that needs visual assets. First reuse suitable registered Taonier art; when the brief's required visual elements are missing or unsuitable, call the reviewed `agc_tools` generation/edit workflow in the same task. After the tool returns, wire its relative paths into the game and verify the rendered result. A game with unused generated assets or placeholder emoji/CSS where requested art should appear is not complete. Load media defensively only for genuinely optional effects, and never relabel a local placeholder as platform art.
|
||||||
7. Let Phaser own the render loop and input dispatch. Avoid duplicate scenes, stale event listeners, and state that survives restart unintentionally.
|
7. Let Phaser own the render loop and input dispatch. Avoid duplicate scenes, stale event listeners, and state that survives restart unintentionally.
|
||||||
8. After a meaningful game change, use the browser playtest Skill and fix issues shown by real evidence before reporting completion.
|
8. After a meaningful game change, use the browser playtest Skill and fix issues shown by real evidence before reporting completion.
|
||||||
|
|||||||
-2
@@ -7,7 +7,5 @@
|
|||||||
- Score, steps, health, timer, or other core state updates consistently.
|
- Score, steps, health, timer, or other core state updates consistently.
|
||||||
- Restart restores all state and does not duplicate timers, animation loops, or event listeners.
|
- Restart restores all state and does not duplicate timers, animation loops, or event listeners.
|
||||||
- Desktop and mobile layouts keep the core scene visible without accidental document scrolling.
|
- Desktop and mobile layouts keep the core scene visible without accidental document scrolling.
|
||||||
- 画布的缩放与居中由 Phaser 或 CSS 中的一方独立负责。`FIT + CENTER_BOTH` 不与同一 canvas 父容器的 Grid/Flex 居中、自动外边距或居中 transform 叠加;使用 CSS 居中时关闭 Phaser 自动居中(`NO_CENTER`)。
|
|
||||||
- 在构建后的实际页面检查桌面、移动和 resize:比较 canvas 与游戏父容器的中心,预期居中时水平/垂直误差不超过 1 CSS px,并检查画面没有溢出或意外滚动条。偏移先修游戏 CSS/scale 配置,不用修改 AGC 预览位置掩盖。
|
|
||||||
- HUD and overlays reserve space and do not cover essential interactive content.
|
- HUD and overlays reserve space and do not cover essential interactive content.
|
||||||
- Requested Taonier art is visibly integrated into the core experience when available.
|
- Requested Taonier art is visibly integrated into the core experience when available.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": "agc-skill-pack.v1",
|
"schemaVersion": "agc-skill-pack.v1",
|
||||||
"version": "2026-08-26.25",
|
"version": "2026-08-26.24",
|
||||||
"skills": [
|
"skills": [
|
||||||
{
|
{
|
||||||
"name": "agc-game-production-workflow",
|
"name": "agc-game-production-workflow",
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
"agents/openai.yaml",
|
"agents/openai.yaml",
|
||||||
"references/game-quality-checklist.md"
|
"references/game-quality-checklist.md"
|
||||||
],
|
],
|
||||||
"sha256": "e122d8f3a6d986b594b95c971754d68197bf7896912fa8267d44a7aa129a57ba"
|
"sha256": "05b5cfbf7a40fd303717491f5cea84ff339a73359c9678b283fd54d2b5c45efd"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "agc-browser-playtest",
|
"name": "agc-browser-playtest",
|
||||||
|
|||||||
@@ -797,16 +797,6 @@ fn direct_thread_visible_item(
|
|||||||
direct_thread_event_item(root, item)
|
direct_thread_event_item(root, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AGC 预写的 canonical 用户条目 id:`direct-codex:{clientTurnId}:user`。
|
|
||||||
///
|
|
||||||
/// 与 `direct_project_history::is_direct_project_codex_user_item` 的判据同一份口径(前缀 +
|
|
||||||
/// `:user` 后缀)。回合生命周期事件的 `userItemId` 只能来自这里或已落盘条目自身的 id;
|
|
||||||
/// clientTurnId 缺失时不猜身份,返回 `None` 让前端按"未知归属"处理。
|
|
||||||
fn direct_codex_user_item_id_for_client_turn_id(client_turn_id: &str) -> Option<String> {
|
|
||||||
let client_turn_id = client_turn_id.trim();
|
|
||||||
(!client_turn_id.is_empty()).then(|| format!("direct-codex:{client_turn_id}:user"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn direct_codex_command_is_game_verification(command: &str) -> bool {
|
fn direct_codex_command_is_game_verification(command: &str) -> bool {
|
||||||
let command = command.to_ascii_lowercase();
|
let command = command.to_ascii_lowercase();
|
||||||
command.contains("game.static_smoke")
|
command.contains("game.static_smoke")
|
||||||
@@ -1143,7 +1133,6 @@ fn direct_codex_thread_delta_event(
|
|||||||
) -> DirectThreadEvent {
|
) -> DirectThreadEvent {
|
||||||
DirectThreadEvent::item_delta(item_id, kind, direct_thread_delta_text(root, delta))
|
DirectThreadEvent::item_delta(item_id, kind, direct_thread_delta_text(root, delta))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 通知 → 回合事件的唯一分类函数:运行态读取器与单测共用这一份。
|
/// 通知 → 回合事件的唯一分类函数:运行态读取器与单测共用这一份。
|
||||||
///
|
///
|
||||||
/// 读取器只负责"必须有 turnId 才处理"的前置条件与节流(活动 / 正文),分类不在这里之外
|
/// 读取器只负责"必须有 turnId 才处理"的前置条件与节流(活动 / 正文),分类不在这里之外
|
||||||
@@ -2937,7 +2926,7 @@ impl CodexAppServerConnection {
|
|||||||
None => direct_project_local_message_item(
|
None => direct_project_local_message_item(
|
||||||
"user",
|
"user",
|
||||||
current_prompt,
|
current_prompt,
|
||||||
direct_codex_user_item_id_for_client_turn_id(client_turn_id).as_deref(),
|
Some(&format!("direct-codex:{client_turn_id}:user")),
|
||||||
)
|
)
|
||||||
.map_err(platform_llm::LlmError::InvalidRequest)?,
|
.map_err(platform_llm::LlmError::InvalidRequest)?,
|
||||||
};
|
};
|
||||||
@@ -3056,30 +3045,13 @@ impl CodexAppServerConnection {
|
|||||||
};
|
};
|
||||||
turn_start_guard.armed = false;
|
turn_start_guard.armed = false;
|
||||||
let direct_thread_id = direct_thread_id_for_project(history_root);
|
let direct_thread_id = direct_thread_id_for_project(history_root);
|
||||||
// 回合边界的阶段时间:Turn 上游只有**秒**级 `startedAt` / `completedAt`,秒级截断
|
|
||||||
// 撑不起前端 0.1 秒粒度的展示,也可能让完成时刻落进该轮用户消息的同一秒、落在真实
|
|
||||||
// 发送时间之前,被判成无效边界后整轮新回合被吞掉。因此这里只在宿主处理对应阶段时取
|
|
||||||
// 毫秒钟(与条目侧"没有原生阶段时间就用宿主钟"同一口径),不再读上游秒字段。
|
|
||||||
let direct_turn_started_at_ms = direct_tool_call_now_ms();
|
|
||||||
// 本轮开口用户条目的 canonical id:只从已落盘的那条条目上读身份(`id`,工具条目才用
|
|
||||||
// `call_id`),不在事件侧重造一份。拿不到就留空,让前端按"归属不可证明"处理。
|
|
||||||
let direct_turn_user_item_id = direct_persisted_user_item
|
|
||||||
.as_ref()
|
|
||||||
.and_then(direct_thread_item_identity);
|
|
||||||
if self.inner.workspace_mode == CodexAppServerWorkspaceMode::DirectProject {
|
if self.inner.workspace_mode == CodexAppServerWorkspaceMode::DirectProject {
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(&direct_thread_id, DirectThreadEvent::turn_started());
|
||||||
&direct_thread_id,
|
|
||||||
DirectThreadEvent::turn_started(direct_turn_started_at_ms)
|
|
||||||
.with_user_item_id(direct_turn_user_item_id.as_deref()),
|
|
||||||
);
|
|
||||||
if let Some(user_item) = direct_persisted_user_item.as_ref() {
|
if let Some(user_item) = direct_persisted_user_item.as_ref() {
|
||||||
if let Some(entry_item) = direct_thread_event_item(history_root, user_item) {
|
if let Some(entry_item) = direct_thread_event_item(history_root, user_item) {
|
||||||
// 这里的条目时间可能是启动应答后的观测时间;前端按同一用户条目身份
|
|
||||||
// 保留更早的真实发送时间,不用此事件时间覆盖它。
|
|
||||||
let user_item_at = entry_item.at();
|
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::item_completed(entry_item, user_item_at),
|
DirectThreadEvent::item_completed(entry_item),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3218,14 +3190,9 @@ impl CodexAppServerConnection {
|
|||||||
.map_err(platform_llm::LlmError::InvalidRequest)?;
|
.map_err(platform_llm::LlmError::InvalidRequest)?;
|
||||||
direct_project_history.complete_item(&item);
|
direct_project_history.complete_item(&item);
|
||||||
if let Some(entry_item) = entry_item {
|
if let Some(entry_item) = entry_item {
|
||||||
// `rawResponseItem/completed` 不带阶段时间,宿主处理到这条
|
|
||||||
// 通知的钟就是该阶段唯一可证明的时间。
|
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::item_completed(
|
DirectThreadEvent::item_completed(entry_item),
|
||||||
entry_item,
|
|
||||||
direct_tool_call_now_ms(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3354,19 +3321,9 @@ impl CodexAppServerConnection {
|
|||||||
if let Some(entry_item) =
|
if let Some(entry_item) =
|
||||||
direct_thread_visible_item(history_root, item)
|
direct_thread_visible_item(history_root, item)
|
||||||
{
|
{
|
||||||
// `item/started` 的通知层带 `startedAtMs`:这是工具真正
|
|
||||||
// 开始的阶段时间,优先于条目展示时间与宿主钟。
|
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::item_started(
|
DirectThreadEvent::item_started(entry_item),
|
||||||
entry_item,
|
|
||||||
direct_thread_item_event_at_ms(
|
|
||||||
¶ms,
|
|
||||||
item,
|
|
||||||
false,
|
|
||||||
direct_tool_call_now_ms(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3409,19 +3366,9 @@ impl CodexAppServerConnection {
|
|||||||
&& matches!(status, "completed" | "interrupted" | "failed")
|
&& matches!(status, "completed" | "interrupted" | "failed")
|
||||||
{
|
{
|
||||||
terminal_recorded = true;
|
terminal_recorded = true;
|
||||||
// 终态时间:`durationMs` 与宿主记下的毫秒起点都可靠时才派生,
|
|
||||||
// 否则取宿主处理这条终态的钟;上游秒级 `completedAt` 一律不用。
|
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id,
|
&direct_thread_id,
|
||||||
DirectThreadEvent::turn_completed(
|
DirectThreadEvent::turn_completed(status.to_string()),
|
||||||
status.to_string(),
|
|
||||||
direct_thread_turn_completed_at_ms(
|
|
||||||
turn,
|
|
||||||
Some(direct_turn_started_at_ms),
|
|
||||||
direct_tool_call_now_ms(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.with_user_item_id(direct_turn_user_item_id.as_deref()),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
match status {
|
match status {
|
||||||
@@ -3478,11 +3425,7 @@ impl CodexAppServerConnection {
|
|||||||
"failed"
|
"failed"
|
||||||
}
|
}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
// 这条兜底终态没有对应的 app-server 终态载荷,只能取宿主处理它的钟,
|
),
|
||||||
// 不能拿最后一次正文或工具更新时间当回合终点。
|
|
||||||
direct_tool_call_now_ms(),
|
|
||||||
)
|
|
||||||
.with_user_item_id(direct_turn_user_item_id.as_deref()),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let text = match collect_result {
|
let text = match collect_result {
|
||||||
@@ -3680,15 +3623,6 @@ enum DirectCodexTurnCancelTarget {
|
|||||||
/// 这时显式释放这条守卫并把可读原因返回给界面。释放条件见
|
/// 这时显式释放这条守卫并把可读原因返回给界面。释放条件见
|
||||||
/// [`release_stale_direct_taonier_active_invocation`] 的注释;"正在跑的是另一轮"仍然
|
/// [`release_stale_direct_taonier_active_invocation`] 的注释;"正在跑的是另一轮"仍然
|
||||||
/// 保持原拒绝语义,什么都不释放。
|
/// 保持原拒绝语义,什么都不释放。
|
||||||
///
|
|
||||||
/// 兜底终态带 `userItemId`:身份取 `release_stale_direct_taonier_active_invocation` 返回的
|
|
||||||
/// clientTurnId(客户端回合身份的唯一来源),与正常路径的开口条目 id 同一份 canonical 口径。
|
|
||||||
/// 拿不到 clientTurnId 就留空——这一轮不会再有原生终态,猜一个身份会让前端把边界盖到别人身上。
|
|
||||||
fn direct_stale_cancel_turn_completed_event(client_turn_id: &str) -> DirectThreadEvent {
|
|
||||||
DirectThreadEvent::turn_completed("aborted".to_string(), direct_tool_call_now_ms())
|
|
||||||
.with_user_item_id(direct_codex_user_item_id_for_client_turn_id(client_turn_id).as_deref())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn cancel_direct_codex_turn_at(
|
pub(crate) fn cancel_direct_codex_turn_at(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
client_turn_id: Option<&str>,
|
client_turn_id: Option<&str>,
|
||||||
@@ -3745,7 +3679,7 @@ pub(crate) fn cancel_direct_codex_turn_at(
|
|||||||
// 兜底补一条,否则前端的"最新回合是否在跑"会永远停在运行中。
|
// 兜底补一条,否则前端的"最新回合是否在跑"会永远停在运行中。
|
||||||
append_direct_thread_event(
|
append_direct_thread_event(
|
||||||
&direct_thread_id_for_project(root),
|
&direct_thread_id_for_project(root),
|
||||||
direct_stale_cancel_turn_completed_event(&released),
|
DirectThreadEvent::turn_completed("aborted".to_string()),
|
||||||
);
|
);
|
||||||
Ok(DirectTurnCancelView {
|
Ok(DirectTurnCancelView {
|
||||||
outcome: DIRECT_TURN_CANCEL_OUTCOME_RELEASED.to_string(),
|
outcome: DIRECT_TURN_CANCEL_OUTCOME_RELEASED.to_string(),
|
||||||
@@ -5071,109 +5005,6 @@ mod tests {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 阶段时间取自**通知层**字段,形状照抄 codex-cli 0.147 / 0.155 的 v2 协议 schema:
|
|
||||||
/// `item/started` 带 `startedAtMs`、`item/completed` 带 `completedAtMs`(毫秒),
|
|
||||||
/// `turn/completed` 带 `turn.startedAt` / `turn.completedAt`(秒)与 `turn.durationMs`(毫秒)。
|
|
||||||
/// 分类函数把 params 原样交给事件级 `at` 的投影函数,所以字段位置必须在这里钉住;
|
|
||||||
/// 回合边界的秒字段按"不用"锁在这里,避免以后有人再把秒级截断当 0.1 秒精度。
|
|
||||||
#[test]
|
|
||||||
fn direct_lifecycle_stage_times_come_from_notification_params() {
|
|
||||||
let started = serde_json::json!({
|
|
||||||
"threadId": "thread-1",
|
|
||||||
"turnId": "turn-1",
|
|
||||||
"startedAtMs": 1_700_000_000_123u64,
|
|
||||||
"item": {"id": "call-1", "type": "commandExecution", "command": "ls"},
|
|
||||||
});
|
|
||||||
let completed = serde_json::json!({
|
|
||||||
"threadId": "thread-1",
|
|
||||||
"turnId": "turn-1",
|
|
||||||
"completedAtMs": 1_700_000_001_500u64,
|
|
||||||
"item": {"id": "call-1", "type": "commandExecution", "command": "ls"},
|
|
||||||
});
|
|
||||||
for (method, params, expected_at_ms) in [
|
|
||||||
("item/started", &started, 1_700_000_000_123u64),
|
|
||||||
("item/completed", &completed, 1_700_000_001_500u64),
|
|
||||||
] {
|
|
||||||
let Some(CodexTurnEvent::Item {
|
|
||||||
completed,
|
|
||||||
params: event_params,
|
|
||||||
}) = direct_codex_notification_event(method, params, None, None, "turn-1")
|
|
||||||
else {
|
|
||||||
panic!("{method} 必须分类成条目生命周期事件");
|
|
||||||
};
|
|
||||||
let item = event_params.get("item").expect("item payload");
|
|
||||||
assert_eq!(
|
|
||||||
direct_thread_item_event_at_ms(&event_params, item, completed, 9_999),
|
|
||||||
expected_at_ms,
|
|
||||||
"{method} 必须用通知层的阶段时间,而不是宿主钟"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let terminal = serde_json::json!({
|
|
||||||
"threadId": "thread-1",
|
|
||||||
"turn": {
|
|
||||||
"id": "turn-1",
|
|
||||||
"items": [],
|
|
||||||
"status": "completed",
|
|
||||||
"startedAt": 1_700_000_000i64,
|
|
||||||
"completedAt": 1_700_000_042i64,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
let Some(CodexTurnEvent::Terminal(params)) =
|
|
||||||
direct_codex_notification_event("turn/completed", &terminal, None, None, "turn-1")
|
|
||||||
else {
|
|
||||||
panic!("turn/completed 必须分类成终态事件");
|
|
||||||
};
|
|
||||||
let turn = params.get("turn").unwrap_or(¶ms);
|
|
||||||
assert_eq!(
|
|
||||||
direct_thread_turn_completed_at_ms(turn, Some(1_700_000_000_500), 9_999),
|
|
||||||
9_999,
|
|
||||||
"上游只有秒级 completedAt:不采用,取宿主处理终态的毫秒钟"
|
|
||||||
);
|
|
||||||
let with_duration = serde_json::json!({
|
|
||||||
"id": "turn-1",
|
|
||||||
"items": [],
|
|
||||||
"status": "completed",
|
|
||||||
"startedAt": 1_700_000_000i64,
|
|
||||||
"completedAt": 1_700_000_042i64,
|
|
||||||
"durationMs": 42_500u64,
|
|
||||||
});
|
|
||||||
assert_eq!(
|
|
||||||
direct_thread_turn_completed_at_ms(&with_duration, Some(1_700_000_000_500), 9_999),
|
|
||||||
1_700_000_043_000,
|
|
||||||
"durationMs + 宿主高精度起点才派生结束"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 取消兜底终态也要带开口用户条目身份,且身份只有一个来源:release 返回的 clientTurnId
|
|
||||||
/// 走与正常路径同一份 canonical 口径;拿不到(空 / 空白)就留空,不猜。
|
|
||||||
#[test]
|
|
||||||
fn stale_cancel_terminal_event_keeps_opener_user_item_id_from_client_turn_id() {
|
|
||||||
let event = direct_stale_cancel_turn_completed_event("turn-0001");
|
|
||||||
assert_eq!(event.user_item_id(), Some("direct-codex:turn-0001:user"));
|
|
||||||
assert!(event.at().is_some(), "兜底终态仍要带宿主观测时间");
|
|
||||||
assert!(matches!(
|
|
||||||
event,
|
|
||||||
DirectThreadEvent::TurnCompleted { ref status, .. } if status == "aborted"
|
|
||||||
));
|
|
||||||
|
|
||||||
for missing in ["", " "] {
|
|
||||||
let event = direct_stale_cancel_turn_completed_event(missing);
|
|
||||||
assert_eq!(
|
|
||||||
event.user_item_id(),
|
|
||||||
None,
|
|
||||||
"拿不到 clientTurnId 时不得编造开口条目身份"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// canonical 口径与落盘侧同一份:`direct-codex:{clientTurnId}:user`。
|
|
||||||
assert_eq!(
|
|
||||||
direct_codex_user_item_id_for_client_turn_id(" turn-0001 ").as_deref(),
|
|
||||||
Some("direct-codex:turn-0001:user")
|
|
||||||
);
|
|
||||||
assert_eq!(direct_codex_user_item_id_for_client_turn_id(""), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_llm() -> GameCreatorLlmConfig {
|
fn test_llm() -> GameCreatorLlmConfig {
|
||||||
GameCreatorLlmConfig {
|
GameCreatorLlmConfig {
|
||||||
custom_enabled: false,
|
custom_enabled: false,
|
||||||
@@ -6908,33 +6739,12 @@ done
|
|||||||
|
|
||||||
let consumed = crate::agent::consume_direct_thread(&bootstrap.subscription_id)
|
let consumed = crate::agent::consume_direct_thread(&bootstrap.subscription_id)
|
||||||
.expect("consume events");
|
.expect("consume events");
|
||||||
// 回合起止必须与开口用户条目同源:前端在「只有锚点 + 历史、运行态为空」的回合里靠这个
|
|
||||||
// 身份把边界认领给同一条用户条目,缺了它就只能隐藏未知用时。
|
|
||||||
let lifecycle_user_item_ids = consumed
|
|
||||||
.events
|
|
||||||
.iter()
|
|
||||||
.filter(|event| {
|
|
||||||
matches!(
|
|
||||||
event,
|
|
||||||
DirectThreadEvent::TurnStarted { .. } | DirectThreadEvent::TurnCompleted { .. }
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.map(DirectThreadEvent::user_item_id)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
assert_eq!(
|
|
||||||
lifecycle_user_item_ids,
|
|
||||||
vec![
|
|
||||||
Some("direct-codex:turn-0001:user"),
|
|
||||||
Some("direct-codex:turn-0001:user"),
|
|
||||||
],
|
|
||||||
"turn.started / turn.completed 都要带本轮开口用户条目的 canonical itemId"
|
|
||||||
);
|
|
||||||
let mut user_items = Vec::new();
|
let mut user_items = Vec::new();
|
||||||
let mut assistant_items = Vec::new();
|
let mut assistant_items = Vec::new();
|
||||||
for event in &consumed.events {
|
for event in &consumed.events {
|
||||||
let item = match event {
|
let item = match event {
|
||||||
DirectThreadEvent::ItemStarted { item, .. }
|
DirectThreadEvent::ItemStarted { item }
|
||||||
| DirectThreadEvent::ItemCompleted { item, .. } => item,
|
| DirectThreadEvent::ItemCompleted { item } => item,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
match item {
|
match item {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
//! 有项目路径或导入状态时输出路径映射;否则保持首页元数据文案。不灌正文。
|
//! 有项目路径或导入状态时输出路径映射;否则保持首页元数据文案。不灌正文。
|
||||||
|
|
||||||
pub(crate) const MAX_DIRECT_CODEX_ATTACHMENTS: usize = 8;
|
pub(crate) const MAX_DIRECT_CODEX_ATTACHMENTS: usize = 8;
|
||||||
const MAX_DIRECT_CODEX_ATTACHMENT_NAME_CHARS: usize = 160;
|
pub(crate) const MAX_DIRECT_CODEX_ATTACHMENT_NAME_CHARS: usize = 160;
|
||||||
const MAX_DIRECT_CODEX_ATTACHMENT_MEDIA_TYPE_CHARS: usize = 96;
|
pub(crate) const MAX_DIRECT_CODEX_ATTACHMENT_MEDIA_TYPE_CHARS: usize = 96;
|
||||||
const MAX_DIRECT_CODEX_ATTACHMENT_LOCAL_PATH_CHARS: usize = 512;
|
pub(crate) const MAX_DIRECT_CODEX_ATTACHMENT_LOCAL_PATH_CHARS: usize = 512;
|
||||||
|
|
||||||
const HOME_ATTACHMENT_HEADER: &str =
|
const HOME_ATTACHMENT_HEADER: &str =
|
||||||
"[首页附件说明:当前尚未打开项目,以下仅为附件元数据,附件内容尚不可读取]";
|
"[首页附件说明:当前尚未打开项目,以下仅为附件元数据,附件内容尚不可读取]";
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ mod validation;
|
|||||||
mod wire;
|
mod wire;
|
||||||
|
|
||||||
pub(crate) use model::{
|
pub(crate) use model::{
|
||||||
DirectCodexUserContentPart, DirectCodexUserItem, DirectCodexUserMessageItem,
|
DirectCodexUserAttachmentReferencePart, DirectCodexUserContentPart, DirectCodexUserItem,
|
||||||
DirectCodexUserRole, DirectCodexUserRuntimeRegionPart,
|
DirectCodexUserMessageItem, DirectCodexUserRole, DirectCodexUserRuntimeRegionPart,
|
||||||
};
|
};
|
||||||
pub(crate) use validation::validate_direct_codex_user_item;
|
pub(crate) use validation::validate_direct_codex_user_item;
|
||||||
pub(crate) use wire::{
|
pub(crate) use wire::{
|
||||||
|
|||||||
@@ -36,6 +36,21 @@ pub(crate) enum DirectCodexUserContentPart {
|
|||||||
AgcResourceReference { resource_id: String },
|
AgcResourceReference { resource_id: String },
|
||||||
#[serde(rename = "agc_runtime_region_reference")]
|
#[serde(rename = "agc_runtime_region_reference")]
|
||||||
AgcRuntimeRegionReference(DirectCodexUserRuntimeRegionPart),
|
AgcRuntimeRegionReference(DirectCodexUserRuntimeRegionPart),
|
||||||
|
/// Uploaded project attachment kept inline in canonical content.
|
||||||
|
#[serde(rename = "agc_attachment_reference")]
|
||||||
|
AgcAttachmentReference(DirectCodexUserAttachmentReferencePart),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
|
||||||
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||||
|
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/project-workspace/generated/"))]
|
||||||
|
pub(crate) struct DirectCodexUserAttachmentReferencePart {
|
||||||
|
pub(crate) name: String,
|
||||||
|
pub(crate) media_type: String,
|
||||||
|
#[ts(type = "number")]
|
||||||
|
pub(crate) size: u64,
|
||||||
|
pub(crate) local_path: String,
|
||||||
|
pub(crate) status: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
|
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
|
||||||
|
|||||||
+200
-6
@@ -4,6 +4,8 @@ use super::model::{
|
|||||||
};
|
};
|
||||||
use crate::agent::{
|
use crate::agent::{
|
||||||
read_manifest_for_project, sanitize_attachment_local_path, GameCreationAppManifest,
|
read_manifest_for_project, sanitize_attachment_local_path, GameCreationAppManifest,
|
||||||
|
MAX_DIRECT_CODEX_ATTACHMENTS, MAX_DIRECT_CODEX_ATTACHMENT_MEDIA_TYPE_CHARS,
|
||||||
|
MAX_DIRECT_CODEX_ATTACHMENT_NAME_CHARS,
|
||||||
};
|
};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
@@ -20,18 +22,17 @@ pub(crate) fn validate_direct_codex_user_item(
|
|||||||
if message.id.trim().is_empty() {
|
if message.id.trim().is_empty() {
|
||||||
return Err("DirectProject user item 缺少稳定 id".to_string());
|
return Err("DirectProject user item 缺少稳定 id".to_string());
|
||||||
}
|
}
|
||||||
if message.content.is_empty() {
|
// 有效输入只判一整条 content:单个纯空白 `input_text` 是合法 part —— 编辑器里的段落
|
||||||
|
// 分隔、软换行与 chip 后的分隔空格就是这样落进 canonical content 的,前端不为它过滤。
|
||||||
|
if !content_has_meaningful_input(&message.content) {
|
||||||
return Err("DirectProject user item content 不能为空".to_string());
|
return Err("DirectProject user item content 不能为空".to_string());
|
||||||
}
|
}
|
||||||
let manifest = read_manifest_for_project(root)?;
|
let manifest = read_manifest_for_project(root)?;
|
||||||
let mut reference_count = 0usize;
|
let mut reference_count = 0usize;
|
||||||
|
let mut attachment_count = 0usize;
|
||||||
for part in &message.content {
|
for part in &message.content {
|
||||||
match part {
|
match part {
|
||||||
DirectCodexUserContentPart::InputText { text } => {
|
DirectCodexUserContentPart::InputText { .. } => {}
|
||||||
if text.trim().is_empty() {
|
|
||||||
return Err("DirectProject input_text 不能为空".to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DirectCodexUserContentPart::AgcResourceReference { resource_id } => {
|
DirectCodexUserContentPart::AgcResourceReference { resource_id } => {
|
||||||
reference_count = reference_count.saturating_add(1);
|
reference_count = reference_count.saturating_add(1);
|
||||||
validate_resource_id_and_manifest(&manifest, resource_id)?;
|
validate_resource_id_and_manifest(&manifest, resource_id)?;
|
||||||
@@ -40,6 +41,44 @@ pub(crate) fn validate_direct_codex_user_item(
|
|||||||
reference_count = reference_count.saturating_add(1);
|
reference_count = reference_count.saturating_add(1);
|
||||||
validate_runtime_region_reference(&manifest, reference)?;
|
validate_runtime_region_reference(&manifest, reference)?;
|
||||||
}
|
}
|
||||||
|
DirectCodexUserContentPart::AgcAttachmentReference(reference) => {
|
||||||
|
attachment_count = attachment_count.saturating_add(1);
|
||||||
|
if attachment_count > MAX_DIRECT_CODEX_ATTACHMENTS {
|
||||||
|
return Err(format!(
|
||||||
|
"一次最多携带 {MAX_DIRECT_CODEX_ATTACHMENTS} 个附件"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if reference.name.trim().is_empty() {
|
||||||
|
return Err("附件缺少文件名".to_string());
|
||||||
|
}
|
||||||
|
let name = reference.name.trim();
|
||||||
|
if name.chars().count() > MAX_DIRECT_CODEX_ATTACHMENT_NAME_CHARS
|
||||||
|
|| name.chars().any(char::is_control)
|
||||||
|
{
|
||||||
|
return Err("附件文件名无效或过长".to_string());
|
||||||
|
}
|
||||||
|
let media_type = reference.media_type.trim();
|
||||||
|
if media_type.is_empty()
|
||||||
|
|| media_type.chars().count() > MAX_DIRECT_CODEX_ATTACHMENT_MEDIA_TYPE_CHARS
|
||||||
|
|| media_type.chars().any(|character| {
|
||||||
|
!(character.is_ascii_alphanumeric()
|
||||||
|
|| matches!(character, '/' | '+' | '-' | '.' | '_'))
|
||||||
|
})
|
||||||
|
{
|
||||||
|
return Err("附件媒体类型无效或过长".to_string());
|
||||||
|
}
|
||||||
|
let status = reference.status.trim();
|
||||||
|
if status == "imported" && reference.local_path.trim().is_empty() {
|
||||||
|
return Err("已导入附件缺少项目路径".to_string());
|
||||||
|
}
|
||||||
|
if !reference.local_path.trim().is_empty() {
|
||||||
|
sanitize_attachment_local_path(&reference.local_path)
|
||||||
|
.ok_or_else(|| "附件项目路径无效".to_string())?;
|
||||||
|
}
|
||||||
|
if !matches!(status, "imported" | "failed") {
|
||||||
|
return Err("附件状态无效".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if reference_count > MAX_DIRECT_CODEX_REFERENCES {
|
if reference_count > MAX_DIRECT_CODEX_REFERENCES {
|
||||||
@@ -48,6 +87,14 @@ pub(crate) fn validate_direct_codex_user_item(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 整条 content 是否还有有效输入:任何一段非空白文本、或任何一个非文本 part 都算。
|
||||||
|
pub(crate) fn content_has_meaningful_input(content: &[DirectCodexUserContentPart]) -> bool {
|
||||||
|
content.iter().any(|part| match part {
|
||||||
|
DirectCodexUserContentPart::InputText { text } => !text.trim().is_empty(),
|
||||||
|
_ => true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn validate_resource_id_and_manifest(
|
pub(crate) fn validate_resource_id_and_manifest(
|
||||||
manifest: &GameCreationAppManifest,
|
manifest: &GameCreationAppManifest,
|
||||||
resource_id: &str,
|
resource_id: &str,
|
||||||
@@ -86,3 +133,150 @@ fn validate_runtime_region_reference(
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::{content_has_meaningful_input, validate_direct_codex_user_item};
|
||||||
|
use crate::agent::direct_codex_user_item::model::DirectCodexUserContentPart;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
fn input_text(text: &str) -> DirectCodexUserContentPart {
|
||||||
|
DirectCodexUserContentPart::InputText {
|
||||||
|
text: text.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn only_all_blank_content_counts_as_empty_input() {
|
||||||
|
// 空数组与「整条只有空白」是同一种空输入。
|
||||||
|
assert!(!content_has_meaningful_input(&[]));
|
||||||
|
assert!(!content_has_meaningful_input(&[input_text(" \n ")]));
|
||||||
|
assert!(!content_has_meaningful_input(&[
|
||||||
|
input_text("\n"),
|
||||||
|
input_text(" "),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn whitespace_parts_are_valid_next_to_meaningful_input() {
|
||||||
|
// 段落分隔 / 软换行 / chip 后的分隔空格都是合法的单个 part。
|
||||||
|
assert!(content_has_meaningful_input(&[
|
||||||
|
input_text("\n"),
|
||||||
|
input_text("看"),
|
||||||
|
]));
|
||||||
|
assert!(content_has_meaningful_input(&[
|
||||||
|
input_text("看"),
|
||||||
|
input_text("\n\n"),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_text_parts_always_count_as_input() {
|
||||||
|
assert!(content_has_meaningful_input(&[
|
||||||
|
DirectCodexUserContentPart::AgcResourceReference {
|
||||||
|
resource_id: "asset-hero".to_string(),
|
||||||
|
},
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inline_attachment_count_is_bounded_independently() {
|
||||||
|
let root = tempfile::tempdir().expect("temp project");
|
||||||
|
crate::init_local_game_project_at(root.path(), "validation-test", "校验测试")
|
||||||
|
.expect("init project");
|
||||||
|
let content = (0..=crate::agent::MAX_DIRECT_CODEX_ATTACHMENTS)
|
||||||
|
.map(|index| {
|
||||||
|
json!({
|
||||||
|
"type": "agc_attachment_reference",
|
||||||
|
"name": format!("attachment-{index}.txt"),
|
||||||
|
"mediaType": "text/plain",
|
||||||
|
"size": 1,
|
||||||
|
"localPath": "",
|
||||||
|
"status": "failed"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let item = serde_json::from_value(json!({
|
||||||
|
"type": "message",
|
||||||
|
"role": "user",
|
||||||
|
"content": content,
|
||||||
|
"id": "turn-1:user"
|
||||||
|
}))
|
||||||
|
.expect("deserialize user item");
|
||||||
|
let error = validate_direct_codex_user_item(root.path(), &item)
|
||||||
|
.expect_err("too many inline attachments must be rejected");
|
||||||
|
assert!(error.contains("最多携带"), "{error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn imported_attachment_requires_a_project_path() {
|
||||||
|
let root = tempfile::tempdir().expect("temp project");
|
||||||
|
crate::init_local_game_project_at(root.path(), "validation-test", "校验测试")
|
||||||
|
.expect("init project");
|
||||||
|
let item = serde_json::from_value(json!({
|
||||||
|
"type": "message",
|
||||||
|
"role": "user",
|
||||||
|
"content": [{
|
||||||
|
"type": "agc_attachment_reference",
|
||||||
|
"name": "attachment.txt",
|
||||||
|
"mediaType": "text/plain",
|
||||||
|
"size": 1,
|
||||||
|
"localPath": "",
|
||||||
|
"status": "imported"
|
||||||
|
}],
|
||||||
|
"id": "turn-1:user"
|
||||||
|
}))
|
||||||
|
.expect("deserialize user item");
|
||||||
|
let error = validate_direct_codex_user_item(root.path(), &item)
|
||||||
|
.expect_err("imported attachment without a project path must fail");
|
||||||
|
assert!(error.contains("缺少项目路径"), "{error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn attachment_name_and_media_type_are_bounded_and_well_formed() {
|
||||||
|
let root = tempfile::tempdir().expect("temp project");
|
||||||
|
crate::init_local_game_project_at(root.path(), "validation-test", "校验测试")
|
||||||
|
.expect("init project");
|
||||||
|
let long_name = "a".repeat(crate::agent::MAX_DIRECT_CODEX_ATTACHMENT_NAME_CHARS + 1);
|
||||||
|
let cases = [
|
||||||
|
(
|
||||||
|
json!({
|
||||||
|
"name": "bad\nname.txt",
|
||||||
|
"mediaType": "text/plain"
|
||||||
|
}),
|
||||||
|
"文件名",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
json!({
|
||||||
|
"name": "ok.txt",
|
||||||
|
"mediaType": "text/plain\nsecret"
|
||||||
|
}),
|
||||||
|
"媒体类型",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
json!({
|
||||||
|
"name": long_name,
|
||||||
|
"mediaType": "text/plain"
|
||||||
|
}),
|
||||||
|
"文件名",
|
||||||
|
),
|
||||||
|
];
|
||||||
|
for (metadata, expected) in cases {
|
||||||
|
let mut value = metadata;
|
||||||
|
value["type"] = json!("agc_attachment_reference");
|
||||||
|
value["size"] = json!(1);
|
||||||
|
value["localPath"] = json!("");
|
||||||
|
value["status"] = json!("failed");
|
||||||
|
let item = serde_json::from_value(json!({
|
||||||
|
"type": "message",
|
||||||
|
"role": "user",
|
||||||
|
"content": [value],
|
||||||
|
"id": "turn-1:user"
|
||||||
|
}))
|
||||||
|
.expect("deserialize user item");
|
||||||
|
let error = validate_direct_codex_user_item(root.path(), &item)
|
||||||
|
.expect_err("invalid attachment metadata must fail");
|
||||||
|
assert!(error.contains(expected), "{error}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
use super::model::{DirectCodexUserContentPart, DirectCodexUserItem};
|
use super::model::{DirectCodexUserContentPart, DirectCodexUserItem};
|
||||||
use super::validation::validate_direct_codex_user_item;
|
use super::validation::validate_direct_codex_user_item;
|
||||||
use crate::agent::{read_manifest_for_project, sanitize_attachment_local_path};
|
use crate::agent::{
|
||||||
|
read_manifest_for_project, sanitize_attachment_local_path, sanitize_attachment_media_type,
|
||||||
|
sanitize_attachment_name,
|
||||||
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
@@ -100,6 +103,21 @@ pub(crate) fn direct_codex_user_item_to_wire_input(
|
|||||||
summary.push(']');
|
summary.push(']');
|
||||||
summary
|
summary
|
||||||
}
|
}
|
||||||
|
DirectCodexUserContentPart::AgcAttachmentReference(reference) => {
|
||||||
|
let name = sanitize_attachment_name(&reference.name);
|
||||||
|
let media_type = sanitize_attachment_media_type(&reference.media_type);
|
||||||
|
let local_path = sanitize_attachment_local_path(&reference.local_path);
|
||||||
|
let mut summary = format!(
|
||||||
|
"[附件:名称={};类型={};大小={} 字节",
|
||||||
|
name, media_type, reference.size
|
||||||
|
);
|
||||||
|
if let Some(local_path) = local_path {
|
||||||
|
summary.push_str(&format!(";项目路径={local_path}"));
|
||||||
|
}
|
||||||
|
summary.push_str(&format!(";状态={}", reference.status.trim()));
|
||||||
|
summary.push(']');
|
||||||
|
summary
|
||||||
|
}
|
||||||
};
|
};
|
||||||
input.push(serde_json::json!({ "type": "text", "text": text }));
|
input.push(serde_json::json!({ "type": "text", "text": text }));
|
||||||
}
|
}
|
||||||
@@ -130,7 +148,8 @@ pub(crate) fn direct_codex_user_item_to_prompt(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::direct_codex_user_item_to_response_item;
|
use super::{direct_codex_user_item_to_response_item, direct_codex_user_item_to_wire_input};
|
||||||
|
use crate::agent::direct_codex_user_item::model::DirectCodexUserItem;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
@@ -174,4 +193,99 @@ mod tests {
|
|||||||
.expect_err("history item without type must fail");
|
.expect_err("history item without type must fail");
|
||||||
assert!(error.contains("缺少 type"), "{error}");
|
assert!(error.contains("缺少 type"), "{error}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn attachment_parts_remain_in_canonical_order_when_projected() {
|
||||||
|
let root = tempfile::tempdir().expect("temp project");
|
||||||
|
crate::init_local_game_project_at(root.path(), "wire-test", "wire 投影测试")
|
||||||
|
.expect("init project");
|
||||||
|
let item = json!({
|
||||||
|
"type": "message",
|
||||||
|
"role": "user",
|
||||||
|
"id": "turn-1:user",
|
||||||
|
"content": [
|
||||||
|
{"type": "input_text", "text": "先看"},
|
||||||
|
{"type": "agc_attachment_reference", "name": "notes.txt", "mediaType": "text/plain", "size": 4, "localPath": "assets/notes.txt", "status": "imported"}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
let projected = direct_codex_user_item_to_response_item(root.path(), &item)
|
||||||
|
.expect("user response item should project");
|
||||||
|
let content = projected["content"].as_array().expect("content array");
|
||||||
|
assert_eq!(content.len(), 2);
|
||||||
|
assert!(content[0]["text"].as_str().unwrap().contains("先看"));
|
||||||
|
assert!(content[1]["text"].as_str().unwrap().contains("notes.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn attachment_metadata_is_sanitized_before_prompt_projection() {
|
||||||
|
let root = tempfile::tempdir().expect("temp project");
|
||||||
|
crate::init_local_game_project_at(root.path(), "wire-test", "wire 投影测试")
|
||||||
|
.expect("init project");
|
||||||
|
let item = json!({
|
||||||
|
"type": "message",
|
||||||
|
"role": "user",
|
||||||
|
"id": "turn-1:user",
|
||||||
|
"content": [{
|
||||||
|
"type": "agc_attachment_reference",
|
||||||
|
"name": "C:\\tmp\\notes.md",
|
||||||
|
"mediaType": "text/plain",
|
||||||
|
"size": 4,
|
||||||
|
"localPath": "assets\\.\\notes.txt",
|
||||||
|
"status": "imported"
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
let wire = super::direct_codex_user_item_to_wire_input(
|
||||||
|
root.path(),
|
||||||
|
&serde_json::from_value(item).expect("deserialize user item"),
|
||||||
|
)
|
||||||
|
.expect("attachment metadata should project");
|
||||||
|
let text = wire[0]["text"].as_str().expect("wire text");
|
||||||
|
assert!(text.contains("名称=notes.md"), "{text}");
|
||||||
|
assert!(text.contains("类型=text/plain"), "{text}");
|
||||||
|
assert!(text.contains("项目路径=assets/notes.txt"), "{text}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn whitespace_only_text_parts_survive_validation() {
|
||||||
|
let root = tempfile::tempdir().expect("temp project");
|
||||||
|
crate::init_local_game_project_at(root.path(), "wire-test", "wire 投影测试")
|
||||||
|
.expect("init project");
|
||||||
|
let item: DirectCodexUserItem = serde_json::from_value(json!({
|
||||||
|
"type": "message",
|
||||||
|
"role": "user",
|
||||||
|
"id": "turn-1:user",
|
||||||
|
"content": [
|
||||||
|
{"type": "input_text", "text": "先看"},
|
||||||
|
{"type": "input_text", "text": "\n"},
|
||||||
|
{"type": "input_text", "text": " "}
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
.expect("deserialize user item");
|
||||||
|
let wire = direct_codex_user_item_to_wire_input(root.path(), &item)
|
||||||
|
.expect("whitespace-only part next to real text must pass");
|
||||||
|
let parts = wire.as_array().expect("wire input array");
|
||||||
|
assert_eq!(parts.len(), 3);
|
||||||
|
assert_eq!(parts[1]["text"].as_str(), Some("\n"));
|
||||||
|
assert_eq!(parts[2]["text"].as_str(), Some(" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn all_blank_content_is_rejected() {
|
||||||
|
let root = tempfile::tempdir().expect("temp project");
|
||||||
|
crate::init_local_game_project_at(root.path(), "wire-test", "wire 投影测试")
|
||||||
|
.expect("init project");
|
||||||
|
let item: DirectCodexUserItem = serde_json::from_value(json!({
|
||||||
|
"type": "message",
|
||||||
|
"role": "user",
|
||||||
|
"id": "turn-1:user",
|
||||||
|
"content": [
|
||||||
|
{"type": "input_text", "text": "\n"},
|
||||||
|
{"type": "input_text", "text": " "}
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
.expect("deserialize user item");
|
||||||
|
let error = direct_codex_user_item_to_wire_input(root.path(), &item)
|
||||||
|
.expect_err("all-blank content must fail closed");
|
||||||
|
assert!(error.contains("不能为空"), "{error}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -31,10 +31,9 @@ pub(crate) fn normalize_direct_client_turn_id(
|
|||||||
pub(crate) async fn chat_with_game_creator_direct_codex(
|
pub(crate) async fn chat_with_game_creator_direct_codex(
|
||||||
project_path: String,
|
project_path: String,
|
||||||
prompt: String,
|
prompt: String,
|
||||||
mut user_item: DirectCodexUserItem,
|
user_item: DirectCodexUserItem,
|
||||||
creation_type: Option<String>,
|
creation_type: Option<String>,
|
||||||
client_turn_id: Option<String>,
|
client_turn_id: Option<String>,
|
||||||
attachments: Option<Vec<DirectCodexTurnAttachment>>,
|
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
let root = Path::new(project_path.trim());
|
let root = Path::new(project_path.trim());
|
||||||
let turn_id = normalize_direct_client_turn_id(client_turn_id.as_deref())?;
|
let turn_id = normalize_direct_client_turn_id(client_turn_id.as_deref())?;
|
||||||
@@ -43,34 +42,9 @@ pub(crate) async fn chat_with_game_creator_direct_codex(
|
|||||||
redact_agent_runtime_error(root, &format!("恢复上一轮陶泥儿整包事务失败:{error}"), 500)
|
redact_agent_runtime_error(root, &format!("恢复上一轮陶泥儿整包事务失败:{error}"), 500)
|
||||||
})?;
|
})?;
|
||||||
let turn_emitter = DirectGameCreatorTurnUpdateEmitter::new(root, turn_id.clone());
|
let turn_emitter = DirectGameCreatorTurnUpdateEmitter::new(root, turn_id.clone());
|
||||||
let mut audit = DirectCodexTurnAudit::start(
|
validate_direct_codex_user_item(root, &user_item)?;
|
||||||
root,
|
let user_prompt = direct_codex_user_item_to_prompt(root, &user_item)?;
|
||||||
&turn_id,
|
|
||||||
&prompt,
|
|
||||||
attachments.as_deref().unwrap_or_default(),
|
|
||||||
);
|
|
||||||
let attachments = attachments.unwrap_or_default();
|
|
||||||
if !attachments.is_empty() {
|
|
||||||
let attachment_context =
|
|
||||||
render_direct_codex_user_prompt("", &attachments).map_err(|error| {
|
|
||||||
audit.finish(false);
|
|
||||||
error
|
|
||||||
})?;
|
|
||||||
let DirectCodexUserItem::Message(message) = &mut user_item;
|
|
||||||
message.content.push(DirectCodexUserContentPart::InputText {
|
|
||||||
text: attachment_context,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
validate_direct_codex_user_item(root, &user_item).map_err(|error| {
|
|
||||||
audit.finish(false);
|
|
||||||
error
|
|
||||||
})?;
|
|
||||||
let user_prompt = direct_codex_user_item_to_prompt(root, &user_item).map_err(|error| {
|
|
||||||
audit.finish(false);
|
|
||||||
error
|
|
||||||
})?;
|
|
||||||
if user_prompt.trim().is_empty() {
|
if user_prompt.trim().is_empty() {
|
||||||
audit.finish(false);
|
|
||||||
return Err("聊天内容不能为空".to_string());
|
return Err("聊天内容不能为空".to_string());
|
||||||
}
|
}
|
||||||
let canonical_user_item =
|
let canonical_user_item =
|
||||||
@@ -80,18 +54,15 @@ pub(crate) async fn chat_with_game_creator_direct_codex(
|
|||||||
&user_prompt,
|
&user_prompt,
|
||||||
creation_type.as_deref(),
|
creation_type.as_deref(),
|
||||||
Some(&turn_emitter),
|
Some(&turn_emitter),
|
||||||
Some(&mut audit),
|
// DirectProject 的完整回合权威已经落在 project.jsonl;不再创建平行审计日志。
|
||||||
|
None,
|
||||||
canonical_user_item,
|
canonical_user_item,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(reply) => reply,
|
Ok(reply) => reply,
|
||||||
Err(error) => {
|
Err(error) => return Err(error),
|
||||||
audit.finish(false);
|
|
||||||
return Err(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
audit.finish(true);
|
|
||||||
turn_emitter.emit("completed", Some("none"), Some(reply.clone()), None);
|
turn_emitter.emit("completed", Some("none"), Some(reply.clone()), None);
|
||||||
Ok(reply)
|
Ok(reply)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -427,16 +427,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 事件级阶段时间只在重放稳定性用例里逐个指定;其余用例用一个固定值即可,
|
|
||||||
/// 它们断言的是队列 / 游标语义,不是时间本身。
|
|
||||||
const FIXED_AT_MS: u64 = 1_000;
|
|
||||||
|
|
||||||
fn item_started(item_id: &str) -> DirectThreadEvent {
|
fn item_started(item_id: &str) -> DirectThreadEvent {
|
||||||
DirectThreadEvent::item_started(message(item_id), FIXED_AT_MS)
|
DirectThreadEvent::item_started(message(item_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_completed(item_id: &str) -> DirectThreadEvent {
|
fn item_completed(item_id: &str) -> DirectThreadEvent {
|
||||||
DirectThreadEvent::item_completed(message(item_id), FIXED_AT_MS)
|
DirectThreadEvent::item_completed(message(item_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_delta(item_id: &str) -> DirectThreadEvent {
|
fn item_delta(item_id: &str) -> DirectThreadEvent {
|
||||||
@@ -454,7 +450,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn subscribers_have_independent_cursors_on_one_global_queue() {
|
fn subscribers_have_independent_cursors_on_one_global_queue() {
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
manager.append("thread-1", DirectThreadEvent::turn_started(FIXED_AT_MS));
|
manager.append("thread-1", DirectThreadEvent::turn_started());
|
||||||
let first = manager.subscribe("thread-1");
|
let first = manager.subscribe("thread-1");
|
||||||
let second = manager.subscribe("thread-1");
|
let second = manager.subscribe("thread-1");
|
||||||
manager.append("thread-1", item_started("item-1"));
|
manager.append("thread-1", item_started("item-1"));
|
||||||
@@ -478,7 +474,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn bootstrap_contains_lifecycle_anchor_and_unfinished_events_only() {
|
fn bootstrap_contains_lifecycle_anchor_and_unfinished_events_only() {
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
manager.append("thread-1", DirectThreadEvent::turn_started(FIXED_AT_MS));
|
manager.append("thread-1", DirectThreadEvent::turn_started());
|
||||||
manager.append("thread-1", item_started("item-1"));
|
manager.append("thread-1", item_started("item-1"));
|
||||||
manager.append("thread-1", item_delta("item-1"));
|
manager.append("thread-1", item_delta("item-1"));
|
||||||
manager.append("thread-1", item_completed("item-1"));
|
manager.append("thread-1", item_completed("item-1"));
|
||||||
@@ -488,7 +484,7 @@ mod tests {
|
|||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
bootstrap.events.as_slice(),
|
bootstrap.events.as_slice(),
|
||||||
[
|
[
|
||||||
DirectThreadEvent::TurnStarted { .. },
|
DirectThreadEvent::TurnStarted {},
|
||||||
DirectThreadEvent::ItemStarted { item, .. },
|
DirectThreadEvent::ItemStarted { item, .. },
|
||||||
] if item.item_id() == "item-2"
|
] if item.item_id() == "item-2"
|
||||||
));
|
));
|
||||||
@@ -593,118 +589,15 @@ mod tests {
|
|||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
manager.append(
|
manager.append(
|
||||||
"thread-1",
|
"thread-1",
|
||||||
DirectThreadEvent::turn_completed("completed".to_string(), FIXED_AT_MS),
|
DirectThreadEvent::turn_completed("completed".to_string()),
|
||||||
);
|
);
|
||||||
let bootstrap = manager.subscribe("thread-1");
|
let bootstrap = manager.subscribe("thread-1");
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
bootstrap.events.as_slice(),
|
bootstrap.events.as_slice(),
|
||||||
[DirectThreadEvent::TurnCompleted { status, at, .. }]
|
[DirectThreadEvent::TurnCompleted { status }] if status == "completed"
|
||||||
if status == "completed" && *at == Some(FIXED_AT_MS)
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 阶段时间必须随事件一起进队列:bootstrap 与重复订阅都拿到**原值**,
|
|
||||||
/// 重放不得重新取钟(否则每次重连都会把已固定的起止时间改掉)。
|
|
||||||
#[test]
|
|
||||||
fn replayed_events_keep_their_original_stage_time() {
|
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
|
||||||
manager.append("thread-1", DirectThreadEvent::turn_started(1_000));
|
|
||||||
manager.append(
|
|
||||||
"thread-1",
|
|
||||||
DirectThreadEvent::item_started(message("item-1"), 2_000),
|
|
||||||
);
|
|
||||||
|
|
||||||
let first = manager.subscribe("thread-1");
|
|
||||||
assert_eq!(
|
|
||||||
first
|
|
||||||
.events
|
|
||||||
.iter()
|
|
||||||
.map(DirectThreadEvent::at)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![Some(1_000), Some(2_000)]
|
|
||||||
);
|
|
||||||
|
|
||||||
// 第二个订阅看到的是同一份事件,时间不因"又取了一次当前时间"而漂移。
|
|
||||||
let second = manager.subscribe("thread-1");
|
|
||||||
assert_eq!(second.events, first.events);
|
|
||||||
|
|
||||||
manager.append(
|
|
||||||
"thread-1",
|
|
||||||
DirectThreadEvent::item_completed(message("item-1"), 3_000),
|
|
||||||
);
|
|
||||||
let completion = manager
|
|
||||||
.consume(&first.subscription_id)
|
|
||||||
.expect("consume completion")
|
|
||||||
.events;
|
|
||||||
assert_eq!(
|
|
||||||
completion
|
|
||||||
.iter()
|
|
||||||
.map(DirectThreadEvent::at)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![Some(3_000)]
|
|
||||||
);
|
|
||||||
// 重复消费不产生新事件,也不改写已下发过的时间。
|
|
||||||
assert!(manager
|
|
||||||
.consume(&first.subscription_id)
|
|
||||||
.expect("empty consume")
|
|
||||||
.events
|
|
||||||
.is_empty());
|
|
||||||
assert_eq!(
|
|
||||||
completion
|
|
||||||
.iter()
|
|
||||||
.map(DirectThreadEvent::at)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![Some(3_000)]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 生命周期锚点重放时必须带上开口用户条目身份:前端在「只有锚点 + 历史切片、运行态一直空」
|
|
||||||
/// 的回合里也要能把边界认领给同一条用户条目,而不是按时间戳猜。
|
|
||||||
#[test]
|
|
||||||
fn bootstrap_replays_opener_user_item_id() {
|
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
|
||||||
manager.append(
|
|
||||||
"thread-1",
|
|
||||||
DirectThreadEvent::turn_started(1_000)
|
|
||||||
.with_user_item_id(Some("direct-codex:turn-1:user")),
|
|
||||||
);
|
|
||||||
let bootstrap = manager.subscribe("thread-1");
|
|
||||||
assert_eq!(
|
|
||||||
bootstrap
|
|
||||||
.events
|
|
||||||
.iter()
|
|
||||||
.map(DirectThreadEvent::user_item_id)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![Some("direct-codex:turn-1:user")]
|
|
||||||
);
|
|
||||||
assert_eq!(bootstrap.events[0].at(), Some(1_000));
|
|
||||||
|
|
||||||
// 锚点是独立保存的副本:队列里那条事件被回收之后,新订阅仍拿到同一个身份。
|
|
||||||
manager
|
|
||||||
.consume(&bootstrap.subscription_id)
|
|
||||||
.expect("consume anchor");
|
|
||||||
manager.append(
|
|
||||||
"thread-1",
|
|
||||||
DirectThreadEvent::item_completed(message("item-1"), 2_000),
|
|
||||||
);
|
|
||||||
manager.append(
|
|
||||||
"thread-1",
|
|
||||||
DirectThreadEvent::turn_completed("completed".to_string(), 3_000)
|
|
||||||
.with_user_item_id(Some("direct-codex:turn-1:user")),
|
|
||||||
);
|
|
||||||
let second = manager.subscribe("thread-1");
|
|
||||||
assert_eq!(
|
|
||||||
second
|
|
||||||
.events
|
|
||||||
.iter()
|
|
||||||
.map(DirectThreadEvent::user_item_id)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![Some("direct-codex:turn-1:user")],
|
|
||||||
"起止同源:终态锚点也带同一个开口用户条目身份"
|
|
||||||
);
|
|
||||||
assert_eq!(second.events[0].at(), Some(3_000));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn queue_cleanup_only_removes_a_cleanable_prefix() {
|
fn queue_cleanup_only_removes_a_cleanable_prefix() {
|
||||||
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
let mut manager = DirectThreadManager::with_limits(100, 100_000);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2391,8 +2391,6 @@ async fn bridge_generate_image(state: &DirectToolBridgeState, arguments: &Value)
|
|||||||
slice_mode,
|
slice_mode,
|
||||||
grid_x,
|
grid_x,
|
||||||
grid_y,
|
grid_y,
|
||||||
reference_asset_ids: Vec::new(),
|
|
||||||
target_category: None,
|
|
||||||
screen_color,
|
screen_color,
|
||||||
};
|
};
|
||||||
let _generation_guard = state.image_generation_gate.lock().await;
|
let _generation_guard = state.image_generation_gate.lock().await;
|
||||||
|
|||||||
@@ -67,11 +67,10 @@ pub(crate) use canvas_generation::{
|
|||||||
generate_platform_art_asset_with_options_at,
|
generate_platform_art_asset_with_options_at,
|
||||||
generate_platform_art_asset_with_required_slices_at, maybe_generate_platform_art_asset_step,
|
generate_platform_art_asset_with_required_slices_at, maybe_generate_platform_art_asset_step,
|
||||||
needs_platform_art_asset_generation, normalize_platform_art_asset_generation_kind,
|
needs_platform_art_asset_generation, normalize_platform_art_asset_generation_kind,
|
||||||
normalize_platform_art_reference_asset_ids, normalize_platform_art_target_category,
|
|
||||||
platform_art_asset_art_spec, platform_art_asset_output_extension_matches,
|
platform_art_asset_art_spec, platform_art_asset_output_extension_matches,
|
||||||
platform_art_runtime_references_match_request_contract, prepare_platform_art_asset_output_path,
|
prepare_platform_art_asset_output_path, project_canvas_asset_media_types,
|
||||||
project_canvas_asset_media_types, role_has_canvas_assets, suggested_canvas_tool_call,
|
role_has_canvas_assets, suggested_canvas_tool_call, PlatformArtAssetGenerationOptions,
|
||||||
PlatformArtAssetGenerationOptions, PLATFORM_ART_ASSET_GENERATION_KINDS,
|
PLATFORM_ART_ASSET_GENERATION_KINDS,
|
||||||
};
|
};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub(crate) use draft_validation::{
|
pub(crate) use draft_validation::{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -577,8 +577,6 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio
|
|||||||
slice_mode: (!slice_mode.trim().is_empty()).then_some(slice_mode.clone()),
|
slice_mode: (!slice_mode.trim().is_empty()).then_some(slice_mode.clone()),
|
||||||
grid_x,
|
grid_x,
|
||||||
grid_y,
|
grid_y,
|
||||||
reference_asset_ids: Vec::new(),
|
|
||||||
target_category: None,
|
|
||||||
screen_color: None,
|
screen_color: None,
|
||||||
};
|
};
|
||||||
if let Some(pending) = pending_action {
|
if let Some(pending) = pending_action {
|
||||||
@@ -631,9 +629,6 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio
|
|||||||
.or_else(|| (!slice_mode.trim().is_empty()).then_some(slice_mode)),
|
.or_else(|| (!slice_mode.trim().is_empty()).then_some(slice_mode)),
|
||||||
grid_x,
|
grid_x,
|
||||||
grid_y,
|
grid_y,
|
||||||
reference_asset_ids: requested_options.reference_asset_ids,
|
|
||||||
// Agent 运行时不会指定完成登记的目标栏目,保持调用方给的值(默认 `None`)。
|
|
||||||
target_category: requested_options.target_category,
|
|
||||||
screen_color: requested_options.screen_color,
|
screen_color: requested_options.screen_color,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -390,12 +390,6 @@ pub(crate) async fn start_local_project_asset_generation(
|
|||||||
image_size: Option<String>,
|
image_size: Option<String>,
|
||||||
asset_name: Option<String>,
|
asset_name: Option<String>,
|
||||||
output_path: Option<String>,
|
output_path: Option<String>,
|
||||||
// 前端 IPC 字段 `referenceAssetIds`:当前项目 manifest 里的图片素材 id,只做参考输入,
|
|
||||||
// 不进任务账本(重试由调用方继续用同一份引用提交,账本本身不新增字段)。
|
|
||||||
reference_asset_ids: Option<Vec<String>>,
|
|
||||||
// 前端 IPC 字段 `targetCategory`:完成登记时要落盘的正式栏目分类。同样不进任务账本:
|
|
||||||
// 它与引用一样属于「同一次提交的本地落点」,重试由调用方继续用同一个栏目提交。
|
|
||||||
target_category: Option<String>,
|
|
||||||
) -> Result<AssetGenerationTaskRecord, String> {
|
) -> Result<AssetGenerationTaskRecord, String> {
|
||||||
let task_id = asset_generation_task_id(&task_id)?;
|
let task_id = asset_generation_task_id(&task_id)?;
|
||||||
let request = prepare_local_project_asset_generation(
|
let request = prepare_local_project_asset_generation(
|
||||||
@@ -406,8 +400,6 @@ pub(crate) async fn start_local_project_asset_generation(
|
|||||||
image_size.as_deref(),
|
image_size.as_deref(),
|
||||||
asset_name.as_deref(),
|
asset_name.as_deref(),
|
||||||
output_path.as_deref(),
|
output_path.as_deref(),
|
||||||
reference_asset_ids.as_deref().unwrap_or_default(),
|
|
||||||
target_category.as_deref(),
|
|
||||||
)?;
|
)?;
|
||||||
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
||||||
enforce_project_permission_policy(&request.root, "asset.register")?;
|
enforce_project_permission_policy(&request.root, "asset.register")?;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use sha2::{Digest as _, Sha256};
|
use sha2::{Digest as _, Sha256};
|
||||||
use shared_contracts::game_creation_app::GameCreationAppAssetCategory;
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
const PRIVATE_EXTERNAL_EDITOR_API_KEY_FILE_PREFIX: &str = "external-editor-api-";
|
const PRIVATE_EXTERNAL_EDITOR_API_KEY_FILE_PREFIX: &str = "external-editor-api-";
|
||||||
@@ -663,7 +662,6 @@ pub(crate) fn register_design_artifacts_at(root: &Path) -> Result<bool, String>
|
|||||||
generation_kind: None,
|
generation_kind: None,
|
||||||
reference_resource_ids: Vec::new(),
|
reference_resource_ids: Vec::new(),
|
||||||
},
|
},
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
changed |= asset_changed;
|
changed |= asset_changed;
|
||||||
}
|
}
|
||||||
@@ -1878,58 +1876,10 @@ pub(crate) fn register_local_asset_entry(
|
|||||||
id_prefix: &str,
|
id_prefix: &str,
|
||||||
source: GameCreationAppAssetSource,
|
source: GameCreationAppAssetSource,
|
||||||
) -> Result<UploadLocalAssetResult, String> {
|
) -> Result<UploadLocalAssetResult, String> {
|
||||||
register_local_asset_entry_with_change(
|
register_local_asset_entry_with_change(root, local_path, kind, media_type, id_prefix, source)
|
||||||
root, local_path, kind, media_type, id_prefix, source, None,
|
|
||||||
)
|
|
||||||
.map(|(result, _)| result)
|
.map(|(result, _)| result)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 带**显式目标分类**的登记入口:只给 GUI 生成完成路径用(前端 `targetCategory`)。
|
|
||||||
///
|
|
||||||
/// 入口栏目与生成 kind 不是同一套词汇(栏目 `character` / `scene` / `ui-interaction`,
|
|
||||||
/// 生成 kind 的派生分类会把图片落到 `unclassified`、规范图落到 `document`),所以要落回
|
|
||||||
/// 入口栏目只能由调用方把目标分类显式交进来。取值必须先过
|
|
||||||
/// [`shared_contracts::game_creation_app::game_creation_app_asset_category_from_str`],
|
|
||||||
/// 非法值失败关闭,绝不回退到 kind 派生;其它调用方继续走
|
|
||||||
/// [`register_local_asset_entry`],行为不变。
|
|
||||||
pub(crate) fn register_local_asset_entry_with_category(
|
|
||||||
root: &Path,
|
|
||||||
local_path: &str,
|
|
||||||
kind: &str,
|
|
||||||
media_type: &str,
|
|
||||||
id_prefix: &str,
|
|
||||||
source: GameCreationAppAssetSource,
|
|
||||||
target_category: Option<&str>,
|
|
||||||
) -> Result<UploadLocalAssetResult, String> {
|
|
||||||
let target_category = normalize_asset_category_override(target_category)?;
|
|
||||||
register_local_asset_entry_with_change(
|
|
||||||
root,
|
|
||||||
local_path,
|
|
||||||
kind,
|
|
||||||
media_type,
|
|
||||||
id_prefix,
|
|
||||||
source,
|
|
||||||
target_category,
|
|
||||||
)
|
|
||||||
.map(|(result, _)| result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 归一显式目标分类:只接受合法枚举值,返回落盘字符串。
|
|
||||||
fn normalize_asset_category_override(
|
|
||||||
target_category: Option<&str>,
|
|
||||||
) -> Result<Option<GameCreationAppAssetCategory>, String> {
|
|
||||||
let Some(target_category) = target_category else {
|
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
let target_category = target_category.trim();
|
|
||||||
if target_category.is_empty() {
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
game_creation_app_asset_category_from_str(target_category)
|
|
||||||
.map(Some)
|
|
||||||
.ok_or_else(|| format!("非法资源分类:{target_category}"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_local_asset_entry_with_change(
|
fn register_local_asset_entry_with_change(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
local_path: &str,
|
local_path: &str,
|
||||||
@@ -1937,7 +1887,6 @@ fn register_local_asset_entry_with_change(
|
|||||||
media_type: &str,
|
media_type: &str,
|
||||||
id_prefix: &str,
|
id_prefix: &str,
|
||||||
source: GameCreationAppAssetSource,
|
source: GameCreationAppAssetSource,
|
||||||
target_category: Option<GameCreationAppAssetCategory>,
|
|
||||||
) -> Result<(UploadLocalAssetResult, bool), String> {
|
) -> Result<(UploadLocalAssetResult, bool), String> {
|
||||||
let normalized_path = normalize_relative_path(local_path)?;
|
let normalized_path = normalize_relative_path(local_path)?;
|
||||||
let absolute_path = resolve_local_project_path(root, &normalized_path)?;
|
let absolute_path = resolve_local_project_path(root, &normalized_path)?;
|
||||||
@@ -1963,17 +1912,11 @@ fn register_local_asset_entry_with_change(
|
|||||||
// kind 没变时刻意不动 category——落盘分类是权威值,同 kind 重登记不得抹掉它。
|
// kind 没变时刻意不动 category——落盘分类是权威值,同 kind 重登记不得抹掉它。
|
||||||
let changed = existing.kind != kind
|
let changed = existing.kind != kind
|
||||||
|| existing.media_type != media_type
|
|| existing.media_type != media_type
|
||||||
|| existing.source != source
|
|| existing.source != source;
|
||||||
|| target_category.is_some_and(|category| existing.category != category);
|
|
||||||
if existing.kind != kind {
|
if existing.kind != kind {
|
||||||
existing.kind = kind.to_string();
|
existing.kind = kind.to_string();
|
||||||
existing.category = game_creation_app_asset_category_for_kind(kind);
|
existing.category = game_creation_app_asset_category_for_kind(kind);
|
||||||
}
|
}
|
||||||
// 调用方显式给出目标分类时它就是权威值:GUI 完成登记必须能落回入口栏目,
|
|
||||||
// 这也是同路径重新生成时把资产从旧栏目(或 unclassified)原位接管过来的唯一入口。
|
|
||||||
if let Some(category) = target_category {
|
|
||||||
existing.category = category;
|
|
||||||
}
|
|
||||||
existing.media_type = media_type.to_string();
|
existing.media_type = media_type.to_string();
|
||||||
existing.source = source;
|
existing.source = source;
|
||||||
Ok((existing.id.clone(), "asset.update", changed))
|
Ok((existing.id.clone(), "asset.update", changed))
|
||||||
@@ -1990,8 +1933,7 @@ fn register_local_asset_entry_with_change(
|
|||||||
local_path: normalized_path.clone(),
|
local_path: normalized_path.clone(),
|
||||||
image_sequence_frames: None,
|
image_sequence_frames: None,
|
||||||
image_sequence_duration_ms: None,
|
image_sequence_duration_ms: None,
|
||||||
category: target_category
|
category: game_creation_app_asset_category_for_kind(kind),
|
||||||
.unwrap_or_else(|| game_creation_app_asset_category_for_kind(kind)),
|
|
||||||
tags: Vec::new(),
|
tags: Vec::new(),
|
||||||
source,
|
source,
|
||||||
});
|
});
|
||||||
@@ -2211,7 +2153,6 @@ pub(crate) fn delete_manifest_asset_at(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use shared_contracts::game_creation_app::GameCreationAppAssetCategory;
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2235,121 +2176,6 @@ mod tests {
|
|||||||
assert!(!register_design_artifacts_at(root).expect("register idempotently"));
|
assert!(!register_design_artifacts_at(root).expect("register idempotently"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GUI 完成登记可以显式指定目标栏目:新建条目与已登记条目都按显式值落盘。
|
|
||||||
///
|
|
||||||
/// 入口栏目(character / scene / ui-interaction)与生成 kind 不是同一套词汇,按 kind 派生
|
|
||||||
/// 会把图片落到 unclassified,占位拿不回原位;非法值必须失败关闭,不传时保持 kind 派生。
|
|
||||||
#[test]
|
|
||||||
fn explicit_target_category_overrides_the_kind_derived_category() {
|
|
||||||
fn canvas_source() -> GameCreationAppAssetSource {
|
|
||||||
GameCreationAppAssetSource {
|
|
||||||
kind: GameCreationAppAssetSourceKind::Canvas,
|
|
||||||
canvas_project_id: None,
|
|
||||||
resource_id: None,
|
|
||||||
asset_object_id: None,
|
|
||||||
task_id: None,
|
|
||||||
prompt: None,
|
|
||||||
model: None,
|
|
||||||
generation_route: None,
|
|
||||||
generation_kind: None,
|
|
||||||
reference_resource_ids: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn category_of(root: &Path, asset_id: &str) -> GameCreationAppAssetCategory {
|
|
||||||
read_existing_manifest_for_project(root)
|
|
||||||
.expect("read manifest")
|
|
||||||
.assets
|
|
||||||
.into_iter()
|
|
||||||
.find(|asset| asset.id == asset_id)
|
|
||||||
.expect("registered asset is present")
|
|
||||||
.category
|
|
||||||
}
|
|
||||||
|
|
||||||
let temporary = tempfile::tempdir().expect("tempdir");
|
|
||||||
let root = temporary.path();
|
|
||||||
crate::project::init_local_game_project_at(root, "target-category-test", "目标栏目登记")
|
|
||||||
.expect("init project");
|
|
||||||
fs::create_dir_all(root.join("assets")).expect("create assets dir");
|
|
||||||
fs::write(root.join("assets/hero.png"), b"png-bytes").expect("write asset");
|
|
||||||
|
|
||||||
let registered = register_local_asset_entry_with_category(
|
|
||||||
root,
|
|
||||||
"assets/hero.png",
|
|
||||||
"image",
|
|
||||||
"image/png",
|
|
||||||
"platform-art",
|
|
||||||
canvas_source(),
|
|
||||||
Some("character"),
|
|
||||||
)
|
|
||||||
.expect("register with a target category");
|
|
||||||
assert_eq!(
|
|
||||||
category_of(root, ®istered.id),
|
|
||||||
GameCreationAppAssetCategory::Character
|
|
||||||
);
|
|
||||||
|
|
||||||
// 同 kind 重新生成时显式目标分类仍是权威值:资产要能换栏目原位接管。
|
|
||||||
register_local_asset_entry_with_category(
|
|
||||||
root,
|
|
||||||
"assets/hero.png",
|
|
||||||
"image",
|
|
||||||
"image/png",
|
|
||||||
"platform-art",
|
|
||||||
canvas_source(),
|
|
||||||
Some("ui-interaction"),
|
|
||||||
)
|
|
||||||
.expect("re-register with another target category");
|
|
||||||
assert_eq!(
|
|
||||||
category_of(root, ®istered.id),
|
|
||||||
GameCreationAppAssetCategory::UiInteraction
|
|
||||||
);
|
|
||||||
|
|
||||||
// 非法值失败关闭,且不动已落盘的分类。
|
|
||||||
assert!(register_local_asset_entry_with_category(
|
|
||||||
root,
|
|
||||||
"assets/hero.png",
|
|
||||||
"image",
|
|
||||||
"image/png",
|
|
||||||
"platform-art",
|
|
||||||
canvas_source(),
|
|
||||||
Some("version"),
|
|
||||||
)
|
|
||||||
.is_err());
|
|
||||||
assert_eq!(
|
|
||||||
category_of(root, ®istered.id),
|
|
||||||
GameCreationAppAssetCategory::UiInteraction
|
|
||||||
);
|
|
||||||
|
|
||||||
// 不传目标分类时保持原有行为:新条目按 kind 派生(image → unclassified)。
|
|
||||||
fs::write(root.join("assets/plain.png"), b"png-bytes").expect("write plain asset");
|
|
||||||
let plain = register_local_asset_entry(
|
|
||||||
root,
|
|
||||||
"assets/plain.png",
|
|
||||||
"image",
|
|
||||||
"image/png",
|
|
||||||
"platform-art",
|
|
||||||
canvas_source(),
|
|
||||||
)
|
|
||||||
.expect("register without a target category");
|
|
||||||
assert_eq!(
|
|
||||||
category_of(root, &plain.id),
|
|
||||||
GameCreationAppAssetCategory::Unclassified
|
|
||||||
);
|
|
||||||
// 已落盘的显式分类在 kind 未变时仍然是权威值:同 kind 重登记不得把它抹掉。
|
|
||||||
register_local_asset_entry(
|
|
||||||
root,
|
|
||||||
"assets/hero.png",
|
|
||||||
"image",
|
|
||||||
"image/png",
|
|
||||||
"platform-art",
|
|
||||||
canvas_source(),
|
|
||||||
)
|
|
||||||
.expect("re-register without a target category");
|
|
||||||
assert_eq!(
|
|
||||||
category_of(root, ®istered.id),
|
|
||||||
GameCreationAppAssetCategory::UiInteraction
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 画板导出推断出的 kind 必须已经是 canonical 值。
|
/// 画板导出推断出的 kind 必须已经是 canonical 值。
|
||||||
///
|
///
|
||||||
/// 这个值会被原样写进 manifest 并据以派生落盘 `category`;一旦写出非 canonical 值
|
/// 这个值会被原样写进 manifest 并据以派生落盘 `category`;一旦写出非 canonical 值
|
||||||
|
|||||||
@@ -2375,27 +2375,6 @@ pub(crate) fn update_local_project_resource_classification(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 为一批已登记素材追加标签:整批一次校验、一次 manifest 写入、一次 revision 推进。
|
|
||||||
///
|
|
||||||
/// 权限位与单素材分类更新同口径取 `asset.register`(命令包装层只做权限门面,
|
|
||||||
/// 身份 / 写锁 / CAS / 原子写与审计都在 `project/manifest.rs` 内完成)。
|
|
||||||
/// 这里刻意**不**循环调用单素材命令:逐项调用会写出多份 manifest、推进多次 revision,
|
|
||||||
/// 中途失败还会留下"前几个素材改了、后面的没改"的部分写入。
|
|
||||||
#[tauri::command]
|
|
||||||
pub(crate) fn add_local_project_resource_tags(
|
|
||||||
input: AddLocalProjectResourceTagsInput,
|
|
||||||
) -> Result<AddLocalProjectResourceTagsResult, String> {
|
|
||||||
let root = Path::new(input.project_path.trim());
|
|
||||||
enforce_project_permission_policy(root, "asset.register")?;
|
|
||||||
add_manifest_asset_tags_at(
|
|
||||||
root,
|
|
||||||
&input.expected_project_id,
|
|
||||||
input.expected_project_revision,
|
|
||||||
input.asset_ids,
|
|
||||||
input.tags,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub(crate) async fn derive_local_project_resource(
|
pub(crate) async fn derive_local_project_resource(
|
||||||
input: DeriveLocalProjectResourceInput,
|
input: DeriveLocalProjectResourceInput,
|
||||||
@@ -4947,8 +4926,6 @@ pub(crate) fn prepare_local_project_asset_generation(
|
|||||||
image_size: Option<&str>,
|
image_size: Option<&str>,
|
||||||
asset_name: Option<&str>,
|
asset_name: Option<&str>,
|
||||||
output_path: Option<&str>,
|
output_path: Option<&str>,
|
||||||
reference_asset_ids: &[String],
|
|
||||||
target_category: Option<&str>,
|
|
||||||
) -> Result<LocalProjectAssetGenerationRequest, String> {
|
) -> Result<LocalProjectAssetGenerationRequest, String> {
|
||||||
let project_path = project_path.trim();
|
let project_path = project_path.trim();
|
||||||
if project_path.is_empty() {
|
if project_path.is_empty() {
|
||||||
@@ -4956,13 +4933,6 @@ pub(crate) fn prepare_local_project_asset_generation(
|
|||||||
}
|
}
|
||||||
let asset_kind = normalize_platform_art_asset_generation_kind(kind)
|
let asset_kind = normalize_platform_art_asset_generation_kind(kind)
|
||||||
.ok_or_else(|| format!("素材类型不受支持:{}", kind.trim()))?;
|
.ok_or_else(|| format!("素材类型不受支持:{}", kind.trim()))?;
|
||||||
// 参考入参只接受当前项目 manifest 素材 id:路径、远端 resourceId 与超限在这里就被拒绝,
|
|
||||||
// 不把校验推迟到远端(远端只该收到当前账号绑定下的 resource ID)。
|
|
||||||
let reference_asset_ids =
|
|
||||||
normalize_platform_art_reference_asset_ids(asset_kind, reference_asset_ids)?;
|
|
||||||
// GUI 完成登记层参数:入口栏目与生成 kind 不是同一套词汇,只有调用方显式给出目标分类
|
|
||||||
// 才能把产物原位落回入口栏目。非法值(含 `version` / `all` 这类栏目伪值)直接失败关闭。
|
|
||||||
let target_category = normalize_platform_art_target_category(target_category)?;
|
|
||||||
Ok(LocalProjectAssetGenerationRequest {
|
Ok(LocalProjectAssetGenerationRequest {
|
||||||
root: PathBuf::from(project_path),
|
root: PathBuf::from(project_path),
|
||||||
prompt: local_project_asset_prompt(prompt)?,
|
prompt: local_project_asset_prompt(prompt)?,
|
||||||
@@ -4999,8 +4969,6 @@ pub(crate) fn prepare_local_project_asset_generation(
|
|||||||
.then(|| "connected-components".to_string()),
|
.then(|| "connected-components".to_string()),
|
||||||
grid_x: None,
|
grid_x: None,
|
||||||
grid_y: None,
|
grid_y: None,
|
||||||
reference_asset_ids,
|
|
||||||
target_category,
|
|
||||||
screen_color: None,
|
screen_color: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -5023,10 +4991,6 @@ pub(crate) async fn generate_local_project_asset(
|
|||||||
image_size: Option<String>,
|
image_size: Option<String>,
|
||||||
asset_name: Option<String>,
|
asset_name: Option<String>,
|
||||||
output_path: Option<String>,
|
output_path: Option<String>,
|
||||||
reference_asset_ids: Option<Vec<String>>,
|
|
||||||
// 前端 IPC 字段 `targetCategory`:本次生成完成登记时要落盘的正式栏目分类,
|
|
||||||
// 只走 GUI 命令,取值必须是合法素材分类,Agent / Direct 路径不传。
|
|
||||||
target_category: Option<String>,
|
|
||||||
) -> Result<UploadLocalAssetResult, String> {
|
) -> Result<UploadLocalAssetResult, String> {
|
||||||
let request = prepare_local_project_asset_generation(
|
let request = prepare_local_project_asset_generation(
|
||||||
&project_path,
|
&project_path,
|
||||||
@@ -5036,8 +5000,6 @@ pub(crate) async fn generate_local_project_asset(
|
|||||||
image_size.as_deref(),
|
image_size.as_deref(),
|
||||||
asset_name.as_deref(),
|
asset_name.as_deref(),
|
||||||
output_path.as_deref(),
|
output_path.as_deref(),
|
||||||
reference_asset_ids.as_deref().unwrap_or_default(),
|
|
||||||
target_category.as_deref(),
|
|
||||||
)?;
|
)?;
|
||||||
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
enforce_project_permission_policy(&request.root, "canvas.asset_generate")?;
|
||||||
enforce_project_permission_policy(&request.root, "asset.register")?;
|
enforce_project_permission_policy(&request.root, "asset.register")?;
|
||||||
@@ -5056,17 +5018,7 @@ mod local_project_asset_generation_tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn prepare(kind: &str, prompt: &str) -> Result<LocalProjectAssetGenerationRequest, String> {
|
fn prepare(kind: &str, prompt: &str) -> Result<LocalProjectAssetGenerationRequest, String> {
|
||||||
prepare_local_project_asset_generation(
|
prepare_local_project_asset_generation("/tmp/project", kind, prompt, None, None, None, None)
|
||||||
"/tmp/project",
|
|
||||||
kind,
|
|
||||||
prompt,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -5106,8 +5058,6 @@ mod local_project_asset_generation_tests {
|
|||||||
Some("2K"),
|
Some("2K"),
|
||||||
Some(" 主角图集 "),
|
Some(" 主角图集 "),
|
||||||
Some(" assets/hero.png "),
|
Some(" assets/hero.png "),
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.expect("explicit options");
|
.expect("explicit options");
|
||||||
assert_eq!(explicit.root, PathBuf::from("/tmp/project"));
|
assert_eq!(explicit.root, PathBuf::from("/tmp/project"));
|
||||||
@@ -5135,17 +5085,7 @@ mod local_project_asset_generation_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn invalid_toolbar_arguments_are_rejected_before_any_generation() {
|
fn invalid_toolbar_arguments_are_rejected_before_any_generation() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
prepare_local_project_asset_generation(
|
prepare_local_project_asset_generation("", "image", "要求", None, None, None, None)
|
||||||
"",
|
|
||||||
"image",
|
|
||||||
"要求",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.expect_err("empty project path"),
|
.expect_err("empty project path"),
|
||||||
"项目路径不能为空"
|
"项目路径不能为空"
|
||||||
);
|
);
|
||||||
@@ -5157,60 +5097,6 @@ mod local_project_asset_generation_tests {
|
|||||||
prepare("game-art", "要求").expect_err("unverified kind"),
|
prepare("game-art", "要求").expect_err("unverified kind"),
|
||||||
"素材类型不受支持:game-art"
|
"素材类型不受支持:game-art"
|
||||||
);
|
);
|
||||||
// 目标分类只接受合法素材分类枚举:栏目侧伪值 `version` / `all` 与任意其它值都失败关闭。
|
|
||||||
for rejected in ["version", "all", "bogus", "UI"] {
|
|
||||||
assert_eq!(
|
|
||||||
prepare_local_project_asset_generation(
|
|
||||||
"/tmp/project",
|
|
||||||
"image",
|
|
||||||
"要求",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&[],
|
|
||||||
Some(rejected),
|
|
||||||
)
|
|
||||||
.expect_err("illegal target category"),
|
|
||||||
format!("目标分类不是合法素材分类:{rejected}")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// 合法值归一成落盘字符串(trim + kebab-case),供 manifest `category` 直接使用。
|
|
||||||
assert_eq!(
|
|
||||||
prepare_local_project_asset_generation(
|
|
||||||
"/tmp/project",
|
|
||||||
"image",
|
|
||||||
"要求",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&[],
|
|
||||||
Some(" ui-interaction "),
|
|
||||||
)
|
|
||||||
.expect("legal target category")
|
|
||||||
.options
|
|
||||||
.target_category
|
|
||||||
.as_deref(),
|
|
||||||
Some("ui-interaction")
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
prepare_local_project_asset_generation(
|
|
||||||
"/tmp/project",
|
|
||||||
"image",
|
|
||||||
"要求",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.expect("omitted target category")
|
|
||||||
.options
|
|
||||||
.target_category,
|
|
||||||
None
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
prepare(
|
prepare(
|
||||||
"spec",
|
"spec",
|
||||||
@@ -5227,9 +5113,7 @@ mod local_project_asset_generation_tests {
|
|||||||
Some("4:3"),
|
Some("4:3"),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.expect_err("unsupported ratio"),
|
.expect_err("unsupported ratio"),
|
||||||
"图片比例不受支持:4:3"
|
"图片比例不受支持:4:3"
|
||||||
@@ -5242,9 +5126,7 @@ mod local_project_asset_generation_tests {
|
|||||||
None,
|
None,
|
||||||
Some("4K"),
|
Some("4K"),
|
||||||
None,
|
None,
|
||||||
None,
|
None
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.expect_err("unsupported size"),
|
.expect_err("unsupported size"),
|
||||||
"图片尺寸不受支持:4K"
|
"图片尺寸不受支持:4K"
|
||||||
@@ -5257,9 +5139,7 @@ mod local_project_asset_generation_tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Some("坏\u{7}名字"),
|
Some("坏\u{7}名字"),
|
||||||
None,
|
None
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.expect_err("control character in asset name"),
|
.expect_err("control character in asset name"),
|
||||||
"素材名称超出安全边界"
|
"素材名称超出安全边界"
|
||||||
@@ -5272,9 +5152,7 @@ mod local_project_asset_generation_tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Some(&"a".repeat(LOCAL_PROJECT_ASSET_MAX_OUTPUT_PATH_CHARS + 1)),
|
Some(&"a".repeat(LOCAL_PROJECT_ASSET_MAX_OUTPUT_PATH_CHARS + 1))
|
||||||
&[],
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.expect_err("oversized output path"),
|
.expect_err("oversized output path"),
|
||||||
"输出路径超出安全边界"
|
"输出路径超出安全边界"
|
||||||
|
|||||||
@@ -2589,7 +2589,6 @@ fn main() {
|
|||||||
register_local_asset,
|
register_local_asset,
|
||||||
create_ui_design_resource,
|
create_ui_design_resource,
|
||||||
update_local_project_resource_classification,
|
update_local_project_resource_classification,
|
||||||
add_local_project_resource_tags,
|
|
||||||
derive_local_project_resource,
|
derive_local_project_resource,
|
||||||
list_pending_local_project_resource_edits,
|
list_pending_local_project_resource_edits,
|
||||||
resume_local_project_resource_edit,
|
resume_local_project_resource_edit,
|
||||||
|
|||||||
@@ -1131,17 +1131,8 @@ pub(crate) fn validate_manifest_required_visual_asset(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if task_id == "art-director" {
|
if task_id == "art-director" {
|
||||||
// 规范图是视觉来源链的根:它自身不派生任何视觉资产,但 icon-spec 生成允许用户参考
|
if !asset.source.reference_resource_ids.is_empty() {
|
||||||
// (没有规范前置,最多总上限),这些参考只是风格输入,不构成派生关系。这里改为验证
|
return Err("统一视觉规范图不得声明派生资源引用".to_string());
|
||||||
// 参考集合仍符合 icon-spec 请求合同;route / generation kind / canvasProjectId /
|
|
||||||
// resourceId / PNG 解码等身份判据全部保持不变。
|
|
||||||
if !crate::agent::platform_art_runtime_references_match_request_contract(
|
|
||||||
&asset.source.reference_resource_ids,
|
|
||||||
expected_kind,
|
|
||||||
) {
|
|
||||||
return Err(format!(
|
|
||||||
"统一视觉规范图的参考集合不符合请求合同:{expected_path}"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -1166,17 +1157,11 @@ pub(crate) fn validate_manifest_required_visual_asset(
|
|||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
.filter(|value| !value.is_empty())
|
.filter(|value| !value.is_empty())
|
||||||
.ok_or_else(|| "统一视觉规范图缺少 resourceId".to_string())?;
|
.ok_or_else(|| "统一视觉规范图缺少 resourceId".to_string())?;
|
||||||
// 派生素材的参考合同是「规范图前置在最前,用户参考按顺序追加在后」,图集不接受用户参考:
|
let [reference_resource_id] = asset.source.reference_resource_ids.as_slice() else {
|
||||||
// 规范身份仍只由首项承担,用户参考不能顶替也不能冒充规范引用。
|
|
||||||
if !crate::agent::platform_art_runtime_references_match_request_contract(
|
|
||||||
&asset.source.reference_resource_ids,
|
|
||||||
expected_kind,
|
|
||||||
) {
|
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"派生视觉资产未精确引用当前统一视觉规范图:{expected_path}"
|
"派生视觉资产未精确引用当前统一视觉规范图:{expected_path}"
|
||||||
));
|
));
|
||||||
}
|
};
|
||||||
let reference_resource_id = asset.source.reference_resource_ids[0].as_str();
|
|
||||||
let original_provenance_matches =
|
let original_provenance_matches =
|
||||||
canvas_project_id == art_spec_project_id && reference_resource_id == art_spec_resource_id;
|
canvas_project_id == art_spec_project_id && reference_resource_id == art_spec_resource_id;
|
||||||
let rebound_local_source_matches = if original_provenance_matches {
|
let rebound_local_source_matches = if original_provenance_matches {
|
||||||
@@ -1343,240 +1328,6 @@ pub(crate) fn update_manifest_asset_classification_at(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
|
||||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
|
||||||
pub(crate) struct AddLocalProjectResourceTagsInput {
|
|
||||||
pub(crate) project_path: String,
|
|
||||||
pub(crate) expected_project_id: String,
|
|
||||||
pub(crate) expected_project_revision: u64,
|
|
||||||
pub(crate) asset_ids: Vec<String>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub(crate) tags: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub(crate) struct AddLocalProjectResourceTagsResult {
|
|
||||||
pub(crate) assets: Vec<GameCreationAppAssetManifestEntry>,
|
|
||||||
pub(crate) committed_project_revision: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 一次批量追加的素材上限:与主规范「每批最多 200 个不同素材」一致,按**去重后**数量计算。
|
|
||||||
/// 批次越大,锁内要重算的合并结果越多,manifest 也越大;无界批次会把成本摊到之后每一次读写上。
|
|
||||||
pub(crate) const ASSET_BATCH_TAG_MAX_ASSETS: usize = 200;
|
|
||||||
|
|
||||||
/// 批量追加标签的素材 ID 归一化:trim、按**首次出现顺序**去重,再在此处收口批次上下界。
|
|
||||||
///
|
|
||||||
/// 这里是"整句拒绝"的失败关闭口径,不做任何静默容忍:
|
|
||||||
///
|
|
||||||
/// - 空白 `assetId` 直接失败,不 `continue` 跳过。静默跳过会让"请求了 N 个素材"和"实际写了
|
|
||||||
/// N-1 个"分叉,而调用方拿到的仍是成功——这正是本合同要排除的静默部分写;
|
|
||||||
/// - 空批次失败;
|
|
||||||
/// - 去重后超限立即失败(在扫描到第 201 个不同 ID 时就返回,不对剩余 ID 继续做去重扫描),
|
|
||||||
/// 更不做"截断到 200 个":截断会让用户以为 250 个素材都加上了标签。
|
|
||||||
fn normalize_manifest_batch_asset_ids(asset_ids: &[String]) -> Result<Vec<String>, String> {
|
|
||||||
let mut normalized: Vec<String> = Vec::new();
|
|
||||||
for asset_id in asset_ids {
|
|
||||||
let asset_id = asset_id.trim();
|
|
||||||
if asset_id.is_empty() {
|
|
||||||
return Err("批量标签 assetId 不能为空".to_string());
|
|
||||||
}
|
|
||||||
if !normalized.iter().any(|existing| existing == asset_id) {
|
|
||||||
normalized.push(asset_id.to_string());
|
|
||||||
if normalized.len() > ASSET_BATCH_TAG_MAX_ASSETS {
|
|
||||||
return Err(format!(
|
|
||||||
"批量标签最多支持 {ASSET_BATCH_TAG_MAX_ASSETS} 个素材"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if normalized.is_empty() {
|
|
||||||
return Err("批量标签至少需要一个素材".to_string());
|
|
||||||
}
|
|
||||||
Ok(normalized)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 批量追加的标签归一化:沿用主规范的 trim / 去空 / 去重口径(复用
|
|
||||||
/// [`normalize_manifest_asset_tags`],其中已含数量与单标签长度收口)。
|
|
||||||
///
|
|
||||||
/// 只有**归一后为空**才拒绝:请求里全是空白标签时,用户填的东西一个字都不会落盘,
|
|
||||||
/// 此时若当成"成功且无变化"返回,界面会显示保存成功而素材上什么都没有。
|
|
||||||
fn normalize_manifest_batch_tags(tags: &[String]) -> Result<Vec<String>, String> {
|
|
||||||
let normalized = normalize_manifest_asset_tags(tags)?;
|
|
||||||
if normalized.is_empty() {
|
|
||||||
return Err("批量标签不能为空".to_string());
|
|
||||||
}
|
|
||||||
Ok(normalized)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 追加语义:只把请求里**尚不存在**的标签按请求顺序补到原有标签之后。
|
|
||||||
/// 原有标签的顺序、分类、类型、路径与来源都不参与改写——本命令没有删除或替换语义。
|
|
||||||
fn merge_manifest_asset_tags(existing: &[String], incoming: &[String]) -> Vec<String> {
|
|
||||||
let mut merged = existing.to_vec();
|
|
||||||
for tag in incoming {
|
|
||||||
if !merged.iter().any(|current| current == tag) {
|
|
||||||
merged.push(tag.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
merged
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 锁内先算完的整批计划:任何一项缺失或超限都在这里失败,此时 manifest 一个字节都没动。
|
|
||||||
struct ManifestAssetTagAppendPlan {
|
|
||||||
/// 按请求顺序(去重后)返回的素材条目,标签为合并后的完整列表。
|
|
||||||
assets: Vec<GameCreationAppAssetManifestEntry>,
|
|
||||||
/// 真正需要落值的目标:`(assets 下标, 合并后的标签)`。
|
|
||||||
updates: Vec<(usize, Vec<String>)>,
|
|
||||||
/// 确实发生变化的素材 ID,供审计记录使用;空表示整批无变化。
|
|
||||||
changed_asset_ids: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 先校验**全部**目标与**全部**合并结果,再决定是否写值。
|
|
||||||
///
|
|
||||||
/// 顺序是刻意的:第一阶段只读,任一目标不存在、任一合并结果超过标签上界都在写之前返回错误;
|
|
||||||
/// 只有全部通过,第二阶段才逐项落值。这样"缺任一资产 / 超限"都不可能留下部分写入。
|
|
||||||
fn plan_manifest_asset_tag_append(
|
|
||||||
manifest: &GameCreationAppManifest,
|
|
||||||
asset_ids: &[String],
|
|
||||||
tags: &[String],
|
|
||||||
) -> Result<ManifestAssetTagAppendPlan, String> {
|
|
||||||
let mut assets = Vec::with_capacity(asset_ids.len());
|
|
||||||
let mut updates: Vec<(usize, Vec<String>)> = Vec::with_capacity(asset_ids.len());
|
|
||||||
let mut changed_asset_ids = Vec::new();
|
|
||||||
for asset_id in asset_ids {
|
|
||||||
let index = manifest
|
|
||||||
.assets
|
|
||||||
.iter()
|
|
||||||
.position(|asset| &asset.id == asset_id)
|
|
||||||
.ok_or_else(|| format!("项目资源不存在:{asset_id}"))?;
|
|
||||||
let asset = &manifest.assets[index];
|
|
||||||
// 合并结果复用同一个上界函数:已有标签已归一化,这里等价于对整份新列表再收口一次。
|
|
||||||
// 上界函数只报"16 个"这种通用口径,200 个素材的批次里看不出是哪一项超了,所以在**调用点**
|
|
||||||
// 补上目标身份(ID + 可读 localPath)并说明整批未写:用户要能直接定位到那一张素材。
|
|
||||||
let merged = normalize_manifest_asset_tags(&merge_manifest_asset_tags(&asset.tags, tags))
|
|
||||||
.map_err(|error| {
|
|
||||||
format!(
|
|
||||||
"素材 {}({})的标签合并结果不合法:{error};本次未写入任何素材",
|
|
||||||
asset.id, asset.local_path
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
if merged != asset.tags {
|
|
||||||
changed_asset_ids.push(asset.id.clone());
|
|
||||||
}
|
|
||||||
updates.push((index, merged.clone()));
|
|
||||||
assets.push(GameCreationAppAssetManifestEntry {
|
|
||||||
tags: merged,
|
|
||||||
..asset.clone()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(ManifestAssetTagAppendPlan {
|
|
||||||
assets,
|
|
||||||
updates,
|
|
||||||
changed_asset_ids,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 为一批已登记素材追加标签:一次校验、一次 manifest 写入、一次 revision 推进。
|
|
||||||
///
|
|
||||||
/// 语义与 [`update_manifest_asset_classification_at`] 同源(`asset.register` 权限位、项目身份、
|
|
||||||
/// 项目写锁、revision CAS、manifest 原子写、审计在 manifest 落盘之后 / revision 推进之前),
|
|
||||||
/// 但作用域是**整批**:
|
|
||||||
///
|
|
||||||
/// - 项目身份校验两次(进入前与持锁后各一次),锁内按 `expectedProjectRevision` 做一次 CAS;
|
|
||||||
/// - 锁内先算完整批计划,任一目标缺失或任一合并结果超限都**不写任何一项**;
|
|
||||||
/// - 整批无变化时**不写盘、不审计、不推进 revision**,直接返回当前条目与当前 revision;
|
|
||||||
/// - 真正有变化时才写一次 manifest、追加一条审计、推进一次 revision。
|
|
||||||
///
|
|
||||||
/// 已落盘之后的审计或 revision 失败照实报"整批已写入",不回滚、也不谎称回滚:manifest 是权威
|
|
||||||
/// 真相且已经改变,把错误说成"没写"只会让用户拿错状态去重试。
|
|
||||||
pub(crate) fn add_manifest_asset_tags_at(
|
|
||||||
root: &Path,
|
|
||||||
expected_project_id: &str,
|
|
||||||
expected_project_revision: u64,
|
|
||||||
asset_ids: Vec<String>,
|
|
||||||
tags: Vec<String>,
|
|
||||||
) -> Result<AddLocalProjectResourceTagsResult, String> {
|
|
||||||
if expected_project_revision
|
|
||||||
> shared_contracts::game_creation_app::GAME_CREATION_RESOURCE_LAYOUT_MAX_SAFE_REVISION
|
|
||||||
{
|
|
||||||
return Err("expectedProjectRevision 超出 JavaScript 安全整数范围".to_string());
|
|
||||||
}
|
|
||||||
let expected_project_id = expected_project_id.trim();
|
|
||||||
if expected_project_id.is_empty() {
|
|
||||||
return Err("批量标签 expectedProjectId 不能为空".to_string());
|
|
||||||
}
|
|
||||||
let asset_ids = normalize_manifest_batch_asset_ids(&asset_ids)?;
|
|
||||||
let tags = normalize_manifest_batch_tags(&tags)?;
|
|
||||||
|
|
||||||
if read_existing_manifest_for_project(root)?.project_id != expected_project_id {
|
|
||||||
return Err("project-identity-conflict".to_string());
|
|
||||||
}
|
|
||||||
// 锁的 commandId 用本命令自己的动作名(审计/排障时能区分是批量追加还是别的写路径);
|
|
||||||
// 权限门面仍然是 `asset.register`,见 `commands.rs` 的命令包装层。
|
|
||||||
let _lock = acquire_project_write_lock(root, ASSET_BATCH_TAG_AUDIT_RECORD_TYPE)?;
|
|
||||||
if read_existing_manifest_for_project(root)?.project_id != expected_project_id {
|
|
||||||
return Err("project-identity-conflict".to_string());
|
|
||||||
}
|
|
||||||
if read_game_creator_agent_runtime_project_revision(root)?.revision != expected_project_revision
|
|
||||||
{
|
|
||||||
return Err("project-revision-conflict".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
// no-op 判定发生在锁内、写盘之前:整批标签都已经存在时,连 manifest 都不必重写一次。
|
|
||||||
// 这不是优化洁癖——重写会换掉文件 mtime 与内容字节,让"什么都没做"看起来像一次真实改动。
|
|
||||||
let plan = plan_manifest_asset_tag_append(
|
|
||||||
&read_existing_manifest_for_project(root)?,
|
|
||||||
&asset_ids,
|
|
||||||
&tags,
|
|
||||||
)?;
|
|
||||||
if plan.changed_asset_ids.is_empty() {
|
|
||||||
return Ok(AddLocalProjectResourceTagsResult {
|
|
||||||
assets: plan.assets,
|
|
||||||
committed_project_revision: expected_project_revision,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let plan = mutate_manifest_at(root, |manifest| {
|
|
||||||
// 锁内复核:`mutate_manifest_at` 自己重新读盘,所以这里按同一套规则重算一遍再落值。
|
|
||||||
// 复核失败会在 `write_manifest_locked` 之前返回错误,仍然零写入;重算也保证不会拿
|
|
||||||
// 锁外算出的绝对标签列表去覆盖这份 manifest 上刚出现的新标签。
|
|
||||||
let plan = plan_manifest_asset_tag_append(manifest, &asset_ids, &tags)?;
|
|
||||||
for (index, merged) in &plan.updates {
|
|
||||||
manifest.assets[*index].tags = merged.clone();
|
|
||||||
}
|
|
||||||
Ok(plan)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
// 复核阶段才发现"锁外以为有变化、锁内其实已无变化"的极端竞态:这一次写盘写出的就是原内容,
|
|
||||||
// 不能凭空补一条审计或推进 revision。正常路径不会走到这里——整批目标在此之前已经通过锁内 no-op 判定。
|
|
||||||
if plan.changed_asset_ids.is_empty() {
|
|
||||||
return Ok(AddLocalProjectResourceTagsResult {
|
|
||||||
assets: plan.assets,
|
|
||||||
committed_project_revision: expected_project_revision,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
append_agent_db_record(
|
|
||||||
root,
|
|
||||||
serde_json::json!({
|
|
||||||
"recordType": ASSET_BATCH_TAG_AUDIT_RECORD_TYPE,
|
|
||||||
"assetIds": plan.changed_asset_ids,
|
|
||||||
"expectedProjectRevision": expected_project_revision,
|
|
||||||
"appendedTags": tags,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.map_err(|error| format!("批量标签已写入,但审计记录失败:{error}"))?;
|
|
||||||
let committed_project_revision = advance_agent_runtime_project_revision_locked(root)
|
|
||||||
.map_err(|error| format!("批量标签已写入,但项目 revision 未能推进:{error}"))?;
|
|
||||||
Ok(AddLocalProjectResourceTagsResult {
|
|
||||||
assets: plan.assets,
|
|
||||||
committed_project_revision,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 批量标签写入的审计类型:一次批量追加只留一条记录,装的是"谁被追加了什么"。
|
|
||||||
pub(crate) const ASSET_BATCH_TAG_AUDIT_RECORD_TYPE: &str = "asset.tags.append";
|
|
||||||
|
|
||||||
pub(crate) fn create_manifest_task_at(
|
pub(crate) fn create_manifest_task_at(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
task_id: &str,
|
task_id: &str,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -6927,22 +6927,6 @@ fn agent_native_function_catalog_exposes_each_runtime_tool_with_core_schemas() {
|
|||||||
"sliceCount"
|
"sliceCount"
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
let canvas_properties = &canvas_asset.parameters["properties"]["input"]["properties"];
|
|
||||||
assert_eq!(
|
|
||||||
canvas_properties["sliceMode"]["enum"],
|
|
||||||
serde_json::json!(["connected-components", "grid", null])
|
|
||||||
);
|
|
||||||
for field in ["gridX", "gridY", "sliceCount"] {
|
|
||||||
assert_eq!(
|
|
||||||
canvas_properties[field]["type"],
|
|
||||||
serde_json::json!(["integer", "null"])
|
|
||||||
);
|
|
||||||
assert_eq!(canvas_properties[field]["minimum"], 1);
|
|
||||||
assert_eq!(
|
|
||||||
canvas_properties[field]["maximum"],
|
|
||||||
if field == "sliceCount" { 256 } else { 32 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
canvas_asset.parameters["properties"]["input"]["properties"]["aspectRatio"]["enum"],
|
canvas_asset.parameters["properties"]["input"]["properties"]["aspectRatio"]["enum"],
|
||||||
serde_json::json!(["1:1", "2:3", "3:2", "9:16", "16:9", null])
|
serde_json::json!(["1:1", "2:3", "3:2", "9:16", "16:9", null])
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user