diff --git a/package-lock.json b/package-lock.json index 2a905869..5eca9709 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@microsoft/vscode-azext-azureauth": "^5.1.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", - "@microsoft/vscode-azext-utils": "^4.0.0", + "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.2.tgz", "buffer": "^6.0.3", "form-data": "^4.0.4", "fs-extra": "^11.3.0", @@ -1068,9 +1068,9 @@ } }, "node_modules/@microsoft/vscode-azext-utils": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-4.0.0.tgz", - "integrity": "sha512-c5e4LD8Xkir6KqAVzIF0f+u1w/QDH7b3AFgYYcWqPyYN0HVp+YCvI97zP1uqb/YzZFTYjr2NbO54xgtftsePAA==", + "version": "4.0.2", + "resolved": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.2.tgz", + "integrity": "sha512-5r7QaInfYnjc6OZDmOvFnQFee0t3cpqWs2JWGLdhsuy0K/7PT66EUZB8z10u9lpf8x1SyVGDUx894Rl1mK+qVQ==", "license": "MIT", "dependencies": { "@microsoft/vscode-azureresources-api": "^3.0.0", diff --git a/package.json b/package.json index db85557d..31233df2 100644 --- a/package.json +++ b/package.json @@ -337,6 +337,12 @@ "category": "Azure", "icon": "$(chat-sparkle)" }, + { + "command": "azureResourceGroups.reRunWithCopilot", + "title": "%azureResourceGroups.reRunWithCopilot%", + "category": "Azure", + "icon": "$(refresh)" + }, { "command": "azureTenantsView.refresh", "title": "%azureResourceGroups.refresh%", @@ -624,6 +630,11 @@ "command": "azureResourceGroups.askAgentAboutActivityLogItem", "when": "view == azureActivityLog && viewItem =~ /activityItem/i", "group": "inline" + }, + { + "command": "azureResourceGroups.reRunWithCopilot", + "when": "view == azureActivityLog && viewItem =~ /activityItem/i", + "group": "inline" } ], "commandPalette": [ @@ -678,6 +689,10 @@ { "command": "azureResourceGroups.askAgentAboutActivityLogItem", "when": "never" + }, + { + "command": "azureResourceGroups.reRunWithCopilot", + "when": "never" } ], "azureResourceGroups.groupBy": [ @@ -946,7 +961,7 @@ "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@microsoft/vscode-azext-azureauth": "^5.1.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", - "@microsoft/vscode-azext-utils": "^4.0.0", + "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.2.tgz", "buffer": "^6.0.3", "form-data": "^4.0.4", "fs-extra": "^11.3.0", diff --git a/package.nls.json b/package.nls.json index 766e8a32..70704bfe 100644 --- a/package.nls.json +++ b/package.nls.json @@ -55,6 +55,7 @@ "Do not translate '@azure'; it is syntax for addressing the Azure agent." ] }, + "azureResourceGroups.reRunWithCopilot": "Rerun Command with Copilot...", "walkthrough.askAzure.description": { "message": "Enter @azure in the GitHub Copilot Chat to start a conversation.\n @azure can help with learning about Azure, deploying resources, troubleshooting web app problems, querying Azure costs and more without having to switch to the Azure Portal.\n[Chat with @azure](command:azureResourceGroups.askAzure?%5B%22What%20kinds%20of%20things%20can%20you%20help%20me%20with?%22%5D)", "comment": [ diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index 873ae56a..05febeb4 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -10,6 +10,7 @@ import { askAgentAboutActivityLog } from '../chat/askAgentAboutActivityLog/askAg import { askAgentAboutResource } from '../chat/askAgentAboutResource'; import { askAzureInCommandPalette } from '../chat/askAzure'; import { uploadFileToCloudShell } from '../cloudConsole/uploadFileToCloudShell'; +import { reRunWithCopilot } from '../copilot/reRunWithCopilot'; import { ext } from '../extensionVariables'; import { TargetServiceRoleAssignmentItem } from '../managedIdentity/TargetServiceRoleAssignmentItem'; import { BranchDataItemWrapper } from '../tree/BranchDataItemWrapper'; @@ -134,6 +135,7 @@ export function registerCommands(): void { registerCommand("azureResourceGroups.askAgentAboutActivityLog", async (context: IActionContext, _node: ActivityItem) => await askAgentAboutActivityLog(context)); registerCommandWithTreeNodeUnwrapping("azureResourceGroups.askAgentAboutActivityLogItem", askAgentAboutActivityLog); registerCommandWithTreeNodeUnwrapping<{ id?: string }>("azureResourceGroups.askAgentAboutResource", (context, node) => askAgentAboutResource(context, node)); + registerCommand('azureResourceGroups.reRunWithCopilot', async (context: IActionContext, item: ActivityItem) => await reRunWithCopilot(context, item)); } async function handleAzExtTreeItemRefresh(context: IActionContext, node?: ResourceGroupsItem): Promise { diff --git a/src/copilot/reRunWithCopilot.ts b/src/copilot/reRunWithCopilot.ts new file mode 100644 index 00000000..cd8786d9 --- /dev/null +++ b/src/copilot/reRunWithCopilot.ts @@ -0,0 +1,41 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Microsoft Corporation. All rights reserved. +* Licensed under the MIT License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import { CopilotUserInput, createSubscriptionContext, executeCommandWithAddedContext, type IActionContext } from "@microsoft/vscode-azext-utils"; +import * as vscode from "vscode"; +import { ActivitySelectedCache } from "../chat/askAgentAboutActivityLog/ActivitySelectedCache"; +import { convertActivityTreeToSimpleObjectArray, ConvertedActivityItem } from "../chat/tools/GetAzureActivityLog/convertActivityTree"; +import { GetAzureActivityLogContext } from "../chat/tools/GetAzureActivityLog/GetAzureActivityLogContext"; +import { ActivityItem } from "../tree/activityLog/ActivityItem"; + +export async function reRunWithCopilot(context: IActionContext, item: ActivityItem): Promise { + const activitySelectedCache = ActivitySelectedCache.getInstance(); + activitySelectedCache.addActivity(item.id); + + const activityContext: GetAzureActivityLogContext = { + ...context, + activitySelectedCache: activitySelectedCache + } + + const activityItems: ConvertedActivityItem[] = await convertActivityTreeToSimpleObjectArray(activityContext); + context.ui = new CopilotUserInput(vscode, JSON.stringify(activityItems)); + + // if subscription exists then add it to the context and + let wizardContext = context + const subscription = activityItems[0].activityAttributes?.subscription + if (subscription) { + const subscriptionContext = createSubscriptionContext(subscription); + wizardContext = { ...context, ...subscriptionContext }; + } + + // An item will always be passed in so we will only need to look at the first item in the array + const callbackId = activityItems[0]?.callbackId; + if (callbackId) { + // todo: change this as the subscription may not always be the third thing passed in + await executeCommandWithAddedContext(callbackId, wizardContext, undefined, undefined, subscription) + } else { + throw new Error(vscode.l10n.t('Failed to rerun with Copilot. Activity item callback ID not found.')); + } +}