分页 offset 上限收成必填参数与单一常量,三个列表工具口径一致
- arguments::page 的 max_offset 由 Option<usize> 改成 usize:调用点必须显式给出上限,不能靠漏传 Option 变成无上限 - 新增 TOOL_PAGE_MAX_OFFSET = 500(与 agc_list_project_files / agc_list_account_assets 的 inputSchema offset.maximum 一致),三个列表工具统一传它;agc_list_registered_assets 原来传 None(无上限),现在同样收敛到 500 - agc_list_registered_assets 的 inputSchema offset 同步补 maximum: 500,保持 schema 与校验一致(这是一个公开入参范围的收窄) - 只改 offset 边界来源;limit 默认值与上限、分页语义不变 验证:cargo test --bin genarrative-ai-game-creator-shell -- agent:: 952 passed / 0 failed
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use super::*;
|
||||
use crate::agent::tool::apply_patch::error::ApplyPatchError;
|
||||
use crate::agent::tool::arguments::{optional_text, page, required_text, ToolPage, ToolTextField};
|
||||
use crate::agent::tool::arguments::{
|
||||
optional_text, page, required_text, ToolPage, ToolTextField, TOOL_PAGE_MAX_OFFSET,
|
||||
};
|
||||
use crate::agent::tool::browser_playtest::error::BrowserPlaytestError;
|
||||
#[cfg(all(windows, feature = "cocos-editor-execute"))]
|
||||
use crate::agent::tool::cocos_execute::error::CocosExecuteError;
|
||||
@@ -1191,7 +1193,7 @@ pub(in crate::agent) fn list_registered_assets_input(
|
||||
arguments,
|
||||
50,
|
||||
DIRECT_TOOL_BRIDGE_MAX_RESOURCE_PAGE_SIZE,
|
||||
None,
|
||||
TOOL_PAGE_MAX_OFFSET,
|
||||
)?;
|
||||
Ok(ListRegisteredAssetsInput {
|
||||
kind,
|
||||
@@ -1537,7 +1539,7 @@ pub(in crate::agent) fn list_project_files_input(
|
||||
arguments,
|
||||
100,
|
||||
DIRECT_TOOL_BRIDGE_MAX_RESOURCE_PAGE_SIZE,
|
||||
Some(500),
|
||||
TOOL_PAGE_MAX_OFFSET,
|
||||
)?;
|
||||
Ok(ListProjectFilesInput {
|
||||
path,
|
||||
@@ -1955,7 +1957,7 @@ pub(in crate::agent) fn list_account_assets_input(
|
||||
arguments,
|
||||
100,
|
||||
DIRECT_TOOL_BRIDGE_MAX_RESOURCE_PAGE_SIZE,
|
||||
Some(500),
|
||||
TOOL_PAGE_MAX_OFFSET,
|
||||
)?;
|
||||
Ok(ListAccountAssetsInput {
|
||||
folder_id,
|
||||
|
||||
@@ -405,7 +405,7 @@ fn direct_tools_mcp_specs_for_plugins(
|
||||
"default": false,
|
||||
"description": prompt_text!("directTools.agc_list_registered_assets.parameters.includeSequenceFrames")
|
||||
},
|
||||
"offset": { "type": "integer", "minimum": 0, "default": 0 },
|
||||
"offset": { "type": "integer", "minimum": 0, "maximum": 500, "default": 0 },
|
||||
"limit": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 }
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
||||
@@ -53,12 +53,18 @@ pub(crate) struct ToolPage {
|
||||
pub limit: usize,
|
||||
}
|
||||
|
||||
/// 三个列表工具共用的 `offset` 上限:每个调用点都必须显式传值,避免某一路悄悄不设上限。
|
||||
///
|
||||
/// 取值与 `agc_list_project_files` / `agc_list_account_assets` 的 inputSchema
|
||||
/// `offset.maximum` 一致;`agc_list_registered_assets` 的 schema 同步为同一个值。
|
||||
pub(crate) const TOOL_PAGE_MAX_OFFSET: usize = 500;
|
||||
|
||||
/// 解析 `offset`/`limit`。分页规则在三个列表工具之间一致,只有默认值与上限不同。
|
||||
pub(crate) fn page(
|
||||
arguments: &Value,
|
||||
default_limit: usize,
|
||||
max_limit: usize,
|
||||
max_offset: Option<usize>,
|
||||
max_offset: usize,
|
||||
) -> Result<ToolPage, ToolPageRejection> {
|
||||
let offset = arguments
|
||||
.get("offset")
|
||||
@@ -73,8 +79,11 @@ pub(crate) fn page(
|
||||
})
|
||||
.transpose()?
|
||||
.unwrap_or(0);
|
||||
if let Some(max) = max_offset.filter(|max| offset > *max) {
|
||||
return Err(ToolPageRejection::OffsetTooLarge { got: offset, max });
|
||||
if offset > max_offset {
|
||||
return Err(ToolPageRejection::OffsetTooLarge {
|
||||
got: offset,
|
||||
max: max_offset,
|
||||
});
|
||||
}
|
||||
let limit = arguments
|
||||
.get("limit")
|
||||
|
||||
Reference in New Issue
Block a user