Compare commits
116 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 38ad2ce256 | |||
| 65f8e44a88 | |||
| ade1b7803e | |||
| 71000b6df1 | |||
| c047543825 | |||
| 34b3af1d2a | |||
| f7cba30b6b | |||
| 273f12633c | |||
| 5f5aa17152 | |||
| 3a57d9fbdf | |||
| 382b925ab9 | |||
| c1482012c6 | |||
| c3a17a6efc | |||
| 1bfdc3a760 | |||
| 1e27cd229d | |||
| 774710452f | |||
| aaecb82622 | |||
| 64ad24ac77 | |||
| 75ec3361dc | |||
| bc1dc868a1 | |||
| 50204ff7aa | |||
| 70fa160819 | |||
| 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 |
@@ -23,6 +23,3 @@
|
|||||||
*.meta text
|
*.meta text
|
||||||
*.anim text
|
*.anim text
|
||||||
*.controller text
|
*.controller text
|
||||||
|
|
||||||
# Rust ts-rs 生成的共享契约:保留在仓库中供 TS 消费,但不作为手写源文件统计。
|
|
||||||
packages/shared/src/contracts/generated/** linguist-generated=true
|
|
||||||
|
|||||||
+1
-10
@@ -1,14 +1,5 @@
|
|||||||
{
|
{
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"semi": true,
|
"semi": true,
|
||||||
"trailingComma": "all",
|
"trailingComma": "all"
|
||||||
"overrides": [
|
|
||||||
{
|
|
||||||
"files": "packages/shared/src/contracts/generated/**/*.ts",
|
|
||||||
"options": {
|
|
||||||
"printWidth": 1000,
|
|
||||||
"singleQuote": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,6 +174,14 @@ _Avoid_: mock 先行堆积、前后端各自发散、先做排行榜 UI
|
|||||||
|
|
||||||
## 项目开发对话(DirectProject)
|
## 项目开发对话(DirectProject)
|
||||||
|
|
||||||
|
**DirectProject 专属聊天模块**:
|
||||||
|
AGC 普通项目聊天的独立容器,拥有 DirectProject 的聊天状态、运行态订阅、历史读取、发送队列、附件和中止交互,并把聊天投影交给专属表现层渲染;它不承接 Supervisor、Design Agent 或 Planning V2 的运行态。
|
||||||
|
_Avoid_: 把 DirectProject 作为项目总控聊天的一个布尔分支、把四种 Agent 会话抽象成同一事实源
|
||||||
|
|
||||||
|
**项目工作台布局**:
|
||||||
|
承载本地项目的资源工作区、项目级工具和独立聊天产品路径的外层界面;布局拥有跨面板的账户/钱包入口,聊天模块只负责项目对话,不嵌套账户展示。
|
||||||
|
_Avoid_: 把钱包入口塞进聊天设置、让聊天组件拥有工作台级账户状态
|
||||||
|
|
||||||
**项目对话历史**:
|
**项目对话历史**:
|
||||||
AGC 本地项目内 Codex 原始对话条目的持久集合,是聊天展示、工具卡片和线程恢复注入的唯一持久事实源。
|
AGC 本地项目内 Codex 原始对话条目的持久集合,是聊天展示、工具卡片和线程恢复注入的唯一持久事实源。
|
||||||
_Avoid_: 会话缓存、展示态历史、按 UI 需要另存的对话副本
|
_Avoid_: 会话缓存、展示态历史、按 UI 需要另存的对话副本
|
||||||
|
|||||||
@@ -676,11 +676,11 @@ async function runSelfTest() {
|
|||||||
designFoundationAssetCall?.arguments?.input?.outputPath ===
|
designFoundationAssetCall?.arguments?.input?.outputPath ===
|
||||||
'assets/ui-prototype.png' &&
|
'assets/ui-prototype.png' &&
|
||||||
designFoundationAssetCall.arguments.input.aspectRatio === '16:9' &&
|
designFoundationAssetCall.arguments.input.aspectRatio === '16:9' &&
|
||||||
designFoundationAssetCall.arguments.input.assetKind === 'ui-design' &&
|
designFoundationAssetCall.arguments.input.assetKind === 'ui-prototype' &&
|
||||||
artAssetPlanAssetCall?.arguments?.input?.outputPath ===
|
artAssetPlanAssetCall?.arguments?.input?.outputPath ===
|
||||||
'assets/art-spritesheet.png' &&
|
'assets/art-spritesheet.png' &&
|
||||||
artAssetPlanAssetCall.arguments.input.aspectRatio === '1:1' &&
|
artAssetPlanAssetCall.arguments.input.aspectRatio === '1:1' &&
|
||||||
artAssetPlanAssetCall.arguments.input.assetKind === 'icon-spritesheet',
|
artAssetPlanAssetCall.arguments.input.assetKind === 'art-spritesheet',
|
||||||
'self-test-visual-assets-invalid',
|
'self-test-visual-assets-invalid',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const requiredFormalArtifactSpecs = [
|
|||||||
{ path: 'game/balance.json', kind: 'json' },
|
{ path: 'game/balance.json', kind: 'json' },
|
||||||
{ path: 'assets/manifest.art.json', kind: 'json' },
|
{ path: 'assets/manifest.art.json', kind: 'json' },
|
||||||
{ path: 'assets/manifest.audio.json', kind: 'json' },
|
{ path: 'assets/manifest.audio.json', kind: 'json' },
|
||||||
{ path: 'game/index.html', kind: 'file' },
|
{ path: 'game/index.html', kind: 'game-entry' },
|
||||||
{ path: 'exports/README.md', kind: 'file' },
|
{ path: 'exports/README.md', kind: 'file' },
|
||||||
];
|
];
|
||||||
const editorImageArtifactSpecs = [
|
const editorImageArtifactSpecs = [
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ function deterministicArtManifest(
|
|||||||
{
|
{
|
||||||
id: 'garden-guardians-spritesheet',
|
id: 'garden-guardians-spritesheet',
|
||||||
path: 'assets/art-spritesheet.png',
|
path: 'assets/art-spritesheet.png',
|
||||||
kind: 'icon-spritesheet',
|
kind: 'art-spritesheet',
|
||||||
usage: ['defenders', 'enemies', 'battlefield-ui'],
|
usage: ['defenders', 'enemies', 'battlefield-ui'],
|
||||||
source: 'canvas',
|
source: 'canvas',
|
||||||
status: 'ready',
|
status: 'ready',
|
||||||
@@ -710,7 +710,7 @@ function canvasAssetCall(agentId) {
|
|||||||
outputPath: 'assets/ui-prototype.png',
|
outputPath: 'assets/ui-prototype.png',
|
||||||
aspectRatio: '16:9',
|
aspectRatio: '16:9',
|
||||||
imageSize: '2K',
|
imageSize: '2K',
|
||||||
assetKind: 'ui-design',
|
assetKind: 'ui-prototype',
|
||||||
assetLabel: '游戏横屏界面原型图',
|
assetLabel: '游戏横屏界面原型图',
|
||||||
replaceExisting: false,
|
replaceExisting: false,
|
||||||
});
|
});
|
||||||
@@ -721,7 +721,7 @@ function canvasAssetCall(agentId) {
|
|||||||
outputPath: 'assets/art-spritesheet.png',
|
outputPath: 'assets/art-spritesheet.png',
|
||||||
aspectRatio: '1:1',
|
aspectRatio: '1:1',
|
||||||
imageSize: '1K',
|
imageSize: '1K',
|
||||||
assetKind: 'icon-spritesheet',
|
assetKind: 'art-spritesheet',
|
||||||
assetLabel: '游戏首版核心美术素材',
|
assetLabel: '游戏首版核心美术素材',
|
||||||
replaceExisting: false,
|
replaceExisting: false,
|
||||||
sliceMode: 'connected-components',
|
sliceMode: 'connected-components',
|
||||||
@@ -830,12 +830,12 @@ function missingGeneratedVisualAssetObservation(context, agentId) {
|
|||||||
},
|
},
|
||||||
'design-foundation': {
|
'design-foundation': {
|
||||||
path: 'assets/ui-prototype.png',
|
path: 'assets/ui-prototype.png',
|
||||||
kind: 'ui-design',
|
kind: 'ui-prototype',
|
||||||
summary: '策划界面原型图尚未按正式视觉流程生成并登记,不能完成任务',
|
summary: '策划界面原型图尚未按正式视觉流程生成并登记,不能完成任务',
|
||||||
},
|
},
|
||||||
'art-asset-plan': {
|
'art-asset-plan': {
|
||||||
path: 'assets/art-spritesheet.png',
|
path: 'assets/art-spritesheet.png',
|
||||||
kind: 'icon-spritesheet',
|
kind: 'art-spritesheet',
|
||||||
summary: '首版美术素材图尚未按正式视觉流程生成并登记,不能完成任务',
|
summary: '首版美术素材图尚未按正式视觉流程生成并登记,不能完成任务',
|
||||||
},
|
},
|
||||||
}[agentId];
|
}[agentId];
|
||||||
@@ -2667,7 +2667,7 @@ function createDeterministicCanvasFixture(apiKey) {
|
|||||||
asset: {
|
asset: {
|
||||||
assetId: `asset-${sliceImageId}`,
|
assetId: `asset-${sliceImageId}`,
|
||||||
assetObjectId: sliceAssetObjectId,
|
assetObjectId: sliceAssetObjectId,
|
||||||
assetKind: 'icon',
|
assetKind: 'art-spritesheet-slice',
|
||||||
projectId,
|
projectId,
|
||||||
taskId,
|
taskId,
|
||||||
},
|
},
|
||||||
@@ -2707,7 +2707,7 @@ function createDeterministicCanvasFixture(apiKey) {
|
|||||||
spritesheetAsset: {
|
spritesheetAsset: {
|
||||||
assetId: `asset-${imageId}`,
|
assetId: `asset-${imageId}`,
|
||||||
assetObjectId,
|
assetObjectId,
|
||||||
assetKind: 'icon-spritesheet',
|
assetKind: 'art-spritesheet',
|
||||||
projectId,
|
projectId,
|
||||||
taskId,
|
taskId,
|
||||||
},
|
},
|
||||||
@@ -2749,7 +2749,7 @@ function createDeterministicCanvasFixture(apiKey) {
|
|||||||
const assetObjectId = `asset-object-${imageId}`;
|
const assetObjectId = `asset-object-${imageId}`;
|
||||||
const resourceId = `resource-${imageId}`;
|
const resourceId = `resource-${imageId}`;
|
||||||
const assetKind =
|
const assetKind =
|
||||||
typeof body?.assetKind === 'string' ? body.assetKind : 'image';
|
typeof body?.assetKind === 'string' ? body.assetKind : 'game-art';
|
||||||
images.set(imageId, {
|
images.set(imageId, {
|
||||||
...image,
|
...image,
|
||||||
objectKey,
|
objectKey,
|
||||||
|
|||||||
-1
@@ -5016,7 +5016,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"ts-rs",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ platform-agent = { path = "../../../server-rs/crates/platform-agent" }
|
|||||||
portable-pty = "0.9"
|
portable-pty = "0.9"
|
||||||
reqwest = { version = "0.12", default-features = false, features = ["json", "multipart", "native-tls", "stream"] }
|
reqwest = { version = "0.12", default-features = false, features = ["json", "multipart", "native-tls", "stream"] }
|
||||||
regex = "1"
|
regex = "1"
|
||||||
shared-contracts = { path = "../../../server-rs/crates/shared-contracts", default-features = false, features = ["ts-bindings"] }
|
shared-contracts = { path = "../../../server-rs/crates/shared-contracts", default-features = false }
|
||||||
tauri = { version = "2.11.2", features = [] }
|
tauri = { version = "2.11.2", features = [] }
|
||||||
tauri-plugin-dialog = "2.7.1"
|
tauri-plugin-dialog = "2.7.1"
|
||||||
tauri-plugin-http = { version = "2.5.9", default-features = false, features = ["charset", "cookies", "http2", "rustls-tls"] }
|
tauri-plugin-http = { version = "2.5.9", default-features = false, features = ["charset", "cookies", "http2", "rustls-tls"] }
|
||||||
|
|||||||
-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",
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
"agents/openai.yaml",
|
"agents/openai.yaml",
|
||||||
"references/platform-art-contract.md"
|
"references/platform-art-contract.md"
|
||||||
],
|
],
|
||||||
"sha256": "6668bf1aa69601bcc65c97fdcd879c699c3139befcd70805d95614997f6e44e9"
|
"sha256": "47ac742d9b88e5d6cd9833484ab212152578e58ae27f7add312fd1d78183385c"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "agc-web-game-development",
|
"name": "agc-web-game-development",
|
||||||
@@ -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",
|
||||||
|
|||||||
+2
-2
@@ -19,13 +19,13 @@ image, UI design image, or publication material; use `agc_edit_image` for an
|
|||||||
edit of an existing registered image; use `taonier_prepare_game_art` only for
|
edit of an existing registered image; use `taonier_prepare_game_art` only for
|
||||||
the complete game-art package and its canonical slices.
|
the complete game-art package and its canonical slices.
|
||||||
|
|
||||||
With `agc_generate_image`, `kind="character"` and `kind="icon-spritesheet"`
|
With `agc_generate_image`, `kind="character"` and `kind="art-spritesheet"`
|
||||||
generate the subject on a solid-colour background and automatically matte it
|
generate the subject on a solid-colour background and automatically matte it
|
||||||
away afterwards, producing transparent-background results; write the prompt
|
away afterwards, producing transparent-background results; write the prompt
|
||||||
for the subject only, never for a scene. `kind="image"` keeps the rendered
|
for the subject only, never for a scene. `kind="image"` keeps the rendered
|
||||||
frame without extra processing.
|
frame without extra processing.
|
||||||
|
|
||||||
When `agc_generate_image` is used with `kind="icon-spritesheet"`, `sliceMode` is
|
When `agc_generate_image` is used with `kind="art-spritesheet"`, `sliceMode` is
|
||||||
required and has no default, so decide it explicitly:
|
required and has no default, so decide it explicitly:
|
||||||
|
|
||||||
- Use `sliceMode="grid"` with `gridX` and `gridY` (1-32 each) only when the user
|
- Use `sliceMode="grid"` with `gridX` and `gridY` (1-32 each) only when the user
|
||||||
|
|||||||
@@ -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)?,
|
||||||
};
|
};
|
||||||
@@ -2971,8 +2960,22 @@ impl CodexAppServerConnection {
|
|||||||
codex_app_server_text_prompt(&request)
|
codex_app_server_text_prompt(&request)
|
||||||
.map_err(platform_llm::LlmError::InvalidRequest)?
|
.map_err(platform_llm::LlmError::InvalidRequest)?
|
||||||
};
|
};
|
||||||
let input =
|
let input = if self.inner.workspace_mode == CodexAppServerWorkspaceMode::DirectProject {
|
||||||
codex_app_server_turn_input(&request, &prompt, &self.inner.workspace_path).await?;
|
if let Some(item) = direct_user_item {
|
||||||
|
let canonical: DirectCodexUserItem = serde_json::from_value(item.clone())
|
||||||
|
.map_err(|error| platform_llm::LlmError::InvalidRequest(error.to_string()))?;
|
||||||
|
direct_codex_user_item_to_codex_turn_input(
|
||||||
|
&self.inner.workspace_path,
|
||||||
|
&canonical,
|
||||||
|
self.inner._skill_roots.as_deref().unwrap_or_default(),
|
||||||
|
)
|
||||||
|
.map_err(platform_llm::LlmError::InvalidRequest)?
|
||||||
|
} else {
|
||||||
|
codex_app_server_turn_input(&request, &prompt, &self.inner.workspace_path).await?
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
codex_app_server_turn_input(&request, &prompt, &self.inner.workspace_path).await?
|
||||||
|
};
|
||||||
let _direct_tool_bridge_turn_guard =
|
let _direct_tool_bridge_turn_guard =
|
||||||
if self.inner.workspace_mode == CodexAppServerWorkspaceMode::DirectProject {
|
if self.inner.workspace_mode == CodexAppServerWorkspaceMode::DirectProject {
|
||||||
Some(
|
Some(
|
||||||
@@ -3056,30 +3059,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 +3204,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 +3335,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 +3380,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 +3439,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 +3637,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 +3693,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 +5019,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 +6753,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 =
|
||||||
"[首页附件说明:当前尚未打开项目,以下仅为附件元数据,附件内容尚不可读取]";
|
"[首页附件说明:当前尚未打开项目,以下仅为附件元数据,附件内容尚不可读取]";
|
||||||
|
|||||||
@@ -1198,7 +1198,7 @@ mod tests {
|
|||||||
"tool": "agc_generate_image",
|
"tool": "agc_generate_image",
|
||||||
"arguments": {
|
"arguments": {
|
||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
"kind": "icon-spritesheet",
|
"kind": "art-spritesheet",
|
||||||
"sliceMode": "connected-components",
|
"sliceMode": "connected-components",
|
||||||
"sliceCount": 8,
|
"sliceCount": 8,
|
||||||
"screenColor": "#CFEFFF"
|
"screenColor": "#CFEFFF"
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ 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::{
|
||||||
direct_codex_user_item_to_prompt, direct_codex_user_item_to_response_item,
|
direct_codex_user_item_to_codex_turn_input, direct_codex_user_item_to_prompt,
|
||||||
direct_codex_user_item_to_wire_input,
|
direct_codex_user_item_to_response_item, direct_codex_user_item_to_wire_input,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,8 +34,25 @@ pub(crate) enum DirectCodexUserContentPart {
|
|||||||
InputText { text: String },
|
InputText { text: String },
|
||||||
#[serde(rename = "agc_resource_reference")]
|
#[serde(rename = "agc_resource_reference")]
|
||||||
AgcResourceReference { resource_id: String },
|
AgcResourceReference { resource_id: String },
|
||||||
|
#[serde(rename = "agc_skill_reference")]
|
||||||
|
AgcSkillReference { name: 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)]
|
||||||
|
|||||||
+216
-8
@@ -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;
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ pub(crate) const MAX_DIRECT_CODEX_REFERENCES: usize = 32;
|
|||||||
pub(crate) fn validate_direct_codex_user_item(
|
pub(crate) fn validate_direct_codex_user_item(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
item: &DirectCodexUserItem,
|
item: &DirectCodexUserItem,
|
||||||
) -> Result<(), String> {
|
) -> Result<GameCreationAppManifest, String> {
|
||||||
let DirectCodexUserItem::Message(message) = item;
|
let DirectCodexUserItem::Message(message) = item;
|
||||||
if !matches!(message.role, DirectCodexUserRole::User) {
|
if !matches!(message.role, DirectCodexUserRole::User) {
|
||||||
return Err("DirectProject 只接受 user message item".to_string());
|
return Err("DirectProject 只接受 user message item".to_string());
|
||||||
@@ -20,32 +22,91 @@ 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)?;
|
||||||
}
|
}
|
||||||
|
DirectCodexUserContentPart::AgcSkillReference { name } => {
|
||||||
|
let name = name.trim();
|
||||||
|
if name.is_empty()
|
||||||
|
|| name.chars().count() > 120
|
||||||
|
|| matches!(name, "." | "..")
|
||||||
|
|| name.chars().any(|character| {
|
||||||
|
character.is_control()
|
||||||
|
|| character.is_whitespace()
|
||||||
|
|| matches!(character, '/' | '\\' | ':' | '$')
|
||||||
|
})
|
||||||
|
{
|
||||||
|
return Err("引用的 Skill 名称无效,请移除后重新选择".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
DirectCodexUserContentPart::AgcRuntimeRegionReference(reference) => {
|
DirectCodexUserContentPart::AgcRuntimeRegionReference(reference) => {
|
||||||
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 {
|
||||||
return Err(format!("一次最多引用 {MAX_DIRECT_CODEX_REFERENCES} 个素材"));
|
return Err(format!("一次最多引用 {MAX_DIRECT_CODEX_REFERENCES} 个素材"));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(manifest)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 整条 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(
|
||||||
@@ -86,3 +147,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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
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
@@ -27,6 +27,7 @@ const DIRECT_TOOL_BRIDGE_SEARCH_URL: &str = "https://www.bing.com/search?format=
|
|||||||
const DIRECT_TOOL_BRIDGE_MAX_RESOURCE_NAME_CHARS: usize = 120;
|
const DIRECT_TOOL_BRIDGE_MAX_RESOURCE_NAME_CHARS: usize = 120;
|
||||||
const DIRECT_TOOL_BRIDGE_MAX_RESOURCE_KIND_CHARS: usize = 80;
|
const DIRECT_TOOL_BRIDGE_MAX_RESOURCE_KIND_CHARS: usize = 80;
|
||||||
const DIRECT_TOOL_BRIDGE_MAX_RESOURCE_PAGE_SIZE: usize = 100;
|
const DIRECT_TOOL_BRIDGE_MAX_RESOURCE_PAGE_SIZE: usize = 100;
|
||||||
|
const DIRECT_TOOL_BRIDGE_MAX_RESOURCE_CALLS_PER_TURN: usize = 4;
|
||||||
const DIRECT_TOOL_BRIDGE_MAX_ACCOUNT_ASSET_ID_CHARS: usize = 512;
|
const DIRECT_TOOL_BRIDGE_MAX_ACCOUNT_ASSET_ID_CHARS: usize = 512;
|
||||||
const DIRECT_TOOL_BRIDGE_MAX_LOCAL_ASSET_PATH_CHARS: usize = 512;
|
const DIRECT_TOOL_BRIDGE_MAX_LOCAL_ASSET_PATH_CHARS: usize = 512;
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ struct DirectToolBridgeActiveTurnAuthorization {
|
|||||||
turn_id: String,
|
turn_id: String,
|
||||||
brief_sha256: Option<String>,
|
brief_sha256: Option<String>,
|
||||||
completed_result: Option<Value>,
|
completed_result: Option<Value>,
|
||||||
|
resource_request_ids: BTreeMap<String, (String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DirectToolBridgeRegenerationCall {
|
enum DirectToolBridgeRegenerationCall {
|
||||||
@@ -205,6 +207,7 @@ impl DirectToolBridgeState {
|
|||||||
turn_id: turn_id.clone(),
|
turn_id: turn_id.clone(),
|
||||||
brief_sha256: None,
|
brief_sha256: None,
|
||||||
completed_result: None,
|
completed_result: None,
|
||||||
|
resource_request_ids: BTreeMap::new(),
|
||||||
});
|
});
|
||||||
Ok(DirectToolBridgeTurnGuard {
|
Ok(DirectToolBridgeTurnGuard {
|
||||||
state: Arc::clone(self),
|
state: Arc::clone(self),
|
||||||
@@ -634,17 +637,30 @@ impl DirectToolBridgeState {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 取当前回合身份,媒体资源请求按回合身份与请求指纹确定性派生 operation/idempotency id。
|
fn resource_request_ids(&self, request_fingerprint: &str) -> Result<(String, String), String> {
|
||||||
fn active_resource_turn_id(&self) -> Result<String, String> {
|
let mut authorization = self
|
||||||
let authorization = self
|
|
||||||
.turn_authorization
|
.turn_authorization
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| "AGC 工具桥回合授权状态不可用".to_string())?;
|
.map_err(|_| "AGC 工具桥回合授权状态不可用".to_string())?;
|
||||||
authorization
|
let active = authorization
|
||||||
.active
|
.active
|
||||||
.as_ref()
|
.as_mut()
|
||||||
.map(|active| active.turn_id.clone())
|
.ok_or_else(|| "当前没有客户端签发的资源生成回合身份".to_string())?;
|
||||||
.ok_or_else(|| "当前没有客户端签发的资源生成回合身份".to_string())
|
if let Some(ids) = active.resource_request_ids.get(request_fingerprint) {
|
||||||
|
return Ok(ids.clone());
|
||||||
|
}
|
||||||
|
if active.resource_request_ids.len() >= DIRECT_TOOL_BRIDGE_MAX_RESOURCE_CALLS_PER_TURN {
|
||||||
|
return Err("单个用户回合最多只能创建四项媒体资源请求".to_string());
|
||||||
|
}
|
||||||
|
let operation_id =
|
||||||
|
direct_resource_request_uuid(&active.turn_id, "operation", request_fingerprint);
|
||||||
|
let idempotency_key =
|
||||||
|
direct_resource_request_uuid(&active.turn_id, "idempotency", request_fingerprint);
|
||||||
|
active.resource_request_ids.insert(
|
||||||
|
request_fingerprint.to_string(),
|
||||||
|
(operation_id.clone(), idempotency_key.clone()),
|
||||||
|
);
|
||||||
|
Ok((operation_id, idempotency_key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1197,9 +1213,9 @@ fn bridge_registered_resource(
|
|||||||
"mediaType": asset.media_type,
|
"mediaType": asset.media_type,
|
||||||
// Agent 与 UI 必须看到同一个口径:UI 栏目走 TS 的 `gameCreationAppAssetCategory`
|
// Agent 与 UI 必须看到同一个口径:UI 栏目走 TS 的 `gameCreationAppAssetCategory`
|
||||||
// (落盘值 + 按 kind 派生 + 读时自愈),这里走 Rust 的同构实现。
|
// (落盘值 + 按 kind 派生 + 读时自愈),这里走 Rust 的同构实现。
|
||||||
// 直接透传落盘 `asset.category` 会让 UI 设计资产在 UI 显示「UI 交互」、
|
// 直接透传落盘 `asset.category` 会让 `kind:"ui"` 的资产在 UI 显示「UI 交互」、
|
||||||
// 在 Agent 侧读到 `unclassified`(真机 55 条分歧)。
|
// 在 Agent 侧读到 `unclassified`(真机 55 条分歧)。
|
||||||
"category": game_creation_app_asset_effective_category(asset.kind, asset.category),
|
"category": game_creation_app_asset_effective_category(&asset.kind, asset.category),
|
||||||
"tags": asset.tags,
|
"tags": asset.tags,
|
||||||
"canvasProjectId": asset.source.canvas_project_id,
|
"canvasProjectId": asset.source.canvas_project_id,
|
||||||
"resourceId": asset.source.resource_id,
|
"resourceId": asset.source.resource_id,
|
||||||
@@ -1240,9 +1256,7 @@ fn bridge_list_registered_assets(root: &Path, arguments: &Value) -> Value {
|
|||||||
arguments,
|
arguments,
|
||||||
"kind",
|
"kind",
|
||||||
DIRECT_TOOL_BRIDGE_MAX_RESOURCE_KIND_CHARS,
|
DIRECT_TOOL_BRIDGE_MAX_RESOURCE_KIND_CHARS,
|
||||||
)?
|
)?;
|
||||||
.map(|kind| bridge_asset_list_kind_filter(&kind))
|
|
||||||
.transpose()?;
|
|
||||||
let asset_id = bridge_optional_bounded_string(
|
let asset_id = bridge_optional_bounded_string(
|
||||||
arguments,
|
arguments,
|
||||||
"assetId",
|
"assetId",
|
||||||
@@ -1262,7 +1276,7 @@ fn bridge_list_registered_assets(root: &Path, arguments: &Value) -> Value {
|
|||||||
let mut assets = manifest
|
let mut assets = manifest
|
||||||
.assets
|
.assets
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|asset| kind.is_none_or(|kind| asset.kind == kind))
|
.filter(|asset| kind.as_ref().is_none_or(|kind| asset.kind == *kind))
|
||||||
.filter(|asset| {
|
.filter(|asset| {
|
||||||
asset_id
|
asset_id
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -1328,24 +1342,6 @@ fn bridge_list_registered_assets(root: &Path, arguments: &Value) -> Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `asset.list` 的 `kind` 过滤:只接受 canonical 值,认不出的值直接报错。
|
|
||||||
///
|
|
||||||
/// 以前认不出的值会收口成 `unknown` 再参与等值过滤,结果是**静默返回空列表**:调用方(模型)
|
|
||||||
/// 会以为项目里没有这类资产,而不是"你传的 kind 不合法",于是继续按错误前提往下走。
|
|
||||||
/// `unknown` 本身仍是合法输入(确有 kind 未知的资产),只拒绝"既不是 canonical、也不是字面
|
|
||||||
/// `unknown`"的原值。
|
|
||||||
fn bridge_asset_list_kind_filter(raw: &str) -> Result<GameCreationAppAssetKind, String> {
|
|
||||||
let kind = GameCreationAppAssetKind::parse_with_context(raw, "asset.list.kind");
|
|
||||||
if kind == GameCreationAppAssetKind::Unknown
|
|
||||||
&& raw.trim() != GameCreationAppAssetKind::Unknown.as_str()
|
|
||||||
{
|
|
||||||
return Err(format!(
|
|
||||||
"kind 不是已知的 manifest 资源 kind:{raw};请改用 canonical kind(如 image、scene、character、icon、icon-spritesheet、character-animation、audio、video、document)"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bridge_project_file_class(path: &str) -> (&'static str, Option<&'static str>) {
|
fn bridge_project_file_class(path: &str) -> (&'static str, Option<&'static str>) {
|
||||||
let extension = Path::new(path)
|
let extension = Path::new(path)
|
||||||
.extension()
|
.extension()
|
||||||
@@ -1894,11 +1890,8 @@ async fn bridge_create_or_derive_resource(
|
|||||||
))
|
))
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
let turn_id = state.active_resource_turn_id()?;
|
let (operation_id, idempotency_key) =
|
||||||
let operation_id =
|
state.resource_request_ids(&request_fingerprint)?;
|
||||||
direct_resource_request_uuid(&turn_id, "operation", &request_fingerprint);
|
|
||||||
let idempotency_key =
|
|
||||||
direct_resource_request_uuid(&turn_id, "idempotency", &request_fingerprint);
|
|
||||||
let revision = read_game_creator_agent_runtime_project_revision(&state.root)?.revision;
|
let revision = read_game_creator_agent_runtime_project_revision(&state.root)?.revision;
|
||||||
let source_resource_id = source_asset
|
let source_resource_id = source_asset
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -1916,7 +1909,7 @@ async fn bridge_create_or_derive_resource(
|
|||||||
source_asset_id: source_asset.as_ref().map(|asset| asset.id.clone()),
|
source_asset_id: source_asset.as_ref().map(|asset| asset.id.clone()),
|
||||||
source_path: source_asset.as_ref().map(|asset| asset.local_path.clone()),
|
source_path: source_asset.as_ref().map(|asset| asset.local_path.clone()),
|
||||||
source_media_type: source_asset.as_ref().map(|asset| asset.media_type.clone()),
|
source_media_type: source_asset.as_ref().map(|asset| asset.media_type.clone()),
|
||||||
source_subtype: source_asset.as_ref().map(|asset| asset.kind.to_string()),
|
source_subtype: source_asset.as_ref().map(|asset| asset.kind.clone()),
|
||||||
producer_task_id: source_asset
|
producer_task_id: source_asset
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|asset| asset.source.task_id.clone()),
|
.and_then(|asset| asset.source.task_id.clone()),
|
||||||
@@ -2008,11 +2001,7 @@ async fn bridge_remove_background(state: &DirectToolBridgeState, arguments: &Val
|
|||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
// id 按回合身份与请求指纹确定性派生,同指纹重试与 pending 对账语义不变。
|
let (operation_id, idempotency_key) = state.resource_request_ids(&fingerprint)?;
|
||||||
let turn_id = state.active_resource_turn_id()?;
|
|
||||||
let operation_id = direct_resource_request_uuid(&turn_id, "operation", &fingerprint);
|
|
||||||
let idempotency_key =
|
|
||||||
direct_resource_request_uuid(&turn_id, "idempotency", &fingerprint);
|
|
||||||
let revision = read_game_creator_agent_runtime_project_revision(&state.root)?.revision;
|
let revision = read_game_creator_agent_runtime_project_revision(&state.root)?.revision;
|
||||||
let request = DeriveLocalProjectResourceInput {
|
let request = DeriveLocalProjectResourceInput {
|
||||||
project_path: state.root.to_string_lossy().into_owned(),
|
project_path: state.root.to_string_lossy().into_owned(),
|
||||||
@@ -2026,7 +2015,7 @@ async fn bridge_remove_background(state: &DirectToolBridgeState, arguments: &Val
|
|||||||
source_asset_id: Some(source_asset_id.clone()),
|
source_asset_id: Some(source_asset_id.clone()),
|
||||||
source_path: Some(source_asset.local_path.clone()),
|
source_path: Some(source_asset.local_path.clone()),
|
||||||
source_media_type: Some(source_asset.media_type.clone()),
|
source_media_type: Some(source_asset.media_type.clone()),
|
||||||
source_subtype: Some(source_asset.kind.to_string()),
|
source_subtype: Some(source_asset.kind.clone()),
|
||||||
producer_task_id: source_asset.source.task_id.clone(),
|
producer_task_id: source_asset.source.task_id.clone(),
|
||||||
source_version_id: None,
|
source_version_id: None,
|
||||||
prompt: "去除背景".to_string(),
|
prompt: "去除背景".to_string(),
|
||||||
@@ -2194,37 +2183,35 @@ async fn bridge_prepare_game_art(state: &DirectToolBridgeState, arguments: &Valu
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bridge_image_generation_kind(arguments: &Value) -> Result<GameCreationAppAssetKind, String> {
|
fn bridge_image_generation_kind(arguments: &Value) -> Result<String, String> {
|
||||||
let kind = arguments
|
let kind = arguments
|
||||||
.get("kind")
|
.get("kind")
|
||||||
.and_then(Value::as_str)
|
.and_then(Value::as_str)
|
||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
.filter(|value| !value.is_empty())
|
.filter(|value| !value.is_empty())
|
||||||
.unwrap_or("image");
|
.unwrap_or("image");
|
||||||
normalize_platform_art_asset_generation_kind(kind).ok_or_else(|| {
|
normalize_platform_art_asset_generation_kind(kind)
|
||||||
format!(
|
.map(str::to_string)
|
||||||
"工具参数 kind 只允许 {}",
|
.ok_or_else(|| {
|
||||||
PLATFORM_ART_ASSET_GENERATION_KINDS
|
format!(
|
||||||
.iter()
|
"工具参数 kind 只允许 {}",
|
||||||
.map(|kind| kind.as_str())
|
PLATFORM_ART_ASSET_GENERATION_KINDS.join("、")
|
||||||
.collect::<Vec<_>>()
|
)
|
||||||
.join("、")
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 切分模式没有默认值:图集必须显式声明,且声明必须与 kind 和网格参数自洽。
|
/// 切分模式没有默认值:图集必须显式声明,且声明必须与 kind 和网格参数自洽。
|
||||||
fn validate_generate_image_slice_declaration(
|
fn validate_generate_image_slice_declaration(
|
||||||
kind: GameCreationAppAssetKind,
|
kind: &str,
|
||||||
slice_mode: Option<&str>,
|
slice_mode: Option<&str>,
|
||||||
grid_x: Option<u32>,
|
grid_x: Option<u32>,
|
||||||
grid_y: Option<u32>,
|
grid_y: Option<u32>,
|
||||||
slice_count: Option<usize>,
|
slice_count: Option<usize>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
if kind == GameCreationAppAssetKind::IconSpritesheet {
|
if kind == "art-spritesheet" {
|
||||||
if slice_mode.is_none() {
|
if slice_mode.is_none() {
|
||||||
return Err(
|
return Err(
|
||||||
"kind=icon-spritesheet 必须显式声明 sliceMode,没有默认值:需求要求等分网格、固定槽位或指定行列数时传 sliceMode=grid 并提供 gridX/gridY;自由排布、数量不定或只要求一张图集时传 sliceMode=connected-components"
|
"kind=art-spritesheet 必须显式声明 sliceMode,没有默认值:需求要求等分网格、固定槽位或指定行列数时传 sliceMode=grid 并提供 gridX/gridY;自由排布、数量不定或只要求一张图集时传 sliceMode=connected-components"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2237,19 +2224,19 @@ fn validate_generate_image_slice_declaration(
|
|||||||
}
|
}
|
||||||
if slice_mode.is_some() || grid_x.is_some() || grid_y.is_some() || slice_count.is_some() {
|
if slice_mode.is_some() || grid_x.is_some() || grid_y.is_some() || slice_count.is_some() {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"工具参数 sliceMode/gridX/gridY/sliceCount 仅对 kind=icon-spritesheet 生效,当前 kind={kind}"
|
"工具参数 sliceMode/gridX/gridY/sliceCount 仅对 kind=art-spritesheet 生效,当前 kind={kind}"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 抠图纯色背景只服务 character 与 icon-spritesheet 链路;格式校验收口为
|
/// 抠图纯色背景只服务 character 与 art-spritesheet 链路;格式校验收口为
|
||||||
/// `auto` 或 `#RRGGBB`(服务端另有支持色板,客户端不复制),`auto`/空串归一为
|
/// `auto` 或 `#RRGGBB`(服务端另有支持色板,客户端不复制),`auto`/空串归一为
|
||||||
/// None(服务端自动决策),hex 统一大写后透传。其它 kind 携带该字段直接拒绝,
|
/// None(服务端自动决策),hex 统一大写后透传。其它 kind 携带该字段直接拒绝,
|
||||||
/// 避免服务端静默忽略造成“已生效”的误解。
|
/// 避免服务端静默忽略造成“已生效”的误解。
|
||||||
fn normalize_generate_image_screen_color(
|
fn normalize_generate_image_screen_color(
|
||||||
arguments: &Value,
|
arguments: &Value,
|
||||||
kind: GameCreationAppAssetKind,
|
kind: &str,
|
||||||
) -> Result<Option<String>, String> {
|
) -> Result<Option<String>, String> {
|
||||||
let Some(value) = arguments.get("screenColor") else {
|
let Some(value) = arguments.get("screenColor") else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
@@ -2257,12 +2244,9 @@ fn normalize_generate_image_screen_color(
|
|||||||
if value.is_null() {
|
if value.is_null() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
if !matches!(
|
if !matches!(kind, "character" | "art-spritesheet") {
|
||||||
kind,
|
|
||||||
GameCreationAppAssetKind::Character | GameCreationAppAssetKind::IconSpritesheet
|
|
||||||
) {
|
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"工具参数 screenColor 仅对 kind=character 和 kind=icon-spritesheet 生效,当前 kind={kind}"
|
"工具参数 screenColor 仅对 kind=character 和 kind=art-spritesheet 生效,当前 kind={kind}"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let raw = value
|
let raw = value
|
||||||
@@ -2389,26 +2373,24 @@ async fn bridge_generate_image(state: &DirectToolBridgeState, arguments: &Value)
|
|||||||
})
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
validate_generate_image_slice_declaration(
|
validate_generate_image_slice_declaration(
|
||||||
kind,
|
kind.as_str(),
|
||||||
slice_mode.as_deref(),
|
slice_mode.as_deref(),
|
||||||
grid_x,
|
grid_x,
|
||||||
grid_y,
|
grid_y,
|
||||||
slice_count,
|
slice_count,
|
||||||
)?;
|
)?;
|
||||||
let screen_color = normalize_generate_image_screen_color(arguments, kind)?;
|
let screen_color = normalize_generate_image_screen_color(arguments, kind.as_str())?;
|
||||||
let options = PlatformArtAssetGenerationOptions {
|
let options = PlatformArtAssetGenerationOptions {
|
||||||
output_path,
|
output_path,
|
||||||
aspect_ratio,
|
aspect_ratio,
|
||||||
image_size,
|
image_size,
|
||||||
asset_kind: kind,
|
asset_kind: kind.clone(),
|
||||||
asset_label: asset_name.clone(),
|
asset_label: asset_name.clone(),
|
||||||
replace_existing: false,
|
replace_existing: false,
|
||||||
slice_count,
|
slice_count,
|
||||||
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;
|
||||||
@@ -2889,19 +2871,14 @@ pub(crate) async fn start_direct_tool_bridge(
|
|||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_image_slice_declaration_is_explicit_and_self_consistent() {
|
fn generate_image_slice_declaration_is_explicit_and_self_consistent() {
|
||||||
let missing = validate_generate_image_slice_declaration(
|
let missing =
|
||||||
GameCreationAppAssetKind::IconSpritesheet,
|
validate_generate_image_slice_declaration("art-spritesheet", None, None, None, None)
|
||||||
None,
|
.expect_err("art-spritesheet without sliceMode must fail closed");
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.expect_err("icon-spritesheet without sliceMode must fail closed");
|
|
||||||
assert!(missing.contains("没有默认值"), "{missing}");
|
assert!(missing.contains("没有默认值"), "{missing}");
|
||||||
assert!(missing.contains("connected-components"), "{missing}");
|
assert!(missing.contains("connected-components"), "{missing}");
|
||||||
|
|
||||||
assert!(validate_generate_image_slice_declaration(
|
assert!(validate_generate_image_slice_declaration(
|
||||||
GameCreationAppAssetKind::IconSpritesheet,
|
"art-spritesheet",
|
||||||
Some("connected-components"),
|
Some("connected-components"),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@@ -2909,7 +2886,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
assert!(validate_generate_image_slice_declaration(
|
assert!(validate_generate_image_slice_declaration(
|
||||||
GameCreationAppAssetKind::IconSpritesheet,
|
"art-spritesheet",
|
||||||
Some("grid"),
|
Some("grid"),
|
||||||
Some(3),
|
Some(3),
|
||||||
Some(2),
|
Some(2),
|
||||||
@@ -2917,7 +2894,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
let grid_with_count = validate_generate_image_slice_declaration(
|
let grid_with_count = validate_generate_image_slice_declaration(
|
||||||
GameCreationAppAssetKind::IconSpritesheet,
|
"art-spritesheet",
|
||||||
Some("grid"),
|
Some("grid"),
|
||||||
Some(2),
|
Some(2),
|
||||||
Some(2),
|
Some(2),
|
||||||
@@ -2927,80 +2904,58 @@ mod tests {
|
|||||||
assert!(grid_with_count.contains("gridX×gridY"), "{grid_with_count}");
|
assert!(grid_with_count.contains("gridX×gridY"), "{grid_with_count}");
|
||||||
|
|
||||||
let wrong_kind = validate_generate_image_slice_declaration(
|
let wrong_kind = validate_generate_image_slice_declaration(
|
||||||
GameCreationAppAssetKind::Image,
|
"image",
|
||||||
Some("connected-components"),
|
Some("connected-components"),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.expect_err("slice declaration must stay scoped to icon-spritesheet");
|
.expect_err("slice declaration must stay scoped to art-spritesheet");
|
||||||
assert!(
|
assert!(
|
||||||
wrong_kind.contains("仅对 kind=icon-spritesheet 生效"),
|
wrong_kind.contains("仅对 kind=art-spritesheet 生效"),
|
||||||
"{wrong_kind}"
|
"{wrong_kind}"
|
||||||
);
|
);
|
||||||
let wrong_kind_count = validate_generate_image_slice_declaration(
|
let wrong_kind_count =
|
||||||
GameCreationAppAssetKind::Image,
|
validate_generate_image_slice_declaration("image", None, None, None, Some(8))
|
||||||
None,
|
.expect_err("sliceCount-only violation must be rejected");
|
||||||
None,
|
|
||||||
None,
|
|
||||||
Some(8),
|
|
||||||
)
|
|
||||||
.expect_err("sliceCount-only violation must be rejected");
|
|
||||||
assert!(
|
assert!(
|
||||||
wrong_kind_count.contains("sliceCount"),
|
wrong_kind_count.contains("sliceCount"),
|
||||||
"sliceCount-only violation must name sliceCount: {wrong_kind_count}"
|
"sliceCount-only violation must name sliceCount: {wrong_kind_count}"
|
||||||
);
|
);
|
||||||
assert!(validate_generate_image_slice_declaration(
|
assert!(validate_generate_image_slice_declaration("image", None, None, None, None).is_ok());
|
||||||
GameCreationAppAssetKind::Image,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None
|
|
||||||
)
|
|
||||||
.is_ok());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_image_screen_color_is_normalized_and_kind_gated() {
|
fn generate_image_screen_color_is_normalized_and_kind_gated() {
|
||||||
// 省略与显式 null 等价,且不触发 kind 门禁。
|
// 省略与显式 null 等价,且不触发 kind 门禁。
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
normalize_generate_image_screen_color(&json!({}), GameCreationAppAssetKind::Image)
|
normalize_generate_image_screen_color(&json!({}), "image").expect("omitted"),
|
||||||
.expect("omitted"),
|
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
normalize_generate_image_screen_color(
|
normalize_generate_image_screen_color(&json!({"screenColor": null}), "image")
|
||||||
&json!({"screenColor": null}),
|
.expect("null"),
|
||||||
GameCreationAppAssetKind::Image
|
|
||||||
)
|
|
||||||
.expect("null"),
|
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
// auto 家族归一为 None(服务端自动决策),大小写与空白不敏感。
|
// auto 家族归一为 None(服务端自动决策),大小写与空白不敏感。
|
||||||
for raw in ["auto", "AUTO", " auto ", ""] {
|
for raw in ["auto", "AUTO", " auto ", ""] {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
normalize_generate_image_screen_color(
|
normalize_generate_image_screen_color(&json!({"screenColor": raw}), "character")
|
||||||
&json!({"screenColor": raw}),
|
.expect("auto variants"),
|
||||||
GameCreationAppAssetKind::Character
|
|
||||||
)
|
|
||||||
.expect("auto variants"),
|
|
||||||
None,
|
None,
|
||||||
"{raw}"
|
"{raw}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// hex 统一大写透传;色板白名单由服务端权威校验,客户端只守格式。
|
// hex 统一大写透传;色板白名单由服务端权威校验,客户端只守格式。
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
normalize_generate_image_screen_color(
|
normalize_generate_image_screen_color(&json!({"screenColor": "#cfefff"}), "character")
|
||||||
&json!({"screenColor": "#cfefff"}),
|
.expect("lowercase hex"),
|
||||||
GameCreationAppAssetKind::Character
|
|
||||||
)
|
|
||||||
.expect("lowercase hex"),
|
|
||||||
Some("#CFEFFF".to_string())
|
Some("#CFEFFF".to_string())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
normalize_generate_image_screen_color(
|
normalize_generate_image_screen_color(
|
||||||
&json!({"screenColor": " #A0BBA0 "}),
|
&json!({"screenColor": " #A0BBA0 "}),
|
||||||
GameCreationAppAssetKind::IconSpritesheet
|
"art-spritesheet"
|
||||||
)
|
)
|
||||||
.expect("padded hex"),
|
.expect("padded hex"),
|
||||||
Some("#A0BBA0".to_string())
|
Some("#A0BBA0".to_string())
|
||||||
@@ -3008,24 +2963,19 @@ mod tests {
|
|||||||
// 非 auto/非 hex、非字符串一律拒绝。
|
// 非 auto/非 hex、非字符串一律拒绝。
|
||||||
for bad in [json!("green"), json!("#GGGGGG"), json!("#FFF"), json!(12)] {
|
for bad in [json!("green"), json!("#GGGGGG"), json!("#FFF"), json!(12)] {
|
||||||
assert!(
|
assert!(
|
||||||
normalize_generate_image_screen_color(
|
normalize_generate_image_screen_color(&json!({"screenColor": bad}), "character")
|
||||||
&json!({"screenColor": bad}),
|
.is_err(),
|
||||||
GameCreationAppAssetKind::Character
|
|
||||||
)
|
|
||||||
.is_err(),
|
|
||||||
"{bad}"
|
"{bad}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// 其它 kind 携带该字段直接拒绝,即使取值合法。
|
// 其它 kind 携带该字段直接拒绝,即使取值合法。
|
||||||
let gated = normalize_generate_image_screen_color(
|
let gated =
|
||||||
&json!({"screenColor": "#CFEFFF"}),
|
normalize_generate_image_screen_color(&json!({"screenColor": "#CFEFFF"}), "image")
|
||||||
GameCreationAppAssetKind::Image,
|
.expect_err("screenColor must stay scoped to character/art-spritesheet");
|
||||||
)
|
|
||||||
.expect_err("screenColor must stay scoped to character/icon-spritesheet");
|
|
||||||
assert!(gated.contains("kind=character"), "{gated}");
|
assert!(gated.contains("kind=character"), "{gated}");
|
||||||
assert!(normalize_generate_image_screen_color(
|
assert!(normalize_generate_image_screen_color(
|
||||||
&json!({"screenColor": "auto"}),
|
&json!({"screenColor": "auto"}),
|
||||||
GameCreationAppAssetKind::UiDesign
|
"ui-prototype"
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
}
|
}
|
||||||
@@ -3794,14 +3744,12 @@ mod tests {
|
|||||||
fn bridge_art_resource_exposes_only_the_safe_identity_projection() {
|
fn bridge_art_resource_exposes_only_the_safe_identity_projection() {
|
||||||
let asset = GameCreationAppAssetManifestEntry {
|
let asset = GameCreationAppAssetManifestEntry {
|
||||||
id: "local-art-1".to_string(),
|
id: "local-art-1".to_string(),
|
||||||
kind: GameCreationAppAssetKind::Icon,
|
kind: "art-spritesheet-slice".to_string(),
|
||||||
media_type: "image/png".to_string(),
|
media_type: "image/png".to_string(),
|
||||||
local_path: "assets/art-spritesheet-slices/player.png".to_string(),
|
local_path: "assets/art-spritesheet-slices/player.png".to_string(),
|
||||||
image_sequence_frames: None,
|
image_sequence_frames: None,
|
||||||
image_sequence_duration_ms: None,
|
image_sequence_duration_ms: None,
|
||||||
category: game_creation_app_asset_category_for_kind(
|
category: game_creation_app_asset_category_for_kind("art-spritesheet-slice"),
|
||||||
GameCreationAppAssetKind::IconSpritesheet,
|
|
||||||
),
|
|
||||||
tags: Vec::new(),
|
tags: Vec::new(),
|
||||||
source: GameCreationAppAssetSource {
|
source: GameCreationAppAssetSource {
|
||||||
kind: GameCreationAppAssetSourceKind::Canvas,
|
kind: GameCreationAppAssetSourceKind::Canvas,
|
||||||
@@ -3853,7 +3801,7 @@ mod tests {
|
|||||||
fn bridge_registered_resource_exposes_formal_sequence_without_private_generation_fields() {
|
fn bridge_registered_resource_exposes_formal_sequence_without_private_generation_fields() {
|
||||||
let asset = GameCreationAppAssetManifestEntry {
|
let asset = GameCreationAppAssetManifestEntry {
|
||||||
id: "animation-1".to_string(),
|
id: "animation-1".to_string(),
|
||||||
kind: GameCreationAppAssetKind::CharacterAnimation,
|
kind: "character-animation".to_string(),
|
||||||
media_type: "video/mp4".to_string(),
|
media_type: "video/mp4".to_string(),
|
||||||
local_path: "assets/edits/animation.mp4".to_string(),
|
local_path: "assets/edits/animation.mp4".to_string(),
|
||||||
image_sequence_frames: Some(vec![
|
image_sequence_frames: Some(vec![
|
||||||
@@ -3866,9 +3814,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
image_sequence_duration_ms: Some(4_000),
|
image_sequence_duration_ms: Some(4_000),
|
||||||
category: game_creation_app_asset_category_for_kind(
|
category: game_creation_app_asset_category_for_kind("character-animation"),
|
||||||
GameCreationAppAssetKind::CharacterAnimation,
|
|
||||||
),
|
|
||||||
tags: Vec::new(),
|
tags: Vec::new(),
|
||||||
source: GameCreationAppAssetSource {
|
source: GameCreationAppAssetSource {
|
||||||
kind: GameCreationAppAssetSourceKind::Canvas,
|
kind: GameCreationAppAssetSourceKind::Canvas,
|
||||||
@@ -3906,7 +3852,7 @@ mod tests {
|
|||||||
fn bridge_registered_resource_keeps_explicit_manifest_classification() {
|
fn bridge_registered_resource_keeps_explicit_manifest_classification() {
|
||||||
let asset = GameCreationAppAssetManifestEntry {
|
let asset = GameCreationAppAssetManifestEntry {
|
||||||
id: "spec-1".to_string(),
|
id: "spec-1".to_string(),
|
||||||
kind: GameCreationAppAssetKind::Spec,
|
kind: "spec".to_string(),
|
||||||
media_type: "application/json".to_string(),
|
media_type: "application/json".to_string(),
|
||||||
local_path: "assets/specs/hero.json".to_string(),
|
local_path: "assets/specs/hero.json".to_string(),
|
||||||
image_sequence_frames: None,
|
image_sequence_frames: None,
|
||||||
@@ -3942,13 +3888,13 @@ mod tests {
|
|||||||
///
|
///
|
||||||
/// UI 栏目走 TS 的 `gameCreationAppAssetCategory`(落盘值 + 按 kind 派生 + 读时自愈),
|
/// UI 栏目走 TS 的 `gameCreationAppAssetCategory`(落盘值 + 按 kind 派生 + 读时自愈),
|
||||||
/// Agent 走 Rust 的同构实现 `game_creation_app_asset_effective_category`。直接透传落盘
|
/// Agent 走 Rust 的同构实现 `game_creation_app_asset_effective_category`。直接透传落盘
|
||||||
/// `category` 会让 `ui-design` 的资产在 UI 显示「UI 交互」、在 Agent 侧读到
|
/// `category` 会让 `kind:"ui"` 的资产在 UI 显示「UI 交互」、在 Agent 侧读到
|
||||||
/// `unclassified`,两侧分类口径必须一致。
|
/// `unclassified`——真机 122 条资产里有 55 条这样分叉。
|
||||||
#[test]
|
#[test]
|
||||||
fn bridge_registered_resource_projects_effective_category_not_raw_persisted_value() {
|
fn bridge_registered_resource_projects_effective_category_not_raw_persisted_value() {
|
||||||
let asset = GameCreationAppAssetManifestEntry {
|
let asset = GameCreationAppAssetManifestEntry {
|
||||||
id: "ui-design-1".to_string(),
|
id: "ui-1".to_string(),
|
||||||
kind: GameCreationAppAssetKind::UiDesign,
|
kind: "ui".to_string(),
|
||||||
media_type: "application/json".to_string(),
|
media_type: "application/json".to_string(),
|
||||||
local_path: "assets/UI 设计 1.json".to_string(),
|
local_path: "assets/UI 设计 1.json".to_string(),
|
||||||
image_sequence_frames: None,
|
image_sequence_frames: None,
|
||||||
@@ -3971,7 +3917,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let projection = bridge_registered_resource(&asset, false);
|
let projection = bridge_registered_resource(&asset, false);
|
||||||
assert_eq!(projection["kind"], "ui-design");
|
assert_eq!(projection["kind"], "ui");
|
||||||
assert_eq!(projection["category"], "ui-interaction");
|
assert_eq!(projection["category"], "ui-interaction");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ fn direct_tools_mcp_specs_for(controlled_web_search: bool, _cocos_editor_availab
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": PLATFORM_ART_ASSET_GENERATION_KINDS,
|
"enum": PLATFORM_ART_ASSET_GENERATION_KINDS,
|
||||||
"default": "image",
|
"default": "image",
|
||||||
"description": "image=普通新图(不做额外处理),character=角色图(纯色底生成后自动抠图,产出透明背景立绘,prompt 只描述角色主体),icon-spec=统一视觉规范图,ui-design=完整 UI 设计图,icon-spritesheet=透明游戏素材图集(纯色底生成后自动抠图并切片,项目须已有 icon-spec 规范图),publication-material=发布宣传图"
|
"description": "image=普通新图(不做额外处理),character=角色图(纯色底生成后自动抠图,产出透明背景立绘,prompt 只描述角色主体),spec/icon-spec=统一视觉规范图(spec 是服务端同义词,客户端统一登记为 icon-spec),ui-prototype=完整 UI 设计图,art-spritesheet=透明游戏素材图集(纯色底生成后自动抠图并切片,项目须已有 icon-spec 规范图),publication-material=发布宣传图"
|
||||||
},
|
},
|
||||||
"aspectRatio": {
|
"aspectRatio": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@@ -273,7 +273,7 @@ fn direct_tools_mcp_specs_for(controlled_web_search: bool, _cocos_editor_availab
|
|||||||
"sliceMode": {
|
"sliceMode": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["connected-components", "grid"],
|
"enum": ["connected-components", "grid"],
|
||||||
"description": "仅 kind=icon-spritesheet 生效,且必填、没有默认值:需求明确要求等分网格、固定槽位或指定行列数时传 grid,并用 gridX/gridY 传入来自需求本身的行列数;自由排布、数量不定或只要求一张图集时传 connected-components,需要约束素材张数时用 sliceCount。省略、与 kind 不匹配或与 gridX/gridY 互相矛盾时客户端直接拒绝,不会替你选择"
|
"description": "仅 kind=art-spritesheet 生效,且必填、没有默认值:需求明确要求等分网格、固定槽位或指定行列数时传 grid,并用 gridX/gridY 传入来自需求本身的行列数;自由排布、数量不定或只要求一张图集时传 connected-components,需要约束素材张数时用 sliceCount。省略、与 kind 不匹配或与 gridX/gridY 互相矛盾时客户端直接拒绝,不会替你选择"
|
||||||
},
|
},
|
||||||
"gridX": {
|
"gridX": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
@@ -291,11 +291,11 @@ fn direct_tools_mcp_specs_for(controlled_web_search: bool, _cocos_editor_availab
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"minimum": 1,
|
"minimum": 1,
|
||||||
"maximum": 256,
|
"maximum": 256,
|
||||||
"description": "只与 kind=icon-spritesheet 且 sliceMode=connected-components 同时提供,用于约束目标素材张数;省略时按图像内容自动识别"
|
"description": "只与 kind=art-spritesheet 且 sliceMode=connected-components 同时提供,用于约束目标素材张数;省略时按图像内容自动识别"
|
||||||
},
|
},
|
||||||
"screenColor": {
|
"screenColor": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "抠图纯色背景,仅 kind=character(角色形象)和 kind=icon-spritesheet(图标素材)生效,其它 kind 携带会被拒绝。生成时把主体置于该纯色背景上,回图后据此抠除背景。取值只能是 auto 或下列色板 hex 之一,传值只填 hex 本身、不要附带色名:#CFEFFF(浅雾蓝)、#B0C2E0(浅钢蓝)、#FFD6C2(暖浅桃色)、#E6D8FF(淡薰衣草紫)、#F4D8E8(浅粉灰)、#7FB3FF(中度天蓝)、#FFF2A8(浅柠黄)、#CFFFE1(淡薄荷绿)、#D8DEE8(浅中性灰)、#D8D2E8(淡灰紫)、#A8F7F0(高对比浅青)、#A0BBA0(灰竹绿);auto 时由服务端自动选色。手动指定时不能与角色或素材本体的颜色接近"
|
"description": "抠图纯色背景,仅 kind=character(角色形象)和 kind=art-spritesheet(图标素材)生效,其它 kind 携带会被拒绝。生成时把主体置于该纯色背景上,回图后据此抠除背景。取值只能是 auto 或下列色板 hex 之一,传值只填 hex 本身、不要附带色名:#CFEFFF(浅雾蓝)、#B0C2E0(浅钢蓝)、#FFD6C2(暖浅桃色)、#E6D8FF(淡薰衣草紫)、#F4D8E8(浅粉灰)、#7FB3FF(中度天蓝)、#FFF2A8(浅柠黄)、#CFFFE1(淡薄荷绿)、#D8DEE8(浅中性灰)、#D8D2E8(淡灰紫)、#A8F7F0(高对比浅青)、#A0BBA0(灰竹绿);auto 时由服务端自动选色。手动指定时不能与角色或素材本体的颜色接近"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["prompt"],
|
"required": ["prompt"],
|
||||||
@@ -341,7 +341,7 @@ fn direct_tools_mcp_specs_for(controlled_web_search: bool, _cocos_editor_availab
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
"maxLength": 80,
|
"maxLength": 80,
|
||||||
"description": "可选的 manifest 资源 kind 精确过滤,必须是 canonical kind(例如 video、character-animation、sound-effect、background-music、icon-spritesheet);传非 canonical 值会被拒绝并报错,不会静默返回空列表"
|
"description": "可选的 manifest 资源 kind 精确过滤,例如 video、character-animation、sound-effect、background-music 或 art-spritesheet-slice"
|
||||||
},
|
},
|
||||||
"assetId": {
|
"assetId": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@@ -2523,7 +2523,7 @@ mod tests {
|
|||||||
// 目录外的 kind 必须在本地拒绝:既不下发 bridge,也不产生任何计费副作用。
|
// 目录外的 kind 必须在本地拒绝:既不下发 bridge,也不产生任何计费副作用。
|
||||||
let unsupported_kind = call_agc_generate_image(&json!({
|
let unsupported_kind = call_agc_generate_image(&json!({
|
||||||
"prompt": "像素月光主角",
|
"prompt": "像素月光主角",
|
||||||
"kind": "future-kind"
|
"kind": "game-art"
|
||||||
}))
|
}))
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(unsupported_kind["isError"], json!(true));
|
assert_eq!(unsupported_kind["isError"], json!(true));
|
||||||
@@ -2533,7 +2533,7 @@ mod tests {
|
|||||||
|
|
||||||
let oversized_prompt = call_agc_generate_image(&json!({
|
let oversized_prompt = call_agc_generate_image(&json!({
|
||||||
"prompt": "x".repeat(DIRECT_TOOLS_MCP_MAX_IMAGE_PROMPT_CHARS + 1),
|
"prompt": "x".repeat(DIRECT_TOOLS_MCP_MAX_IMAGE_PROMPT_CHARS + 1),
|
||||||
"kind": "icon-spritesheet"
|
"kind": "art-spritesheet"
|
||||||
}))
|
}))
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(oversized_prompt["isError"], json!(true));
|
assert_eq!(oversized_prompt["isError"], json!(true));
|
||||||
@@ -2897,12 +2897,12 @@ mod tests {
|
|||||||
fn tool_chain_image_asset(id: &str, local_path: &str) -> GameCreationAppAssetManifestEntry {
|
fn tool_chain_image_asset(id: &str, local_path: &str) -> GameCreationAppAssetManifestEntry {
|
||||||
GameCreationAppAssetManifestEntry {
|
GameCreationAppAssetManifestEntry {
|
||||||
id: id.to_string(),
|
id: id.to_string(),
|
||||||
kind: GameCreationAppAssetKind::Image,
|
kind: "image".to_string(),
|
||||||
media_type: "image/png".to_string(),
|
media_type: "image/png".to_string(),
|
||||||
local_path: local_path.to_string(),
|
local_path: local_path.to_string(),
|
||||||
image_sequence_frames: None,
|
image_sequence_frames: None,
|
||||||
image_sequence_duration_ms: None,
|
image_sequence_duration_ms: None,
|
||||||
category: game_creation_app_asset_category_for_kind(GameCreationAppAssetKind::Image),
|
category: game_creation_app_asset_category_for_kind("image"),
|
||||||
tags: Vec::new(),
|
tags: Vec::new(),
|
||||||
source: GameCreationAppAssetSource {
|
source: GameCreationAppAssetSource {
|
||||||
kind: GameCreationAppAssetSourceKind::Canvas,
|
kind: GameCreationAppAssetSourceKind::Canvas,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user