前端UI推理、工具、消息的基础实现
This commit is contained in:
parent
52148f6936
commit
35054ee7c0
@ -132,6 +132,14 @@
|
|||||||
<EmbeddedResource Include="resource\img\tool.png">
|
<EmbeddedResource Include="resource\img\tool.png">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<None Remove="resource\img\unfold.png" />
|
||||||
|
<EmbeddedResource Include="resource\img\unfold.png">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<None Remove="resource\img\fold.png" />
|
||||||
|
<EmbeddedResource Include="resource\img\fold.png">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="C:\Program Files\ArcGIS\Pro\bin\Esri.ProApp.SDK.Desktop.targets" Condition="Exists('C:\Program Files\ArcGIS\Pro\bin\Esri.ProApp.SDK.Desktop.targets') AND !Exists('Esri.ArcGISPro.Extensions.targets')" />
|
<Import Project="C:\Program Files\ArcGIS\Pro\bin\Esri.ProApp.SDK.Desktop.targets" Condition="Exists('C:\Program Files\ArcGIS\Pro\bin\Esri.ProApp.SDK.Desktop.targets') AND !Exists('Esri.ArcGISPro.Extensions.targets')" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -282,12 +282,28 @@ public class Gateway
|
|||||||
{
|
{
|
||||||
//如果本次回复不包含任何工具的调用或提示词的调用,则不再请求
|
//如果本次回复不包含任何工具的调用或提示词的调用,则不再请求
|
||||||
goOn = false;
|
goOn = false;
|
||||||
|
MessageListItem endMessageListItem1 = new ChatMessageItem
|
||||||
|
{
|
||||||
|
type = MessageType.END_TAG,
|
||||||
|
content = "",
|
||||||
|
id = (timestamp+3).ToString(),
|
||||||
|
role = "assistant"
|
||||||
|
};
|
||||||
|
callback?.Invoke(endMessageListItem1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await foreach(LlmStreamChat llmStreamChat in bailian.SendChatStreamAsync(jsonContent))
|
await foreach(LlmStreamChat llmStreamChat in bailian.SendChatStreamAsync(jsonContent))
|
||||||
{
|
{
|
||||||
if (!goOn)
|
if (!goOn)
|
||||||
{
|
{
|
||||||
|
MessageListItem endMessageListItem2 = new ChatMessageItem
|
||||||
|
{
|
||||||
|
type = MessageType.END_TAG,
|
||||||
|
content = "",
|
||||||
|
id = (timestamp+3).ToString(),
|
||||||
|
role = "assistant"
|
||||||
|
};
|
||||||
|
callback?.Invoke(endMessageListItem2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +315,7 @@ public class Gateway
|
|||||||
content = llmStreamChat.Choices[0].Delta.ResoningContent,
|
content = llmStreamChat.Choices[0].Delta.ResoningContent,
|
||||||
role = "assistant",
|
role = "assistant",
|
||||||
type = MessageType.REASON_MESSAGE,
|
type = MessageType.REASON_MESSAGE,
|
||||||
id = (timestamp-1).ToString()
|
id = (timestamp+2).ToString()
|
||||||
};
|
};
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
@ -328,17 +344,14 @@ public class Gateway
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//包含Prompt调用请求的消息
|
//包含Prompt调用请求的消息
|
||||||
if (remainingPrompt != "")
|
MessageListItem chatMessageListItem = new ChatMessageItem()
|
||||||
{
|
{
|
||||||
MessageListItem chatMessageListItem = new ChatMessageItem()
|
content = remainingPrompt,
|
||||||
{
|
role = "assistant",
|
||||||
content = remainingPrompt,
|
type = MessageType.CHAT_MESSAGE,
|
||||||
role = "assistant",
|
id = timestamp.ToString()
|
||||||
type = MessageType.CHAT_MESSAGE,
|
};
|
||||||
id = timestamp.ToString()
|
callback?.Invoke(chatMessageListItem);
|
||||||
};
|
|
||||||
callback?.Invoke(chatMessageListItem);
|
|
||||||
}
|
|
||||||
XElement promptUse = XElement.Parse(matchedPrompt);
|
XElement promptUse = XElement.Parse(matchedPrompt);
|
||||||
string promptKey = promptUse.Element("name")?.Value;
|
string promptKey = promptUse.Element("name")?.Value;
|
||||||
string promptArgs = promptUse.Element("arguments")?.Value;
|
string promptArgs = promptUse.Element("arguments")?.Value;
|
||||||
@ -355,20 +368,6 @@ public class Gateway
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//包含工具调用请求的消息
|
//包含工具调用请求的消息
|
||||||
if (remaining != "")
|
|
||||||
{
|
|
||||||
MessageListItem chatMessageListItem = new ChatMessageItem()
|
|
||||||
{
|
|
||||||
content = remaining,
|
|
||||||
role = "assistant",
|
|
||||||
type = MessageType.CHAT_MESSAGE,
|
|
||||||
id = timestamp.ToString()
|
|
||||||
};
|
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
callback?.Invoke(chatMessageListItem);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
XElement toolUse = XElement.Parse(matched);
|
XElement toolUse = XElement.Parse(matched);
|
||||||
string fullToolName = toolUse.Element("name")?.Value;
|
string fullToolName = toolUse.Element("name")?.Value;
|
||||||
string toolArgs = toolUse.Element("arguments")?.Value;
|
string toolArgs = toolUse.Element("arguments")?.Value;
|
||||||
@ -377,6 +376,32 @@ public class Gateway
|
|||||||
string toolName = fullToolName.Contains(":") ? fullToolName.Split(':')[1] : fullToolName;
|
string toolName = fullToolName.Contains(":") ? fullToolName.Split(':')[1] : fullToolName;
|
||||||
McpServer mcpServer = mcpServerList.GetServer(serverName);
|
McpServer mcpServer = mcpServerList.GetServer(serverName);
|
||||||
//将工具调用请求添加至列表中待一次回答完整后再统一进行调用
|
//将工具调用请求添加至列表中待一次回答完整后再统一进行调用
|
||||||
|
MessageListItem chatMessageListItem = new ChatMessageItem()
|
||||||
|
{
|
||||||
|
content = remaining,
|
||||||
|
role = "assistant",
|
||||||
|
type = MessageType.CHAT_MESSAGE,
|
||||||
|
id = timestamp.ToString()
|
||||||
|
};
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
callback?.Invoke(chatMessageListItem);
|
||||||
|
});
|
||||||
|
MessageListItem toolMessageListItem = new ToolMessageItem()
|
||||||
|
{
|
||||||
|
content = "",
|
||||||
|
result = "",
|
||||||
|
toolName = toolName,
|
||||||
|
toolParams = toolParams,
|
||||||
|
role = "user",
|
||||||
|
type = MessageType.TOOL_MESSAGE,
|
||||||
|
id = (timestamp+1).ToString(),
|
||||||
|
status = "loading"
|
||||||
|
};
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
callback?.Invoke(toolMessageListItem);
|
||||||
|
});
|
||||||
mcpToolRequests = new List<McpToolRequest>();
|
mcpToolRequests = new List<McpToolRequest>();
|
||||||
McpToolRequest mcpToolRequest = new McpToolRequest()
|
McpToolRequest mcpToolRequest = new McpToolRequest()
|
||||||
{
|
{
|
||||||
@ -421,6 +446,7 @@ public class Gateway
|
|||||||
type = MessageType.TOOL_MESSAGE,
|
type = MessageType.TOOL_MESSAGE,
|
||||||
status = toolResponse.IsError ? "fail" : "success",
|
status = toolResponse.IsError ? "fail" : "success",
|
||||||
content = JsonConvert.SerializeObject(toolResponse),
|
content = JsonConvert.SerializeObject(toolResponse),
|
||||||
|
result = JsonConvert.SerializeObject(toolResponse),
|
||||||
id = (timestamp + 1).ToString(),
|
id = (timestamp + 1).ToString(),
|
||||||
role = "user"
|
role = "user"
|
||||||
};
|
};
|
||||||
@ -448,6 +474,7 @@ public class Gateway
|
|||||||
type = MessageType.TOOL_MESSAGE,
|
type = MessageType.TOOL_MESSAGE,
|
||||||
status = toolResponse.IsError ? "fail" : "success",
|
status = toolResponse.IsError ? "fail" : "success",
|
||||||
content = JsonConvert.SerializeObject(toolResponse),
|
content = JsonConvert.SerializeObject(toolResponse),
|
||||||
|
result = JsonConvert.SerializeObject(toolResponse),
|
||||||
id = (timestamp + 1).ToString(),
|
id = (timestamp + 1).ToString(),
|
||||||
role = "user"
|
role = "user"
|
||||||
};
|
};
|
||||||
@ -494,6 +521,7 @@ public class Gateway
|
|||||||
type = MessageType.TOOL_MESSAGE,
|
type = MessageType.TOOL_MESSAGE,
|
||||||
status = "fail",
|
status = "fail",
|
||||||
content = JsonConvert.SerializeObject(innerResult),
|
content = JsonConvert.SerializeObject(innerResult),
|
||||||
|
result = JsonConvert.SerializeObject(innerResult),
|
||||||
id = (timestamp + 1).ToString(),
|
id = (timestamp + 1).ToString(),
|
||||||
role = "user"
|
role = "user"
|
||||||
};
|
};
|
||||||
@ -516,6 +544,7 @@ public class Gateway
|
|||||||
type = MessageType.TOOL_MESSAGE,
|
type = MessageType.TOOL_MESSAGE,
|
||||||
status = "success",
|
status = "success",
|
||||||
content = JsonConvert.SerializeObject(innerResult),
|
content = JsonConvert.SerializeObject(innerResult),
|
||||||
|
result = JsonConvert.SerializeObject(innerResult),
|
||||||
id = (timestamp + 1).ToString(),
|
id = (timestamp + 1).ToString(),
|
||||||
role = "user"
|
role = "user"
|
||||||
};
|
};
|
||||||
@ -569,6 +598,14 @@ public class Gateway
|
|||||||
log.Error(e.Message);
|
log.Error(e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MessageListItem endMessageListItem = new ChatMessageItem
|
||||||
|
{
|
||||||
|
type = MessageType.END_TAG,
|
||||||
|
content = "",
|
||||||
|
id = (timestamp+3).ToString(),
|
||||||
|
role = "assistant"
|
||||||
|
};
|
||||||
|
callback?.Invoke(endMessageListItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
resource/img/fold.png
Normal file
BIN
resource/img/fold.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 261 B |
BIN
resource/img/unfold.png
Normal file
BIN
resource/img/unfold.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 962 B |
@ -22,7 +22,7 @@ namespace LinkToolAddin
|
|||||||
{
|
{
|
||||||
internal class VersionButton : Button
|
internal class VersionButton : Button
|
||||||
{
|
{
|
||||||
private string version = "0.1.0";
|
private string version = "0.1.1";
|
||||||
protected override void OnClick()
|
protected override void OnClick()
|
||||||
{
|
{
|
||||||
MessageBox.Show($"当前LinkTool版本为{version}", "版本信息");
|
MessageBox.Show($"当前LinkTool版本为{version}", "版本信息");
|
||||||
|
|||||||
@ -25,18 +25,30 @@
|
|||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="24"/>
|
<RowDefinition Height="24"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Button Grid.Row="0" Content="Test" Name="TestButton" Click="TestButton_OnClick"></Button>
|
<Grid Grid.Row="0" HorizontalAlignment="Center">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="36"/>
|
||||||
|
<ColumnDefinition Width="36"/>
|
||||||
|
<ColumnDefinition Width="36"/>
|
||||||
|
<ColumnDefinition Width="36"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Button Grid.Column="0" Content="清除" Name="ClearButton" Click="ClearButton_OnClick"></Button>
|
||||||
|
<Button Grid.Column="1" Content="顶部" Name="TopButton" Click="TopButton_OnClick"></Button>
|
||||||
|
<Button Grid.Column="2" Content="底部" Name="BottomButton" Click="BottomButton_OnClick"></Button>
|
||||||
|
<Button Grid.Column="3" Content="停止" Name="StopButton" Click="StopButton_OnClick"></Button>
|
||||||
|
</Grid>
|
||||||
|
<!-- <Button Grid.Row="0" Content="Test" Name="TestButton" Click="TestButton_OnClick"></Button> -->
|
||||||
<!-- <TextBlock Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Text="LinkTool"/> -->
|
<!-- <TextBlock Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Text="LinkTool"/> -->
|
||||||
<ScrollViewer Grid.Row="1" HorizontalContentAlignment="Stretch" VerticalAlignment="Top">
|
<ScrollViewer Grid.Row="1" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" Name="ScrollViewer">
|
||||||
<StackPanel Name="ChatHistoryStackPanel"></StackPanel>
|
<StackPanel Name="ChatHistoryStackPanel"></StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
<TextBlock Grid.Row="2" VerticalAlignment="Center" Name="StatusTextBlock" Text="思考中..."/>
|
<TextBlock Grid.Row="2" VerticalAlignment="Center" Name="StatusTextBlock" Text=""/>
|
||||||
<Grid Grid.Row="3">
|
<Grid Grid.Row="3">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="48"></ColumnDefinition>
|
<ColumnDefinition Width="48"></ColumnDefinition>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<TextBox Grid.Column="0" Name="QuestionTextbox" Text="这是用户的问题"></TextBox>
|
<TextBox Grid.Column="0" Name="QuestionTextbox" Text="这是用户的问题" TextWrapping="Wrap"></TextBox>
|
||||||
<Button Grid.Column="1" Name="SendButton" Content="发送" Click="SendButton_OnClick"></Button>
|
<Button Grid.Column="1" Name="SendButton" Content="发送" Click="SendButton_OnClick"></Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@ -117,13 +117,17 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
QuestionTextbox.Text = "";
|
QuestionTextbox.Text = "";
|
||||||
borderItemsDict[timestamp.ToString()] = userMsgBoder;
|
borderItemsDict[timestamp.ToString()] = userMsgBoder;
|
||||||
ChatHistoryStackPanel.Children.Add(userMsgBoder);
|
ChatHistoryStackPanel.Children.Add(userMsgBoder);
|
||||||
Gateway.SendMessageStream(question,"qwen-max",defaultGdbPath,NewMessage_Recall);
|
Gateway.SendMessageStream(question,"qwen3-235b-a22b",defaultGdbPath,NewMessage_Recall);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewMessage_Recall(MessageListItem msg)
|
public void NewMessage_Recall(MessageListItem msg)
|
||||||
{
|
{
|
||||||
string msgId = msg.id;
|
string msgId = msg.id;
|
||||||
log.Info(msg.content);
|
log.Info(msg.content);
|
||||||
|
double verticalOffset = ScrollViewer.VerticalOffset;
|
||||||
|
double viewportHeight = ScrollViewer.ViewportHeight;
|
||||||
|
double contentHeight = ChatHistoryStackPanel.ActualHeight;
|
||||||
|
double tolerance = 24;
|
||||||
if (!idList.Contains(msgId))
|
if (!idList.Contains(msgId))
|
||||||
{
|
{
|
||||||
//不存在该消息,需添加到ListView中
|
//不存在该消息,需添加到ListView中
|
||||||
@ -147,17 +151,32 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
ChatHistoryStackPanel.Children.Add(border);
|
ChatHistoryStackPanel.Children.Add(border);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if(msg.role == "assistant")
|
||||||
{
|
{
|
||||||
Border border = GetAiChatBorder(msg);
|
if (msg.type == MessageType.REASON_MESSAGE)
|
||||||
borderItemsDict[msgId] = border;
|
{
|
||||||
ChatHistoryStackPanel.Children.Add(border);
|
Border border = GetAiReasonBorder(msg);
|
||||||
|
borderItemsDict[msgId] = border;
|
||||||
|
ChatHistoryStackPanel.Children.Add(border);
|
||||||
|
}else if (msg.type == MessageType.CHAT_MESSAGE)
|
||||||
|
{
|
||||||
|
Border border = GetAiChatBorder(msg);
|
||||||
|
borderItemsDict[msgId] = border;
|
||||||
|
ChatHistoryStackPanel.Children.Add(border);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//已有该消息,只需要修改内容
|
//已有该消息,只需要修改内容
|
||||||
messageDict[msgId] = msg;
|
messageDict[msgId] = msg;
|
||||||
|
if (msg.content == "")
|
||||||
|
{
|
||||||
|
ChatHistoryStackPanel.Children.Remove(borderItemsDict[msgId]);
|
||||||
|
borderItemsDict.TryRemove(msgId, out Border border);
|
||||||
|
messageDict.TryRemove(msgId, out MessageListItem tempMsg);
|
||||||
|
idList.Remove(msgId);
|
||||||
|
}
|
||||||
if (msg.role == "user")
|
if (msg.role == "user")
|
||||||
{
|
{
|
||||||
if (msg.type == MessageType.TOOL_MESSAGE)
|
if (msg.type == MessageType.TOOL_MESSAGE)
|
||||||
@ -166,22 +185,42 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
Grid grid = borderItem.Child as Grid;
|
Grid grid = borderItem.Child as Grid;
|
||||||
TextBlock textBlock = grid.Children[1] as TextBlock;
|
TextBlock textBlock = grid.Children[1] as TextBlock;
|
||||||
textBlock.Text = (msg as ToolMessageItem).toolName;
|
textBlock.Text = (msg as ToolMessageItem).toolName;
|
||||||
|
StatusTextBlock.Text = "正在执行工具";
|
||||||
}else if (msg.type == MessageType.CHAT_MESSAGE)
|
}else if (msg.type == MessageType.CHAT_MESSAGE)
|
||||||
{
|
{
|
||||||
Border borderItem = borderItemsDict[msgId];
|
Border borderItem = borderItemsDict[msgId];
|
||||||
Grid grid = borderItem.Child as Grid;
|
Grid grid = borderItem.Child as Grid;
|
||||||
TextBox textBox = grid.Children[1] as TextBox;
|
TextBox textBox = grid.Children[1] as TextBox;
|
||||||
textBox.Text = msg.content;
|
textBox.Text = msg.content;
|
||||||
|
StatusTextBlock.Text = "正在读取用户输入";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Border borderItem = borderItemsDict[msgId];
|
if (msg.type == MessageType.REASON_MESSAGE)
|
||||||
Grid grid = borderItem.Child as Grid;
|
{
|
||||||
TextBox textBox = grid.Children[1] as TextBox;
|
Border borderItem = borderItemsDict[msgId];
|
||||||
textBox.Text = msg.content;
|
Grid grid = borderItem.Child as Grid;
|
||||||
|
TextBox textBox = grid.Children[0] as TextBox;
|
||||||
|
textBox.Text = msg.content;
|
||||||
|
StatusTextBlock.Text = "深度思考中";
|
||||||
|
}else if (msg.type == MessageType.CHAT_MESSAGE)
|
||||||
|
{
|
||||||
|
Border borderItem = borderItemsDict[msgId];
|
||||||
|
Grid grid = borderItem.Child as Grid;
|
||||||
|
TextBox textBox = grid.Children[1] as TextBox;
|
||||||
|
textBox.Text = msg.content;
|
||||||
|
StatusTextBlock.Text = "回答生成中";
|
||||||
|
}else if (msg.type == MessageType.END_TAG)
|
||||||
|
{
|
||||||
|
StatusTextBlock.Text = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Math.Abs(verticalOffset + viewportHeight - contentHeight) < tolerance)
|
||||||
|
{
|
||||||
|
ScrollViewer.ScrollToBottom();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Border GetAiChatBorder(MessageListItem msg)
|
private Border GetAiChatBorder(MessageListItem msg)
|
||||||
@ -204,6 +243,8 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
grid.Children.Add(textBox);
|
grid.Children.Add(textBox);
|
||||||
Grid.SetColumn(icon, 0);
|
Grid.SetColumn(icon, 0);
|
||||||
Grid.SetColumn(textBox, 1);
|
Grid.SetColumn(textBox, 1);
|
||||||
|
textBox.IsReadOnly = true;
|
||||||
|
textBox.BorderThickness = new Thickness(0);
|
||||||
textBox.Background = Brushes.Transparent;
|
textBox.Background = Brushes.Transparent;
|
||||||
textBox.Text = msg.content;
|
textBox.Text = msg.content;
|
||||||
textBox.TextWrapping = TextWrapping.Wrap;
|
textBox.TextWrapping = TextWrapping.Wrap;
|
||||||
@ -211,6 +252,105 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
return border;
|
return border;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Border GetAiReasonBorder(MessageListItem msg)
|
||||||
|
{
|
||||||
|
Border border = new Border();
|
||||||
|
border.Margin = new Thickness(8, 12, 8, 12);
|
||||||
|
border.BorderThickness = new Thickness(0);
|
||||||
|
// border.Background = Brushes.DarkSeaGreen;
|
||||||
|
Grid grid = new Grid();
|
||||||
|
Image icon = new Image()
|
||||||
|
{
|
||||||
|
Source = LocalResource.ReadImageByResource("LinkToolAddin.resource.img.linktool.png"),
|
||||||
|
Stretch = Stretch.Fill,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
|
||||||
|
};
|
||||||
|
Image fold = new Image()
|
||||||
|
{
|
||||||
|
Source = LocalResource.ReadImageByResource("LinkToolAddin.resource.img.fold.png"),
|
||||||
|
Stretch = Stretch.Fill,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
|
||||||
|
};
|
||||||
|
Image unfold = new Image()
|
||||||
|
{
|
||||||
|
Source = LocalResource.ReadImageByResource("LinkToolAddin.resource.img.unfold.png"),
|
||||||
|
Stretch = Stretch.Fill,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
|
||||||
|
};
|
||||||
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(24, GridUnitType.Pixel)});
|
||||||
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)});
|
||||||
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(16, GridUnitType.Pixel)});
|
||||||
|
TextBox textBox = new TextBox();
|
||||||
|
// grid.Children.Add(icon);
|
||||||
|
grid.Children.Add(textBox);
|
||||||
|
// Grid.SetColumn(icon, 0);
|
||||||
|
Grid.SetColumn(textBox, 1);
|
||||||
|
textBox.IsReadOnly = true;
|
||||||
|
textBox.Foreground = Brushes.Gray;
|
||||||
|
textBox.BorderThickness = new Thickness(2,0,0,0);
|
||||||
|
textBox.BorderBrush = Brushes.Gray;
|
||||||
|
textBox.Background = Brushes.Transparent;
|
||||||
|
textBox.Text = msg.content;
|
||||||
|
textBox.TextWrapping = TextWrapping.Wrap;
|
||||||
|
Button button = new Button();
|
||||||
|
StackPanel panel = new StackPanel();
|
||||||
|
panel.Orientation = Orientation.Horizontal;
|
||||||
|
panel.Children.Add(fold);
|
||||||
|
button.Content = panel;
|
||||||
|
button.BorderThickness = new Thickness(0);
|
||||||
|
button.Background = Brushes.Transparent;
|
||||||
|
button.Width = 16;
|
||||||
|
button.Height = 16;
|
||||||
|
button.Padding = new Thickness(0);
|
||||||
|
button.HorizontalAlignment = HorizontalAlignment.Center;
|
||||||
|
button.VerticalAlignment = VerticalAlignment.Top;
|
||||||
|
button.Tag = "fold";
|
||||||
|
button.Click += FoldButton_OnClick;
|
||||||
|
Grid.SetColumn(button, 2);
|
||||||
|
grid.Children.Add(button);
|
||||||
|
border.Child = grid;
|
||||||
|
return border;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FoldButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Button button = sender as Button;
|
||||||
|
string tag = button.Tag.ToString();
|
||||||
|
if (tag == "fold")
|
||||||
|
{
|
||||||
|
button.Tag = "unfold";
|
||||||
|
Grid grid = button.Parent as Grid;
|
||||||
|
TextBox textBox = grid.Children[0] as TextBox;
|
||||||
|
textBox.Visibility = Visibility.Collapsed;
|
||||||
|
StackPanel stackPanel = button.Content as StackPanel;
|
||||||
|
Image unfold = new Image()
|
||||||
|
{
|
||||||
|
Source = LocalResource.ReadImageByResource("LinkToolAddin.resource.img.unfold.png"),
|
||||||
|
Stretch = Stretch.Fill,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
|
||||||
|
};
|
||||||
|
stackPanel.Children.Clear();
|
||||||
|
stackPanel.Children.Add(unfold);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
button.Tag = "fold";
|
||||||
|
Image fold = new Image()
|
||||||
|
{
|
||||||
|
Source = LocalResource.ReadImageByResource("LinkToolAddin.resource.img.fold.png"),
|
||||||
|
Stretch = Stretch.Fill,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top
|
||||||
|
};
|
||||||
|
Grid grid = button.Parent as Grid;
|
||||||
|
TextBox textBox = grid.Children[0] as TextBox;
|
||||||
|
textBox.Visibility = Visibility.Visible;
|
||||||
|
StackPanel stackPanel = button.Content as StackPanel;
|
||||||
|
stackPanel.Children.Clear();
|
||||||
|
stackPanel.Children.Add(fold);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private Border GetUserChatBorder(MessageListItem msg)
|
private Border GetUserChatBorder(MessageListItem msg)
|
||||||
{
|
{
|
||||||
Border border = new Border();
|
Border border = new Border();
|
||||||
@ -227,11 +367,14 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)});
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)});
|
||||||
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(24, GridUnitType.Pixel)});
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(24, GridUnitType.Pixel)});
|
||||||
TextBox textBox = new TextBox();
|
TextBox textBox = new TextBox();
|
||||||
|
textBox.HorizontalAlignment = HorizontalAlignment.Right;
|
||||||
grid.Children.Add(icon);
|
grid.Children.Add(icon);
|
||||||
grid.Children.Add(textBox);
|
grid.Children.Add(textBox);
|
||||||
Grid.SetColumn(icon, 1);
|
Grid.SetColumn(icon, 1);
|
||||||
Grid.SetColumn(textBox, 0);
|
Grid.SetColumn(textBox, 0);
|
||||||
textBox.Background = Brushes.Transparent;
|
textBox.Background = Brushes.Transparent;
|
||||||
|
textBox.IsReadOnly = true;
|
||||||
|
textBox.BorderThickness = new Thickness(0);
|
||||||
textBox.Text = msg.content;
|
textBox.Text = msg.content;
|
||||||
textBox.TextWrapping = TextWrapping.Wrap;
|
textBox.TextWrapping = TextWrapping.Wrap;
|
||||||
border.Child = grid;
|
border.Child = grid;
|
||||||
@ -245,6 +388,7 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
border.Padding = new Thickness(8);
|
border.Padding = new Thickness(8);
|
||||||
border.BorderThickness = new Thickness(1);
|
border.BorderThickness = new Thickness(1);
|
||||||
border.BorderBrush = Brushes.Gray;
|
border.BorderBrush = Brushes.Gray;
|
||||||
|
border.CornerRadius = new CornerRadius(3);
|
||||||
// border.Background = Brushes.DarkSeaGreen;
|
// border.Background = Brushes.DarkSeaGreen;
|
||||||
Grid grid = new Grid();
|
Grid grid = new Grid();
|
||||||
Image icon = new Image()
|
Image icon = new Image()
|
||||||
@ -256,17 +400,46 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
icon.Margin = new Thickness(0, 0, 8, 0);
|
icon.Margin = new Thickness(0, 0, 8, 0);
|
||||||
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(24, GridUnitType.Pixel)});
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(24, GridUnitType.Pixel)});
|
||||||
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)});
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)});
|
||||||
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(36, GridUnitType.Pixel)});
|
||||||
|
grid.ColumnDefinitions.Add(new ColumnDefinition(){Width = new GridLength(36, GridUnitType.Pixel)});
|
||||||
TextBlock textBlock = new TextBlock();
|
TextBlock textBlock = new TextBlock();
|
||||||
textBlock.Text = (msg as ToolMessageItem).toolName;
|
ToolMessageItem toolMsg = msg as ToolMessageItem;
|
||||||
|
textBlock.Text = toolMsg.toolName + " | " + toolMsg.status;
|
||||||
textBlock.TextWrapping = TextWrapping.Wrap;
|
textBlock.TextWrapping = TextWrapping.Wrap;
|
||||||
grid.Children.Add(icon);
|
grid.Children.Add(icon);
|
||||||
grid.Children.Add(textBlock);
|
grid.Children.Add(textBlock);
|
||||||
Grid.SetColumn(icon, 0);
|
Grid.SetColumn(icon, 0);
|
||||||
Grid.SetColumn(textBlock, 1);
|
Grid.SetColumn(textBlock, 1);
|
||||||
|
Button argsButton = new Button();
|
||||||
|
argsButton.Content = "参数";
|
||||||
|
argsButton.Tag = msg as ToolMessageItem;
|
||||||
|
argsButton.Click += ToolArgsButton_OnClick;
|
||||||
border.Child = grid;
|
border.Child = grid;
|
||||||
|
Button resButton = new Button();
|
||||||
|
resButton.Content = "结果";
|
||||||
|
resButton.Tag = msg as ToolMessageItem;
|
||||||
|
resButton.Click += ToolResButton_OnClick;
|
||||||
|
grid.Children.Add(argsButton);
|
||||||
|
Grid.SetColumn(argsButton, 2);
|
||||||
|
grid.Children.Add(resButton);
|
||||||
|
Grid.SetColumn(resButton, 3);
|
||||||
return border;
|
return border;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ToolArgsButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Button button = sender as Button;
|
||||||
|
ToolMessageItem toolItem = button.Tag as ToolMessageItem;
|
||||||
|
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(JsonConvert.SerializeObject(toolItem.toolParams),toolItem.toolName+"工具参数");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToolResButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Button button = sender as Button;
|
||||||
|
ToolMessageItem toolItem = button.Tag as ToolMessageItem;
|
||||||
|
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(toolItem.result,toolItem.toolName+"运行结果");
|
||||||
|
}
|
||||||
|
|
||||||
private void TestButton_OnClick(object sender, RoutedEventArgs e)
|
private void TestButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
@ -282,5 +455,29 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
};
|
};
|
||||||
NewMessage_Recall(toolMessageItem);
|
NewMessage_Recall(toolMessageItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ClearButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
idList.Clear();
|
||||||
|
messageDict.Clear();
|
||||||
|
borderItemsDict.Clear();
|
||||||
|
ChatHistoryStackPanel.Children.Clear();
|
||||||
|
QuestionTextbox.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TopButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ScrollViewer.ScrollToTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BottomButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ScrollViewer.ScrollToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Gateway.StopConversation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ public enum MessageType
|
|||||||
TOOL_MESSAGE,
|
TOOL_MESSAGE,
|
||||||
CHAT_MESSAGE,
|
CHAT_MESSAGE,
|
||||||
REASON_MESSAGE,
|
REASON_MESSAGE,
|
||||||
|
END_TAG
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface MessageListItem
|
public interface MessageListItem
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user