From 43ea7dd06afa01ed61796d3f3c736e705099cad5 Mon Sep 17 00:00:00 2001 From: PeterZhong Date: Mon, 26 May 2025 00:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=81=9C=E6=AD=A2=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E6=8C=89=E9=92=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=A1=86=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/dockpane/TestDockpane.xaml | 10 ++++--- ui/dockpane/TestDockpane.xaml.cs | 45 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/ui/dockpane/TestDockpane.xaml b/ui/dockpane/TestDockpane.xaml index fd7d8c8..53c1501 100644 --- a/ui/dockpane/TestDockpane.xaml +++ b/ui/dockpane/TestDockpane.xaml @@ -20,7 +20,9 @@ - + + + @@ -31,9 +33,11 @@ - + - + + + \ No newline at end of file diff --git a/ui/dockpane/TestDockpane.xaml.cs b/ui/dockpane/TestDockpane.xaml.cs index abf8b4a..da572db 100644 --- a/ui/dockpane/TestDockpane.xaml.cs +++ b/ui/dockpane/TestDockpane.xaml.cs @@ -1,12 +1,18 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Xml.Linq; using LinkToolAddin.client; using LinkToolAddin.host; using LinkToolAddin.host.llm; using LinkToolAddin.host.llm.entity; +using LinkToolAddin.host.mcp; +using LinkToolAddin.host.prompt; using LinkToolAddin.message; using LinkToolAddin.resource; using LinkToolAddin.server; @@ -231,5 +237,42 @@ namespace LinkToolAddin.ui.dockpane { Request_Bailian_Stream_Test(); } + + private void StopConversation_OnClick(object sender, RoutedEventArgs e) + { + Gateway.StopConversation(); + } + + private async void TestArcGisTool_OnClick(object sender, RoutedEventArgs e) + { + string xmlStr = + "\nArcGisPro:ArcGisProTool\n{\"toolName\": \"Buffer\", \"toolParams\": [\"D:\\\\01_Project\\\\20250305_LinkTool\\\\20250420_AiDemoProject\\\\20250420_AiDemoProject.gdb\\\\LandUse_2005_Copy\", \"D:\\\\01_Project\\\\20250305_LinkTool\\\\20250420_AiDemoProject\\\\20250420_AiDemoProject.gdb\\\\LandUse_2005_Buffer30m\", \"30 Meters\", \"NONE\", \"ROUND\", \"ALL\"]}\n"; + XElement toolUse = XElement.Parse(xmlStr); + string fullToolName = toolUse.Element("name")?.Value; + string toolArgs = toolUse.Element("arguments")?.Value; + Dictionary toolParams = JsonConvert.DeserializeObject>(toolArgs); + string serverName = fullToolName.Contains(":") ? fullToolName.Split(':')[0] : fullToolName; + string toolName = fullToolName.Contains(":") ? fullToolName.Split(':')[1] : fullToolName; + McpServerList mcpServerList = new McpServerList(); + McpServer mcpServer = mcpServerList.GetServer(serverName); + if (mcpServer is InnerMcpServer) + { + Type type = Type.GetType("LinkToolAddin.client.tool." + serverName); + var toolParamsValues = toolParams.Values.ToArray(); + MethodInfo method = type.GetMethod(toolName, BindingFlags.Public | BindingFlags.Static); + var task = method.Invoke(null, toolParams.Values.ToArray()) as Task; + JsonRpcResultEntity innerResult = await task; + MessageListItem toolMessageItem = new ToolMessageItem + { + toolName = toolName, + toolParams = toolParams, + type = MessageType.TOOL_MESSAGE, + status = "fail", + content = JsonConvert.SerializeObject(innerResult), + id = "1test" + }; + AddReply(toolMessageItem); + } + } } }