feat: 解决工具沙箱缓存机制问题,增加forceReinstall参数支持 (#114)
* feat: 为promptx_tool增加forceReinstall选项支持 解决工具沙箱缓存机制问题,允许强制重新安装工具依赖。 ## 修改内容 ### 1. 工具定义更新 (toolDefinitions.js) - 增加 context.options.forceReinstall 参数支持 - 增加 context.options.timeout 参数支持 - 完善参数描述,说明context用途 - 移除暂时不需要的role_id和session_id参数 ### 2. 执行逻辑优化 (ToolCommand.js) - 支持从context.options提取执行选项 - 将选项传递给ToolSandbox构造函数 - 增加调试日志输出沙箱选项 - 完善JSDoc注释 ## 解决的问题 - Issue #107: PromptX工具沙箱缓存机制不支持工具集更新 - 鲁班等AI角色在调试工具时遇到的缓存问题 - 工具依赖更新后无法自动重新安装的问题 ## 使用方式 ```javascript // 强制重新安装依赖 { tool_resource: "@tool://tool-name", parameters: { /* 工具参数 */ }, context: { options: { forceReinstall: true } } } ``` 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: 简化context参数,移除暂时不需要的role_id和session_id 按照奥卡姆剃刀原则,移除当前没有实际用途的参数: - 移除 context.role_id - 移除 context.session_id - 保留 context.options 用于执行配置 - 简化API接口,降低复杂度 未来如需要可重新添加这些参数。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: 简化promptx_tool参数结构,移除context层级 ## 主要改进 ### 1. 扁平化参数结构 - 移除复杂的context嵌套,直接使用顶级参数 - forceReinstall 和 timeout 作为可选的顶级参数 - 遵循MCP协议惯例,降低AI理解成本 ### 2. 参数说明优化 - forceReinstall: 明确默认值为false - 详细说明使用场景:工具开发和调试中的缓存问题 - timeout: 明确默认值为30000ms ### 3. 防止盲目调用 - 增加重要提醒:要求AI先了解工具说明再调用 - 避免大模型在不了解工具的情况下盲目执行 ## 新的调用方式 ## 优势 - 符合MCP预训练共识,降低AI学习成本 - 参数结构简洁直观 - 保持向后兼容性 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@ -97,7 +97,8 @@ ${JSON.stringify(result.result, null, 2)}
|
||||
* @param {Object} args - 命令参数
|
||||
* @param {string} args.tool_resource - 工具资源引用,格式:@tool://tool-name
|
||||
* @param {Object} args.parameters - 传递给工具的参数
|
||||
* @param {Object} args.context - 执行上下文信息(可选)
|
||||
* @param {boolean} args.forceReinstall - 是否强制重新安装工具依赖(默认false)
|
||||
* @param {number} args.timeout - 工具执行超时时间(毫秒,默认30000ms)
|
||||
* @returns {Promise<Object>} 执行结果
|
||||
*/
|
||||
async executeToolInternal(args) {
|
||||
@ -108,12 +109,14 @@ ${JSON.stringify(result.result, null, 2)}
|
||||
// 1. 参数验证
|
||||
this.validateArguments(args)
|
||||
|
||||
const { tool_resource, parameters, context = {} } = args
|
||||
const { tool_resource, parameters, forceReinstall = false, timeout = 30000 } = args
|
||||
|
||||
logger.debug(`[PromptXTool] 开始执行工具: ${tool_resource}`)
|
||||
|
||||
// 2. 创建ToolSandbox实例
|
||||
sandbox = new ToolSandbox(tool_resource)
|
||||
// 2. 构建沙箱选项并创建ToolSandbox实例
|
||||
const sandboxOptions = { forceReinstall, timeout }
|
||||
logger.debug(`[PromptXTool] 沙箱选项:`, sandboxOptions)
|
||||
sandbox = new ToolSandbox(tool_resource, sandboxOptions)
|
||||
|
||||
// 3. 设置ResourceManager
|
||||
const resourceManager = await this.getResourceManager()
|
||||
|
||||
Reference in New Issue
Block a user