-
Notifications
You must be signed in to change notification settings - Fork 47
Add Rerun with copilot command #1316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<void> { | ||
| const activitySelectedCache = ActivitySelectedCache.getInstance(); | ||
| activitySelectedCache.addActivity(item.id); | ||
|
|
||
| const activityContext: GetAzureActivityLogContext = { | ||
| ...context, | ||
| activitySelectedCache: activitySelectedCache | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think I should make a separate update to uncouple the cache from this context so you won't be forced to add it like this just to leverage the helper function below. |
||
| } | ||
|
|
||
| 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.')); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We discussed it offline, but prefer it to be rerunWithCopilot just for stylistic reasons. Also may want to be more specific, like
rerunAzureActivityWithCopilotso people are aware that this is specifically for retrying commands that are in the activity log.