|
1 | 1 | package cn.lineai.data.repository; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
| 4 | +import cn.lineai.R; |
4 | 5 | import cn.lineai.model.ChatMode; |
5 | 6 | import cn.lineai.model.McpSettingsState; |
6 | 7 | import cn.lineai.model.McpToolConfig; |
@@ -41,44 +42,72 @@ public final class ToolSettingsRepository implements ToolSettingsStore { |
41 | 42 | private static final Set<String> MODE_REMOTE = java.util.Collections.unmodifiableSet(new HashSet<>(java.util.Arrays.asList(EXECUTION_SSH, EXECUTION_TERMINAL_PROVIDER))); |
42 | 43 | private static final Set<String> MODE_ALL = java.util.Collections.unmodifiableSet(new HashSet<>(java.util.Arrays.asList(EXECUTION_LOCAL, EXECUTION_SSH, EXECUTION_TERMINAL_PROVIDER))); |
43 | 44 |
|
44 | | - private static final McpToolConfig[] DEFAULT_CONFIGS = new McpToolConfig[] { |
45 | | - new McpToolConfig("file_ops", "文件操作", "读取、写入、编辑和删除文件", true, |
46 | | - new String[] {ToolNames.FILE_READ, ToolNames.FILE_WRITE, ToolNames.FILE_EDIT, ToolNames.FILE_DELETE, ToolNames.GLOB, ToolNames.LIST_DIR}, |
47 | | - MODE_LOCAL, "file_ops"), |
48 | | - new McpToolConfig(ToolNames.AGENT, "Agent", "分派 Agent 处理任务", true, |
49 | | - new String[] {ToolNames.AGENT, ToolNames.AGENT_PIPELINE}, |
50 | | - MODE_ALL, "agent"), |
51 | | - new McpToolConfig("phone_control", "手机控制", "通过无障碍服务控制本机操作", true, |
52 | | - new String[] {ToolNames.PHONE_SCREENSHOT, ToolNames.PHONE_CLICK, ToolNames.PHONE_SWIPE, ToolNames.PHONE_LONG_PRESS, ToolNames.PHONE_VIEW_HIERARCHY, ToolNames.PHONE_CLICK_VIEW, ToolNames.PHONE_GLOBAL_ACTION}, |
53 | | - MODE_ALL, "phone_control"), |
54 | | - new McpToolConfig("todo", "任务清单", "维护当前会话的 TODO 列表,状态会注入到 system prompt", true, |
55 | | - new String[] {ToolNames.TODO_UPDATE}, |
56 | | - MODE_ALL, "todo"), |
57 | | - new McpToolConfig(ToolNames.IMAGE_UNDERSTANDING, "图片理解", "读取本地或 SSH 工作区图片并调用已选择的视觉模型理解内容", false, |
58 | | - new String[] {ToolNames.IMAGE_UNDERSTANDING}, |
59 | | - MODE_ALL, "image_understanding"), |
60 | | - new McpToolConfig(ToolNames.IMAGE_GENERATION, "图片生成", "调用已选择的生图模型生成图片,并以内联 Markdown 图片返回", false, |
61 | | - new String[] {ToolNames.IMAGE_GENERATION}, |
62 | | - MODE_ALL, "image_generation"), |
63 | | - new McpToolConfig("shell", "SSH Shell", "通过 SSH 执行 shell 命令", true, |
64 | | - new String[] {ToolNames.SHELL_EXECUTE}, |
65 | | - MODE_REMOTE, "shell"), |
66 | | - new McpToolConfig(ToolNames.WEB_SEARCH, "网页搜索", "搜索互联网并查看网页内容", false, |
67 | | - new String[] {ToolNames.WEB_SEARCH, ToolNames.WEB_FETCH}, |
68 | | - MODE_ALL, "web_search") |
69 | | - }; |
70 | | - |
| 45 | + private final Context context; |
71 | 46 | private final SettingsRepository settingsRepository; |
72 | 47 | private final WebSearchConfigRepository webSearchConfigRepository; |
73 | 48 | private final PhoneControlRepository phoneControlRepository; |
74 | 49 | private ToolRegistry toolRegistry; |
75 | 50 |
|
76 | 51 | public ToolSettingsRepository(Context context) { |
| 52 | + this.context = context.getApplicationContext(); |
77 | 53 | settingsRepository = new SettingsRepository(context); |
78 | 54 | webSearchConfigRepository = new WebSearchConfigRepository(context); |
79 | 55 | phoneControlRepository = new PhoneControlRepository(context); |
80 | 56 | } |
81 | 57 |
|
| 58 | + private List<McpToolConfig> buildDefaultConfigs() { |
| 59 | + List<McpToolConfig> configs = new ArrayList<>(); |
| 60 | + configs.add(new McpToolConfig("file_ops", |
| 61 | + context.getString(R.string.tool_group_file_ops_name), |
| 62 | + context.getString(R.string.tool_group_file_ops_desc), |
| 63 | + true, |
| 64 | + new String[] {ToolNames.FILE_READ, ToolNames.FILE_WRITE, ToolNames.FILE_EDIT, ToolNames.FILE_DELETE, ToolNames.GLOB, ToolNames.LIST_DIR}, |
| 65 | + MODE_LOCAL, "file_ops")); |
| 66 | + configs.add(new McpToolConfig(ToolNames.AGENT, |
| 67 | + "Agent", |
| 68 | + context.getString(R.string.tool_group_agent_desc), |
| 69 | + true, |
| 70 | + new String[] {ToolNames.AGENT, ToolNames.AGENT_PIPELINE}, |
| 71 | + MODE_ALL, "agent")); |
| 72 | + configs.add(new McpToolConfig("phone_control", |
| 73 | + context.getString(R.string.tool_group_phone_control_name), |
| 74 | + context.getString(R.string.tool_group_phone_control_desc), |
| 75 | + true, |
| 76 | + new String[] {ToolNames.PHONE_SCREENSHOT, ToolNames.PHONE_CLICK, ToolNames.PHONE_SWIPE, ToolNames.PHONE_LONG_PRESS, ToolNames.PHONE_VIEW_HIERARCHY, ToolNames.PHONE_CLICK_VIEW, ToolNames.PHONE_GLOBAL_ACTION}, |
| 77 | + MODE_ALL, "phone_control")); |
| 78 | + configs.add(new McpToolConfig("todo", |
| 79 | + context.getString(R.string.tool_group_todo_name), |
| 80 | + context.getString(R.string.tool_group_todo_desc), |
| 81 | + true, |
| 82 | + new String[] {ToolNames.TODO_UPDATE}, |
| 83 | + MODE_ALL, "todo")); |
| 84 | + configs.add(new McpToolConfig(ToolNames.IMAGE_UNDERSTANDING, |
| 85 | + context.getString(R.string.tool_group_image_understanding_name), |
| 86 | + context.getString(R.string.tool_group_image_understanding_desc), |
| 87 | + false, |
| 88 | + new String[] {ToolNames.IMAGE_UNDERSTANDING}, |
| 89 | + MODE_ALL, "image_understanding")); |
| 90 | + configs.add(new McpToolConfig(ToolNames.IMAGE_GENERATION, |
| 91 | + context.getString(R.string.tool_group_image_generation_name), |
| 92 | + context.getString(R.string.tool_group_image_generation_desc), |
| 93 | + false, |
| 94 | + new String[] {ToolNames.IMAGE_GENERATION}, |
| 95 | + MODE_ALL, "image_generation")); |
| 96 | + configs.add(new McpToolConfig("shell", |
| 97 | + "SSH Shell", |
| 98 | + context.getString(R.string.tool_group_shell_desc), |
| 99 | + true, |
| 100 | + new String[] {ToolNames.SHELL_EXECUTE}, |
| 101 | + MODE_REMOTE, "shell")); |
| 102 | + configs.add(new McpToolConfig(ToolNames.WEB_SEARCH, |
| 103 | + context.getString(R.string.tool_group_web_search_name), |
| 104 | + context.getString(R.string.tool_group_web_search_desc), |
| 105 | + true, |
| 106 | + new String[] {ToolNames.WEB_SEARCH, ToolNames.WEB_FETCH}, |
| 107 | + MODE_ALL, "web_search")); |
| 108 | + return configs; |
| 109 | + } |
| 110 | + |
82 | 111 | public void setToolRegistry(ToolRegistry toolRegistry) { |
83 | 112 | this.toolRegistry = toolRegistry; |
84 | 113 | } |
@@ -107,9 +136,9 @@ public synchronized void setExecutionMode(String mode) { |
107 | 136 | public synchronized List<McpToolConfig> getConfigs() { |
108 | 137 | String executionMode = getExecutionMode(); |
109 | 138 | ArrayList<McpToolConfig> configs = new ArrayList<>(); |
110 | | - for (McpToolConfig config : DEFAULT_CONFIGS) { |
| 139 | + for (McpToolConfig config : buildDefaultConfigs()) { |
111 | 140 | boolean enabled = getMcpEnabled(executionMode, config); |
112 | | - configs.add(displayConfigForMode(executionMode, config, enabled)); |
| 141 | + configs.add(displayConfigForMode(executionMode, config, enabled, context)); |
113 | 142 | } |
114 | 143 | return configs; |
115 | 144 | } |
@@ -185,8 +214,15 @@ static String mcpEnabledKey(String executionMode, String id) { |
185 | 214 | } |
186 | 215 |
|
187 | 216 | static McpToolConfig displayConfigForMode(String executionMode, McpToolConfig config, boolean enabled) { |
| 217 | + return displayConfigForMode(executionMode, config, enabled, null); |
| 218 | + } |
| 219 | + |
| 220 | + static McpToolConfig displayConfigForMode(String executionMode, McpToolConfig config, boolean enabled, Context context) { |
188 | 221 | if ("shell".equals(config.getId()) && EXECUTION_TERMINAL_PROVIDER.equals(normalizeExecutionMode(executionMode))) { |
189 | | - return new McpToolConfig(config.getId(), "IPC Shell", "通过终端提供者 IPC 执行 shell 命令", enabled, config.getTools(), config.getSupportedExecutionModes(), config.getIconKey()); |
| 222 | + String ipcDesc = context == null |
| 223 | + ? "通过终端提供者 IPC 执行 shell 命令" |
| 224 | + : context.getString(R.string.tool_group_ipc_shell_desc); |
| 225 | + return new McpToolConfig(config.getId(), "IPC Shell", ipcDesc, enabled, config.getTools(), config.getSupportedExecutionModes(), config.getIconKey()); |
190 | 226 | } |
191 | 227 | return new McpToolConfig(config.getId(), config.getName(), config.getDescription(), enabled, config.getTools(), config.getSupportedExecutionModes(), config.getIconKey()); |
192 | 228 | } |
|
0 commit comments