Skip to content

Commit 6eee1fc

Browse files
authored
[Port] Add connection labels to Copilot chat response (#19508) (#19513)
* Add connection labels to Copilot chat response (#19508) * add connection label to chat response * add extra connection check for disconnected case && cleanup * add test cases for connection labels and fix failing tests * format connection label * Fix a few issues in Copilot connection label (#19514) * use property directly for reading server/db * fix text alignment
1 parent c8ef790 commit 6eee1fc

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

localization/l10n/bundle.l10n.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,19 @@
12171217
"No model found.": "No model found.",
12181218
"No tools to process.": "No tools to process.",
12191219
"You are not connected to any database.": "You are not connected to any database.",
1220+
"Connected to:": "Connected to:",
1221+
"Server - {0}/{0} is the server name": {
1222+
"message": "Server - {0}",
1223+
"comment": [
1224+
"{0} is the server name"
1225+
]
1226+
},
1227+
"Database - {0}/{0} is the database name": {
1228+
"message": "Database - {0}",
1229+
"comment": [
1230+
"{0} is the database name"
1231+
]
1232+
},
12201233
"Using {0} ({1}).../{0} is the model name{1} is whether the model can send requests": {
12211234
"message": "Using {0} ({1})...",
12221235
"comment": [

localization/xliff/vscode-mssql.xlf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@
451451
{1} is the document name
452452
{2} is the server info</note>
453453
</trans-unit>
454+
<trans-unit id="++CODE++00aaa2ec4a2146b807cc64a6f59880630adc5d451cd1a68a80e2d2ccf2d21bbc">
455+
<source xml:lang="en">Connected to:</source>
456+
</trans-unit>
454457
<trans-unit id="++CODE++d403c686f6a1048014bdd230f59963271b0123ea48245754fc9f264b962a2182">
455458
<source xml:lang="en">Connecting</source>
456459
</trans-unit>
@@ -568,6 +571,10 @@
568571
<trans-unit id="++CODE++fa7fe67124e94375d97e50896e0c32f44b03bb7ed5e9fb026341b55da724126b">
569572
<source xml:lang="en">Database</source>
570573
</trans-unit>
574+
<trans-unit id="++CODE++84a2b1ae34166a218282ec6156f3af9c67f4ccb6c03ec1cc0a03d9b3792069aa">
575+
<source xml:lang="en">Database - {0}</source>
576+
<note>{0} is the database name</note>
577+
</trans-unit>
571578
<trans-unit id="++CODE++667dd91d86c6b574073536489e39f0c5ab034846a63d946e8ef9f7bedeb1f4fb">
572579
<source xml:lang="en">Database Project</source>
573580
</trans-unit>
@@ -1666,6 +1673,10 @@
16661673
<trans-unit id="++CODE++aef7de28d52977f1b5cd0fecfdc151717610adf41e0aa33b4d9f7522a43337ef">
16671674
<source xml:lang="en">Server</source>
16681675
</trans-unit>
1676+
<trans-unit id="++CODE++f6cd8550a42862c96bedf199eb6415f9f6859b49211e35694080e73978042cf8">
1677+
<source xml:lang="en">Server - {0}</source>
1678+
<note>{0} is the server name</note>
1679+
</trans-unit>
16691680
<trans-unit id="++CODE++1c53883708ab16a3743793905feb38c8e77c295d846ff276491831e1de69b6e1">
16701681
<source xml:lang="en">Server connection in progress. Do you want to cancel?</source>
16711682
</trans-unit>

src/chat/chatAgentRequestHandler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from "../sharedInterfaces/telemetry";
2525
import { getErrorMessage } from "../utils/utils";
2626
import { MssqlChatAgent as loc } from "../constants/locConstants";
27+
import MainController from "../controllers/mainController";
2728

2829
export interface ISqlChatResult extends vscode.ChatResult {
2930
metadata: {
@@ -36,11 +37,15 @@ const MODEL_SELECTOR: vscode.LanguageModelChatSelector = {
3637
vendor: "copilot",
3738
family: "gpt-4o",
3839
};
40+
const DISCONNECTED_LABEL_PREFIX = "> ⚠️";
41+
const CONNECTED_LABEL_PREFIX = "> 🟢";
42+
const SERVER_DATABASE_LABEL_PREFIX = "> ➖";
3943

4044
export const createSqlAgentRequestHandler = (
4145
copilotService: CopilotService,
4246
vscodeWrapper: VscodeWrapper,
4347
context: vscode.ExtensionContext,
48+
controller: MainController,
4449
): vscode.ChatRequestHandler => {
4550
const getNextConversationUri = (() => {
4651
let idCounter = 1;
@@ -230,12 +235,13 @@ export const createSqlAgentRequestHandler = (
230235
);
231236
}
232237

233-
if (!connectionUri) {
238+
const connection = controller.connectionManager.getConnectionInfo(connectionUri);
239+
if (!connectionUri || !connection) {
234240
activity.update({
235241
correlationId: correlationId,
236242
message: "No connection URI found. Sending prompt to default language model.",
237243
});
238-
stream.markdown("⚠️ " + loc.notConnected);
244+
stream.markdown(`${DISCONNECTED_LABEL_PREFIX} ${loc.notConnected}\n\n`);
239245
await sendToDefaultLanguageModel(
240246
prompt,
241247
model,
@@ -247,6 +253,12 @@ export const createSqlAgentRequestHandler = (
247253
return { metadata: { command: "", correlationId: correlationId } };
248254
}
249255

256+
var connectionMessage =
257+
`${CONNECTED_LABEL_PREFIX} ${loc.connectedTo} \n` +
258+
`${SERVER_DATABASE_LABEL_PREFIX} ${loc.server(connection.credentials.server)} \n` +
259+
`${SERVER_DATABASE_LABEL_PREFIX} ${loc.database(connection.credentials.database)}\n\n`;
260+
stream.markdown(connectionMessage);
261+
250262
const success = await copilotService.startConversation(
251263
conversationUri,
252264
connectionUri,

src/constants/locConstants.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,21 @@ export class MssqlChatAgent {
930930
public static noModelFound = l10n.t("No model found.");
931931
public static noToolsToProcess = l10n.t("No tools to process.");
932932
public static notConnected = l10n.t("You are not connected to any database.");
933+
public static connectedTo = l10n.t("Connected to:");
934+
public static server = (serverName: string) => {
935+
return l10n.t({
936+
message: "Server - {0}",
937+
args: [serverName],
938+
comment: ["{0} is the server name"],
939+
});
940+
};
941+
public static database = (databaseName: string) => {
942+
return l10n.t({
943+
message: "Database - {0}",
944+
args: [databaseName],
945+
comment: ["{0} is the database name"],
946+
});
947+
};
933948
public static usingModel = (modelName: string, canSendRequest: boolean | undefined) => {
934949
return l10n.t({
935950
message: "Using {0} ({1})...",

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
4848
await controller.activate();
4949
const participant = vscode.chat.createChatParticipant(
5050
"mssql.agent",
51-
createSqlAgentRequestHandler(controller.copilotService, vscodeWrapper, context),
51+
createSqlAgentRequestHandler(controller.copilotService, vscodeWrapper, context, controller),
5252
);
5353

5454
const receiveFeedbackDisposable = participant.onDidReceiveFeedback(

0 commit comments

Comments
 (0)