forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubagentTurnWidget.java
More file actions
73 lines (63 loc) · 2.23 KB
/
Copy pathSubagentTurnWidget.java
File metadata and controls
73 lines (63 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.chat;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import com.microsoft.copilot.eclipse.core.lsp.protocol.AgentToolCall;
import com.microsoft.copilot.eclipse.ui.chat.services.AvatarService;
import com.microsoft.copilot.eclipse.ui.chat.services.ChatServiceManager;
/**
* A turn widget for displaying subagent messages within a SubagentMessageBlock.
* This widget doesn't show an avatar or role name, only the message content.
*/
public class SubagentTurnWidget extends ThinkingTurnWidget {
/**
* Create the widget.
*/
public SubagentTurnWidget(Composite parent, int style, ChatServiceManager serviceManager, String turnId,
AgentToolCall toolCall) {
super(parent, style, serviceManager, turnId + "_subagent",
getToolCallRoleName(toolCall));
}
/**
* Extract role name from tool call.
*/
private static String getToolCallRoleName(AgentToolCall toolCall) {
if (toolCall != null) {
if (StringUtils.isNotEmpty(toolCall.getProgressMessage())) {
return toolCall.getProgressMessage();
}
if (StringUtils.isNotEmpty(toolCall.getName())) {
return toolCall.getName();
}
}
return "Subagent";
}
@Override
protected Image getAvatar(AvatarService avatarService) {
// Subagent uses the copilot avatar
return avatarService.getAvatarForCopilot();
}
@Override
protected String getRoleName() {
// This is overridden by the constructor parameter
return "Subagent";
}
@Override
protected Label createAvatarLabel(Composite parent) {
// Create a label for the avatar
return new Label(parent, SWT.NONE);
}
@Override
protected void createTextBlock() {
this.currentTextBlock = new ChatMarkupViewer(this, SWT.MULTI | SWT.WRAP);
StyledText styledText = this.currentTextBlock.getTextWidget();
styledText.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, false));
styledText.setEditable(false);
}
}