Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions app/src/main/assets/packages/extended_file_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"description": { "zh": "检查文件或目录是否存在。", "en": "Check if a file or directory exists." },
"parameters": [
{ "name": "path", "description": { "zh": "目标路径", "en": "Target path" }, "type": "string", "required": true },
{ "name": "environment", "description": { "zh": "可选:android/linux", "en": "Optional: android/linux" }, "type": "string", "required": false }
{ "name": "environment", "description": { "zh": "可选:android/linux/repo:<仓库名>", "en": "Optional: android/linux/repo:<name>" }, "type": "string", "required": false }
]
},
{
Expand All @@ -27,7 +27,7 @@
"parameters": [
{ "name": "source", "description": { "zh": "源路径", "en": "Source path" }, "type": "string", "required": true },
{ "name": "destination", "description": { "zh": "目标路径", "en": "Destination path" }, "type": "string", "required": true },
{ "name": "environment", "description": { "zh": "可选:android/linux", "en": "Optional: android/linux" }, "type": "string", "required": false }
{ "name": "environment", "description": { "zh": "可选:android/linux(移动不支持 repo)", "en": "Optional: android/linux (repo not supported for move)" }, "type": "string", "required": false }
]
},
{
Expand All @@ -36,8 +36,8 @@
"parameters": [
{ "name": "source", "description": { "zh": "源路径", "en": "Source path" }, "type": "string", "required": true },
{ "name": "destination", "description": { "zh": "目标路径", "en": "Destination path" }, "type": "string", "required": true },
{ "name": "recursive", "description": { "zh": "可选:是否递归,默认 false", "en": "Optional: recursive (default: false)" }, "type": "boolean", "required": false },
{ "name": "source_environment", "description": { "zh": "可选:源环境 android/linux", "en": "Optional: source environment android/linux" }, "type": "string", "required": false },
{ "name": "recursive", "description": { "zh": "可选:递归复制目录,默认 false;复制目录必须传 true", "en": "Optional: recursive copy for directories, default false; required true when copying a directory" }, "type": "boolean", "required": false },
{ "name": "source_environment", "description": { "zh": "可选:源环境 android/linux(复制不支持 repo)", "en": "Optional: source environment android/linux (repo not supported for copy)" }, "type": "string", "required": false },
{ "name": "dest_environment", "description": { "zh": "可选:目标环境 android/linux", "en": "Optional: destination environment android/linux" }, "type": "string", "required": false }
]
},
Expand All @@ -46,7 +46,7 @@
"description": { "zh": "获取文件/目录信息。", "en": "Get file/directory info." },
"parameters": [
{ "name": "path", "description": { "zh": "目标路径", "en": "Target path" }, "type": "string", "required": true },
{ "name": "environment", "description": { "zh": "可选:android/linux", "en": "Optional: android/linux" }, "type": "string", "required": false }
{ "name": "environment", "description": { "zh": "可选:android/linux/repo:<仓库名>", "en": "Optional: android/linux/repo:<name>" }, "type": "string", "required": false }
]
},
{
Expand All @@ -55,7 +55,7 @@
"parameters": [
{ "name": "source", "description": { "zh": "源路径", "en": "Source path" }, "type": "string", "required": true },
{ "name": "destination", "description": { "zh": "输出 zip 文件路径", "en": "Destination zip path" }, "type": "string", "required": true },
{ "name": "environment", "description": { "zh": "可选:android/linux", "en": "Optional: android/linux" }, "type": "string", "required": false },
{ "name": "environment", "description": { "zh": "可选:android/linux(linux 下路径在 proot 根文件系统内解析;不支持 repo)", "en": "Optional: android/linux (linux paths resolved inside the proot rootfs; repo not supported)" }, "type": "string", "required": false },
{ "name": "include_root_directory", "description": { "zh": "压缩目录时是否保留源目录名作为顶层目录,默认 true", "en": "When zipping a directory, keep the source directory name as the top-level folder, default true" }, "type": "boolean", "required": false }
]
},
Expand All @@ -65,15 +65,15 @@
"parameters": [
{ "name": "source", "description": { "zh": "zip 文件路径", "en": "Zip file path" }, "type": "string", "required": true },
{ "name": "destination", "description": { "zh": "解压目录", "en": "Destination directory" }, "type": "string", "required": true },
{ "name": "environment", "description": { "zh": "可选:android/linux", "en": "Optional: android/linux" }, "type": "string", "required": false }
{ "name": "environment", "description": { "zh": "可选:android/linux(linux 下路径在 proot 根文件系统内解析;不支持 repo)", "en": "Optional: android/linux (linux paths resolved inside the proot rootfs; repo not supported)" }, "type": "string", "required": false }
]
},
{
"name": "open_file",
"description": { "zh": "用系统默认应用打开文件。", "en": "Open a file with system default app." },
"parameters": [
{ "name": "path", "description": { "zh": "文件路径", "en": "File path" }, "type": "string", "required": true },
{ "name": "environment", "description": { "zh": "可选:android/linux", "en": "Optional: android/linux" }, "type": "string", "required": false }
{ "name": "path", "description": { "zh": "Android 文件系统上的文件路径", "en": "File path on the Android file system" }, "type": "string", "required": true },
{ "name": "environment", "description": { "zh": "可选,仅 android(linux/repo 不支持)", "en": "Optional, android only (linux/repo not supported)" }, "type": "string", "required": false }
]
},
{
Expand All @@ -82,15 +82,22 @@
"parameters": [
{ "name": "path", "description": { "zh": "文件路径", "en": "File path" }, "type": "string", "required": true },
{ "name": "title", "description": { "zh": "可选:分享标题", "en": "Optional: share title" }, "type": "string", "required": false },
{ "name": "environment", "description": { "zh": "可选:android/linux", "en": "Optional: android/linux" }, "type": "string", "required": false }
{ "name": "environment", "description": { "zh": "可选,仅 android(linux/repo 不支持)", "en": "Optional, android only (linux/repo not supported)" }, "type": "string", "required": false }
]
}
]
}*/
const ExtendedFileTools = (function () {
async function file_exists(params) {
// 修改意图:原先 success 误用 result.exists,导致"文件不存在"这一正常查询结果
// 被包装成失败;success 只表示查询本身是否成功,存在性结论放进 message/data
const result = await Tools.Files.exists(params.path, params.environment);
return { success: !!result && (result.exists ?? true), message: '检查完成', data: result };
const exists = !!result && (result.exists ?? false);
return {
success: !!result,
message: exists ? '文件或目录存在' : '文件或目录不存在(这是正常的查询结果,不是错误)',
data: result,
};
}
async function move_file(params) {
const result = await Tools.Files.move(params.source, params.destination, params.environment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.ai.assistance.operit.api.chat.enhance.FileBindingService
import com.ai.assistance.operit.api.chat.enhance.MultiServiceManager
import com.ai.assistance.operit.api.chat.enhance.ToolExecutionManager
import com.ai.assistance.operit.api.chat.enhance.SubtaskExecutionState
import com.ai.assistance.operit.core.tools.HighRiskToolCatalog
import com.ai.assistance.operit.api.chat.llmprovider.AIService
import com.ai.assistance.operit.core.chat.logMessageTiming
import com.ai.assistance.operit.core.chat.messageTimingNow
Expand Down Expand Up @@ -269,32 +270,15 @@ class EnhancedAIService private constructor(private val context: Context) {
* 处理文件绑定操作(非实例化方式)
* @param context 应用上下文
* @param originalContent 原始文件内容
* @param aiGeneratedCode AI生成的代码(包含"//existing code"标记)
* @return 混合后的文件内容
* @param operations 结构化编辑操作列表
* @return FileEditApplyResult
*/
suspend fun applyFileBinding(
context: Context,
originalContent: String,
aiGeneratedCode: String,
onProgress: ((Float, String) -> Unit)? = null
): Pair<String, String> {
// 获取EnhancedAIService实例
val instance = getInstance(context)

// 委托给FileBindingService处理
return instance.fileBindingService.processFileBinding(
originalContent,
aiGeneratedCode,
onProgress
)
}

suspend fun applyFileBindingOperations(
context: Context,
originalContent: String,
operations: List<FileBindingService.StructuredEditOperation>,
onProgress: ((Float, String) -> Unit)? = null
): Pair<String, String> {
): FileBindingService.FileEditApplyResult {
val instance = getInstance(context)
return instance.fileBindingService.processFileBindingOperations(
originalContent = originalContent,
Expand Down Expand Up @@ -3104,17 +3088,38 @@ class EnhancedAIService private constructor(private val context: Context) {
return null
}

// 修改意图:function-calling 路径为可审查工具补挂 call_purpose 调用说明参数文档
// (文本提示词路径由 SystemToolPrompts.buildToolPromptCategories 注入)
val toolsWithCallPurpose = withCallPurposeParamDoc(hookedTools)

AppLogger.d(
TAG,
"Tool Call已启用,提供 ${hookedTools.size} 个工具 (base=${selectedTools.size}, enableTools=$enableTools, visibleToolOverrides=${toolPromptVisibility.size}, roleCardCustomTools=${roleCardToolAccess.customEnabled})"
"Tool Call已启用,提供 ${toolsWithCallPurpose.size} 个工具 (base=${selectedTools.size}, enableTools=$enableTools, visibleToolOverrides=${toolPromptVisibility.size}, roleCardCustomTools=${roleCardToolAccess.customEnabled})"
)
hookedTools
toolsWithCallPurpose
} catch (e: Exception) {
AppLogger.e(TAG, "获取工具列表失败", e)
null
}
}

/** 修改意图:为可审查工具(高危工具 + 文件工具族)的 function-calling schema 补挂 call_purpose 参数 */
private fun withCallPurposeParamDoc(tools: List<ToolPrompt>): List<ToolPrompt> =
tools.map { tool ->
if (!HighRiskToolCatalog.isReviewableTool(tool.name)) {
tool
} else {
val structured = tool.parametersStructured ?: emptyList()
if (structured.any { it.name == HighRiskToolCatalog.CALL_PURPOSE_PARAM }) {
tool
} else {
tool.copy(
parametersStructured = structured + HighRiskToolCatalog.callPurposeParamSchema()
)
}
}
}

// --- Service Lifecycle Management ---

/** 启动或更新前台服务为“AI 正在运行”状态,以保持应用活跃 */
Expand Down Expand Up @@ -3216,22 +3221,6 @@ class EnhancedAIService private constructor(private val context: Context) {
ActivityLifecycleManager.checkAndApplyKeepScreenOn(false)
}

/**
* 处理文件绑定操作(实例方法)
* @param originalContent 原始文件内容
* @param aiGeneratedCode AI生成的代码(包含"//existing code"标记)
* @return 混合后的文件内容
*/
suspend fun applyFileBinding(
originalContent: String,
aiGeneratedCode: String
): Pair<String, String> {
return fileBindingService.processFileBinding(
originalContent,
aiGeneratedCode
)
}

/**
* 翻译文本功能
* @param text 要翻译的文本
Expand Down
Loading